OpenSubdiv: opensubdiv/bfr/parameterization.h Source File

| 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
35 class Parameterization {
36public:
45 enum Type { QUAD,
46 TRI,
47 QUAD_SUBFACES
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
69 Parameterization(Parameterization const &) = default;
70 Parameterization & operator=(Parameterization const &) = default;
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>
141 int ConvertCoordToSubFace(
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>
152 int ConvertCoordToNormalizedSubFace(
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
179Parameterization::HasSubFaces() const {
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
198Parameterization::ConvertCoordToSubFace(
199 REAL const uvCoord[2], REAL subCoord[2]) const {
200 return convertCoordToSubFace<REAL>(false, uvCoord, subCoord);
201}
202template <typename REAL>
203inline void
204Parameterization::ConvertSubFaceToCoord(
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
212Parameterization::ConvertCoordToNormalizedSubFace(
213 REAL const uvCoord[2], REAL subCoord[2]) const {
214 return convertCoordToSubFace<REAL>(true, uvCoord, subCoord);
215}
216template <typename REAL>
217inline void
218Parameterization::ConvertNormalizedSubFaceToCoord(
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 */
OpenSubdiv
Definition limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Bfr
Definition limits.h:18
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::SchemeType
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition types.h:20
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:185
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetFaceSize
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
Definition parameterization.h:84
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::Type
Type
Enumerated type for the different kinds of Parameterizations.
Definition parameterization.h:45
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::QUAD_SUBFACES
@ QUAD_SUBFACES
Partitioned into quadrilateral sub-faces.
Definition parameterization.h:47
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::TRI
@ TRI
Triangle.
Definition parameterization.h:46
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::QUAD
@ QUAD
Quadrilateral.
Definition parameterization.h:45
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:198
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:81
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:218
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:67
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::IsValid
bool IsValid() const
Returns true if correctly initialized.
Definition parameterization.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::HasSubFaces
bool HasSubFaces() const
Returns if Parameterization has been partitioned into sub-faces.
Definition parameterization.h:179
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:212
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:204
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::operator=
Parameterization & operator=(Parameterization const &)=default
types.h