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
61 Parameterization(Sdc::SchemeType scheme, int faceSize);
62
64 bool IsValid() const { return (_faceSize > 0); }
65
67 Parameterization() : _type(0), _uDim(0), _faceSize(0) { }
68
71 ~Parameterization() = default;
73
75
79
81 Type GetType() const { return (Type) _type; }
82
84 int GetFaceSize() const { return _faceSize; }
86
87public:
89
99
101 template <typename REAL>
102 void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const;
103
105 template <typename REAL>
106 void GetEdgeCoord(int edgeIndex, REAL t, REAL uvCoord[2]) const;
107
109 template <typename REAL>
110 void GetCenterCoord(REAL uvCoord[2]) const;
112
113public:
115
130
132 bool HasSubFaces() const;
133
135 template <typename REAL>
136 int GetSubFace(REAL const uvCoord[2]) const;
137
140 template <typename REAL>
142 REAL const uvCoord[2], REAL subFaceCoord[2]) const;
143
145 template <typename REAL>
146 void ConvertSubFaceToCoord(int subFace,
147 REAL const subFaceCoord[2], REAL uvCoord[2]) const;
148
151 template <typename REAL>
153 REAL const uvCoord[2], REAL subFaceCoord[2]) const;
154
156 template <typename REAL>
157 void ConvertNormalizedSubFaceToCoord(int subFace,
158 REAL const subFaceCoord[2], REAL uvCoord[2]) const;
160
161private:
162 template <typename REAL>
163 int convertCoordToSubFace(bool normalized,
164 REAL const uvCoord[2], REAL subFaceCoord[2]) const;
165 template <typename REAL>
166 void convertSubFaceToCoord(bool normalized, int subFace,
167 REAL const subFaceCoord[2], REAL uvCoord[2]) const;
168
169private:
170 unsigned char _type;
171 unsigned char _uDim;
172 unsigned short _faceSize;
173};
174
175//
176// Inline sub-face coordinate conversion methods:
177//
178inline bool
180 return (_type == QUAD_SUBFACES);
181}
182
183template <typename REAL>
184inline int
185Parameterization::GetSubFace(REAL const uvCoord[2]) const {
186
187 if (!HasSubFaces()) return 0;
188
189 int uTile = (int) uvCoord[0];
190 int vTile = (int) uvCoord[1];
191 return (vTile + ((uvCoord[1] - (REAL) vTile) > 0.75f)) * _uDim +
192 (uTile + ((uvCoord[0] - (REAL) uTile) > 0.75f));
193}
194
195// Conversions to unnormalized sub-face coordinates:
196template <typename REAL>
197inline int
199 REAL const uvCoord[2], REAL subCoord[2]) const {
200 return convertCoordToSubFace<REAL>(false, uvCoord, subCoord);
201}
202template <typename REAL>
203inline void
205 int subFace, REAL const subCoord[2], REAL uvCoord[2]) const {
206 convertSubFaceToCoord<REAL>(false, subFace, subCoord, uvCoord);
207}
208
209// Conversions to normalized sub-face coordinates:
210template <typename REAL>
211inline int
213 REAL const uvCoord[2], REAL subCoord[2]) const {
214 return convertCoordToSubFace<REAL>(true, uvCoord, subCoord);
215}
216template <typename REAL>
217inline void
219 int subFace, REAL const subCoord[2], REAL uvCoord[2]) const {
220 convertSubFaceToCoord<REAL>(true, subFace, subCoord, uvCoord);
221}
222
223} // end namespace Bfr
224
225} // end namespace OPENSUBDIV_VERSION
226using namespace OPENSUBDIV_VERSION;
227
228} // end namespace OpenSubdiv
229
230#endif /* OPENSUBDIV3_BFR_PARAMETERIZATION */
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition types.h:20
Simple class defining the 2D parameterization of a face.
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 with subdivision scheme and face size.
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(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