opensubdiv/far/patchParam.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List

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
64 struct PatchParam {
74 //
78 void Set( Index faceid, short u, short v,
79 unsigned short depth, bool nonquad ,
80 unsigned short boundary, unsigned short transition );
81
83 void Clear() { field0 = field1 = 0; }
84
86 Index GetFaceId() const { return Index(field0 & 0xfffffff); }
87
90 unsigned short GetU() const { return (unsigned short)((field1 >> 22) & 0x3ff); }
91
94 unsigned short GetV() const { return (unsigned short)((field1 >> 12) & 0x3ff); }
95
97 unsigned short GetTransition() const { return (unsigned short)((field0 >> 28) & 0xf); }
98
100 unsigned short GetBoundary() const { return (unsigned short)((field1 >> 8) & 0xf); }
101
103 bool NonQuadRoot() const { return (field1 >> 4) & 0x1; }
104
107 float GetParamFraction() const;
108
110 unsigned short GetDepth() const { return (unsigned short)(field1 & 0xf); }
111
117 void Normalize( float & u, float & v ) const;
118
119 unsigned int field0:32;
120 unsigned int field1:32;
121 };
122
123 typedef std::vector<PatchParam> PatchParamTable;
124
125 typedef Vtr::Array<PatchParam> PatchParamArray;
126 typedef Vtr::ConstArray<PatchParam> ConstPatchParamArray;
127
128 inline void
129 PatchParam::Set( Index faceid, short u, short v,
130 unsigned short depth, bool nonquad,
131 unsigned short boundary, unsigned short transition ) {
132 field0 = (((unsigned int)faceid) & 0xfffffff) |
133 ((transition & 0xf) << 28);
134 field1 = ((u & 0x3ff) << 22) |
135 ((v & 0x3ff) << 12) |
136 ((boundary & 0xf) << 8) |
137 ((nonquad ? 1:0) << 4) |
138 (nonquad ? depth+1 : depth);
139 }
140
141 inline float
142 PatchParam::GetParamFraction( ) const {
143 if (NonQuadRoot()) {
144 return 1.0f / float( 1 << (GetDepth()-1) );
145 } else {
146 return 1.0f / float( 1 << GetDepth() );
147 }
148 }
149
150 inline void
151 PatchParam::Normalize( float & u, float & v ) const {
152
153 float frac = GetParamFraction();
154
155 // top left corner
156 float pu = (float)GetU()*frac;
157 float pv = (float)GetV()*frac;
158
159 // normalize u,v coordinates
160 u = (u - pu) / frac,
161 v = (v - pv) / frac;
162 }
163
164 } // end namespace Far
165
166 } // end namespace OPENSUBDIV_VERSION
167 using namespace OPENSUBDIV_VERSION;
168
169 } // end namespace OpenSubdiv
170
171 #endif /* OPENSUBDIV3_FAR_PATCH_PARAM */
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::field1
unsigned int field1
Definition: patchParam.h:120
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::ConstArray
Definition: array.h:53
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam
Local patch parameterization descriptor.
Definition: patchParam.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetTransition
unsigned short GetTransition() const
Returns the transition edge encoding for the patch.
Definition: patchParam.h:97
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::Normalize
void Normalize(float &u, float &v) const
Definition: patchParam.h:151
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParamArray
Vtr::Array< PatchParam > PatchParamArray
Definition: patchParam.h:125
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetFaceId
Index GetFaceId() const
Retuns the faceid.
Definition: patchParam.h:86
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::Set
void Set(Index faceid, short u, short v, unsigned short depth, bool nonquad, unsigned short boundary, unsigned short transition)
Sets the values of the bit fields.
Definition: patchParam.h:129
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::field0
unsigned int field0
Definition: patchParam.h:119
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::Clear
void Clear()
Resets everything to 0.
Definition: patchParam.h:83
OpenSubdiv::OPENSUBDIV_VERSION::Far::Index
Vtr::Index Index
Definition: types.h:41
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParamTable
std::vector< PatchParam > PatchParamTable
Definition: patchParam.h:123
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetDepth
unsigned short GetDepth() const
Returns the level of subdivision of the patch.
Definition: patchParam.h:110
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::NonQuadRoot
bool NonQuadRoot() const
True if the parent coarse face is a non-quad.
Definition: patchParam.h:103
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetBoundary
unsigned short GetBoundary() const
Returns the boundary edge encoding for the patch.
Definition: patchParam.h:100
OpenSubdiv::OPENSUBDIV_VERSION::Far::ConstPatchParamArray
Vtr::ConstArray< PatchParam > ConstPatchParamArray
Definition: patchParam.h:126
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetParamFraction
float GetParamFraction() const
Returns the fraction of normalized parametric space covered by the sub-patch.
Definition: patchParam.h:142
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::Array
Definition: array.h:105
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetU
unsigned short GetU() const
Returns the log2 value of the u parameter at the top left corner of the patch.
Definition: patchParam.h:90
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchParam::GetV
unsigned short GetV() const
Returns the log2 value of the v parameter at the top left corner of the patch.
Definition: patchParam.h:94