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:
65 class Options {
66 public:
67 Options() : _preserveQuads(false), _facetSize4(false),
68 _coordStride(0), _facetStride(0) { }
69
72 Options & PreserveQuads(bool on);
74 bool PreserveQuads() const { return _preserveQuads; }
75
78 Options & SetFacetSize(int numIndices);
79 // @brief Return the number of indices per facet
80 int GetFacetSize() const { return 3 + (int)_facetSize4; }
81
83 Options & SetFacetStride(int stride);
85 int GetFacetStride() const { return _facetStride; }
86
88 Options & SetCoordStride(int stride);
90 int GetCoordStride() const { return _coordStride; }
91
92 private:
93 unsigned int _preserveQuads : 1;
94 unsigned int _facetSize4 : 1;
95
96 short _coordStride;
97 short _facetStride;
98 };
99
100public:
102
111
118 Tessellation(Parameterization const & p, int uniformRate,
119 Options const & options = Options());
120
158 Tessellation(Parameterization const & p, int numRates, int const rates[],
159 Options const & options = Options());
160
162 bool IsValid() const { return _isValid; }
163
165 Tessellation() = delete;
166
167 Tessellation(Tessellation const &) = delete;
168 Tessellation & operator=(Tessellation const &) = delete;
169 ~Tessellation();
171
173
177
179 Parameterization GetParameterization() const { return _param; }
180
182 int GetFaceSize() const { return _param.GetFaceSize(); }
183
185 int GetRates(int rates[]) const;
186
188 bool IsUniform() const { return _isUniform; }
190
192
203
205 int GetNumCoords() const { return _numInteriorPoints + _numBoundaryPoints; }
206
208 int GetCoordStride() const { return _coordStride; }
209
211 int GetNumBoundaryCoords() const { return _numBoundaryPoints; }
212
214 int GetNumInteriorCoords() const { return _numInteriorPoints; }
215
218 int GetNumEdgeCoords(int edge) const { return _outerRates[edge] - 1; }
219
221 template <typename REAL>
222 int GetCoords(REAL coordTuples[]) const;
223
225 template <typename REAL>
226 int GetBoundaryCoords(REAL coordTuples[]) const;
227
229 template <typename REAL>
230 int GetInteriorCoords(REAL coordTuples[]) const;
231
233 template <typename REAL>
234 int GetVertexCoord(int vertex, REAL coordTuples[]) const;
235
238 template <typename REAL>
239 int GetEdgeCoords(int edge, REAL coordTuples[]) const;
241
243
253
255 int GetNumFacets() const { return _numFacets; }
256
258 int GetFacetSize() const { return _facetSize; }
259
261 int GetFacetStride() const { return _facetStride; }
262
264 int GetFacets(int facetTuples[]) const;
266
268
283
285 void TransformFacetCoordIndices(int facetTuples[], int commonOffset);
286
289 void TransformFacetCoordIndices(int facetTuples[],
290 int const boundaryIndices[],
291 int interiorOffset);
292
294 void TransformFacetCoordIndices(int facetTuples[],
295 int const boundaryIndices[],
296 int const interiorIndices[]);
298
299private:
300 // Private initialization methods:
301 bool validateArguments(Parameterization const & p,
302 int nRates, int const rates[], Options const & options);
303
304 void initialize(Parameterization const & p,
305 int nRates, int const rates[], Options const & options);
306
307 void initializeDefaults();
308 int initializeRates(int nRates, int const rates[]);
309 void initializeInventoryForParamTri(int sumOfOuterRates);
310 void initializeInventoryForParamQuad(int sumOfOuterRates);
311 void initializeInventoryForParamQPoly(int sumOfOuterRates);
312
313private:
314 // Private members:
315 Parameterization _param;
316
317 unsigned short _isValid : 1;
318 unsigned short _isUniform : 1;
319 unsigned short _triangulate : 1;
320 unsigned short _singleFace : 1;
321 unsigned short _segmentedFace : 1;
322 unsigned short _triangleFan : 1;
323 unsigned short _splitQuad : 1;
324
325 short _facetSize;
326 int _facetStride;
327 int _coordStride;
328
329 int _numGivenRates;
330 int _numBoundaryPoints;
331 int _numInteriorPoints;
332 int _numFacets;
333
334 int _innerRates[2];
335 int* _outerRates;
336 int _outerRatesLocal[4];
337};
338
339//
340// Inline implementations:
341//
342inline Tessellation::Options &
343 Tessellation::Options::PreserveQuads(bool on) {
344 _preserveQuads = on;
345 return *this;
346}
347inline Tessellation::Options &
348Tessellation::Options::SetFacetSize(int numIndices) {
349 _facetSize4 = (numIndices == 4);
350 return *this;
351}
352inline Tessellation::Options &
353Tessellation::Options::SetFacetStride(int stride) {
354 _facetStride = (short) stride;
355 return *this;
356}
357inline Tessellation::Options &
358Tessellation::Options::SetCoordStride(int stride) {
359 _coordStride = (short) stride;
360 return *this;
361}
362
363template <typename REAL>
364inline int
365Tessellation::GetVertexCoord(int vertex, REAL coord[]) const {
366 _param.GetVertexCoord(vertex, coord);
367 return 1;
368}
369
370template <typename REAL>
371inline int
372Tessellation::GetCoords(REAL coordTuples[]) const {
373 int nCoords = GetBoundaryCoords(coordTuples);
374 nCoords += GetInteriorCoords(coordTuples + nCoords * _coordStride);
375 return nCoords;
376}
377
378} // end namespace Bfr
379
380} // end namespace OPENSUBDIV_VERSION
381using namespace OPENSUBDIV_VERSION;
382
383} // end namespace OpenSubdiv
384
385#endif /* OPENSUBDIV3_BFR_TESSELLATION */
parameterization.h
OpenSubdiv
Definition limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization
Simple class defining the 2D parameterization of a face.
Definition parameterization.h:52
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetFaceSize
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
Definition parameterization.h:101
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::Tessellation
Encapsulates a specific tessellation pattern of a Parameterization.
Definition tessellation.h:51
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetFaceSize
int GetFaceSize() const
Return the size of the face.
Definition tessellation.h:182
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumBoundaryCoords
int GetNumBoundaryCoords() const
Return the number of boundary coordinates.
Definition tessellation.h:211
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:208
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:218
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:261
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::IsUniform
bool IsUniform() const
Return if the pattern is uniform.
Definition tessellation.h:188
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumCoords
int GetNumCoords() const
Return the number of coordinates in the entire pattern.
Definition tessellation.h:205
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetCoords
int GetCoords(REAL coordTuples[]) const
Retrieve the coordinates for the entire pattern.
Definition tessellation.h:372
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:179
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:258
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:255
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::GetNumInteriorCoords
int GetNumInteriorCoords() const
Return the number of interior coordinates.
Definition tessellation.h:214
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:365
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:162
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:65
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::Options
Options()
Definition tessellation.h:67
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetCoordStride
int GetCoordStride() const
Return the stride between (u,v) pairs.
Definition tessellation.h:90
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:348
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetFacetStride
int GetFacetStride() const
Return the stride between facets.
Definition tessellation.h:85
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::GetFacetSize
int GetFacetSize() const
Definition tessellation.h:80
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::SetCoordStride
Options & SetCoordStride(int stride)
Assign the stride between (u,v) pairs (default is 2)
Definition tessellation.h:358
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::SetFacetStride
Options & SetFacetStride(int stride)
Assign the stride between facets (default is facet size)
Definition tessellation.h:353
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Tessellation::Options::PreserveQuads
bool PreserveQuads() const
Return if preservation of quads is set.
Definition tessellation.h:74