OpenSubdiv: opensubdiv/bfr/tessellation.h Source File

| OpenSubdiv

Loading...
Searching...
No Matches
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
51 class Tessellation {
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;
175 Tessellation & operator=(Tessellation const &) = delete;
176 ~Tessellation();
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//
353inline Tessellation::Options &
354 Tessellation::Options::PreserveQuads(bool on) {
355 _preserveQuads = on;
356 return *this;
357}
358inline Tessellation::Options &
359Tessellation::Options::SetFacetSize(int numIndices) {
360 _facetSize4 = (numIndices == 4);
361 return *this;
362}
363inline Tessellation::Options &
364Tessellation::Options::SetFacetStride(int stride) {
365 _facetStride = (short) stride;
366 return *this;
367}
368inline Tessellation::Options &
369Tessellation::Options::SetCoordStride(int stride) {
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 */
parameterization.h
OpenSubdiv
Definition limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:33
OpenSubdiv::OPENSUBDIV_VERSION::Bfr
Definition limits.h:35
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization
Simple class defining the 2D parameterization of a face.
Definition parameterization.h:52
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetFaceSize
int GetFaceSize() const
Return the size of the face.
Definition tessellation.h:189
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumBoundaryCoords
int GetNumBoundaryCoords() const
Return the number of boundary coordinates.
Definition tessellation.h:218
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:215
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:225
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:272
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::IsUniform
bool IsUniform() const
Return if the pattern is uniform.
Definition tessellation.h:195
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumCoords
int GetNumCoords() const
Return the number of coordinates in the entire pattern.
Definition tessellation.h:212
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetCoords
int GetCoords(REAL coordTuples[]) const
Retrieve the coordinates for the entire pattern.
Definition tessellation.h:383
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:186
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:269
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:266
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumInteriorCoords
int GetNumInteriorCoords() const
Return the number of interior coordinates.
Definition tessellation.h:221
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:376
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:169
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:72
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::Options
Options()
Definition tessellation.h:74
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetCoordStride
int GetCoordStride() const
Return the stride between (u,v) pairs.
Definition tessellation.h:97
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:359
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetFacetStride
int GetFacetStride() const
Return the stride between facets.
Definition tessellation.h:92
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetFacetSize
int GetFacetSize() const
Return the number of indices per facet.
Definition tessellation.h:87
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::SetCoordStride
Options & SetCoordStride(int stride)
Assign the stride between (u,v) pairs (default is 2)
Definition tessellation.h:369
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::SetFacetStride
Options & SetFacetStride(int stride)
Assign the stride between facets (default is facet size)
Definition tessellation.h:364
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::PreserveQuads
bool PreserveQuads() const
Return if preservation of quads is set.
Definition tessellation.h:81