OpenSubdiv 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
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;
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//
344 _preserveQuads = on;
345 return *this;
346}
349 _facetSize4 = (numIndices == 4);
350 return *this;
351}
354 _facetStride = (short) stride;
355 return *this;
356}
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 */
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.
int GetFaceSize() const
Return the size of the face.
int GetNumBoundaryCoords() const
Return the number of boundary coordinates.
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.
int GetNumEdgeCoords(int edge) const
Return the number of coordinates within a given edge (excluding those at its end vertices)
int GetInteriorCoords(REAL coordTuples[]) const
Retrieve the coordinates for the boundary.
int GetFacetStride() const
Return the number of elements between each facet.
bool IsUniform() const
Return if the pattern is uniform.
int GetNumCoords() const
Return the number of coordinates in the entire pattern.
int GetCoords(REAL coordTuples[]) const
Retrieve the coordinates for the entire pattern.
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.
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.
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.
int GetNumInteriorCoords() const
Return the number of interior coordinates.
int GetVertexCoord(int vertex, REAL coordTuples[]) const
Retrieve the coordinate for a given vertex of the face.
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.
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...
int GetCoordStride() const
Return the stride between (u,v) pairs.
Options & SetFacetSize(int numIndices)
Assign the number of indices per facet (must be 3 or 4, default is 3)
int GetFacetStride() const
Return the stride between facets.
Options & SetCoordStride(int stride)
Assign the stride between (u,v) pairs (default is 2)
Options & SetFacetStride(int stride)
Assign the stride between facets (default is facet size)
bool PreserveQuads() const
Return if preservation of quads is set.