| OpenSubdiv OpenSubdiv

Loading...
Searching...
No Matches
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
52 class Parameterization {
53 public:
62 enum Type { QUAD,
63 TRI,
64 QUAD_SUBFACES
65 };
66
67 public:
69
76
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
96
98 Type GetType() const { return (Type) _type; }
99
101 int GetFaceSize() const { return _faceSize; }
103
104 public:
106
116
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
147
149 bool HasSubFaces() const;
150
152 template <typename REAL>
153 int GetSubFace(REAL const uvCoord[2]) const;
154
157 template <typename REAL>
158 int ConvertCoordToSubFace(
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>
169 int ConvertCoordToNormalizedSubFace(
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
196 Parameterization::HasSubFaces() const {
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
215 Parameterization::ConvertCoordToSubFace(
216 REAL const uvCoord[2], REAL subCoord[2]) const {
217 return convertCoordToSubFace<REAL>(false, uvCoord, subCoord);
218}
219 template <typename REAL>
220 inline void
221 Parameterization::ConvertSubFaceToCoord(
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
229 Parameterization::ConvertCoordToNormalizedSubFace(
230 REAL const uvCoord[2], REAL subCoord[2]) const {
231 return convertCoordToSubFace<REAL>(true, uvCoord, subCoord);
232}
233 template <typename REAL>
234 inline void
235 Parameterization::ConvertNormalizedSubFaceToCoord(
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 */
OpenSubdiv
Definition limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::SchemeType
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition types.h:37
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization
Simple class defining the 2D parameterization of a face.
Definition parameterization.h:52
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetSubFace
int GetSubFace(REAL const uvCoord[2]) const
Returns the integer sub-face containing the given (u,v)
Definition parameterization.h:202
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetFaceSize
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
Definition parameterization.h:101
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Type
Type
Enumerated type for the different kinds of Parameterizations.
Definition parameterization.h:62
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::QUAD_SUBFACES
@ QUAD_SUBFACES
Partitioned into quadrilateral sub-faces.
Definition parameterization.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::TRI
@ TRI
Triangle.
Definition parameterization.h:63
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::QUAD
@ QUAD
Quadrilateral.
Definition parameterization.h:62
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Parameterization
Parameterization(Sdc::SchemeType scheme, int faceSize)
Primary constructor with subdivision scheme and face size.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::ConvertCoordToSubFace
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.
Definition parameterization.h:215
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetCenterCoord
void GetCenterCoord(REAL uvCoord[2]) const
Returns the (u,v) coordinate for the center of the face.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetType
Type GetType() const
Returns the type of parameterization assigned.
Definition parameterization.h:98
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::~Parameterization
~Parameterization()=default
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Parameterization
Parameterization(Parameterization const &)=default
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetEdgeCoord
void GetEdgeCoord(int edgeIndex, REAL t, REAL uvCoord[2]) const
Returns the (u,v) coordinate at any point on a given edge.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::ConvertNormalizedSubFaceToCoord
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)
Definition parameterization.h:235
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetVertexCoord
void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const
Returns the (u,v) coordinate of a given vertex.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Parameterization
Parameterization()
Default construction produces an invalid instance.
Definition parameterization.h:84
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::IsValid
bool IsValid() const
Returns true if correctly initialized.
Definition parameterization.h:81
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::HasSubFaces
bool HasSubFaces() const
Returns if Parameterization has been partitioned into sub-faces.
Definition parameterization.h:196
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::ConvertCoordToNormalizedSubFace
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.
Definition parameterization.h:229
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::ConvertSubFaceToCoord
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)
Definition parameterization.h:221
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::operator=
Parameterization & operator=(Parameterization const &)=default