All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
patchParam.h
Go to the documentation of this file.
1 //
2 // Copyright 2013 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef OPENSUBDIV3_FAR_PATCH_PARAM_H
26 #define OPENSUBDIV3_FAR_PATCH_PARAM_H
27 
28 #include "../version.h"
29 
30 #include "../far/types.h"
31 
32 namespace OpenSubdiv {
33 namespace OPENSUBDIV_VERSION {
34 
35 namespace Far {
36 
101 
152 struct PatchParam {
168  void Set(Index faceid, short u, short v,
169  unsigned short depth, bool nonquad,
170  unsigned short boundary, unsigned short transition,
171  bool regular = false);
172 
174  void Clear() { field0 = field1 = 0; }
175 
177  Index GetFaceId() const { return Index(unpack(field0,28,0)); }
178 
181  unsigned short GetU() const { return (unsigned short)unpack(field1,10,22); }
182 
185  unsigned short GetV() const { return (unsigned short)unpack(field1,10,12); }
186 
188  unsigned short GetTransition() const { return (unsigned short)unpack(field0,4,28); }
189 
191  unsigned short GetBoundary() const { return (unsigned short)unpack(field1,4,8); }
192 
194  bool NonQuadRoot() const { return (unpack(field1,1,4) != 0); }
195 
197  unsigned short GetDepth() const { return (unsigned short)unpack(field1,4,0); }
198 
200  float GetParamFraction() const;
201 
208  void Normalize( float & u, float & v ) const;
209 
216  void Unnormalize( float & u, float & v ) const;
217 
219  bool IsRegular() const { return (unpack(field1,1,5) != 0); }
220 
221  unsigned int field0:32;
222  unsigned int field1:32;
223 
224 private:
225  unsigned int pack(unsigned int value, int width, int offset) const {
226  return (unsigned int)((value & ((1<<width)-1)) << offset);
227  }
228 
229  unsigned int unpack(unsigned int value, int width, int offset) const {
230  return (unsigned int)((value >> offset) & ((1<<width)-1));
231  }
232 };
233 
234 typedef std::vector<PatchParam> PatchParamTable;
235 
238 
239 inline void
240 PatchParam::Set(Index faceid, short u, short v,
241  unsigned short depth, bool nonquad,
242  unsigned short boundary, unsigned short transition,
243  bool regular) {
244  field0 = pack(faceid, 28, 0) |
245  pack(transition, 4, 28);
246 
247  field1 = pack(u, 10, 22) |
248  pack(v, 10, 12) |
249  pack(boundary, 4, 8) |
250  pack(regular, 1, 5) |
251  pack(nonquad, 1, 4) |
252  pack(depth, 4, 0);
253 }
254 
255 inline float
257  if (NonQuadRoot()) {
258  return 1.0f / float( 1 << (GetDepth()-1) );
259  } else {
260  return 1.0f / float( 1 << GetDepth() );
261  }
262 }
263 
264 inline void
265 PatchParam::Normalize( float & u, float & v ) const {
266 
267  float frac = GetParamFraction();
268 
269  float pu = (float)GetU()*frac;
270  float pv = (float)GetV()*frac;
271 
272  u = (u - pu) / frac,
273  v = (v - pv) / frac;
274 }
275 
276 inline void
277 PatchParam::Unnormalize( float & u, float & v ) const {
278 
279  float frac = GetParamFraction();
280 
281  float pu = (float)GetU()*frac;
282  float pv = (float)GetV()*frac;
283 
284  u = u * frac + pu,
285  v = v * frac + pv;
286 }
287 
288 } // end namespace Far
289 
290 } // end namespace OPENSUBDIV_VERSION
291 using namespace OPENSUBDIV_VERSION;
292 
293 } // end namespace OpenSubdiv
294 
295 #endif /* OPENSUBDIV3_FAR_PATCH_PARAM */
bool IsRegular() const
Returns whether the patch is regular.
Definition: patchParam.h:219
float GetParamFraction() const
Returns the fraction of unit parametric space covered by this face.
Definition: patchParam.h:256
Index GetFaceId() const
Returns the faceid.
Definition: patchParam.h:177
void Set(Index faceid, short u, short v, unsigned short depth, bool nonquad, unsigned short boundary, unsigned short transition, bool regular=false)
Sets the values of the bit fields.
Definition: patchParam.h:240
bool NonQuadRoot() const
True if the parent base face is a non-quad.
Definition: patchParam.h:194
void Unnormalize(float &u, float &v) const
A (u,v) pair in a normalized parametric space is mapped back into the fraction of parametric space co...
Definition: patchParam.h:277
Vtr::ConstArray< PatchParam > ConstPatchParamArray
Definition: patchParam.h:237
void Clear()
Resets everything to 0.
Definition: patchParam.h:174
unsigned short GetTransition() const
Returns the transition edge encoding for the patch.
Definition: patchParam.h:188
unsigned short GetDepth() const
Returns the level of subdivision of the patch.
Definition: patchParam.h:197
unsigned short GetU() const
Returns the log2 value of the u parameter at the first corner of the patch.
Definition: patchParam.h:181
unsigned short GetBoundary() const
Returns the boundary edge encoding for the patch.
Definition: patchParam.h:191
Vtr::Array< PatchParam > PatchParamArray
Definition: patchParam.h:236
unsigned short GetV() const
Returns the log2 value of the v parameter at the first corner of the patch.
Definition: patchParam.h:185
std::vector< PatchParam > PatchParamTable
Definition: patchParam.h:234
void Normalize(float &u, float &v) const
A (u,v) pair in the fraction of parametric space covered by this face is mapped into a normalized par...
Definition: patchParam.h:265