OpenSubdiv
tessellation.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_TESSELLATION_H
26#define OPENSUBDIV3_BFR_TESSELLATION_H
27
28#include "../version.h"
29
30#include "../bfr/parameterization.h"
31
32namespace OpenSubdiv {
33namespace OPENSUBDIV_VERSION {
34
35namespace Bfr {
36
52public:
72 class Options {
73 public:
74 Options() : _preserveQuads(false), _facetSize4(false),
75 _coordStride(0), _facetStride(0) { }
76
79 Options & PreserveQuads(bool on);
81 bool PreserveQuads() const { return _preserveQuads; }
82
85 Options & SetFacetSize(int numIndices);
87 int GetFacetSize() const { return 3 + (int)_facetSize4; }
88
90 Options & SetFacetStride(int stride);
92 int GetFacetStride() const { return _facetStride; }
93
95 Options & SetCoordStride(int stride);
97 int GetCoordStride() const { return _coordStride; }
98
99 private:
100 unsigned int _preserveQuads : 1;
101 unsigned int _facetSize4 : 1;
102
103 short _coordStride;
104 short _facetStride;
105 };
106
107public:
109
118
125 Tessellation(Parameterization const & p, int uniformRate,
126 Options const & options = Options());
127
165 Tessellation(Parameterization const & p, int numRates, int const rates[],
166 Options const & options = Options());
167
169 bool IsValid() const { return _isValid; }
170
172 Tessellation() = delete;
173
174 Tessellation(Tessellation const &) = delete;
178
180
184
186 Parameterization GetParameterization() const { return _param; }
187
189 int GetFaceSize() const { return _param.GetFaceSize(); }
190
192 int GetRates(int rates[]) const;
193
195 bool IsUniform() const { return _isUniform; }
197
199
210
212 int GetNumCoords() const { return _numInteriorPoints + _numBoundaryPoints; }
213
215 int GetCoordStride() const { return _coordStride; }
216
218 int GetNumBoundaryCoords() const { return _numBoundaryPoints; }
219
221 int GetNumInteriorCoords() const { return _numInteriorPoints; }
222
225 int GetNumEdgeCoords(int edge) const { return _outerRates[edge] - 1; }
226
228 template <typename REAL>
229 int GetCoords(REAL coordTuples[]) const;
230
232 template <typename REAL>
233 int GetBoundaryCoords(REAL coordTuples[]) const;
234
236 template <typename REAL>
237 int GetInteriorCoords(REAL coordTuples[]) const;
238
240 template <typename REAL>
241 int GetVertexCoord(int vertex, REAL coordTuples[]) const;
242
245 template <typename REAL>
246 int GetEdgeCoords(int edge, REAL coordTuples[]) const;
248
250
264
266 int GetNumFacets() const { return _numFacets; }
267
269 int GetFacetSize() const { return _facetSize; }
270
272 int GetFacetStride() const { return _facetStride; }
273
275 int GetFacets(int facetTuples[]) const;
277
279
294
296 void TransformFacetCoordIndices(int facetTuples[], int commonOffset);
297
300 void TransformFacetCoordIndices(int facetTuples[],
301 int const boundaryIndices[],
302 int interiorOffset);
303
305 void TransformFacetCoordIndices(int facetTuples[],
306 int const boundaryIndices[],
307 int const interiorIndices[]);
309
310private:
311 // Private initialization methods:
312 bool validateArguments(Parameterization const & p,
313 int nRates, int const rates[], Options const & options);
314
315 void initialize(Parameterization const & p,
316 int nRates, int const rates[], Options const & options);
317
318 void initializeDefaults();
319 int initializeRates(int nRates, int const rates[]);
320 void initializeInventoryForParamTri(int sumOfOuterRates);
321 void initializeInventoryForParamQuad(int sumOfOuterRates);
322 void initializeInventoryForParamQPoly(int sumOfOuterRates);
323
324private:
325 // Private members:
326 Parameterization _param;
327
328 unsigned short _isValid : 1;
329 unsigned short _isUniform : 1;
330 unsigned short _triangulate : 1;
331 unsigned short _singleFace : 1;
332 unsigned short _segmentedFace : 1;
333 unsigned short _triangleFan : 1;
334 unsigned short _splitQuad : 1;
335
336 short _facetSize;
337 int _facetStride;
338 int _coordStride;
339
340 int _numGivenRates;
341 int _numBoundaryPoints;
342 int _numInteriorPoints;
343 int _numFacets;
344
345 int _innerRates[2];
346 int* _outerRates;
347 int _outerRatesLocal[4];
348};
349
350//
351// Inline implementations:
352//
355 _preserveQuads = on;
356 return *this;
357}
360 _facetSize4 = (numIndices == 4);
361 return *this;
362}
365 _facetStride = (short) stride;
366 return *this;
367}
370 _coordStride = (short) stride;
371 return *this;
372}
373
374template <typename REAL>
375inline int
376Tessellation::GetVertexCoord(int vertex, REAL coord[]) const {
377 _param.GetVertexCoord(vertex, coord);
378 return 1;
379}
380
381template <typename REAL>
382inline int
383Tessellation::GetCoords(REAL coordTuples[]) const {
384 int nCoords = GetBoundaryCoords(coordTuples);
385 nCoords += GetInteriorCoords(coordTuples + nCoords * _coordStride);
386 return nCoords;
387}
388
389} // end namespace Bfr
390
391} // end namespace OPENSUBDIV_VERSION
392using namespace OPENSUBDIV_VERSION;
393
394} // end namespace OpenSubdiv
395
396#endif /* OPENSUBDIV3_BFR_TESSELLATION */
Simple class defining the 2D parameterization of a face.
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const
Returns the (u,v) coordinate of a given vertex.
Encapsulates a specific tessellation pattern of a Parameterization.
Definition: tessellation.h:51
int GetFaceSize() const
Return the size of the face.
Definition: tessellation.h:189
int GetNumBoundaryCoords() const
Return the number of boundary coordinates.
Definition: tessellation.h:218
void TransformFacetCoordIndices(int facetTuples[], int const boundaryIndices[], int const interiorIndices[])
Reassign all facet coordinate indices.
int GetCoordStride() const
Return the number of elements between each coordinate.
Definition: tessellation.h:215
int GetNumEdgeCoords(int edge) const
Return the number of coordinates within a given edge (excluding those at its end vertices)
Definition: tessellation.h:225
int GetInteriorCoords(REAL coordTuples[]) const
Retrieve the coordinates for the boundary.
int GetFacetStride() const
Return the number of elements between each facet.
Definition: tessellation.h:272
bool IsUniform() const
Return if the pattern is uniform.
Definition: tessellation.h:195
int GetNumCoords() const
Return the number of coordinates in the entire pattern.
Definition: tessellation.h:212
int GetCoords(REAL coordTuples[]) const
Retrieve the coordinates for the entire pattern.
Definition: tessellation.h:383
void TransformFacetCoordIndices(int facetTuples[], int commonOffset)
Apply a common offset to all facet coordinate indices.
Tessellation(Parameterization const &p, int numRates, int const rates[], Options const &options=Options())
General constructor providing multiple tessellation rates for a non-uniform tessellation.
Parameterization GetParameterization() const
Return the Parameterization.
Definition: tessellation.h:186
void TransformFacetCoordIndices(int facetTuples[], int const boundaryIndices[], int interiorOffset)
Reassign indices of boundary coordinates while offseting those of interior coordinates.
int GetFacetSize() const
Return the number of indices assigned to each facet.
Definition: tessellation.h:269
Tessellation()=delete
Default construction is unavailable.
Tessellation(Parameterization const &p, int uniformRate, Options const &options=Options())
Simple constructor providing a single uniform tessellation rate.
int GetFacets(int facetTuples[]) const
Retrieve the facet indices for the entire pattern.
int GetNumFacets() const
Return the number of facets in the entire pattern.
Definition: tessellation.h:266
int GetNumInteriorCoords() const
Return the number of interior coordinates.
Definition: tessellation.h:221
int GetVertexCoord(int vertex, REAL coordTuples[]) const
Retrieve the coordinate for a given vertex of the face.
Definition: tessellation.h:376
int GetBoundaryCoords(REAL coordTuples[]) const
Retrieve the coordinates for the boundary.
int GetRates(int rates[]) const
Retrieve the rates assigned.
bool IsValid() const
Return true if correctly initialized.
Definition: tessellation.h:169
Tessellation & operator=(Tessellation const &)=delete
int GetEdgeCoords(int edge, REAL coordTuples[]) const
Retrieve the coordinates for a given edge of the face (excluding those at its end vertices)
Options configure a Tessellation to specify the nature of both its results and the structure of the c...
Definition: tessellation.h:72
int GetCoordStride() const
Return the stride between (u,v) pairs.
Definition: tessellation.h:97
Options & SetFacetSize(int numIndices)
Assign the number of indices per facet (must be 3 or 4, default is 3)
Definition: tessellation.h:359
int GetFacetStride() const
Return the stride between facets.
Definition: tessellation.h:92
int GetFacetSize() const
Return the number of indices per facet.
Definition: tessellation.h:87
Options & SetCoordStride(int stride)
Assign the stride between (u,v) pairs (default is 2)
Definition: tessellation.h:369
Options & SetFacetStride(int stride)
Assign the stride between facets (default is facet size)
Definition: tessellation.h:364
bool PreserveQuads() const
Return if preservation of quads is set.
Definition: tessellation.h:81