Loading...
Searching...
No Matches
tessellation.h
Go to the documentation of this file.
//
// Copyright 2021 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef OPENSUBDIV3_BFR_TESSELLATION_H
#define OPENSUBDIV3_BFR_TESSELLATION_H
#include "../version.h"
#include "../bfr/parameterization.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Bfr {
class Tessellation {
public:
class Options {
public:
Options() : _preserveQuads(false), _facetSize4(false),
_coordStride(0), _facetStride(0) { }
Options & PreserveQuads(bool on);
bool PreserveQuads() const { return _preserveQuads; }
Options & SetFacetSize(int numIndices);
// @brief Return the number of indices per facet
int GetFacetSize() const { return 3 + (int)_facetSize4; }
Options & SetFacetStride(int stride);
int GetFacetStride() const { return _facetStride; }
Options & SetCoordStride(int stride);
int GetCoordStride() const { return _coordStride; }
private:
unsigned int _preserveQuads : 1;
unsigned int _facetSize4 : 1;
short _coordStride;
short _facetStride;
};
public:
Tessellation(Parameterization const & p, int uniformRate,
Options const & options = Options());
Tessellation(Parameterization const & p, int numRates, int const rates[],
Options const & options = Options());
bool IsValid() const { return _isValid; }
Tessellation() = delete;
Tessellation(Tessellation const &) = delete;
Tessellation & operator=(Tessellation const &) = delete;
~Tessellation();
Parameterization GetParameterization() const { return _param; }
int GetFaceSize() const { return _param.GetFaceSize(); }
int GetRates(int rates[]) const;
bool IsUniform() const { return _isUniform; }
int GetNumCoords() const { return _numInteriorPoints + _numBoundaryPoints; }
int GetCoordStride() const { return _coordStride; }
int GetNumBoundaryCoords() const { return _numBoundaryPoints; }
int GetNumInteriorCoords() const { return _numInteriorPoints; }
int GetNumEdgeCoords(int edge) const { return _outerRates[edge] - 1; }
template <typename REAL>
int GetCoords(REAL coordTuples[]) const;
template <typename REAL>
int GetBoundaryCoords(REAL coordTuples[]) const;
template <typename REAL>
int GetInteriorCoords(REAL coordTuples[]) const;
template <typename REAL>
int GetVertexCoord(int vertex, REAL coordTuples[]) const;
template <typename REAL>
int GetEdgeCoords(int edge, REAL coordTuples[]) const;
int GetNumFacets() const { return _numFacets; }
int GetFacetSize() const { return _facetSize; }
int GetFacetStride() const { return _facetStride; }
int GetFacets(int facetTuples[]) const;
void TransformFacetCoordIndices(int facetTuples[], int commonOffset);
void TransformFacetCoordIndices(int facetTuples[],
int const boundaryIndices[],
int interiorOffset);
void TransformFacetCoordIndices(int facetTuples[],
int const boundaryIndices[],
int const interiorIndices[]);
private:
// Private initialization methods:
bool validateArguments(Parameterization const & p,
int nRates, int const rates[], Options const & options);
void initialize(Parameterization const & p,
int nRates, int const rates[], Options const & options);
void initializeDefaults();
int initializeRates(int nRates, int const rates[]);
void initializeInventoryForParamTri(int sumOfOuterRates);
void initializeInventoryForParamQuad(int sumOfOuterRates);
void initializeInventoryForParamQPoly(int sumOfOuterRates);
private:
// Private members:
Parameterization _param;
unsigned short _isValid : 1;
unsigned short _isUniform : 1;
unsigned short _triangulate : 1;
unsigned short _singleFace : 1;
unsigned short _segmentedFace : 1;
unsigned short _triangleFan : 1;
unsigned short _splitQuad : 1;
short _facetSize;
int _facetStride;
int _coordStride;
int _numGivenRates;
int _numBoundaryPoints;
int _numInteriorPoints;
int _numFacets;
int _innerRates[2];
int* _outerRates;
int _outerRatesLocal[4];
};
//
// Inline implementations:
//
inline Tessellation::Options &
Tessellation::Options::PreserveQuads(bool on) {
_preserveQuads = on;
return *this;
}
inline Tessellation::Options &
Tessellation::Options::SetFacetSize(int numIndices) {
_facetSize4 = (numIndices == 4);
return *this;
}
inline Tessellation::Options &
Tessellation::Options::SetFacetStride(int stride) {
_facetStride = (short) stride;
return *this;
}
inline Tessellation::Options &
Tessellation::Options::SetCoordStride(int stride) {
_coordStride = (short) stride;
return *this;
}
template <typename REAL>
inline int
Tessellation::GetVertexCoord(int vertex, REAL coord[]) const {
_param.GetVertexCoord(vertex, coord);
return 1;
}
template <typename REAL>
inline int
Tessellation::GetCoords(REAL coordTuples[]) const {
int nCoords = GetBoundaryCoords(coordTuples);
nCoords += GetInteriorCoords(coordTuples + nCoords * _coordStride);
return nCoords;
}
} // end namespace Bfr
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#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: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