| 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
15 namespace OpenSubdiv {
16 namespace OPENSUBDIV_VERSION {
17
18 namespace Bfr {
19
34 class Tessellation {
35 public:
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
90 public:
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;
158 Tessellation & operator=(Tessellation const &) = delete;
159 ~Tessellation();
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
293 private:
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
307 private:
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//
336 inline Tessellation::Options &
337 Tessellation::Options::PreserveQuads(bool on) {
338 _preserveQuads = on;
339 return *this;
340}
341 inline Tessellation::Options &
342 Tessellation::Options::SetFacetSize(int numIndices) {
343 _facetSize4 = (numIndices == 4);
344 return *this;
345}
346 inline Tessellation::Options &
347 Tessellation::Options::SetFacetStride(int stride) {
348 _facetStride = (short) stride;
349 return *this;
350}
351 inline Tessellation::Options &
352 Tessellation::Options::SetCoordStride(int stride) {
353 _coordStride = (short) stride;
354 return *this;
355}
356
357 template <typename REAL>
358 inline int
359 Tessellation::GetVertexCoord(int vertex, REAL coord[]) const {
360 _param.GetVertexCoord(vertex, coord);
361 return 1;
362}
363
364 template <typename REAL>
365 inline int
366 Tessellation::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
375 using namespace OPENSUBDIV_VERSION;
376
377} // end namespace OpenSubdiv
378
379#endif /* OPENSUBDIV3_BFR_TESSELLATION */
parameterization.h
OpenSubdiv
Definition limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Bfr
Definition limits.h:18
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization
Simple class defining the 2D parameterization of a face.
Definition parameterization.h:35
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetFaceSize
int GetFaceSize() const
Return the size of the face.
Definition tessellation.h:172
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumBoundaryCoords
int GetNumBoundaryCoords() const
Return the number of boundary coordinates.
Definition tessellation.h:201
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::~Tessellation
~Tessellation()
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::TransformFacetCoordIndices
void TransformFacetCoordIndices(int facetTuples[], int const boundaryIndices[], int const interiorIndices[])
Reassign all facet coordinate indices.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetCoordStride
int GetCoordStride() const
Return the number of elements between each coordinate.
Definition tessellation.h:198
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumEdgeCoords
int GetNumEdgeCoords(int edge) const
Return the number of coordinates within a given edge (excluding those at its end vertices).
Definition tessellation.h:208
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetInteriorCoords
int GetInteriorCoords(REAL coordTuples[]) const
Retrieve the coordinates for the boundary.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetFacetStride
int GetFacetStride() const
Return the number of elements between each facet.
Definition tessellation.h:255
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::IsUniform
bool IsUniform() const
Return if the pattern is uniform.
Definition tessellation.h:178
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumCoords
int GetNumCoords() const
Return the number of coordinates in the entire pattern.
Definition tessellation.h:195
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetCoords
int GetCoords(REAL coordTuples[]) const
Retrieve the coordinates for the entire pattern.
Definition tessellation.h:366
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::TransformFacetCoordIndices
void TransformFacetCoordIndices(int facetTuples[], int commonOffset)
Apply a common offset to all facet coordinate indices.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Tessellation
Tessellation(Parameterization const &p, int numRates, int const rates[], Options const &options=Options())
General constructor providing multiple tessellation rates for a non-uniform tessellation.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetParameterization
Parameterization GetParameterization() const
Return the Parameterization.
Definition tessellation.h:169
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::TransformFacetCoordIndices
void TransformFacetCoordIndices(int facetTuples[], int const boundaryIndices[], int interiorOffset)
Reassign indices of boundary coordinates while offseting those of interior coordinates.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetFacetSize
int GetFacetSize() const
Return the number of indices assigned to each facet.
Definition tessellation.h:252
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Tessellation
Tessellation()=delete
Default construction is unavailable.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Tessellation
Tessellation(Parameterization const &p, int uniformRate, Options const &options=Options())
Simple constructor providing a single uniform tessellation rate.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetFacets
int GetFacets(int facetTuples[]) const
Retrieve the facet indices for the entire pattern.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumFacets
int GetNumFacets() const
Return the number of facets in the entire pattern.
Definition tessellation.h:249
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumInteriorCoords
int GetNumInteriorCoords() const
Return the number of interior coordinates.
Definition tessellation.h:204
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetVertexCoord
int GetVertexCoord(int vertex, REAL coordTuples[]) const
Retrieve the coordinate for a given vertex of the face.
Definition tessellation.h:359
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetBoundaryCoords
int GetBoundaryCoords(REAL coordTuples[]) const
Retrieve the coordinates for the boundary.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Tessellation
Tessellation(Tessellation const &)=delete
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetRates
int GetRates(int rates[]) const
Retrieve the rates assigned.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::IsValid
bool IsValid() const
Return true if correctly initialized.
Definition tessellation.h:152
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::operator=
Tessellation & operator=(Tessellation const &)=delete
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetEdgeCoords
int GetEdgeCoords(int edge, REAL coordTuples[]) const
Retrieve the coordinates for a given edge of the face (excluding those at its end vertices).
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options
Options configure a Tessellation to specify the nature of both its results and the structure of the c...
Definition tessellation.h:55
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::Options
Options()
Definition tessellation.h:57
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetCoordStride
int GetCoordStride() const
Return the stride between (u,v) pairs.
Definition tessellation.h:80
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::SetFacetSize
Options & SetFacetSize(int numIndices)
Assign the number of indices per facet (must be 3 or 4, default is 3).
Definition tessellation.h:342
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetFacetStride
int GetFacetStride() const
Return the stride between facets.
Definition tessellation.h:75
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetFacetSize
int GetFacetSize() const
Return the number of indices per facet.
Definition tessellation.h:70
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::SetCoordStride
Options & SetCoordStride(int stride)
Assign the stride between (u,v) pairs (default is 2).
Definition tessellation.h:352
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::SetFacetStride
Options & SetFacetStride(int stride)
Assign the stride between facets (default is facet size).
Definition tessellation.h:347
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::PreserveQuads
bool PreserveQuads() const
Return if preservation of quads is set.
Definition tessellation.h:64