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
32namespace OpenSubdiv {
33namespace OPENSUBDIV_VERSION {
34
35namespace Bfr {
36
53public:
62 enum Type { QUAD,
65 };
66
67public:
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
88 ~Parameterization() = default;
90
92
96
98 Type GetType() const { return (Type) _type; }
99
101 int GetFaceSize() const { return _faceSize; }
103
104public:
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
130public:
132
147
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
178private:
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
186private:
187 unsigned char _type;
188 unsigned char _uDim;
189 unsigned short _faceSize;
190};
191
192//
193// Inline sub-face coordinate conversion methods:
194//
195inline bool
197 return (_type == QUAD_SUBFACES);
198}
199
200template <typename REAL>
201inline int
202Parameterization::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:
213template <typename REAL>
214inline int
216 REAL const uvCoord[2], REAL subCoord[2]) const {
217 return convertCoordToSubFace<REAL>(false, uvCoord, subCoord);
218}
219template <typename REAL>
220inline 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:
227template <typename REAL>
228inline int
230 REAL const uvCoord[2], REAL subCoord[2]) const {
231 return convertCoordToSubFace<REAL>(true, uvCoord, subCoord);
232}
233template <typename REAL>
234inline 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
243using namespace OPENSUBDIV_VERSION;
244
245} // end namespace OpenSubdiv
246
247#endif /* OPENSUBDIV3_BFR_PARAMETERIZATION */
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition: types.h:37
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