OpenSubdiv
Loading...
Searching...
No Matches
tessellation.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_TESSELLATION_H
9#define OPENSUBDIV3_BFR_TESSELLATION_H
10
11#include "../version.h"
12
13#include "../bfr/parameterization.h"
14
15namespace OpenSubdiv {
16namespace OPENSUBDIV_VERSION {
17
18namespace Bfr {
19
35public:
55 class Options {
56 public:
57 Options() : _preserveQuads(false), _facetSize4(false),
58 _coordStride(0), _facetStride(0) { }
59
62 Options & PreserveQuads(bool on);
64 bool PreserveQuads() const { return _preserveQuads; }
65
68 Options & SetFacetSize(int numIndices);
70 int GetFacetSize() const { return 3 + (int)_facetSize4; }
71
73 Options & SetFacetStride(int stride);
75 int GetFacetStride() const { return _facetStride; }
76
78 Options & SetCoordStride(int stride);
80 int GetCoordStride() const { return _coordStride; }
81
82 private:
83 unsigned int _preserveQuads : 1;
84 unsigned int _facetSize4 : 1;
85
86 short _coordStride;
87 short _facetStride;
88 };
89
90public:
92
101
108 Tessellation(Parameterization const & p, int uniformRate,
109 Options const & options = Options());
110
148 Tessellation(Parameterization const & p, int numRates, int const rates[],
149 Options const & options = Options());
150
152 bool IsValid() const { return _isValid; }
153
155 Tessellation() = delete;
156
157 Tessellation(Tessellation const &) = delete;
161
163
167
169 Parameterization GetParameterization() const { return _param; }
170
172 int GetFaceSize() const { return _param.GetFaceSize(); }
173
175 int GetRates(int rates[]) const;
176
178 bool IsUniform() const { return _isUniform; }
180
182
193
195 int GetNumCoords() const { return _numInteriorPoints + _numBoundaryPoints; }
196
198 int GetCoordStride() const { return _coordStride; }
199
201 int GetNumBoundaryCoords() const { return _numBoundaryPoints; }
202
204 int GetNumInteriorCoords() const { return _numInteriorPoints; }
205
208 int GetNumEdgeCoords(int edge) const { return _outerRates[edge] - 1; }
209
211 template <typename REAL>
212 int GetCoords(REAL coordTuples[]) const;
213
215 template <typename REAL>
216 int GetBoundaryCoords(REAL coordTuples[]) const;
217
219 template <typename REAL>
220 int GetInteriorCoords(REAL coordTuples[]) const;
221
223 template <typename REAL>
224 int GetVertexCoord(int vertex, REAL coordTuples[]) const;
225
228 template <typename REAL>
229 int GetEdgeCoords(int edge, REAL coordTuples[]) const;
231
233
247
249 int GetNumFacets() const { return _numFacets; }
250
252 int GetFacetSize() const { return _facetSize; }
253
255 int GetFacetStride() const { return _facetStride; }
256
258 int GetFacets(int facetTuples[]) const;
260
262
277
279 void TransformFacetCoordIndices(int facetTuples[], int commonOffset);
280
283 void TransformFacetCoordIndices(int facetTuples[],
284 int const boundaryIndices[],
285 int interiorOffset);
286
288 void TransformFacetCoordIndices(int facetTuples[],
289 int const boundaryIndices[],
290 int const interiorIndices[]);
292
293private:
294 // Private initialization methods:
295 bool validateArguments(Parameterization const & p,
296 int nRates, int const rates[], Options const & options);
297
298 void initialize(Parameterization const & p,
299 int nRates, int const rates[], Options const & options);
300
301 void initializeDefaults();
302 int initializeRates(int nRates, int const rates[]);
303 void initializeInventoryForParamTri(int sumOfOuterRates);
304 void initializeInventoryForParamQuad(int sumOfOuterRates);
305 void initializeInventoryForParamQPoly(int sumOfOuterRates);
306
307private:
308 // Private members:
309 Parameterization _param;
310
311 unsigned short _isValid : 1;
312 unsigned short _isUniform : 1;
313 unsigned short _triangulate : 1;
314 unsigned short _singleFace : 1;
315 unsigned short _segmentedFace : 1;
316 unsigned short _triangleFan : 1;
317 unsigned short _splitQuad : 1;
318
319 short _facetSize;
320 int _facetStride;
321 int _coordStride;
322
323 int _numGivenRates;
324 int _numBoundaryPoints;
325 int _numInteriorPoints;
326 int _numFacets;
327
328 int _innerRates[2];
329 int* _outerRates;
330 int _outerRatesLocal[4];
331};
332
333//
334// Inline implementations:
335//
338 _preserveQuads = on;
339 return *this;
340}
343 _facetSize4 = (numIndices == 4);
344 return *this;
345}
348 _facetStride = (short) stride;
349 return *this;
350}
353 _coordStride = (short) stride;
354 return *this;
355}
356
357template <typename REAL>
358inline int
359Tessellation::GetVertexCoord(int vertex, REAL coord[]) const {
360 _param.GetVertexCoord(vertex, coord);
361 return 1;
362}
363
364template <typename REAL>
365inline int
366Tessellation::GetCoords(REAL coordTuples[]) const {
367 int nCoords = GetBoundaryCoords(coordTuples);
368 nCoords += GetInteriorCoords(coordTuples + nCoords * _coordStride);
369 return nCoords;
370}
371
372} // end namespace Bfr
373
374} // end namespace OPENSUBDIV_VERSION
375using namespace OPENSUBDIV_VERSION;
376
377} // end namespace OpenSubdiv
378
379#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:34
int GetFaceSize() const
Return the size of the face.
Definition: tessellation.h:172
int GetNumBoundaryCoords() const
Return the number of boundary coordinates.
Definition: tessellation.h:201
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:198
int GetNumEdgeCoords(int edge) const
Return the number of coordinates within a given edge (excluding those at its end vertices)
Definition: tessellation.h:208
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:255
bool IsUniform() const
Return if the pattern is uniform.
Definition: tessellation.h:178
int GetNumCoords() const
Return the number of coordinates in the entire pattern.
Definition: tessellation.h:195
int GetCoords(REAL coordTuples[]) const
Retrieve the coordinates for the entire pattern.
Definition: tessellation.h:366
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:169
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:252
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:249
int GetNumInteriorCoords() const
Return the number of interior coordinates.
Definition: tessellation.h:204
int GetVertexCoord(int vertex, REAL coordTuples[]) const
Retrieve the coordinate for a given vertex of the face.
Definition: tessellation.h:359
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:152
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:55
int GetCoordStride() const
Return the stride between (u,v) pairs.
Definition: tessellation.h:80
Options & SetFacetSize(int numIndices)
Assign the number of indices per facet (must be 3 or 4, default is 3)
Definition: tessellation.h:342
int GetFacetStride() const
Return the stride between facets.
Definition: tessellation.h:75
int GetFacetSize() const
Return the number of indices per facet.
Definition: tessellation.h:70
Options & SetCoordStride(int stride)
Assign the stride between (u,v) pairs (default is 2)
Definition: tessellation.h:352
Options & SetFacetStride(int stride)
Assign the stride between facets (default is facet size)
Definition: tessellation.h:347
bool PreserveQuads() const
Return if preservation of quads is set.
Definition: tessellation.h:64