All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 FAR_PATCH_PARAM_H
26 #define FAR_PATCH_PARAM_H
27 
28 #include "../version.h"
29 
30 #include <cassert>
31 
32 namespace OpenSubdiv {
33 namespace OPENSUBDIV_VERSION {
34 
35 namespace Far {
36 
59 struct PatchParam {
60  unsigned int faceIndex:32; // Ptex face index
61 
62  struct BitField {
63  unsigned int field:32;
64 
74  void Set( short u, short v, unsigned char rots, unsigned char depth, bool nonquad ) {
75  field = (u << 17) |
76  (v << 7) |
77  (rots << 5) |
78  ((nonquad ? 1:0) << 4) |
79  (nonquad ? depth+1 : depth);
80  }
81 
84  unsigned short GetU() const { return (unsigned short)((field >> 17) & 0x3ff); }
85 
88  unsigned short GetV() const { return (unsigned short)((field >> 7) & 0x3ff); }
89 
91  unsigned char GetRotation() const { return (unsigned char)((field >> 5) & 0x3); }
92 
94  bool NonQuadRoot() const { return (field >> 4) & 0x1; }
95 
98  float GetParamFraction() const;
99 
101  unsigned char GetDepth() const { return (unsigned char)(field & 0xf); }
102 
109  void Normalize( float & u, float & v ) const;
110 
118  void Rotate( float & u, float & v ) const;
119 
121  void Clear() { field = 0; }
122 
123  } bitField;
124 
136  void Set( unsigned int faceid, short u, short v, unsigned char rots, unsigned char depth, bool nonquad ) {
137  faceIndex = faceid;
138  bitField.Set(u,v,rots,depth,nonquad);
139  }
140 
142  void Clear() {
143  faceIndex = 0;
144  bitField.Clear();
145  }
146 };
147 
148 inline float
150  if (NonQuadRoot()) {
151  return 1.0f / float( 1 << (GetDepth()-1) );
152  } else {
153  return 1.0f / float( 1 << GetDepth() );
154  }
155 }
156 
157 inline void
158 PatchParam::BitField::Normalize( float & u, float & v ) const {
159 
160  float frac = GetParamFraction();
161 
162  // top left corner
163  float pu = (float)GetU()*frac;
164  float pv = (float)GetV()*frac;
165 
166  // normalize u,v coordinates
167  u = (u - pu) / frac,
168  v = (v - pv) / frac;
169 }
170 
171 inline void
172 PatchParam::BitField::Rotate( float & u, float & v ) const {
173  switch( GetRotation() ) {
174  case 0 : break;
175  case 1 : { float tmp=v; v=1.0f-u; u=tmp; } break;
176  case 2 : { u=1.0f-u; v=1.0f-v; } break;
177  case 3 : { float tmp=u; u=1.0f-v; v=tmp; } break;
178  default:
179  assert(0);
180  }
181 }
182 
183 } // end namespace Far
184 
185 } // end namespace OPENSUBDIV_VERSION
186 using namespace OPENSUBDIV_VERSION;
187 
188 } // end namespace OpenSubdiv
189 
190 #endif /* FAR_PATCH_PARAM */
191 
unsigned char GetDepth() const
Returns the level of subdivision of the patch.
Definition: patchParam.h:101
unsigned char GetRotation() const
Returns the rotation of the patch (the number of CCW parameter winding)
Definition: patchParam.h:91
void Clear()
Resets everything to 0.
Definition: patchParam.h:142
void Rotate(float &u, float &v) const
Rotate (u,v) pair to compensate for transition pattern and boundary orientations. ...
Definition: patchParam.h:172
void Set(short u, short v, unsigned char rots, unsigned char depth, bool nonquad)
Sets the values of the bit fields.
Definition: patchParam.h:74
unsigned short GetV() const
Returns the log2 value of the v parameter at the top left corner of the patch.
Definition: patchParam.h:88
bool NonQuadRoot() const
True if the parent coarse face is a non-quad.
Definition: patchParam.h:94
Local patch parameterization descriptor.
Definition: patchParam.h:59
unsigned short GetU() const
Returns the log2 value of the u parameter at the top left corner of the patch.
Definition: patchParam.h:84
struct OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::BitField bitField
float GetParamFraction() const
Returns the fratcion of normalized parametric space covered by the sub-patch.
Definition: patchParam.h:149
void Set(unsigned int faceid, short u, short v, unsigned char rots, unsigned char depth, bool nonquad)
Sets the values of the bit fields.
Definition: patchParam.h:136