OpenSubdiv
parameterization.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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_BFR_PARAMETERIZATION_H
26 #define OPENSUBDIV3_BFR_PARAMETERIZATION_H
27 
28 #include "../version.h"
29 
30 #include "../sdc/types.h"
31 
32 namespace OpenSubdiv {
33 namespace OPENSUBDIV_VERSION {
34 
35 namespace Bfr {
36 
53 public:
62  enum Type { QUAD,
63  TRI,
65  };
66 
67 public:
69 
78  Parameterization(Sdc::SchemeType scheme, int faceSize);
79 
81  bool IsValid() const { return (_faceSize > 0); }
82 
84  Parameterization() : _type(0), _uDim(0), _faceSize(0) { }
85 
86  Parameterization(Parameterization const &) = default;
87  Parameterization & operator=(Parameterization const &) = default;
88  ~Parameterization() = default;
90 
92 
98  Type GetType() const { return (Type) _type; }
99 
101  int GetFaceSize() const { return _faceSize; }
103 
104 public:
106 
118  template <typename REAL>
119  void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const;
120 
122  template <typename REAL>
123  void GetEdgeCoord(int edgeIndex, REAL t, REAL uvCoord[2]) const;
124 
126  template <typename REAL>
127  void GetCenterCoord(REAL uvCoord[2]) const;
129 
130 public:
132 
149  bool HasSubFaces() const;
150 
152  template <typename REAL>
153  int GetSubFace(REAL const uvCoord[2]) const;
154 
157  template <typename REAL>
159  REAL const uvCoord[2], REAL subFaceCoord[2]) const;
160 
162  template <typename REAL>
163  void ConvertSubFaceToCoord(int subFace,
164  REAL const subFaceCoord[2], REAL uvCoord[2]) const;
165 
168  template <typename REAL>
170  REAL const uvCoord[2], REAL subFaceCoord[2]) const;
171 
173  template <typename REAL>
174  void ConvertNormalizedSubFaceToCoord(int subFace,
175  REAL const subFaceCoord[2], REAL uvCoord[2]) const;
177 
178 private:
179  template <typename REAL>
180  int convertCoordToSubFace(bool normalized,
181  REAL const uvCoord[2], REAL subFaceCoord[2]) const;
182  template <typename REAL>
183  void convertSubFaceToCoord(bool normalized, int subFace,
184  REAL const subFaceCoord[2], REAL uvCoord[2]) const;
185 
186 private:
187  unsigned char _type;
188  unsigned char _uDim;
189  unsigned short _faceSize;
190 };
191 
192 //
193 // Inline sub-face coordinate conversion methods:
194 //
195 inline bool
197  return (_type == QUAD_SUBFACES);
198 }
199 
200 template <typename REAL>
201 inline int
202 Parameterization::GetSubFace(REAL const uvCoord[2]) const {
203 
204  if (!HasSubFaces()) return 0;
205 
206  int uTile = (int) uvCoord[0];
207  int vTile = (int) uvCoord[1];
208  return (vTile + ((uvCoord[1] - (REAL) vTile) > 0.75f)) * _uDim +
209  (uTile + ((uvCoord[0] - (REAL) uTile) > 0.75f));
210 }
211 
212 // Conversions to unnormalized sub-face coordinates:
213 template <typename REAL>
214 inline int
216  REAL const uvCoord[2], REAL subCoord[2]) const {
217  return convertCoordToSubFace<REAL>(false, uvCoord, subCoord);
218 }
219 template <typename REAL>
220 inline void
222  int subFace, REAL const subCoord[2], REAL uvCoord[2]) const {
223  convertSubFaceToCoord<REAL>(false, subFace, subCoord, uvCoord);
224 }
225 
226 // Conversions to normalized sub-face coordinates:
227 template <typename REAL>
228 inline int
230  REAL const uvCoord[2], REAL subCoord[2]) const {
231  return convertCoordToSubFace<REAL>(true, uvCoord, subCoord);
232 }
233 template <typename REAL>
234 inline void
236  int subFace, REAL const subCoord[2], REAL uvCoord[2]) const {
237  convertSubFaceToCoord<REAL>(true, subFace, subCoord, uvCoord);
238 }
239 
240 } // end namespace Bfr
241 
242 } // end namespace OPENSUBDIV_VERSION
243 using namespace OPENSUBDIV_VERSION;
244 
245 } // end namespace OpenSubdiv
246 
247 #endif /* OPENSUBDIV3_BFR_PARAMETERIZATION */
Parameterization & operator=(Parameterization const &)=default
Parameterization()
Default construction produces an invalid instance.
void ConvertSubFaceToCoord(int subFace, REAL const subFaceCoord[2], REAL uvCoord[2]) const
Convert a sub-face and its local (u,v) coordinate to (u,v)
Simple class defining the 2D parameterization of a face.
bool IsValid() const
Returns true if correctly initialized.
bool HasSubFaces() const
Returns if Parameterization has been partitioned into sub-faces.
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
int GetSubFace(REAL const uvCoord[2]) const
Returns the integer sub-face containing the given (u,v)
void GetCenterCoord(REAL uvCoord[2]) const
Returns the (u,v) coordinate for the center of the face.
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition: types.h:37
Type GetType() const
Returns the type of parameterization assigned.
void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const
Returns the (u,v) coordinate of a given vertex.
int ConvertCoordToNormalizedSubFace(REAL const uvCoord[2], REAL subFaceCoord[2]) const
Convert (u,v) to a sub-face (return value) and its normalized (u,v) coordinate.
void GetEdgeCoord(int edgeIndex, REAL t, REAL uvCoord[2]) const
Returns the (u,v) coordinate at any point on a given edge.
Type
Enumerated type for the different kinds of Parameterizations.
void ConvertNormalizedSubFaceToCoord(int subFace, REAL const subFaceCoord[2], REAL uvCoord[2]) const
Convert a sub-face and its normalized (u,v) coordinate to (u,v)
int ConvertCoordToSubFace(REAL const uvCoord[2], REAL subFaceCoord[2]) const
Convert (u,v) to a sub-face (return value) and its local (u,v) coordinate.