OpenSubdiv
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 
32 namespace OpenSubdiv {
33 namespace OPENSUBDIV_VERSION {
34 
35 namespace Bfr {
36 
51 class Tessellation {
52 public:
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 
100 public:
102 
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 
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 
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 
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 
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 
299 private:
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 
313 private:
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 //
342 inline Tessellation::Options &
344  _preserveQuads = on;
345  return *this;
346 }
347 inline Tessellation::Options &
349  _facetSize4 = (numIndices == 4);
350  return *this;
351 }
352 inline Tessellation::Options &
354  _facetStride = (short) stride;
355  return *this;
356 }
357 inline Tessellation::Options &
359  _coordStride = (short) stride;
360  return *this;
361 }
362 
363 template <typename REAL>
364 inline int
365 Tessellation::GetVertexCoord(int vertex, REAL coord[]) const {
366  _param.GetVertexCoord(vertex, coord);
367  return 1;
368 }
369 
370 template <typename REAL>
371 inline int
372 Tessellation::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
381 using namespace OPENSUBDIV_VERSION;
382 
383 } // end namespace OpenSubdiv
384 
385 #endif /* OPENSUBDIV3_BFR_TESSELLATION */
Tessellation()=delete
Default construction is unavailable.
bool IsUniform() const
Return if the pattern is uniform.
Definition: tessellation.h:188
int GetFacetStride() const
Return the stride between facets.
Definition: tessellation.h:85
Tessellation & operator=(Tessellation const &)=delete
bool IsValid() const
Return true if correctly initialized.
Definition: tessellation.h:162
int GetNumCoords() const
Return the number of coordinates in the entire pattern.
Definition: tessellation.h:205
bool PreserveQuads() const
Return if preservation of quads is set.
Definition: tessellation.h:74
int GetCoords(REAL coordTuples[]) const
Retrieve the coordinates for the entire pattern.
Definition: tessellation.h:372
int GetNumEdgeCoords(int edge) const
Return the number of coordinates within a given edge (excluding those at its end vertices)
Definition: tessellation.h:218
Simple class defining the 2D parameterization of a face.
Options & SetCoordStride(int stride)
Assign the stride between (u,v) pairs (default is 2)
Definition: tessellation.h:358
int GetNumInteriorCoords() const
Return the number of interior coordinates.
Definition: tessellation.h:214
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
int GetInteriorCoords(REAL coordTuples[]) const
Retrieve the coordinates for the boundary.
int GetRates(int rates[]) const
Retrieve the rates assigned.
int GetFacetSize() const
Return the number of indices assigned to each facet.
Definition: tessellation.h:258
Encapsulates a specific tessellation pattern of a Parameterization.
Definition: tessellation.h:51
void TransformFacetCoordIndices(int facetTuples[], int commonOffset)
Apply a common offset to all facet coordinate indices.
int GetVertexCoord(int vertex, REAL coordTuples[]) const
Retrieve the coordinate for a given vertex of the face.
Definition: tessellation.h:365
void GetVertexCoord(int vertexIndex, REAL uvCoord[2]) const
Returns the (u,v) coordinate of a given vertex.
int GetEdgeCoords(int edge, REAL coordTuples[]) const
Retrieve the coordinates for a given edge of the face (excluding those at its end vertices)
int GetCoordStride() const
Return the number of elements between each coordinate.
Definition: tessellation.h:208
int GetNumBoundaryCoords() const
Return the number of boundary coordinates.
Definition: tessellation.h:211
int GetBoundaryCoords(REAL coordTuples[]) const
Retrieve the coordinates for the boundary.
Options & SetFacetSize(int numIndices)
Assign the number of indices per facet (must be 3 or 4, default is 3)
Definition: tessellation.h:348
int GetFacetStride() const
Return the number of elements between each facet.
Definition: tessellation.h:261
int GetFacets(int facetTuples[]) const
Retrieve the facet indices for the entire pattern.
int GetCoordStride() const
Return the stride between (u,v) pairs.
Definition: tessellation.h:90
int GetNumFacets() const
Return the number of facets in the entire pattern.
Definition: tessellation.h:255
int GetFaceSize() const
Return the size of the face.
Definition: tessellation.h:182
Options configure a Tessellation to specify the nature of both its results and the structure of the c...
Definition: tessellation.h:65
Parameterization GetParameterization() const
Return the Parameterization.
Definition: tessellation.h:179
Options & SetFacetStride(int stride)
Assign the stride between facets (default is facet size)
Definition: tessellation.h:353