OpenSubdiv
Loading...
Searching...
No Matches
parameterization.h
Go to the documentation of this file.
1//
2// Copyright 2021 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7
8#ifndef OPENSUBDIV3_BFR_PARAMETERIZATION_H
9#define OPENSUBDIV3_BFR_PARAMETERIZATION_H
10
11#include "../version.h"
12
13#include "../sdc/types.h"
14
15namespace OpenSubdiv {
16namespace OPENSUBDIV_VERSION {
17
18namespace Bfr {
19
36public:
45 enum Type { QUAD,
48 };
49
50public:
52
59
62 Parameterization(Sdc::SchemeType scheme, int faceSize);
63
67 Parameterization(Type type, int numSubFaces = 0);
68
70 bool IsValid() const { return (_faceSize > 0); }
71
73 Parameterization() : _type(0), _uDim(0), _faceSize(0) { }
74
77 ~Parameterization() = default;
79
81
85
87 Type GetType() const { return (Type) _type; }
88
90 int GetFaceSize() const { return _faceSize; }
92
93public:
95
105
107 template <typename REAL>
108 void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const;
109
111 template <typename REAL>
112 void GetEdgeCoord(int edgeIndex, REAL t, REAL uvCoord[2]) const;
113
115 template <typename REAL>
116 void GetCenterCoord(REAL uvCoord[2]) const;
118
119public:
121
136
138 bool HasSubFaces() const;
139
141 template <typename REAL>
142 int GetSubFace(REAL const uvCoord[2]) const;
143
146 template <typename REAL>
148 REAL const uvCoord[2], REAL subFaceCoord[2]) const;
149
151 template <typename REAL>
152 void ConvertSubFaceToCoord(int subFace,
153 REAL const subFaceCoord[2], REAL uvCoord[2]) const;
154
157 template <typename REAL>
159 REAL const uvCoord[2], REAL subFaceCoord[2]) const;
160
162 template <typename REAL>
163 void ConvertNormalizedSubFaceToCoord(int subFace,
164 REAL const subFaceCoord[2], REAL uvCoord[2]) const;
166
167private:
168 template <typename REAL>
169 int convertCoordToSubFace(bool normalized,
170 REAL const uvCoord[2], REAL subFaceCoord[2]) const;
171 template <typename REAL>
172 void convertSubFaceToCoord(bool normalized, int subFace,
173 REAL const subFaceCoord[2], REAL uvCoord[2]) const;
174
175private:
176 unsigned char _type;
177 unsigned char _uDim;
178 unsigned short _faceSize;
179};
180
181//
182// Inline sub-face coordinate conversion methods:
183//
184inline bool
186 return (_type == QUAD_SUBFACES);
187}
188
189template <typename REAL>
190inline int
191Parameterization::GetSubFace(REAL const uvCoord[2]) const {
192
193 if (!HasSubFaces()) return 0;
194
195 int uTile = (int) uvCoord[0];
196 int vTile = (int) uvCoord[1];
197 return (vTile + ((uvCoord[1] - (REAL) vTile) > 0.75f)) * _uDim +
198 (uTile + ((uvCoord[0] - (REAL) uTile) > 0.75f));
199}
200
201// Conversions to unnormalized sub-face coordinates:
202template <typename REAL>
203inline int
205 REAL const uvCoord[2], REAL subCoord[2]) const {
206 return convertCoordToSubFace<REAL>(false, uvCoord, subCoord);
207}
208template <typename REAL>
209inline void
211 int subFace, REAL const subCoord[2], REAL uvCoord[2]) const {
212 convertSubFaceToCoord<REAL>(false, subFace, subCoord, uvCoord);
213}
214
215// Conversions to normalized sub-face coordinates:
216template <typename REAL>
217inline int
219 REAL const uvCoord[2], REAL subCoord[2]) const {
220 return convertCoordToSubFace<REAL>(true, uvCoord, subCoord);
221}
222template <typename REAL>
223inline void
225 int subFace, REAL const subCoord[2], REAL uvCoord[2]) const {
226 convertSubFaceToCoord<REAL>(true, subFace, subCoord, uvCoord);
227}
228
229} // end namespace Bfr
230
231} // end namespace OPENSUBDIV_VERSION
232using namespace OPENSUBDIV_VERSION;
233
234} // end namespace OpenSubdiv
235
236#endif /* OPENSUBDIV3_BFR_PARAMETERIZATION */
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition types.h:20
int GetSubFace(REAL const uvCoord[2]) const
Returns the integer sub-face containing the given (u,v).
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
Type
Enumerated type for the different kinds of Parameterizations.
@ QUAD_SUBFACES
Partitioned into quadrilateral sub-faces.
Parameterization(Sdc::SchemeType scheme, int faceSize)
Primary constructor that determines the parameterization of a face given the subdivision scheme and f...
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.
void GetCenterCoord(REAL uvCoord[2]) const
Returns the (u,v) coordinate for the center of the face.
Type GetType() const
Returns the type of parameterization assigned.
Parameterization(Type type, int numSubFaces=0)
Alternate constructor that specifies the parameterization directly by its type (the optional number o...
Parameterization(Parameterization const &)=default
void GetEdgeCoord(int edgeIndex, REAL t, REAL uvCoord[2]) const
Returns the (u,v) coordinate at any point on a given edge.
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).
void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const
Returns the (u,v) coordinate of a given vertex.
Parameterization()
Default construction produces an invalid instance.
bool IsValid() const
Returns true if correctly initialized.
bool HasSubFaces() const
Returns if Parameterization has been partitioned into sub-faces.
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 ConvertSubFaceToCoord(int subFace, REAL const subFaceCoord[2], REAL uvCoord[2]) const
Convert a sub-face and its local (u,v) coordinate to (u,v).
Parameterization & operator=(Parameterization const &)=default