add usd-21-11-win64_py39

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:43:55 +01:00
1 parent 41d23e71ba
commit ba5e1f7e67
15684 files changed
+3069957

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
//
// Copyright 2013 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_FAR_ERROR_H
#define OPENSUBDIV3_FAR_ERROR_H
#include "../version.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
typedef enum {
FAR_NO_ERROR, ///< No error. Move along.
FAR_FATAL_ERROR, ///< Issue a fatal error and end the program.
FAR_INTERNAL_CODING_ERROR, ///< Issue an internal programming error, but continue execution.
FAR_CODING_ERROR, ///< Issue a generic programming error, but continue execution.
FAR_RUNTIME_ERROR ///< Issue a generic runtime error, but continue execution.
} ErrorType;
/// \brief The error callback function type (default is "printf")
typedef void (*ErrorCallbackFunc)(ErrorType err, const char *message);
/// \brief Sets the error callback function (default is "printf")
///
/// \note This function is not thread-safe !
///
/// @param func function pointer to the callback function
///
void SetErrorCallback(ErrorCallbackFunc func);
/// \brief The warning callback function type (default is "printf")
typedef void (*WarningCallbackFunc)(const char *message);
/// \brief Sets the warning callback function (default is "printf")
///
/// \note This function is not thread-safe !
///
/// @param func function pointer to the callback function
///
void SetWarningCallback(WarningCallbackFunc func);
//
// The following are intended for internal use only (and will eventually
// be moved within namespace internal)
//
/// \brief Sends an OSD error with a message (internal use only)
///
/// @param err the error type
///
/// @param format the format of the message (followed by arguments)
///
void Error(ErrorType err, const char *format, ...);
/// \brief Sends an OSD warning message (internal use only)
///
/// @param format the format of the message (followed by arguments)
///
void Warning(const char *format, ...);
} // end namespace
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif // OPENSUBDIV3_FAR_ERROR_H
+187
View File
@@ -0,0 +1,187 @@
//
// Copyright 2013 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_FAR_PATCH_DESCRIPTOR_H
#define OPENSUBDIV3_FAR_PATCH_DESCRIPTOR_H
#include "../version.h"
#include "../far/types.h"
#include "../sdc/types.h"
#include <vector>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
/// \brief Describes the type of a patch
///
/// Uniquely identifies all the different types of patches
///
class PatchDescriptor {
public:
enum Type {
NON_PATCH = 0, ///< undefined
POINTS, ///< points (useful for cage drawing)
LINES, ///< lines (useful for cage drawing)
QUADS, ///< 4-sided quadrilateral (bilinear)
TRIANGLES, ///< 3-sided triangle
LOOP, ///< regular triangular patch for the Loop scheme
REGULAR, ///< regular B-Spline patch for the Catmark scheme
GREGORY,
GREGORY_BOUNDARY,
GREGORY_BASIS,
GREGORY_TRIANGLE
};
public:
/// \brief Default constructor.
PatchDescriptor() :
_type(NON_PATCH) { }
/// \brief Constructor
PatchDescriptor(int type) :
_type(type) { }
/// \brief Copy Constructor
PatchDescriptor( PatchDescriptor const & d ) :
_type(d.GetType()) { }
/// \brief Returns the type of the patch
Type GetType() const {
return (Type)_type;
}
/// \brief Returns true if the type is an adaptive (non-linear) patch
static inline bool IsAdaptive(Type type) {
return type > TRIANGLES;
}
/// \brief Returns true if the type is an adaptive patch
bool IsAdaptive() const {
return IsAdaptive( this->GetType() );
}
/// \brief Returns the number of control vertices expected for a patch of the
/// type described
static inline short GetNumControlVertices( Type t );
/// \brief Deprecated @see PatchDescriptor#GetNumControlVertices
static inline short GetNumFVarControlVertices( Type t );
/// \brief Returns the number of control vertices expected for a patch of the
/// type described
short GetNumControlVertices() const {
return GetNumControlVertices( this->GetType() );
}
/// \brief Deprecated @see PatchDescriptor#GetNumControlVertices
short GetNumFVarControlVertices() const {
return GetNumFVarControlVertices( this->GetType() );
}
/// \brief Number of control vertices of Regular Patches in table.
static short GetRegularPatchSize() { return 16; }
/// \brief Number of control vertices of Gregory (and Gregory Boundary) Patches in table.
static short GetGregoryPatchSize() { return 4; }
/// \brief Number of control vertices of Gregory patch basis (20)
static short GetGregoryBasisPatchSize() { return 20; }
/// \brief Returns a vector of all the legal patch descriptors for the
/// given adaptive subdivision scheme
static Vtr::ConstArray<PatchDescriptor> GetAdaptivePatchDescriptors(Sdc::SchemeType type);
/// \brief Allows ordering of patches by type
inline bool operator < ( PatchDescriptor const other ) const;
/// \brief True if the descriptors are identical
inline bool operator == ( PatchDescriptor const other ) const;
// debug helper
void print() const;
private:
unsigned int _type;
};
typedef Vtr::ConstArray<PatchDescriptor> ConstPatchDescriptorArray;
// Returns the number of control vertices expected for a patch of this type
inline short
PatchDescriptor::GetNumControlVertices( Type type ) {
switch (type) {
case REGULAR : return GetRegularPatchSize();
case LOOP : return 12;
case QUADS : return 4;
case GREGORY :
case GREGORY_BOUNDARY : return GetGregoryPatchSize();
case GREGORY_BASIS : return GetGregoryBasisPatchSize();
case GREGORY_TRIANGLE : return 18;
case TRIANGLES : return 3;
case LINES : return 2;
case POINTS : return 1;
default : return -1;
}
}
// Returns the number of face-varying control vertices expected for a patch of this type
inline short
PatchDescriptor::GetNumFVarControlVertices( Type type ) {
return PatchDescriptor::GetNumControlVertices(type);
}
// Allows ordering of patches by type
inline bool
PatchDescriptor::operator < ( PatchDescriptor const other ) const {
return (_type < other._type);
}
// True if the descriptors are identical
inline bool
PatchDescriptor::operator == ( PatchDescriptor const other ) const {
return _type == other._type;
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_PATCH_DESCRIPTOR_H */
+240
View File
@@ -0,0 +1,240 @@
//
// Copyright 2013 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_FAR_PATCH_MAP_H
#define OPENSUBDIV3_FAR_PATCH_MAP_H
#include "../version.h"
#include "../far/patchTable.h"
#include <cassert>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
/// \brief An quadtree-based map connecting coarse faces to their sub-patches
///
/// PatchTable::PatchArrays contain lists of patches that represent the limit
/// surface of a mesh, sorted by their topological type. These arrays break the
/// connection between coarse faces and their sub-patches.
///
/// The PatchMap provides a quad-tree based lookup structure that, given a singular
/// parametric location, can efficiently return a handle to the sub-patch that
/// contains this location.
///
class PatchMap {
public:
typedef PatchTable::PatchHandle Handle;
/// \brief Constructor
///
/// @param patchTable A valid PatchTable
///
PatchMap( PatchTable const & patchTable );
/// \brief Returns a handle to the sub-patch of the face at the given (u,v).
/// Note that the patch face ID corresponds to potentially quadrangulated
/// face indices and not the base face indices (see Far::PtexIndices for more
/// details).
///
/// @param patchFaceId The index of the patch (Ptex) face
///
/// @param u Local u parameter
///
/// @param v Local v parameter
///
/// @return A patch handle or 0 if the face is not supported (index
/// out of bounds) or is tagged as a hole
///
Handle const * FindPatch( int patchFaceId, double u, double v ) const;
private:
void initializeHandles(PatchTable const & patchTable);
void initializeQuadtree(PatchTable const & patchTable);
private:
// Quadtree node with 4 children, tree is just a vector of nodes
struct QuadNode {
QuadNode() { std::memset(this, 0, sizeof(QuadNode)); }
struct Child {
unsigned int isSet : 1; // true if the child has been set
unsigned int isLeaf : 1; // true if the child is a QuadNode
unsigned int index : 30; // child index (either QuadNode or Handle)
};
// sets all the children to point to the patch of given index
void SetChildren(int index);
// sets the child in "quadrant" to point to the node or patch of the given index
void SetChild(int quadrant, int index, bool isLeaf);
Child children[4];
};
typedef std::vector<QuadNode> QuadTree;
// Internal methods supporting quadtree construction and queries
void assignRootNode(QuadNode * node, int index);
QuadNode * assignLeafOrChildNode(QuadNode * node, bool isLeaf, int quad, int index);
template <class T>
static int transformUVToQuadQuadrant(T const & median, T & u, T & v);
template <class T>
static int transformUVToTriQuadrant(T const & median, T & u, T & v, bool & rotated);
private:
bool _patchesAreTriangular; // tri and quad assembly and search requirements differ
int _minPatchFace; // minimum patch face index supported by the map
int _maxPatchFace; // maximum patch face index supported by the map
int _maxDepth; // maximum depth of a patch in the tree
std::vector<Handle> _handles; // all the patches in the PatchTable
std::vector<QuadNode> _quadtree; // quadtree nodes
};
//
// Given a median value for both U and V, these methods transform a (u,v) pair
// into the quadrant that contains them and returns the quadrant index.
//
// Quadrant indexing for tri and quad patches -- consistent with PatchParam's
// usage of UV bits:
//
// (0,1) o-----o-----o (1,1) (0,1) o (1,0) o-----o-----o (0,0)
// | | | |\ \ 1 |\ 0 |
// | 2 | 3 | | \ \ | \ |
// | | | | 2 \ \| 3 \|
// o-----o-----o o-----o o-----o
// | | | |\ 3 |\ \ 2 |
// | 0 | 1 | | \ | \ \ |
// | | | | 0 \| 1 \ \|
// (0,0) o-----o-----o (1,0) (0,0) o-----o-----o (1,0) o (0,1)
//
// The triangular case also takes and returns/affects the rotation of the
// quadrant being searched and identified (quadrant 3 imparts a rotation).
//
template <class T>
inline int
PatchMap::transformUVToQuadQuadrant(T const & median, T & u, T & v) {
int uHalf = (u >= median);
if (uHalf) u -= median;
int vHalf = (v >= median);
if (vHalf) v -= median;
return (vHalf << 1) | uHalf;
}
template <class T>
int inline
PatchMap::transformUVToTriQuadrant(T const & median, T & u, T & v, bool & rotated) {
if (!rotated) {
if (u >= median) {
u -= median;
return 1;
}
if (v >= median) {
v -= median;
return 2;
}
if ((u + v) >= median) {
rotated = true;
return 3;
}
return 0;
} else {
if (u < median) {
v -= median;
return 1;
}
if (v < median) {
u -= median;
return 2;
}
u -= median;
v -= median;
if ((u + v) < median) {
rotated = false;
return 3;
}
return 0;
}
}
/// Returns a handle to the sub-patch of the face at the given (u,v).
inline PatchMap::Handle const *
PatchMap::FindPatch( int faceid, double u, double v ) const {
//
// Reject patch faces not supported by this map, or those corresponding
// to holes or otherwise unassigned (the root node for a patch will
// have all or no quadrants set):
//
if ((faceid < _minPatchFace) || (faceid > _maxPatchFace)) return 0;
QuadNode const * node = &_quadtree[faceid - _minPatchFace];
if (!node->children[0].isSet) return 0;
//
// Search the tree for the sub-patch containing the given (u,v)
//
assert( (u>=0.0) && (u<=1.0) && (v>=0.0) && (v<=1.0) );
double median = 0.5;
bool triRotated = false;
for (int depth = 0; depth <= _maxDepth; ++depth, median *= 0.5) {
int quadrant = _patchesAreTriangular
? transformUVToTriQuadrant(median, u, v, triRotated)
: transformUVToQuadQuadrant(median, u, v);
// holes should have been rejected at the root node of the face
assert(node->children[quadrant].isSet);
if (node->children[quadrant].isLeaf) {
return &_handles[node->children[quadrant].index];
} else {
node = &_quadtree[node->children[quadrant].index];
}
}
assert(0);
return 0;
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_PATCH_PARAM */
+332
View File
@@ -0,0 +1,332 @@
//
// Copyright 2013 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_FAR_PATCH_PARAM_H
#define OPENSUBDIV3_FAR_PATCH_PARAM_H
#include "../version.h"
#include "../far/types.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
/// \brief Patch parameterization
///
/// Topological refinement splits coarse mesh faces into refined faces.
///
/// This patch parameterzation describes the relationship between one
/// of these refined faces and its corresponding coarse face. It is used
/// both for refined faces that are represented as full limit surface
/// parametric patches as well as for refined faces represented as simple
/// triangles or quads. This parameterization is needed to interpolate
/// primvar data across a refined face.
///
/// The U,V and refinement level parameters describe the scale and offset
/// needed to map a location on the patch between levels of refinement.
/// The encoding of these values exploits the quad-tree organization of
/// the faces produced by subdivision. We encode the U,V origin of the
/// patch using two 10-bit integer values and the refinement level as
/// a 4-bit integer. This is sufficient to represent up through 10 levels
/// of refinement.
///
/// Special consideration must be given to the refined faces resulting from
/// irregular coarse faces. We adopt a convention similar to Ptex texture
/// mapping and define the parameterization for these faces in terms of the
/// regular faces resulting from the first topological splitting of the
/// irregular coarse face.
///
/// When computing the basis functions needed to evaluate the limit surface
/// parametric patch representing a refined face, we also need to know which
/// edges of the patch are interpolated boundaries. These edges are encoded
/// as a boundary bitmask identifying the boundary edges of the patch in
/// sequential order starting from the first vertex of the refined face.
///
/// A sparse topological refinement (like feature adaptive refinement) can
/// produce refined faces that are adjacent to faces at the next level of
/// subdivision. We identify these transitional edges with a transition
/// bitmask using the same encoding as the boundary bitmask.
///
/// For triangular subdivision schemes we specify the parameterization using
/// a similar method. Alternate triangles at a given level of refinement
/// are parameterized from their opposite corners and encoded as occupying
/// the opposite diagonal of the quad-tree hierarchy. The third barycentric
/// coordinate is dependent on and can be derived from the other two
/// coordinates. This encoding also takes inspiration from the Ptex
/// texture mapping specification.
///
/// Bitfield layout :
///
/// Field0 | Bits | Content
/// -----------|:----:|------------------------------------------------------
/// faceId | 28 | the faceId of the patch
/// transition | 4 | transition edge mask encoding
///
/// Field1 | Bits | Content
/// -----------|:----:|------------------------------------------------------
/// level | 4 | the subdivision level of the patch
/// nonquad | 1 | whether patch is refined from a non-quad face
/// regular | 1 | whether patch is regular
/// unused | 1 | unused
/// boundary | 5 | boundary edge mask encoding
/// v | 10 | log2 value of u parameter at first patch corner
/// u | 10 | log2 value of v parameter at first patch corner
///
/// Note : the bitfield is not expanded in the struct due to differences in how
/// GPU & CPU compilers pack bit-fields and endian-ness.
///
/*!
\verbatim
Quad Patch Parameterization
(0,1) (1,1)
+-------+-------+---------------+
| | | |
| L2 | L2 | |
|0,3 |1,3 | |
+-------+-------+ L1 |
| | | |
| L2 | L2 | |
|0,2 |1,2 |1,1 |
+-------+-------+---------------+
| | |
| | |
| | |
| L1 | L1 |
| | |
| | |
|0,0 |1,0 |
+---------------+---------------+
(0,0) (1,0)
\endverbatim
*/
/*!
\verbatim
Triangle Patch Parameterization
(0,1) (1,1) (0,1,0)
+-------+-------+---------------+ +
| \ | \ | \ | | \
|L2 \ |L2 \ | \ | | \
|0,3 \ |1,3 \ | \ | | L2 \
+-------+-------+ \ | +-------+
| \ | \ | L1 \ | | \ L2 | \
|L2 \ |L2 \ | \ | | \ | \
|0,2 \ |1,2 \ |1,1 \ | | L2 \ | L2 \
+-------+-------+---------------+ +-------+-------+
| \ | \ | | \ | \
| \ | \ | | \ | \
| \ | \ | | \ L1 | \
| \ | \ | | \ | \
| L1 \ | L1 \ | | L1 \ | L1 \
| \ | \ | | \ | \
|0,0 \ |1,0 \ | | \ | \
+---------------+---------------+ +---------------+---------------+
(0,0) (1,0) (0,0,1) (1,0,0)
\endverbatim
*/
struct PatchParam {
/// \brief Sets the values of the bit fields
///
/// @param faceid face index
///
/// @param u value of the u parameter for the first corner of the face
/// @param v value of the v parameter for the first corner of the face
///
/// @param depth subdivision level of the patch
/// @param nonquad true if the root face is not a quad
///
/// @param boundary 5-bits identifying boundary edges (and verts for tris)
/// @param transition 4-bits identifying transition edges
///
/// @param regular whether the patch is regular
///
void Set(Index faceid, short u, short v,
unsigned short depth, bool nonquad,
unsigned short boundary, unsigned short transition,
bool regular = false);
/// \brief Resets everything to 0
void Clear() { field0 = field1 = 0; }
/// \brief Returns the faceid
Index GetFaceId() const { return Index(unpack(field0,28,0)); }
/// \brief Returns the log2 value of the u parameter at
/// the first corner of the patch
unsigned short GetU() const { return (unsigned short)unpack(field1,10,22); }
/// \brief Returns the log2 value of the v parameter at
/// the first corner of the patch
unsigned short GetV() const { return (unsigned short)unpack(field1,10,12); }
/// \brief Returns the transition edge encoding for the patch.
unsigned short GetTransition() const { return (unsigned short)unpack(field0,4,28); }
/// \brief Returns the boundary edge encoding for the patch.
unsigned short GetBoundary() const { return (unsigned short)unpack(field1,5,7); }
/// \brief True if the parent base face is a non-quad
bool NonQuadRoot() const { return (unpack(field1,1,4) != 0); }
/// \brief Returns the level of subdivision of the patch
unsigned short GetDepth() const { return (unsigned short)unpack(field1,4,0); }
/// \brief Returns the fraction of unit parametric space covered by this face.
float GetParamFraction() const;
/// \brief A (u,v) pair in the fraction of parametric space covered by this
/// face is mapped into a normalized parametric space.
///
/// @param u u parameter
/// @param v v parameter
///
template <typename REAL>
void Normalize( REAL & u, REAL & v ) const;
template <typename REAL>
void NormalizeTriangle( REAL & u, REAL & v ) const;
/// \brief A (u,v) pair in a normalized parametric space is mapped back into the
/// fraction of parametric space covered by this face.
///
/// @param u u parameter
/// @param v v parameter
///
template <typename REAL>
void Unnormalize( REAL & u, REAL & v ) const;
template <typename REAL>
void UnnormalizeTriangle( REAL & u, REAL & v ) const;
/// \brief Returns if a triangular patch is parametrically rotated 180 degrees
bool IsTriangleRotated() const;
/// \brief Returns whether the patch is regular
bool IsRegular() const { return (unpack(field1,1,5) != 0); }
unsigned int field0:32;
unsigned int field1:32;
private:
unsigned int pack(unsigned int value, int width, int offset) const {
return (unsigned int)((value & ((1<<width)-1)) << offset);
}
unsigned int unpack(unsigned int value, int width, int offset) const {
return (unsigned int)((value >> offset) & ((1<<width)-1));
}
};
typedef std::vector<PatchParam> PatchParamTable;
typedef Vtr::Array<PatchParam> PatchParamArray;
typedef Vtr::ConstArray<PatchParam> ConstPatchParamArray;
inline void
PatchParam::Set(Index faceid, short u, short v,
unsigned short depth, bool nonquad,
unsigned short boundary, unsigned short transition,
bool regular) {
field0 = pack(faceid, 28, 0) |
pack(transition, 4, 28);
field1 = pack(u, 10, 22) |
pack(v, 10, 12) |
pack(boundary, 5, 7) |
pack(regular, 1, 5) |
pack(nonquad, 1, 4) |
pack(depth, 4, 0);
}
inline float
PatchParam::GetParamFraction( ) const {
return 1.0f / (float)(1 << (GetDepth() - NonQuadRoot()));
}
template <typename REAL>
inline void
PatchParam::Normalize( REAL & u, REAL & v ) const {
REAL fracInv = (REAL)(1.0f / GetParamFraction());
u = u * fracInv - (REAL)GetU();
v = v * fracInv - (REAL)GetV();
}
template <typename REAL>
inline void
PatchParam::Unnormalize( REAL & u, REAL & v ) const {
REAL frac = (REAL)GetParamFraction();
u = (u + (REAL)GetU()) * frac;
v = (v + (REAL)GetV()) * frac;
}
inline bool
PatchParam::IsTriangleRotated() const {
return (GetU() + GetV()) >= (1 << GetDepth());
}
template <typename REAL>
inline void
PatchParam::NormalizeTriangle( REAL & u, REAL & v ) const {
if (IsTriangleRotated()) {
REAL fracInv = (REAL)(1.0f / GetParamFraction());
int depthFactor = 1 << GetDepth();
u = (REAL)(depthFactor - GetU()) - (u * fracInv);
v = (REAL)(depthFactor - GetV()) - (v * fracInv);
} else {
Normalize(u, v);
}
}
template <typename REAL>
inline void
PatchParam::UnnormalizeTriangle( REAL & u, REAL & v ) const {
if (IsTriangleRotated()) {
REAL frac = GetParamFraction();
int depthFactor = 1 << GetDepth();
u = ((REAL)(depthFactor - GetU()) - u) * frac;
v = ((REAL)(depthFactor - GetV()) - v) * frac;
} else {
Unnormalize(u, v);
}
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_PATCH_PARAM */
+861
View File
@@ -0,0 +1,861 @@
//
// Copyright 2013 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_FAR_PATCH_TABLE_H
#define OPENSUBDIV3_FAR_PATCH_TABLE_H
#include "../version.h"
#include "../far/patchDescriptor.h"
#include "../far/patchParam.h"
#include "../far/stencilTable.h"
#include "../sdc/options.h"
#include <vector>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
/// \brief Container for arrays of parametric patches
///
/// PatchTable contains topology and parametric information about the patches
/// generated by the Refinement process. Patches in the table are sorted into
/// arrays based on their PatchDescriptor Type.
///
/// Note : PatchTable can be accessed either using a PatchHandle or a
/// combination of array and patch indices.
///
/// XXXX manuelk we should add a PatchIterator that can dereference into
/// a PatchHandle for fast linear traversal of the table
///
class PatchTable {
public:
/// \brief Handle that can be used as unique patch identifier within PatchTable
class PatchHandle {
// XXXX manuelk members will eventually be made private
public:
friend class PatchTable;
friend class PatchMap;
Index arrayIndex, // Array index of the patch
patchIndex, // Absolute Index of the patch
vertIndex; // Relative offset to the first CV of the patch in array
};
public:
/// \brief Copy constructor
PatchTable(PatchTable const & src);
/// \brief Destructor
~PatchTable();
/// \brief True if the patches are of feature adaptive types
bool IsFeatureAdaptive() const;
/// \brief Returns the total number of control vertex indices in the table
int GetNumControlVerticesTotal() const {
return (int)_patchVerts.size();
}
/// \brief Returns the total number of patches stored in the table
int GetNumPatchesTotal() const;
/// \brief Returns max vertex valence
int GetMaxValence() const { return _maxValence; }
/// \brief Returns the total number of ptex faces in the mesh
int GetNumPtexFaces() const { return _numPtexFaces; }
//@{
/// @name Individual patches
///
/// \anchor individual_patches
///
/// \brief Accessors for individual patches
///
/// \brief Returns the PatchDescriptor for the patch identified by \p handle
PatchDescriptor GetPatchDescriptor(PatchHandle const & handle) const;
/// \brief Returns the control vertex indices for the patch identified by \p handle
ConstIndexArray GetPatchVertices(PatchHandle const & handle) const;
/// \brief Returns a PatchParam for the patch identified by \p handle
PatchParam GetPatchParam(PatchHandle const & handle) const;
/// \brief Returns the control vertex indices for \p patch in \p array
ConstIndexArray GetPatchVertices(int array, int patch) const;
/// \brief Returns the PatchParam for \p patch in \p array
PatchParam GetPatchParam(int array, int patch) const;
//@}
//@{
/// @name Arrays of patches
///
/// \anchor arrays_of_patches
///
/// \brief Accessors for arrays of patches of the same type
///
/// \brief Returns the number of patch arrays in the table
int GetNumPatchArrays() const;
/// \brief Returns the number of patches in \p array
int GetNumPatches(int array) const;
/// \brief Returns the number of control vertices in \p array
int GetNumControlVertices(int array) const;
/// \brief Returns the PatchDescriptor for the patches in \p array
PatchDescriptor GetPatchArrayDescriptor(int array) const;
/// \brief Returns the control vertex indices for the patches in \p array
ConstIndexArray GetPatchArrayVertices(int array) const;
/// \brief Returns the PatchParams for the patches in \p array
ConstPatchParamArray const GetPatchParams(int array) const;
//@}
//@{
/// @name Change of basis patches
///
/// \anchor change_of_basis_patches
///
/// \brief Accessors for change of basis patches
///
///
/// \brief Returns the number of local vertex points.
int GetNumLocalPoints() const;
/// \brief Returns the stencil table to compute local point vertex values
StencilTable const *GetLocalPointStencilTable() const;
/// \brief Returns the stencil table to compute local point vertex values
template <typename REAL>
StencilTableReal<REAL> const *GetLocalPointStencilTable() const;
/// \brief Tests if the precision of the stencil table to compute local point
/// vertex values matches the given floating point type \<REAL\>.
template <typename REAL> bool LocalPointStencilPrecisionMatchesType() const;
/// \brief Updates local point vertex values.
///
/// @param src Buffer with primvar data for the base and refined
/// vertex values
///
/// @param dst Destination buffer for the computed local point
/// vertex values
///
/// For more flexibility computing local vertex points, retrieval of
/// the local point stencil table and use of its public methods is
/// recommended or often required.
///
template <class T> void
ComputeLocalPointValues(T const *src, T *dst) const;
/// \brief Returns the number of local varying points.
int GetNumLocalPointsVarying() const;
/// \brief Returns the stencil table to compute local point varying values
StencilTable const *GetLocalPointVaryingStencilTable() const;
/// \brief Returns the stencil table to compute local point varying values
template <typename REAL>
StencilTableReal<REAL> const *GetLocalPointVaryingStencilTable() const;
/// \brief Tests if the precision of the stencil table to compute local point
/// varying values matches the given floating point type \<REAL\>.
template <typename REAL> bool LocalPointVaryingStencilPrecisionMatchesType() const;
/// \brief Updates local point varying values.
///
/// @param src Buffer with primvar data for the base and refined
/// varying values
///
/// @param dst Destination buffer for the computed local point
/// varying values
///
/// For more flexibility computing local varying points, retrieval of
/// the local point varying stencil table and use of its public methods
/// is recommended or often required.
///
template <class T> void
ComputeLocalPointValuesVarying(T const *src, T *dst) const;
/// \brief Returns the number of local face-varying points for \p channel
int GetNumLocalPointsFaceVarying(int channel = 0) const;
/// \brief Returns the stencil table to compute local point face-varying values
StencilTable const *GetLocalPointFaceVaryingStencilTable(int channel = 0) const;
/// \brief Returns the stencil table to compute local point face-varying values
template <typename REAL>
StencilTableReal<REAL> const * GetLocalPointFaceVaryingStencilTable(int channel = 0) const;
/// \brief Tests if the precision of the stencil table to compute local point
/// face-varying values matches the given floating point type \<REAL\>.
template <typename REAL> bool LocalPointFaceVaryingStencilPrecisionMatchesType() const;
/// \brief Updates local point face-varying values.
///
/// @param src Buffer with primvar data for the base and refined
/// face-varying values
///
/// @param dst Destination buffer for the computed local point
/// face-varying values
///
/// @param channel face-varying channel
///
/// For more flexibility computing local face-varying points, retrieval
/// of the local point face-varying stencil table and use of its public
/// methods is recommended or often required.
///
template <class T> void
ComputeLocalPointValuesFaceVarying(T const *src, T *dst, int channel = 0) const;
//@}
//@{
/// @name Legacy gregory patch evaluation buffers
/// \brief Accessors for the gregory patch evaluation buffers.
/// These methods will be deprecated.
///
typedef Vtr::ConstArray<unsigned int> ConstQuadOffsetsArray;
/// \brief Returns the 'QuadOffsets' for the Gregory patch identified by \p handle
ConstQuadOffsetsArray GetPatchQuadOffsets(PatchHandle const & handle) const;
typedef std::vector<Index> VertexValenceTable;
/// \brief Returns the 'VertexValences' table (vertex neighborhoods table)
VertexValenceTable const & GetVertexValenceTable() const {
return _vertexValenceTable;
}
//@}
//@{
/// @name Single-crease patches
///
/// \anchor single_crease_patches
///
/// \brief Accessors for single-crease patch edge sharpness
///
/// \brief Returns the crease sharpness for the patch identified by \p handle
/// if it is a single-crease patch, or 0.0f
float GetSingleCreasePatchSharpnessValue(PatchHandle const & handle) const;
/// \brief Returns the crease sharpness for the \p patch in \p array
/// if it is a single-crease patch, or 0.0f
float GetSingleCreasePatchSharpnessValue(int array, int patch) const;
//@}
//@{
/// @name Varying data
///
/// \anchor varying_data
///
/// \brief Accessors for varying data
///
/// \brief Returns the varying patch descriptor
PatchDescriptor GetVaryingPatchDescriptor() const;
/// \brief Returns the varying vertex indices for a given patch
ConstIndexArray GetPatchVaryingVertices(PatchHandle const & handle) const;
/// \brief Returns the varying vertex indices for a given patch
ConstIndexArray GetPatchVaryingVertices(int array, int patch) const;
/// \brief Returns the varying vertex indices for the patches in \p array
ConstIndexArray GetPatchArrayVaryingVertices(int array) const;
/// \brief Returns an array of varying vertex indices for the patches.
ConstIndexArray GetVaryingVertices() const;
//@}
//@{
/// @name Face-varying channels
///
/// \anchor face_varying_channels
///
/// \brief Accessors for face-varying channels
///
/// \brief Returns the number of face-varying channels
int GetNumFVarChannels() const;
/// \brief Returns the regular patch descriptor for \p channel
PatchDescriptor GetFVarPatchDescriptorRegular(int channel = 0) const;
/// \brief Returns the irregular patch descriptor for \p channel
PatchDescriptor GetFVarPatchDescriptorIrregular(int channel = 0) const;
/// \brief Returns the default/irregular patch descriptor for \p channel
PatchDescriptor GetFVarPatchDescriptor(int channel = 0) const;
/// \brief Returns the value indices for a given patch in \p channel
ConstIndexArray GetPatchFVarValues(PatchHandle const & handle, int channel = 0) const;
/// \brief Returns the value indices for a given patch in \p channel
ConstIndexArray GetPatchFVarValues(int array, int patch, int channel = 0) const;
/// \brief Returns the value indices for the patches in \p array in \p channel
ConstIndexArray GetPatchArrayFVarValues(int array, int channel = 0) const;
/// \brief Returns an array of value indices for the patches in \p channel
ConstIndexArray GetFVarValues(int channel = 0) const;
/// \brief Returns the stride between patches in the value index array of \p channel
int GetFVarValueStride(int channel = 0) const;
/// \brief Returns the value indices for a given patch in \p channel
PatchParam GetPatchFVarPatchParam(PatchHandle const & handle, int channel = 0) const;
/// \brief Returns the face-varying params for a given patch \p channel
PatchParam GetPatchFVarPatchParam(int array, int patch, int channel = 0) const;
/// \brief Returns the face-varying for a given patch in \p array in \p channel
ConstPatchParamArray GetPatchArrayFVarPatchParams(int array, int channel = 0) const;
/// \brief Returns an array of face-varying patch param for \p channel
ConstPatchParamArray GetFVarPatchParams(int channel = 0) const;
/// \brief Deprecated @see PatchTable#GetFVarPatchDescriptor
Sdc::Options::FVarLinearInterpolation GetFVarChannelLinearInterpolation(int channel = 0) const;
//@}
//@{
/// @name Direct accessors
///
/// \warning These direct accessors are left for convenience, but they are
/// likely going to be deprecated in future releases
///
typedef std::vector<Index> PatchVertsTable;
/// \brief Get the table of patch control vertices
PatchVertsTable const & GetPatchControlVerticesTable() const { return _patchVerts; }
/// \brief Returns the PatchParamTable (PatchParams order matches patch array sorting)
PatchParamTable const & GetPatchParamTable() const { return _paramTable; }
/// \brief Returns a sharpness index table for each patch (if exists)
std::vector<Index> const &GetSharpnessIndexTable() const { return _sharpnessIndices; }
/// \brief Returns sharpness values table
std::vector<float> const &GetSharpnessValues() const { return _sharpnessValues; }
typedef std::vector<unsigned int> QuadOffsetsTable;
/// \brief Returns the quad-offsets table
QuadOffsetsTable const & GetQuadOffsetsTable() const {
return _quadOffsetsTable;
}
//@}
/// debug helper
void print() const;
public:
//@{
/// @name Evaluation methods
///
/// \brief Evaluate basis functions for position and derivatives at a
/// given (u,v) parametric location of a patch.
///
/// @param handle A patch handle identifying the sub-patch containing the
/// (u,v) location
///
/// @param u Patch coordinate (in base face normalized space)
///
/// @param v Patch coordinate (in base face normalized space)
///
/// @param wP Weights (evaluated basis functions) for the position
///
/// @param wDu Weights (evaluated basis functions) for derivative wrt u
///
/// @param wDv Weights (evaluated basis functions) for derivative wrt v
///
/// @param wDuu Weights (evaluated basis functions) for 2nd derivative wrt u
///
/// @param wDuv Weights (evaluated basis functions) for 2nd derivative wrt u and v
///
/// @param wDvv Weights (evaluated basis functions) for 2nd derivative wrt v
///
template <typename REAL>
void EvaluateBasis(PatchHandle const & handle, REAL u, REAL v,
REAL wP[], REAL wDu[] = 0, REAL wDv[] = 0,
REAL wDuu[] = 0, REAL wDuv[] = 0, REAL wDvv[] = 0) const;
/// \brief An overloaded version to assist template parameter resolution
/// when explicitly declaring unused array arguments as 0.
void EvaluateBasis(PatchHandle const & handle, float u, float v,
float wP[], float wDu[] = 0, float wDv[] = 0,
float wDuu[] = 0, float wDuv[] = 0, float wDvv[] = 0) const;
/// \brief An overloaded version to assist template parameter resolution
/// when explicitly declaring unused array arguments as 0.
void EvaluateBasis(PatchHandle const & handle, double u, double v,
double wP[], double wDu[] = 0, double wDv[] = 0,
double wDuu[] = 0, double wDuv[] = 0, double wDvv[] = 0) const;
/// \brief Evaluate basis functions for a varying value and
/// derivatives at a given (u,v) parametric location of a patch.
///
/// @param handle A patch handle identifying the sub-patch containing the
/// (u,v) location
///
/// @param u Patch coordinate (in base face normalized space)
///
/// @param v Patch coordinate (in base face normalized space)
///
/// @param wP Weights (evaluated basis functions) for the position
///
/// @param wDu Weights (evaluated basis functions) for derivative wrt u
///
/// @param wDv Weights (evaluated basis functions) for derivative wrt v
///
/// @param wDuu Weights (evaluated basis functions) for 2nd derivative wrt u
///
/// @param wDuv Weights (evaluated basis functions) for 2nd derivative wrt u and v
///
/// @param wDvv Weights (evaluated basis functions) for 2nd derivative wrt v
///
template <typename REAL>
void EvaluateBasisVarying(PatchHandle const & handle, REAL u, REAL v,
REAL wP[], REAL wDu[] = 0, REAL wDv[] = 0,
REAL wDuu[] = 0, REAL wDuv[] = 0, REAL wDvv[] = 0) const;
/// \brief An overloaded version to assist template parameter resolution
/// when explicitly declaring unused array arguments as 0.
void EvaluateBasisVarying(PatchHandle const & handle, float u, float v,
float wP[], float wDu[] = 0, float wDv[] = 0,
float wDuu[] = 0, float wDuv[] = 0, float wDvv[] = 0) const;
/// \brief An overloaded version to assist template parameter resolution
/// when explicitly declaring unused array arguments as 0.
void EvaluateBasisVarying(PatchHandle const & handle, double u, double v,
double wP[], double wDu[] = 0, double wDv[] = 0,
double wDuu[] = 0, double wDuv[] = 0, double wDvv[] = 0) const;
/// \brief Evaluate basis functions for a face-varying value and
/// derivatives at a given (u,v) parametric location of a patch.
///
/// @param handle A patch handle identifying the sub-patch containing the
/// (u,v) location
///
/// @param u Patch coordinate (in base face normalized space)
///
/// @param v Patch coordinate (in base face normalized space)
///
/// @param wP Weights (evaluated basis functions) for the position
///
/// @param wDu Weights (evaluated basis functions) for derivative wrt u
///
/// @param wDv Weights (evaluated basis functions) for derivative wrt v
///
/// @param wDuu Weights (evaluated basis functions) for 2nd derivative wrt u
///
/// @param wDuv Weights (evaluated basis functions) for 2nd derivative wrt u and v
///
/// @param wDvv Weights (evaluated basis functions) for 2nd derivative wrt v
///
/// @param channel face-varying channel
///
template <typename REAL>
void EvaluateBasisFaceVarying(PatchHandle const & handle, REAL u, REAL v,
REAL wP[], REAL wDu[] = 0, REAL wDv[] = 0,
REAL wDuu[] = 0, REAL wDuv[] = 0, REAL wDvv[] = 0,
int channel = 0) const;
/// \brief An overloaded version to assist template parameter resolution
/// when explicitly declaring unused array arguments as 0.
void EvaluateBasisFaceVarying(PatchHandle const & handle, float u, float v,
float wP[], float wDu[] = 0, float wDv[] = 0,
float wDuu[] = 0, float wDuv[] = 0, float wDvv[] = 0,
int channel = 0) const;
/// \brief An overloaded version to assist template parameter resolution
/// when explicitly declaring unused array arguments as 0.
void EvaluateBasisFaceVarying(PatchHandle const & handle, double u, double v,
double wP[], double wDu[] = 0, double wDv[] = 0,
double wDuu[] = 0, double wDuv[] = 0, double wDvv[] = 0,
int channel = 0) const;
//@}
protected:
friend class PatchTableBuilder;
// Factory constructor
PatchTable(int maxvalence);
Index getPatchIndex(int array, int patch) const;
PatchParamArray getPatchParams(int arrayIndex);
Index * getSharpnessIndices(Index arrayIndex);
float * getSharpnessValues(Index arrayIndex);
private:
//
// Patch arrays
//
struct PatchArray;
typedef std::vector<PatchArray> PatchArrayVector;
PatchArray & getPatchArray(Index arrayIndex);
PatchArray const & getPatchArray(Index arrayIndex) const;
void reservePatchArrays(int numPatchArrays);
void pushPatchArray(PatchDescriptor desc, int npatches,
Index * vidx, Index * pidx, Index * qoidx=0);
IndexArray getPatchArrayVertices(int arrayIndex);
Index findPatchArray(PatchDescriptor desc);
//
// Varying patch arrays
//
IndexArray getPatchArrayVaryingVertices(int arrayIndex);
void allocateVaryingVertices(
PatchDescriptor desc, int numPatches);
void populateVaryingVertices();
//
// Face-varying patch channels
//
struct FVarPatchChannel;
typedef std::vector<FVarPatchChannel> FVarPatchChannelVector;
FVarPatchChannel & getFVarPatchChannel(int channel);
FVarPatchChannel const & getFVarPatchChannel(int channel) const;
void allocateFVarPatchChannels(int numChannels);
void allocateFVarPatchChannelValues(
PatchDescriptor regDesc, PatchDescriptor irregDesc,
int numPatches, int channel);
// deprecated
void setFVarPatchChannelLinearInterpolation(
Sdc::Options::FVarLinearInterpolation interpolation, int channel);
IndexArray getFVarValues(int channel);
ConstIndexArray getPatchFVarValues(int patch, int channel) const;
PatchParamArray getFVarPatchParams(int channel);
PatchParam getPatchFVarPatchParam(int patch, int channel) const;
private:
//
// Simple private class to hold stencil table pointers of varying precision,
// where the discriminant of the precision is external.
//
// NOTE that this is a simple pointer container and NOT a smart pointer that
// manages the ownership of the object referred to by it.
//
class StencilTablePtr {
private:
typedef StencilTableReal<float> float_type;
typedef StencilTableReal<double> double_type;
union {
float_type * _fPtr;
double_type * _dPtr;
};
public:
StencilTablePtr() { _fPtr = 0; }
StencilTablePtr(float_type * ptr) { _fPtr = ptr; }
StencilTablePtr(double_type * ptr) { _dPtr = ptr; }
operator bool() const { return _fPtr != 0; }
void Set() { _fPtr = 0; }
void Set(float_type * ptr) { _fPtr = ptr; }
void Set(double_type * ptr) { _dPtr = ptr; }
template <typename REAL> StencilTableReal<REAL> * Get() const;
};
private:
//
// Topology
//
int _maxValence, // highest vertex valence found in the mesh
_numPtexFaces; // total number of ptex faces
PatchArrayVector _patchArrays; // Vector of descriptors for arrays of patches
std::vector<Index> _patchVerts; // Indices of the control vertices of the patches
PatchParamTable _paramTable; // PatchParam bitfields (one per patch)
//
// Extraordinary vertex closed-form evaluation / endcap basis conversion
//
// XXXtakahito: these data will probably be replaced with mask coefficient or something
// SchemeWorker populates.
//
QuadOffsetsTable _quadOffsetsTable; // Quad offsets (for Gregory patches)
VertexValenceTable _vertexValenceTable; // Vertex valence table (for Gregory patches)
StencilTablePtr _localPointStencils; // local point conversion stencils
StencilTablePtr _localPointVaryingStencils; // local point varying stencils
//
// Varying data
//
PatchDescriptor _varyingDesc;
std::vector<Index> _varyingVerts;
//
// Face-varying data
//
FVarPatchChannelVector _fvarChannels;
std::vector<StencilTablePtr> _localPointFaceVaryingStencils;
//
// 'single-crease' patch sharpness tables
//
std::vector<Index> _sharpnessIndices; // Indices of single-crease sharpness (one per patch)
std::vector<float> _sharpnessValues; // Sharpness values.
//
// Construction history -- relevant to at least one public query:
//
unsigned int _isUniformLinear : 1;
//
// Precision -- only applies to local-point stencil tables
//
unsigned int _vertexPrecisionIsDouble : 1;
unsigned int _varyingPrecisionIsDouble : 1;
unsigned int _faceVaryingPrecisionIsDouble : 1;
};
//
// Template specializations for float/double -- to be defined before used:
//
template <> inline StencilTableReal<float> *
PatchTable::StencilTablePtr::Get<float>() const { return _fPtr; }
template <> inline StencilTableReal<double> *
PatchTable::StencilTablePtr::Get<double>() const { return _dPtr; }
template <> inline bool
PatchTable::LocalPointStencilPrecisionMatchesType<float>() const {
return !_vertexPrecisionIsDouble;
}
template <> inline bool
PatchTable::LocalPointVaryingStencilPrecisionMatchesType<float>() const {
return !_varyingPrecisionIsDouble;
}
template <> inline bool
PatchTable::LocalPointFaceVaryingStencilPrecisionMatchesType<float>() const {
return !_faceVaryingPrecisionIsDouble;
}
template <> inline bool
PatchTable::LocalPointStencilPrecisionMatchesType<double>() const {
return _vertexPrecisionIsDouble;
}
template <> inline bool
PatchTable::LocalPointVaryingStencilPrecisionMatchesType<double>() const {
return _varyingPrecisionIsDouble;
}
template <> inline bool
PatchTable::LocalPointFaceVaryingStencilPrecisionMatchesType<double>() const {
return _faceVaryingPrecisionIsDouble;
}
//
// StencilTable access -- backward compatible and generic:
//
inline StencilTable const *
PatchTable::GetLocalPointStencilTable() const {
assert(LocalPointStencilPrecisionMatchesType<float>());
return static_cast<StencilTable const *>(_localPointStencils.Get<float>());
}
inline StencilTable const *
PatchTable::GetLocalPointVaryingStencilTable() const {
assert(LocalPointVaryingStencilPrecisionMatchesType<float>());
return static_cast<StencilTable const *>(
_localPointVaryingStencils.Get<float>());
}
inline StencilTable const *
PatchTable::GetLocalPointFaceVaryingStencilTable(int channel) const {
assert(LocalPointFaceVaryingStencilPrecisionMatchesType<float>());
if (channel >= 0 && channel < (int)_localPointFaceVaryingStencils.size()) {
return static_cast<StencilTable const *>(
_localPointFaceVaryingStencils[channel].Get<float>());
}
return NULL;
}
template <typename REAL>
inline StencilTableReal<REAL> const *
PatchTable::GetLocalPointStencilTable() const {
assert(LocalPointStencilPrecisionMatchesType<REAL>());
return _localPointStencils.Get<REAL>();
}
template <typename REAL>
inline StencilTableReal<REAL> const *
PatchTable::GetLocalPointVaryingStencilTable() const {
assert(LocalPointVaryingStencilPrecisionMatchesType<REAL>());
return _localPointVaryingStencils.Get<REAL>();
}
template <typename REAL>
inline StencilTableReal<REAL> const *
PatchTable::GetLocalPointFaceVaryingStencilTable(int channel) const {
assert(LocalPointFaceVaryingStencilPrecisionMatchesType<REAL>());
if (channel >= 0 && channel < (int)_localPointFaceVaryingStencils.size()) {
return _localPointFaceVaryingStencils[channel].Get<REAL>();
}
return NULL;
}
//
// Computation of local point values:
//
template <class T>
inline void
PatchTable::ComputeLocalPointValues(T const *src, T *dst) const {
assert(LocalPointStencilPrecisionMatchesType<float>());
if (_localPointStencils) {
_localPointStencils.Get<float>()->UpdateValues(src, dst);
}
}
template <class T>
inline void
PatchTable::ComputeLocalPointValuesVarying(T const *src, T *dst) const {
assert(LocalPointVaryingStencilPrecisionMatchesType<float>());
if (_localPointVaryingStencils) {
_localPointVaryingStencils.Get<float>()->UpdateValues(src, dst);
}
}
template <class T>
inline void
PatchTable::ComputeLocalPointValuesFaceVarying(T const *src, T *dst, int channel) const {
assert(LocalPointFaceVaryingStencilPrecisionMatchesType<float>());
if (channel >= 0 && channel < (int)_localPointFaceVaryingStencils.size()) {
if (_localPointFaceVaryingStencils[channel]) {
_localPointFaceVaryingStencils[channel].Get<float>()->UpdateValues(src, dst);
}
}
}
//
// Basis evaluation overloads
//
inline void
PatchTable::EvaluateBasis(PatchHandle const & handle, float u, float v,
float wP[], float wDu[], float wDv[],
float wDuu[], float wDuv[], float wDvv[]) const {
EvaluateBasis<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
}
inline void
PatchTable::EvaluateBasis(PatchHandle const & handle, double u, double v,
double wP[], double wDu[], double wDv[],
double wDuu[], double wDuv[], double wDvv[]) const {
EvaluateBasis<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
}
inline void
PatchTable::EvaluateBasisVarying(PatchHandle const & handle, float u, float v,
float wP[], float wDu[], float wDv[],
float wDuu[], float wDuv[], float wDvv[]) const {
EvaluateBasisVarying<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
}
inline void
PatchTable::EvaluateBasisVarying(PatchHandle const & handle, double u, double v,
double wP[], double wDu[], double wDv[],
double wDuu[], double wDuv[], double wDvv[]) const {
EvaluateBasisVarying<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
}
inline void
PatchTable::EvaluateBasisFaceVarying(PatchHandle const & handle, float u, float v,
float wP[], float wDu[], float wDv[],
float wDuu[], float wDuv[], float wDvv[], int channel) const {
EvaluateBasisFaceVarying<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv, channel);
}
inline void
PatchTable::EvaluateBasisFaceVarying(PatchHandle const & handle, double u, double v,
double wP[], double wDu[], double wDv[],
double wDuu[], double wDuv[], double wDvv[], int channel) const {
EvaluateBasisFaceVarying<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv, channel);
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_PATCH_TABLE */
+232
View File
@@ -0,0 +1,232 @@
//
// Copyright 2013 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_FAR_PATCH_TABLE_FACTORY_H
#define OPENSUBDIV3_FAR_PATCH_TABLE_FACTORY_H
#include "../version.h"
#include "../far/topologyRefiner.h"
#include "../far/patchTable.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
/// \brief Factory for constructing a PatchTable from a TopologyRefiner
///
class PatchTableFactory {
public:
/// \brief Public options for the PatchTable factory
///
struct Options {
/// \brief Choice for approximating irregular patches (end-caps)
///
/// This enum specifies how irregular patches (end-caps) are approximated.
/// A basis is chosen, rather than a specific patch type, and has a
/// corresponding patch type for each subdivision scheme, i.e. a quad and
/// triangular patch type exists for each basis. These choices provide a
/// trade-off between surface quality and performance.
///
enum EndCapType {
ENDCAP_NONE = 0, ///< unspecified
ENDCAP_BILINEAR_BASIS, ///< use linear patches (simple quads or tris)
ENDCAP_BSPLINE_BASIS, ///< use BSpline-like patches (same patch type as regular)
ENDCAP_GREGORY_BASIS, ///< use Gregory patches (highest quality, recommended default)
ENDCAP_LEGACY_GREGORY ///< legacy option for 2.x style Gregory patches (Catmark only)
};
Options(unsigned int maxIsolation=10) :
generateAllLevels(false),
includeBaseLevelIndices(true),
includeFVarBaseLevelIndices(false),
triangulateQuads(false),
useSingleCreasePatch(false),
useInfSharpPatch(false),
maxIsolationLevel(maxIsolation),
endCapType(ENDCAP_GREGORY_BASIS),
shareEndCapPatchPoints(true),
generateVaryingTables(true),
generateVaryingLocalPoints(true),
generateFVarTables(false),
patchPrecisionDouble(false),
fvarPatchPrecisionDouble(false),
generateFVarLegacyLinearPatches(true),
generateLegacySharpCornerPatches(true),
numFVarChannels(-1),
fvarChannelIndices(0)
{ }
/// \brief Get endcap basis type
EndCapType GetEndCapType() const { return (EndCapType)endCapType; }
/// \brief Set endcap basis type
void SetEndCapType(EndCapType e) { endCapType = e; }
/// \brief Set precision of vertex patches
template <typename REAL> void SetPatchPrecision();
/// \brief Set precision of face-varying patches
template <typename REAL> void SetFVarPatchPrecision();
/// \brief Determine adaptive refinement options to match assigned patch options
TopologyRefiner::AdaptiveOptions GetRefineAdaptiveOptions() const {
TopologyRefiner::AdaptiveOptions adaptiveOptions(maxIsolationLevel);
adaptiveOptions.useInfSharpPatch = useInfSharpPatch;
adaptiveOptions.useSingleCreasePatch = useSingleCreasePatch;
adaptiveOptions.considerFVarChannels = generateFVarTables &&
!generateFVarLegacyLinearPatches;
return adaptiveOptions;
}
unsigned int generateAllLevels : 1, ///< Generate levels from 'firstLevel' to 'maxLevel' (Uniform mode only)
includeBaseLevelIndices : 1, ///< Include base level in patch point indices (Uniform mode only)
includeFVarBaseLevelIndices : 1, ///< Include base level in face-varying patch point indices (Uniform mode only)
triangulateQuads : 1, ///< Triangulate 'QUADS' primitives (Uniform mode only)
useSingleCreasePatch : 1, ///< Use single crease patch
useInfSharpPatch : 1, ///< Use infinitely-sharp patch
maxIsolationLevel : 4, ///< Cap adaptive feature isolation to the given level (max. 10)
// end-capping
endCapType : 3, ///< EndCapType
shareEndCapPatchPoints : 1, ///< Share endcap patch points among adjacent endcap patches.
///< currently only work with GregoryBasis.
// varying
generateVaryingTables : 1, ///< Generate varying patch tables
generateVaryingLocalPoints : 1, ///< Generate local points with varying patches
// face-varying
generateFVarTables : 1, ///< Generate face-varying patch tables
// precision
patchPrecisionDouble : 1, ///< Generate double-precision stencils for vertex patches
fvarPatchPrecisionDouble : 1, ///< Generate double-precision stencils for face-varying patches
// legacy behaviors (default to true)
generateFVarLegacyLinearPatches : 1, ///< Generate all linear face-varying patches (legacy)
generateLegacySharpCornerPatches : 1; ///< Generate sharp regular patches at smooth corners (legacy)
int numFVarChannels; ///< Number of channel indices and interpolation modes passed
int const * fvarChannelIndices; ///< List containing the indices of the channels selected for the factory
};
/// \brief Instantiates a PatchTable from a client-provided TopologyRefiner.
///
/// A PatchTable can be constructed from a TopologyRefiner that has been
/// either adaptively or uniformly refined. In both cases, the resulting
/// patches reference vertices in the various refined levels by index,
/// and those indices accumulate with the levels in different ways.
///
/// For adaptively refined patches, patches are defined at different levels,
/// including the base level, so the indices of patch vertices include
/// vertices from all levels. A sparse set of patches can be created by
/// restricting the patches generated to those descending from a given set
/// of faces at the base level. This sparse set of base faces is expected
/// to be a subset of the faces that were adaptively refined in the given
/// TopologyRefiner, otherwise results are undefined.
///
/// For uniformly refined patches, all patches are completely defined within
/// the last level. There is often no use for intermediate levels and they
/// can usually be ignored. Indices of patch vertices might therefore be
/// expected to be defined solely within the last level. While this is true
/// for face-varying patches, for historical reasons it is not the case for
/// vertex and varying patches. Indices for vertex and varying patches include
/// the base level in addition to the last level while indices for face-varying
/// patches include only the last level.
///
/// @param refiner TopologyRefiner from which to generate patches
///
/// @param options Options controlling the creation of the table
///
/// @param selectedFaces Only create patches for the given set of base faces.
///
/// @return A new instance of PatchTable
///
static PatchTable * Create(TopologyRefiner const & refiner,
Options options = Options(),
ConstIndexArray selectedFaces = ConstIndexArray());
public:
// PatchFaceTag
//
// This simple struct was previously used within the factory to take inventory of
// various kinds of patches to fully allocate buffers prior to populating them. It
// was not intended to be exposed as part of the public interface.
//
// It is no longer used internally and is being kept here to respect preservation
// of the public interface, but it will be deprecated at the earliest opportunity.
//
/// \brief Obsolete internal struct not intended for public use -- due to
/// be deprecated.
//
struct PatchFaceTag {
public:
unsigned int _hasPatch : 1;
unsigned int _isRegular : 1;
unsigned int _transitionMask : 4;
unsigned int _boundaryMask : 4;
unsigned int _boundaryIndex : 2;
unsigned int _boundaryCount : 3;
unsigned int _hasBoundaryEdge : 3;
unsigned int _isSingleCrease : 1;
void clear();
void assignBoundaryPropertiesFromEdgeMask(int boundaryEdgeMask);
void assignBoundaryPropertiesFromVertexMask(int boundaryVertexMask);
void assignTransitionPropertiesFromEdgeMask(int boundaryVertexMask);
};
typedef std::vector<PatchFaceTag> PatchTagVector;
};
template <> inline void PatchTableFactory::Options::SetPatchPrecision<float>() {
patchPrecisionDouble = false;
}
template <> inline void PatchTableFactory::Options::SetFVarPatchPrecision<float>() {
fvarPatchPrecisionDouble = false;
}
template <> inline void PatchTableFactory::Options::SetPatchPrecision<double>() {
patchPrecisionDouble = true;
}
template <> inline void PatchTableFactory::Options::SetFVarPatchPrecision<double>() {
fvarPatchPrecisionDouble = true;
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_PATCH_TABLE_FACTORY_H */
File diff suppressed because it is too large. Load diff
+106
View File
@@ -0,0 +1,106 @@
//
// Copyright 2015 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_FAR_PTEX_INDICES_H
#define OPENSUBDIV3_FAR_PTEX_INDICES_H
#include "../version.h"
#include "../far/topologyRefiner.h"
#include "../far/types.h"
#include <vector>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
///
/// \brief Object used to compute and query ptex face indices.
///
/// Given a refiner, constructing a PtexIndices object builds the mapping
/// from coarse faces to ptex ids. Once built, the object can be used to
/// query the mapping.
///
class PtexIndices {
public:
/// \brief Constructor
PtexIndices(TopologyRefiner const &refiner);
/// \brief Destructor
~PtexIndices();
//@{
///
/// Ptex
///
/// \brief Returns the number of ptex faces in the mesh
///
int GetNumFaces() const;
/// \brief Returns the ptex face index given a coarse face 'f' or -1
///
int GetFaceId(Index f) const;
/// \brief Returns ptex face adjacency information for a given coarse face
///
/// @param refiner refiner used to build this PtexIndices object.
///
/// @param face coarse face index
///
/// @param quadrant quadrant index if 'face' is not a quad (the local ptex
/// sub-face index). Must be less than the number of face
/// vertices.
///
/// @param adjFaces ptex face indices of adjacent faces
///
/// @param adjEdges ptex edge indices of adjacent faces
///
void GetAdjacency(
TopologyRefiner const &refiner,
int face, int quadrant,
int adjFaces[4], int adjEdges[4]) const;
//@}
private:
void initializePtexIndices(TopologyRefiner const &refiner);
private:
std::vector<Index> _ptexIndices;
};
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_PTEX_INDICES_H */
+793
View File
@@ -0,0 +1,793 @@
//
// Copyright 2013 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_FAR_STENCILTABLE_H
#define OPENSUBDIV3_FAR_STENCILTABLE_H
#include "../version.h"
#include "../far/types.h"
#include <cassert>
#include <cstring>
#include <vector>
#include <iostream>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
// Forward declarations for friends:
class PatchTableBuilder;
template <typename REAL> class StencilTableFactoryReal;
template <typename REAL> class LimitStencilTableFactoryReal;
/// \brief Vertex stencil descriptor
///
/// Allows access and manipulation of a single stencil in a StencilTable.
///
template <typename REAL>
class StencilReal {
public:
/// \brief Default constructor
StencilReal() {}
/// \brief Constructor
///
/// @param size Table pointer to the size of the stencil
///
/// @param indices Table pointer to the vertex indices of the stencil
///
/// @param weights Table pointer to the vertex weights of the stencil
///
StencilReal(int * size, Index * indices, REAL * weights)
: _size(size), _indices(indices), _weights(weights) { }
/// \brief Copy constructor
StencilReal(StencilReal const & other) {
_size = other._size;
_indices = other._indices;
_weights = other._weights;
}
/// \brief Returns the size of the stencil
int GetSize() const {
return *_size;
}
/// \brief Returns the size of the stencil as a pointer
int * GetSizePtr() const {
return _size;
}
/// \brief Returns the control vertices' indices
Index const * GetVertexIndices() const {
return _indices;
}
/// \brief Returns the interpolation weights
REAL const * GetWeights() const {
return _weights;
}
/// \brief Advance to the next stencil in the table
void Next() {
int stride = *_size;
++_size;
_indices += stride;
_weights += stride;
}
protected:
friend class StencilTableFactoryReal<REAL>;
friend class LimitStencilTableFactoryReal<REAL>;
int * _size;
Index * _indices;
REAL * _weights;
};
/// \brief Vertex stencil class wrapping the template for compatibility.
///
class Stencil : public StencilReal<float> {
protected:
typedef StencilReal<float> BaseStencil;
public:
Stencil() : BaseStencil() { }
Stencil(BaseStencil const & other) : BaseStencil(other) { }
Stencil(int * size, Index * indices, float * weights)
: BaseStencil(size, indices, weights) { }
};
/// \brief Table of subdivision stencils.
///
/// Stencils are the most direct method of evaluation of locations on the limit
/// of a surface. Every point of a limit surface can be computed by linearly
/// blending a collection of coarse control vertices.
///
/// A stencil assigns a series of control vertex indices with a blending weight
/// that corresponds to a unique parametric location of the limit surface. When
/// the control vertices move in space, the limit location can be very efficiently
/// recomputed simply by applying the blending weights to the series of coarse
/// control vertices.
///
template <typename REAL>
class StencilTableReal {
protected:
StencilTableReal(int numControlVerts,
std::vector<int> const& offsets,
std::vector<int> const& sizes,
std::vector<int> const& sources,
std::vector<REAL> const& weights,
bool includeCoarseVerts,
size_t firstOffset);
public:
virtual ~StencilTableReal() {};
/// \brief Returns the number of stencils in the table
int GetNumStencils() const {
return (int)_sizes.size();
}
/// \brief Returns the number of control vertices indexed in the table
int GetNumControlVertices() const {
return _numControlVertices;
}
/// \brief Returns a Stencil at index i in the table
StencilReal<REAL> GetStencil(Index i) const;
/// \brief Returns the number of control vertices of each stencil in the table
std::vector<int> const & GetSizes() const {
return _sizes;
}
/// \brief Returns the offset to a given stencil (factory may leave empty)
std::vector<Index> const & GetOffsets() const {
return _offsets;
}
/// \brief Returns the indices of the control vertices
std::vector<Index> const & GetControlIndices() const {
return _indices;
}
/// \brief Returns the stencil interpolation weights
std::vector<REAL> const & GetWeights() const {
return _weights;
}
/// \brief Returns the stencil at index i in the table
StencilReal<REAL> operator[] (Index index) const;
/// \brief Updates point values based on the control values
///
/// \note The destination buffers are assumed to have allocated at least
/// \c GetNumStencils() elements.
///
/// @param srcValues Buffer with primvar data for the control vertices
///
/// @param dstValues Destination buffer for the interpolated primvar data
///
/// @param start Index of first destination value to update
///
/// @param end Index of last destination value to update
///
template <class T, class U>
void UpdateValues(T const &srcValues, U &dstValues, Index start=-1, Index end=-1) const {
this->update(srcValues, dstValues, _weights, start, end);
}
template <class T1, class T2, class U>
void UpdateValues(T1 const &srcBase, int numBase, T2 const &srcRef,
U &dstValues, Index start=-1, Index end=-1) const {
this->update(srcBase, numBase, srcRef, dstValues, _weights, start, end);
}
// Pointer interface for backward compatibility
template <class T, class U>
void UpdateValues(T const *src, U *dst, Index start=-1, Index end=-1) const {
this->update(src, dst, _weights, start, end);
}
template <class T1, class T2, class U>
void UpdateValues(T1 const *srcBase, int numBase, T2 const *srcRef,
U *dst, Index start=-1, Index end=-1) const {
this->update(srcBase, numBase, srcRef, dst, _weights, start, end);
}
/// \brief Clears the stencils from the table
void Clear();
protected:
// Update values by applying cached stencil weights to new control values
template <class T, class U>
void update( T const &srcValues, U &dstValues,
std::vector<REAL> const & valueWeights, Index start, Index end) const;
template <class T1, class T2, class U>
void update( T1 const &srcBase, int numBase, T2 const &srcRef, U &dstValues,
std::vector<REAL> const & valueWeights, Index start, Index end) const;
// Populate the offsets table from the stencil sizes in _sizes (factory helper)
void generateOffsets();
// Resize the table arrays (factory helper)
void resize(int nstencils, int nelems);
// Reserves the table arrays (factory helper)
void reserve(int nstencils, int nelems);
// Reallocates the table arrays to remove excess capacity (factory helper)
void shrinkToFit();
// Performs any final operations on internal tables (factory helper)
void finalize();
protected:
StencilTableReal() : _numControlVertices(0) {}
StencilTableReal(int numControlVerts)
: _numControlVertices(numControlVerts)
{ }
friend class StencilTableFactoryReal<REAL>;
friend class Far::PatchTableBuilder;
int _numControlVertices; // number of control vertices
std::vector<int> _sizes; // number of coefficients for each stencil
std::vector<Index> _offsets, // offset to the start of each stencil
_indices; // indices of contributing coarse vertices
std::vector<REAL> _weights; // stencil weight coefficients
};
/// \brief Stencil table class wrapping the template for compatibility.
///
class StencilTable : public StencilTableReal<float> {
protected:
typedef StencilTableReal<float> BaseTable;
public:
Stencil GetStencil(Index index) const {
return Stencil(BaseTable::GetStencil(index));
}
Stencil operator[] (Index index) const {
return Stencil(BaseTable::GetStencil(index));
}
protected:
StencilTable() : BaseTable() { }
StencilTable(int numControlVerts) : BaseTable(numControlVerts) { }
StencilTable(int numControlVerts,
std::vector<int> const& offsets,
std::vector<int> const& sizes,
std::vector<int> const& sources,
std::vector<float> const& weights,
bool includeCoarseVerts,
size_t firstOffset)
: BaseTable(numControlVerts, offsets,
sizes, sources, weights, includeCoarseVerts, firstOffset) { }
};
/// \brief Limit point stencil descriptor
///
template <typename REAL>
class LimitStencilReal : public StencilReal<REAL> {
public:
/// \brief Constructor
///
/// @param size Table pointer to the size of the stencil
///
/// @param indices Table pointer to the vertex indices of the stencil
///
/// @param weights Table pointer to the vertex weights of the stencil
///
/// @param duWeights Table pointer to the 'u' derivative weights
///
/// @param dvWeights Table pointer to the 'v' derivative weights
///
/// @param duuWeights Table pointer to the 'uu' derivative weights
///
/// @param duvWeights Table pointer to the 'uv' derivative weights
///
/// @param dvvWeights Table pointer to the 'vv' derivative weights
///
LimitStencilReal( int* size,
Index * indices,
REAL * weights,
REAL * duWeights=0,
REAL * dvWeights=0,
REAL * duuWeights=0,
REAL * duvWeights=0,
REAL * dvvWeights=0)
: StencilReal<REAL>(size, indices, weights),
_duWeights(duWeights),
_dvWeights(dvWeights),
_duuWeights(duuWeights),
_duvWeights(duvWeights),
_dvvWeights(dvvWeights) {
}
/// \brief Returns the u derivative weights
REAL const * GetDuWeights() const {
return _duWeights;
}
/// \brief Returns the v derivative weights
REAL const * GetDvWeights() const {
return _dvWeights;
}
/// \brief Returns the uu derivative weights
REAL const * GetDuuWeights() const {
return _duuWeights;
}
/// \brief Returns the uv derivative weights
REAL const * GetDuvWeights() const {
return _duvWeights;
}
/// \brief Returns the vv derivative weights
REAL const * GetDvvWeights() const {
return _dvvWeights;
}
/// \brief Advance to the next stencil in the table
void Next() {
int stride = *this->_size;
++this->_size;
this->_indices += stride;
this->_weights += stride;
if (_duWeights) _duWeights += stride;
if (_dvWeights) _dvWeights += stride;
if (_duuWeights) _duuWeights += stride;
if (_duvWeights) _duvWeights += stride;
if (_dvvWeights) _dvvWeights += stride;
}
private:
friend class StencilTableFactoryReal<REAL>;
friend class LimitStencilTableFactoryReal<REAL>;
REAL * _duWeights, // pointer to stencil u derivative limit weights
* _dvWeights, // pointer to stencil v derivative limit weights
* _duuWeights, // pointer to stencil uu derivative limit weights
* _duvWeights, // pointer to stencil uv derivative limit weights
* _dvvWeights; // pointer to stencil vv derivative limit weights
};
/// \brief Limit point stencil class wrapping the template for compatibility.
///
class LimitStencil : public LimitStencilReal<float> {
protected:
typedef LimitStencilReal<float> BaseStencil;
public:
LimitStencil(BaseStencil const & other) : BaseStencil(other) { }
LimitStencil(int* size, Index * indices, float * weights,
float * duWeights=0, float * dvWeights=0,
float * duuWeights=0, float * duvWeights=0, float * dvvWeights=0)
: BaseStencil(size, indices, weights,
duWeights, dvWeights, duuWeights, duvWeights, dvvWeights) { }
};
/// \brief Table of limit subdivision stencils.
///
template <typename REAL>
class LimitStencilTableReal : public StencilTableReal<REAL> {
protected:
LimitStencilTableReal(
int numControlVerts,
std::vector<int> const& offsets,
std::vector<int> const& sizes,
std::vector<int> const& sources,
std::vector<REAL> const& weights,
std::vector<REAL> const& duWeights,
std::vector<REAL> const& dvWeights,
std::vector<REAL> const& duuWeights,
std::vector<REAL> const& duvWeights,
std::vector<REAL> const& dvvWeights,
bool includeCoarseVerts,
size_t firstOffset);
public:
/// \brief Returns a LimitStencil at index i in the table
LimitStencilReal<REAL> GetLimitStencil(Index i) const;
/// \brief Returns the limit stencil at index i in the table
LimitStencilReal<REAL> operator[] (Index index) const;
/// \brief Returns the 'u' derivative stencil interpolation weights
std::vector<REAL> const & GetDuWeights() const {
return _duWeights;
}
/// \brief Returns the 'v' derivative stencil interpolation weights
std::vector<REAL> const & GetDvWeights() const {
return _dvWeights;
}
/// \brief Returns the 'uu' derivative stencil interpolation weights
std::vector<REAL> const & GetDuuWeights() const {
return _duuWeights;
}
/// \brief Returns the 'uv' derivative stencil interpolation weights
std::vector<REAL> const & GetDuvWeights() const {
return _duvWeights;
}
/// \brief Returns the 'vv' derivative stencil interpolation weights
std::vector<REAL> const & GetDvvWeights() const {
return _dvvWeights;
}
/// \brief Updates derivative values based on the control values
///
/// \note The destination buffers ('uderivs' & 'vderivs') are assumed to
/// have allocated at least \c GetNumStencils() elements.
///
/// @param srcValues Buffer with primvar data for the control vertices
///
/// @param uderivs Destination buffer for the interpolated 'u'
/// derivative primvar data
///
/// @param vderivs Destination buffer for the interpolated 'v'
/// derivative primvar data
///
/// @param start Index of first destination derivative to update
///
/// @param end Index of last destination derivative to update
///
template <class T, class U>
void UpdateDerivs(T const & srcValues, U & uderivs, U & vderivs,
int start=-1, int end=-1) const {
this->update(srcValues, uderivs, _duWeights, start, end);
this->update(srcValues, vderivs, _dvWeights, start, end);
}
template <class T1, class T2, class U>
void UpdateDerivs(T1 const & srcBase, int numBase, T2 const & srcRef,
U & uderivs, U & vderivs, int start=-1, int end=-1) const {
this->update(srcBase, numBase, srcRef, uderivs, _duWeights, start, end);
this->update(srcBase, numBase, srcRef, vderivs, _dvWeights, start, end);
}
// Pointer interface for backward compatibility
template <class T, class U>
void UpdateDerivs(T const *src, U *uderivs, U *vderivs,
int start=-1, int end=-1) const {
this->update(src, uderivs, _duWeights, start, end);
this->update(src, vderivs, _dvWeights, start, end);
}
template <class T1, class T2, class U>
void UpdateDerivs(T1 const *srcBase, int numBase, T2 const *srcRef,
U *uderivs, U *vderivs, int start=-1, int end=-1) const {
this->update(srcBase, numBase, srcRef, uderivs, _duWeights, start, end);
this->update(srcBase, numBase, srcRef, vderivs, _dvWeights, start, end);
}
/// \brief Updates 2nd derivative values based on the control values
///
/// \note The destination buffers ('uuderivs', 'uvderivs', & 'vderivs') are
/// assumed to have allocated at least \c GetNumStencils() elements.
///
/// @param srcValues Buffer with primvar data for the control vertices
///
/// @param uuderivs Destination buffer for the interpolated 'uu'
/// derivative primvar data
///
/// @param uvderivs Destination buffer for the interpolated 'uv'
/// derivative primvar data
///
/// @param vvderivs Destination buffer for the interpolated 'vv'
/// derivative primvar data
///
/// @param start Index of first destination derivative to update
///
/// @param end Index of last destination derivative to update
///
template <class T, class U>
void Update2ndDerivs(T const & srcValues,
U & uuderivs, U & uvderivs, U & vvderivs,
int start=-1, int end=-1) const {
this->update(srcValues, uuderivs, _duuWeights, start, end);
this->update(srcValues, uvderivs, _duvWeights, start, end);
this->update(srcValues, vvderivs, _dvvWeights, start, end);
}
template <class T1, class T2, class U>
void Update2ndDerivs(T1 const & srcBase, int numBase, T2 const & srcRef,
U & uuderivs, U & uvderivs, U & vvderivs, int start=-1, int end=-1) const {
this->update(srcBase, numBase, srcRef, uuderivs, _duuWeights, start, end);
this->update(srcBase, numBase, srcRef, uvderivs, _duvWeights, start, end);
this->update(srcBase, numBase, srcRef, vvderivs, _dvvWeights, start, end);
}
// Pointer interface for backward compatibility
template <class T, class U>
void Update2ndDerivs(T const *src, T *uuderivs, U *uvderivs, U *vvderivs,
int start=-1, int end=-1) const {
this->update(src, uuderivs, _duuWeights, start, end);
this->update(src, uvderivs, _duvWeights, start, end);
this->update(src, vvderivs, _dvvWeights, start, end);
}
template <class T1, class T2, class U>
void Update2ndDerivs(T1 const *srcBase, int numBase, T2 const *srcRef,
U *uuderivs, U *uvderivs, U *vvderivs, int start=-1, int end=-1) const {
this->update(srcBase, numBase, srcRef, uuderivs, _duuWeights, start, end);
this->update(srcBase, numBase, srcRef, uvderivs, _duvWeights, start, end);
this->update(srcBase, numBase, srcRef, vvderivs, _dvvWeights, start, end);
}
/// \brief Clears the stencils from the table
void Clear();
private:
friend class LimitStencilTableFactoryReal<REAL>;
// Resize the table arrays (factory helper)
void resize(int nstencils, int nelems);
private:
std::vector<REAL> _duWeights, // u derivative limit stencil weights
_dvWeights, // v derivative limit stencil weights
_duuWeights, // uu derivative limit stencil weights
_duvWeights, // uv derivative limit stencil weights
_dvvWeights; // vv derivative limit stencil weights
};
/// \brief Limit stencil table class wrapping the template for compatibility.
///
class LimitStencilTable : public LimitStencilTableReal<float> {
protected:
typedef LimitStencilTableReal<float> BaseTable;
public:
LimitStencil GetLimitStencil(Index index) const {
return LimitStencil(BaseTable::GetLimitStencil(index));
}
LimitStencil operator[] (Index index) const {
return LimitStencil(BaseTable::GetLimitStencil(index));
}
protected:
LimitStencilTable(int numControlVerts,
std::vector<int> const& offsets,
std::vector<int> const& sizes,
std::vector<int> const& sources,
std::vector<float> const& weights,
std::vector<float> const& duWeights,
std::vector<float> const& dvWeights,
std::vector<float> const& duuWeights,
std::vector<float> const& duvWeights,
std::vector<float> const& dvvWeights,
bool includeCoarseVerts,
size_t firstOffset)
: BaseTable(numControlVerts,
offsets, sizes, sources, weights,
duWeights, dvWeights, duuWeights, duvWeights, dvvWeights,
includeCoarseVerts, firstOffset) { }
};
// Update values by applying cached stencil weights to new control values
template <typename REAL>
template <class T1, class T2, class U> void
StencilTableReal<REAL>::update(T1 const &srcBase, int numBase,
T2 const &srcRef, U &dstValues,
std::vector<REAL> const &valueWeights, Index start, Index end) const {
int const * sizes = &_sizes.at(0);
Index const * indices = &_indices.at(0);
REAL const * weights = &valueWeights.at(0);
if (start > 0) {
assert(start < (Index)_offsets.size());
sizes += start;
indices += _offsets[start];
weights += _offsets[start];
} else {
start = 0;
}
int nstencils = ((end < start) ? GetNumStencils() : end) - start;
for (int i = 0; i < nstencils; ++i, ++sizes) {
dstValues[start + i].Clear();
for (int j = 0; j < *sizes; ++j, ++indices, ++weights) {
if (*indices < numBase) {
dstValues[start + i].AddWithWeight(srcBase[*indices], *weights);
} else {
dstValues[start + i].AddWithWeight(srcRef[*indices - numBase], *weights);
}
}
}
}
template <typename REAL>
template <class T, class U> void
StencilTableReal<REAL>::update(T const &srcValues, U &dstValues,
std::vector<REAL> const &valueWeights, Index start, Index end) const {
int const * sizes = &_sizes.at(0);
Index const * indices = &_indices.at(0);
REAL const * weights = &valueWeights.at(0);
if (start > 0) {
assert(start < (Index)_offsets.size());
sizes += start;
indices += _offsets[start];
weights += _offsets[start];
} else {
start = 0;
}
int nstencils = ((end < start) ? GetNumStencils() : end) - start;
for (int i = 0; i < nstencils; ++i, ++sizes) {
dstValues[start + i].Clear();
for (int j = 0; j < *sizes; ++j, ++indices, ++weights) {
dstValues[start + i].AddWithWeight(srcValues[*indices], *weights);
}
}
}
template <typename REAL>
inline void
StencilTableReal<REAL>::generateOffsets() {
Index offset=0;
int noffsets = (int)_sizes.size();
_offsets.resize(noffsets);
for (int i=0; i<(int)_sizes.size(); ++i ) {
_offsets[i]=offset;
offset+=_sizes[i];
}
}
template <typename REAL>
inline void
StencilTableReal<REAL>::resize(int nstencils, int nelems) {
_sizes.resize(nstencils);
_indices.resize(nelems);
_weights.resize(nelems);
}
template <typename REAL>
inline void
StencilTableReal<REAL>::reserve(int nstencils, int nelems) {
_sizes.reserve(nstencils);
_indices.reserve(nelems);
_weights.reserve(nelems);
}
template <typename REAL>
inline void
StencilTableReal<REAL>::shrinkToFit() {
std::vector<int>(_sizes).swap(_sizes);
std::vector<Index>(_indices).swap(_indices);
std::vector<REAL>(_weights).swap(_weights);
}
template <typename REAL>
inline void
StencilTableReal<REAL>::finalize() {
shrinkToFit();
generateOffsets();
}
// Returns a Stencil at index i in the table
template <typename REAL>
inline StencilReal<REAL>
StencilTableReal<REAL>::GetStencil(Index i) const {
assert((! _offsets.empty()) && i<(int)_offsets.size());
Index ofs = _offsets[i];
return StencilReal<REAL>(const_cast<int*>(&_sizes[i]),
const_cast<Index*>(&_indices[ofs]),
const_cast<REAL*>(&_weights[ofs]));
}
template <typename REAL>
inline StencilReal<REAL>
StencilTableReal<REAL>::operator[] (Index index) const {
return GetStencil(index);
}
template <typename REAL>
inline void
LimitStencilTableReal<REAL>::resize(int nstencils, int nelems) {
StencilTableReal<REAL>::resize(nstencils, nelems);
_duWeights.resize(nelems);
_dvWeights.resize(nelems);
}
// Returns a LimitStencil at index i in the table
template <typename REAL>
inline LimitStencilReal<REAL>
LimitStencilTableReal<REAL>::GetLimitStencil(Index i) const {
assert((! this->GetOffsets().empty()) && i<(int)this->GetOffsets().size());
Index ofs = this->GetOffsets()[i];
if (!_duWeights.empty() && !_dvWeights.empty() &&
!_duuWeights.empty() && !_duvWeights.empty() && !_dvvWeights.empty()) {
return LimitStencilReal<REAL>(
const_cast<int *>(&this->GetSizes()[i]),
const_cast<Index *>(&this->GetControlIndices()[ofs]),
const_cast<REAL *>(&this->GetWeights()[ofs]),
const_cast<REAL *>(&GetDuWeights()[ofs]),
const_cast<REAL *>(&GetDvWeights()[ofs]),
const_cast<REAL *>(&GetDuuWeights()[ofs]),
const_cast<REAL *>(&GetDuvWeights()[ofs]),
const_cast<REAL *>(&GetDvvWeights()[ofs]) );
} else if (!_duWeights.empty() && !_dvWeights.empty()) {
return LimitStencilReal<REAL>(
const_cast<int *>(&this->GetSizes()[i]),
const_cast<Index *>(&this->GetControlIndices()[ofs]),
const_cast<REAL *>(&this->GetWeights()[ofs]),
const_cast<REAL *>(&GetDuWeights()[ofs]),
const_cast<REAL *>(&GetDvWeights()[ofs]) );
} else {
return LimitStencilReal<REAL>(
const_cast<int *>(&this->GetSizes()[i]),
const_cast<Index *>(&this->GetControlIndices()[ofs]),
const_cast<REAL *>(&this->GetWeights()[ofs]) );
}
}
template <typename REAL>
inline LimitStencilReal<REAL>
LimitStencilTableReal<REAL>::operator[] (Index index) const {
return GetLimitStencil(index);
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif // OPENSUBDIV3_FAR_STENCILTABLE_H
@@ -0,0 +1,384 @@
//
// Copyright 2013 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_FAR_STENCILTABLE_FACTORY_H
#define OPENSUBDIV3_FAR_STENCILTABLE_FACTORY_H
#include "../version.h"
#include "../far/patchTable.h"
#include <vector>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
class TopologyRefiner;
template <typename REAL> class StencilReal;
template <typename REAL> class StencilTableReal;
template <typename REAL> class LimitStencilReal;
template <typename REAL> class LimitStencilTableReal;
/// \brief A specialized factory for StencilTable
///
template <typename REAL>
class StencilTableFactoryReal {
public:
enum Mode {
INTERPOLATE_VERTEX=0, ///< vertex primvar stencils
INTERPOLATE_VARYING, ///< varying primvar stencils
INTERPOLATE_FACE_VARYING ///< face-varying primvar stencils
};
struct Options {
Options() : interpolationMode(INTERPOLATE_VERTEX),
generateOffsets(false),
generateControlVerts(false),
generateIntermediateLevels(true),
factorizeIntermediateLevels(true),
maxLevel(10),
fvarChannel(0) { }
unsigned int interpolationMode : 2, ///< interpolation mode
generateOffsets : 1, ///< populate optional "_offsets" field
generateControlVerts : 1, ///< generate stencils for control-vertices
generateIntermediateLevels : 1, ///< vertices at all levels or highest only
factorizeIntermediateLevels : 1, ///< accumulate stencil weights from control
/// vertices or from the stencils of the
/// previous level
maxLevel : 4; ///< generate stencils up to 'maxLevel'
unsigned int fvarChannel; ///< face-varying channel to use
/// when generating face-varying stencils
};
/// \brief Instantiates StencilTable from TopologyRefiner that have been
/// refined uniformly or adaptively.
///
/// \note The factory only creates stencils for vertices that have already
/// been refined in the TopologyRefiner. Use RefineUniform() or
/// RefineAdaptive() before constructing the stencils.
///
/// @param refiner The TopologyRefiner containing the topology
///
/// @param options Options controlling the creation of the table
///
static StencilTableReal<REAL> const * Create(
TopologyRefiner const & refiner, Options options = Options());
/// \brief Instantiates StencilTable by concatenating an array of existing
/// stencil tables.
///
/// \note This factory checks that the stencil tables point to the same set
/// of supporting control vertices - no re-indexing is done.
/// GetNumControlVertices() *must* return the same value for all input
/// tables.
///
/// @param numTables Number of input StencilTables
///
/// @param tables Array of input StencilTables
///
static StencilTableReal<REAL> const * Create(
int numTables, StencilTableReal<REAL> const ** tables);
/// \brief Utility function for stencil splicing for local point stencils.
///
/// @param refiner The TopologyRefiner containing the topology
///
/// @param baseStencilTable Input StencilTable for refined vertices
///
/// @param localPointStencilTable
/// StencilTable for the change of basis patch points.
///
/// @param factorize If factorize is set to true, endcap stencils will be
/// factorized with supporting vertices from baseStencil
/// table so that the endcap points can be computed
/// directly from control vertices.
///
static StencilTableReal<REAL> const * AppendLocalPointStencilTable(
TopologyRefiner const &refiner,
StencilTableReal<REAL> const *baseStencilTable,
StencilTableReal<REAL> const *localPointStencilTable,
bool factorize = true);
/// \brief Utility function for stencil splicing for local point varying stencils.
///
/// @param refiner The TopologyRefiner containing the topology
///
/// @param baseStencilTable Input StencilTable for refined vertices
///
/// @param localPointStencilTable
/// StencilTable for the change of basis patch points.
///
/// @param factorize If factorize is set to true, endcap stencils will be
/// factorized with supporting vertices from baseStencil
/// table so that the endcap points can be computed
/// directly from control vertices.
///
static StencilTableReal<REAL> const * AppendLocalPointStencilTableVarying(
TopologyRefiner const &refiner,
StencilTableReal<REAL> const *baseStencilTable,
StencilTableReal<REAL> const *localPointStencilTable,
bool factorize = true) {
return AppendLocalPointStencilTable(
refiner, baseStencilTable, localPointStencilTable, factorize);
}
/// \brief Utility function for stencil splicing for local point
/// face-varying stencils.
///
/// @param refiner The TopologyRefiner containing the topology
///
/// @param baseStencilTable Input StencilTable for refined vertices
///
/// @param localPointStencilTable
/// StencilTable for the change of basis patch points.
///
/// @param channel face-varying channel
///
/// @param factorize If factorize is set to true, endcap stencils will be
/// factorized with supporting vertices from baseStencil
/// table so that the endcap points can be computed
/// directly from control vertices.
///
static StencilTableReal<REAL> const * AppendLocalPointStencilTableFaceVarying(
TopologyRefiner const &refiner,
StencilTableReal<REAL> const *baseStencilTable,
StencilTableReal<REAL> const *localPointStencilTable,
int channel = 0,
bool factorize = true);
private:
// Generate stencils for the coarse control-vertices (single weight = 1.0f)
static void generateControlVertStencils(
int numControlVerts,
StencilReal<REAL> & dst);
// Internal method to splice local point stencils
static StencilTableReal<REAL> const * appendLocalPointStencilTable(
TopologyRefiner const &refiner,
StencilTableReal<REAL> const * baseStencilTable,
StencilTableReal<REAL> const * localPointStencilTable,
int channel,
bool factorize);
};
/// \brief A specialized factory for LimitStencilTable
///
/// The LimitStencilTableFactory creates a table of limit stencils. Limit
/// stencils can interpolate any arbitrary location on the limit surface.
/// The stencils will be bilinear if the surface is refined uniformly, and
/// bicubic if feature adaptive isolation is used instead.
///
/// Surface locations are expressed as a combination of ptex face index and
/// normalized (s,t) patch coordinates. The factory exposes the LocationArray
/// struct as a container for these location descriptors.
///
template <typename REAL>
class LimitStencilTableFactoryReal {
public:
enum Mode {
INTERPOLATE_VERTEX=0, ///< vertex primvar stencils
INTERPOLATE_VARYING, ///< varying primvar stencils
INTERPOLATE_FACE_VARYING ///< face-varying primvar stencils
};
struct Options {
Options() : interpolationMode(INTERPOLATE_VERTEX),
generate1stDerivatives(true),
generate2ndDerivatives(false),
fvarChannel(0) { }
unsigned int interpolationMode : 2, ///< interpolation mode
generate1stDerivatives : 1, ///< Generate weights for 1st derivatives
generate2ndDerivatives : 1; ///< Generate weights for 2nd derivatives
unsigned int fvarChannel; ///< face-varying channel to use
};
/// \brief Descriptor for limit surface locations
struct LocationArray {
LocationArray() : ptexIdx(-1), numLocations(0), s(0), t(0) { }
int ptexIdx, ///< ptex face index
numLocations; ///< number of (u,v) coordinates in the array
REAL const * s, ///< array of u coordinates
* t; ///< array of v coordinates
};
typedef std::vector<LocationArray> LocationArrayVec;
/// \brief Instantiates LimitStencilTable from a TopologyRefiner that has
/// been refined either uniformly or adaptively.
///
/// @param refiner The TopologyRefiner containing the topology
///
/// @param locationArrays An array of surface location descriptors
/// (see LocationArray)
///
/// @param cvStencils A StencilTable generated from the TopologyRefiner
/// (Optional: prevents redundant instantiation of the
/// table if available. The given table must at least
/// contain stencils for all control points and all
/// refined points -- any stencils for local points of
/// a PatchTable must match the PatchTable provided or
/// internally generated)
///
/// @param patchTable A PatchTable generated from the TopologyRefiner
/// (Optional: prevents redundant instantiation of the
/// table if available. The given table must match
/// the optional StencilTable if also provided)
///
/// @param options Options controlling the creation of the table
///
static LimitStencilTableReal<REAL> const * Create(
TopologyRefiner const & refiner,
LocationArrayVec const & locationArrays,
StencilTableReal<REAL> const * cvStencils = 0,
PatchTable const * patchTable = 0,
Options options = Options());
};
//
// Public wrapper classes for the templates
//
class Stencil;
class StencilTable;
/// \brief Stencil table factory class wrapping the template for compatibility.
///
class StencilTableFactory : public StencilTableFactoryReal<float> {
private:
typedef StencilTableFactoryReal<float> BaseFactory;
typedef StencilTableReal<float> BaseTable;
public:
static StencilTable const * Create(
TopologyRefiner const & refiner, Options options = Options()) {
return static_cast<StencilTable const *>(
BaseFactory::Create(refiner, options));
}
static StencilTable const * Create(
int numTables, StencilTable const ** tables) {
return static_cast<StencilTable const *>(
BaseFactory::Create(numTables,
reinterpret_cast<BaseTable const **>(tables)));
}
static StencilTable const * AppendLocalPointStencilTable(
TopologyRefiner const &refiner,
StencilTable const *baseStencilTable,
StencilTable const *localPointStencilTable,
bool factorize = true) {
return static_cast<StencilTable const *>(
BaseFactory::AppendLocalPointStencilTable(refiner,
static_cast<BaseTable const *>(baseStencilTable),
static_cast<BaseTable const *>(localPointStencilTable),
factorize));
}
static StencilTable const * AppendLocalPointStencilTableVarying(
TopologyRefiner const &refiner,
StencilTable const *baseStencilTable,
StencilTable const *localPointStencilTable,
bool factorize = true) {
return static_cast<StencilTable const *>(
BaseFactory::AppendLocalPointStencilTableVarying(refiner,
static_cast<BaseTable const *>(baseStencilTable),
static_cast<BaseTable const *>(localPointStencilTable),
factorize));
}
static StencilTable const * AppendLocalPointStencilTableFaceVarying(
TopologyRefiner const &refiner,
StencilTable const *baseStencilTable,
StencilTable const *localPointStencilTable,
int channel = 0,
bool factorize = true) {
return static_cast<StencilTable const *>(
BaseFactory::AppendLocalPointStencilTableFaceVarying(refiner,
static_cast<BaseTable const *>(baseStencilTable),
static_cast<BaseTable const *>(localPointStencilTable),
channel, factorize));
}
};
class LimitStencil;
class LimitStencilTable;
/// \brief Stencil table factory class wrapping the template for compatibility.
///
class LimitStencilTableFactory : public LimitStencilTableFactoryReal<float> {
private:
typedef LimitStencilTableFactoryReal<float> BaseFactory;
typedef StencilTableReal<float> BaseTable;
public:
static LimitStencilTable const * Create(
TopologyRefiner const & refiner,
LocationArrayVec const & locationArrays,
StencilTable const * cvStencils = 0,
PatchTable const * patchTable = 0,
Options options = Options()) {
return static_cast<LimitStencilTable const *>(
BaseFactory::Create(
refiner,
locationArrays,
static_cast<BaseTable const *>(cvStencils),
patchTable,
options));
}
};
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif // OPENSUBDIV3_FAR_STENCILTABLE_FACTORY_H
+127
View File
@@ -0,0 +1,127 @@
//
// Copyright 2014 DreamWorks Animation LLC.
//
// 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_FAR_TOPOLOGY_DESCRIPTOR_H
#define OPENSUBDIV3_FAR_TOPOLOGY_DESCRIPTOR_H
#include "../version.h"
#include "../far/topologyRefiner.h"
#include "../far/topologyRefinerFactory.h"
#include "../far/error.h"
#include <cassert>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
///
/// \brief A simple reference to raw topology data for use with TopologyRefinerFactory
///
/// TopologyDescriptor is a simple struct containing references to raw topology data used
/// to construct a TopologyRefiner. It is not a requirement but a convenience for use
/// with TopologyRefinerFactory when mesh topology is not available in an existing mesh
/// data structure. It should be functionally complete and simple to use, but for more
/// demanding situations, writing a custom Factory is usually warranted.
///
struct TopologyDescriptor {
int numVertices,
numFaces;
int const * numVertsPerFace;
Index const * vertIndicesPerFace;
int numCreases;
Index const * creaseVertexIndexPairs;
float const * creaseWeights;
int numCorners;
Index const * cornerVertexIndices;
float const * cornerWeights;
int numHoles;
Index const * holeIndices;
bool isLeftHanded;
// Face-varying data channel -- value indices correspond to vertex indices,
// i.e. one for every vertex of every face:
//
struct FVarChannel {
int numValues;
Index const * valueIndices;
FVarChannel() : numValues(0), valueIndices(0) { }
};
int numFVarChannels;
FVarChannel const * fvarChannels;
TopologyDescriptor();
};
//
// Forward declarations of required TopologyRefinerFactory<TopologyDescriptor>
// specializations (defined internally):
//
// @cond EXCLUDE_DOXYGEN
template <>
bool
TopologyRefinerFactory<TopologyDescriptor>::resizeComponentTopology(
TopologyRefiner & refiner, TopologyDescriptor const & desc);
template <>
bool
TopologyRefinerFactory<TopologyDescriptor>::assignComponentTopology(
TopologyRefiner & refiner, TopologyDescriptor const & desc);
template <>
bool
TopologyRefinerFactory<TopologyDescriptor>::assignComponentTags(
TopologyRefiner & refiner, TopologyDescriptor const & desc);
template <>
bool
TopologyRefinerFactory<TopologyDescriptor>::assignFaceVaryingTopology(
TopologyRefiner & refiner, TopologyDescriptor const & desc);
template <>
void
TopologyRefinerFactory<TopologyDescriptor>::reportInvalidTopology(
TopologyError errCode, char const * msg, TopologyDescriptor const & desc);
// @endcond
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_TOPOLOGY_DESCRIPTOR_H */
+273
View File
@@ -0,0 +1,273 @@
//
// Copyright 2015 DreamWorks Animation LLC.
//
// 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_FAR_TOPOLOGY_LEVEL_H
#define OPENSUBDIV3_FAR_TOPOLOGY_LEVEL_H
#include "../version.h"
#include "../vtr/level.h"
#include "../vtr/refinement.h"
#include "../far/types.h"
#include <vector>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
///
/// \brief An interface for accessing data in a specific level of a refined topology hierarchy.
///
/// TopologyLevel provides an interface to data in a specific level of a topology hierarchy.
/// Instances of TopologyLevel are created and owned by a TopologyRefiner,
/// which will return const-references to them. Such references are only valid during the
/// lifetime of the TopologyRefiner that created and returned them, and only for a given refinement,
/// i.e. if the TopologyRefiner is re-refined, any references to TopoologyLevels are invalidated.
///
class TopologyLevel {
public:
//@{
/// @name Methods to inspect the overall inventory of components:
///
/// All three main component types are indexed locally within each level. For
/// some topological relationships -- notably face-vertices, which is often
/// the only relationship of interest -- the total number of entries is also
/// made available.
///
/// \brief Return the number of vertices in this level
int GetNumVertices() const { return _level->getNumVertices(); }
/// \brief Return the number of faces in this level
int GetNumFaces() const { return _level->getNumFaces(); }
/// \brief Return the number of edges in this level
int GetNumEdges() const { return _level->getNumEdges(); }
/// \brief Return the total number of face-vertices, i.e. the sum of all vertices for all faces
int GetNumFaceVertices() const { return _level->getNumFaceVerticesTotal(); }
//@}
//@{
/// @name Methods to inspect topological relationships for individual components:
///
/// With three main component types (vertices, faces and edges), for each of the
/// three components the TopologyLevel stores the incident/adjacent components of
/// the other two types. So there are six relationships available for immediate
/// inspection. All are accessed by methods that return an array of fixed size
/// containing the indices of the incident components.
///
/// For some of the relations, i.e. those for which the incident components are
/// of higher order or 'contain' the component itself (e.g. a vertex has incident
/// faces that contain it), an additional 'local index' is available that identifies
/// the component within each of its neighbors. For example, if vertex V is the k'th
/// vertex in some face F, then when F occurs in the set of incident vertices of V,
/// the local index corresponding to F will be k. The ordering of local indices
/// matches the ordering of the incident component to which it corresponds.
//
/// \brief Access the vertices incident a given face
ConstIndexArray GetFaceVertices(Index f) const { return _level->getFaceVertices(f); }
/// \brief Access the edges incident a given face
ConstIndexArray GetFaceEdges(Index f) const { return _level->getFaceEdges(f); }
/// \brief Access the vertices incident a given edge
ConstIndexArray GetEdgeVertices(Index e) const { return _level->getEdgeVertices(e); }
/// \brief Access the faces incident a given edge
ConstIndexArray GetEdgeFaces(Index e) const { return _level->getEdgeFaces(e); }
/// \brief Access the faces incident a given vertex
ConstIndexArray GetVertexFaces(Index v) const { return _level->getVertexFaces(v); }
/// \brief Access the edges incident a given vertex
ConstIndexArray GetVertexEdges(Index v) const { return _level->getVertexEdges(v); }
/// \brief Access the local indices of a vertex with respect to its incident faces
ConstLocalIndexArray GetVertexFaceLocalIndices(Index v) const { return _level->getVertexFaceLocalIndices(v); }
/// \brief Access the local indices of a vertex with respect to its incident edges
ConstLocalIndexArray GetVertexEdgeLocalIndices(Index v) const { return _level->getVertexEdgeLocalIndices(v); }
/// \brief Access the local indices of an edge with respect to its incident faces
ConstLocalIndexArray GetEdgeFaceLocalIndices(Index e) const { return _level->getEdgeFaceLocalIndices(e); }
/// \brief Identify the edge matching the given vertex pair
Index FindEdge(Index v0, Index v1) const { return _level->findEdge(v0, v1); }
//@}
//@{
/// @name Methods to inspect other topological properties of individual components:
///
/// \brief Return if the edge is non-manifold
bool IsEdgeNonManifold(Index e) const { return _level->isEdgeNonManifold(e); }
/// \brief Return if the vertex is non-manifold
bool IsVertexNonManifold(Index v) const { return _level->isVertexNonManifold(v); }
/// \brief Return if the edge is a boundary
bool IsEdgeBoundary(Index e) const { return _level->getEdgeTag(e)._boundary; }
/// \brief Return if the vertex is a boundary
bool IsVertexBoundary(Index v) const { return _level->getVertexTag(v)._boundary; }
//@}
//@{
/// @name Methods to inspect feature tags for individual components:
///
/// While only a subset of components may have been tagged with features such
/// as sharpness, all such features have a default value and so all components
/// can be inspected.
/// \brief Return the sharpness assigned a given edge
float GetEdgeSharpness(Index e) const { return _level->getEdgeSharpness(e); }
/// \brief Return the sharpness assigned a given vertex
float GetVertexSharpness(Index v) const { return _level->getVertexSharpness(v); }
/// \brief Return if a given face has been tagged as a hole
bool IsFaceHole(Index f) const { return _level->isFaceHole(f); }
/// \brief Return the subdivision rule assigned a given vertex specific to this level
Sdc::Crease::Rule GetVertexRule(Index v) const { return _level->getVertexRule(v); }
//@}
//@{
/// @name Methods to inspect face-varying data:
///
/// Face-varying data is organized into topologically independent channels,
/// each with an integer identifier. Access to face-varying data generally
/// requires the specification of a channel, though with a single channel
/// being a common situation the first/only channel will be assumed if
/// unspecified.
///
/// A face-varying channel is composed of a set of values that may be shared
/// by faces meeting at a common vertex. Just as there are sets of vertices
/// that are associated with faces by index (ranging from 0 to
/// num-vertices - 1), face-varying values are also referenced by index
/// (ranging from 0 to num-values -1).
///
/// The face-varying values associated with a face are accessed similarly to
/// the way in which vertices associated with the face are accessed -- an
/// array of fixed size containing the indices for each corner is provided
/// for inspection, iteration, etc.
///
/// When the face-varying topology around a vertex "matches", it has the
/// same limit properties and so results in the same limit surface when
/// collections of adjacent vertices match. Like other references to
/// "topology", this includes consideration of sharpness. So it may be
/// that face-varying values are assigned around a vertex on a boundary in
/// a way that appears to match, but the face-varying interpolation option
/// requires sharpening of that vertex in face-varying space -- the
/// difference in the topology of the resulting limit surfaces leading to
/// the query returning false for the match. The edge case is simpler in
/// that it only considers continuity across the edge, not the entire
/// neighborhood around each end vertex.
/// \brief Return the number of face-varying channels (should be same for all levels)
int GetNumFVarChannels() const { return _level->getNumFVarChannels(); }
/// \brief Return the total number of face-varying values in a particular channel
/// (the upper bound of a face-varying value index)
int GetNumFVarValues(int channel = 0) const { return _level->getNumFVarValues(channel); }
/// \brief Access the face-varying values associated with a particular face
ConstIndexArray GetFaceFVarValues(Index f, int channel = 0) const {
return _level->getFaceFVarValues(f, channel);
}
/// \brief Return if face-varying topology around a vertex matches
bool DoesVertexFVarTopologyMatch(Index v, int channel = 0) const {
return _level->doesVertexFVarTopologyMatch(v, channel);
}
/// \brief Return if face-varying topology across the edge only matches
bool DoesEdgeFVarTopologyMatch(Index e, int channel = 0) const {
return _level->doesEdgeFVarTopologyMatch(e, channel);
}
/// \brief Return if face-varying topology around a face matches
bool DoesFaceFVarTopologyMatch(Index f, int channel = 0) const {
return _level->doesFaceFVarTopologyMatch(f, channel);
}
//@}
//@{
/// @name Methods to identify parent or child components in adjoining levels of refinement:
/// \brief Access the child faces (in the next level) of a given face
ConstIndexArray GetFaceChildFaces(Index f) const { return _refToChild->getFaceChildFaces(f); }
/// \brief Access the child edges (in the next level) of a given face
ConstIndexArray GetFaceChildEdges(Index f) const { return _refToChild->getFaceChildEdges(f); }
/// \brief Access the child edges (in the next level) of a given edge
ConstIndexArray GetEdgeChildEdges(Index e) const { return _refToChild->getEdgeChildEdges(e); }
/// \brief Return the child vertex (in the next level) of a given face
Index GetFaceChildVertex( Index f) const { return _refToChild->getFaceChildVertex(f); }
/// \brief Return the child vertex (in the next level) of a given edge
Index GetEdgeChildVertex( Index e) const { return _refToChild->getEdgeChildVertex(e); }
/// \brief Return the child vertex (in the next level) of a given vertex
Index GetVertexChildVertex(Index v) const { return _refToChild->getVertexChildVertex(v); }
/// \brief Return the parent face (in the previous level) of a given face
Index GetFaceParentFace(Index f) const { return _refToParent->getChildFaceParentFace(f); }
//@}
//@{
/// @name Debugging aides:
bool ValidateTopology() const { return _level->validateTopology(); }
void PrintTopology(bool children = true) const { _level->print((children && _refToChild) ? _refToChild : 0); }
//@}
private:
friend class TopologyRefiner;
Vtr::internal::Level const * _level;
Vtr::internal::Refinement const * _refToParent;
Vtr::internal::Refinement const * _refToChild;
public:
// Not intended for public use, but required by std::vector, etc...
TopologyLevel() { }
~TopologyLevel() { }
};
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_TOPOLOGY_LEVEL_H */
+298
View File
@@ -0,0 +1,298 @@
//
// Copyright 2014 DreamWorks Animation LLC.
//
// 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_FAR_TOPOLOGY_REFINER_H
#define OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H
#include "../version.h"
#include "../sdc/types.h"
#include "../sdc/options.h"
#include "../far/types.h"
#include "../far/topologyLevel.h"
#include <vector>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Vtr { namespace internal { class SparseSelector; } }
namespace Far { namespace internal { class FeatureMask; } }
namespace Far {
template <typename REAL> class PrimvarRefinerReal;
template <class MESH> class TopologyRefinerFactory;
///
/// \brief Stores topology data for a specified set of refinement options.
///
class TopologyRefiner {
public:
/// \brief Constructor
TopologyRefiner(Sdc::SchemeType type, Sdc::Options options = Sdc::Options());
/// \brief Destructor
~TopologyRefiner();
/// \brief Returns the subdivision scheme
Sdc::SchemeType GetSchemeType() const { return _subdivType; }
/// \brief Returns the subdivision options
Sdc::Options GetSchemeOptions() const { return _subdivOptions; }
/// \brief Returns true if uniform refinement has been applied
bool IsUniform() const { return _isUniform; }
/// \brief Returns the number of refinement levels
int GetNumLevels() const { return (int)_farLevels.size(); }
/// \brief Returns the highest level of refinement
int GetMaxLevel() const { return _maxLevel; }
/// \brief Returns the maximum vertex valence in all levels
int GetMaxValence() const { return _maxValence; }
/// \brief Returns true if faces have been tagged as holes
bool HasHoles() const { return _hasHoles; }
/// \brief Returns the total number of vertices in all levels
int GetNumVerticesTotal() const { return _totalVertices; }
/// \brief Returns the total number of edges in all levels
int GetNumEdgesTotal() const { return _totalEdges; }
/// \brief Returns the total number of edges in all levels
int GetNumFacesTotal() const { return _totalFaces; }
/// \brief Returns the total number of face vertices in all levels
int GetNumFaceVerticesTotal() const { return _totalFaceVertices; }
/// \brief Returns a handle to access data specific to a particular level
TopologyLevel const & GetLevel(int level) const { return _farLevels[level]; }
//@{
/// @name High-level refinement and related methods
///
//
// Uniform refinement
//
/// \brief Uniform refinement options
///
/// Options for uniform refinement, including the number of levels, vertex
/// ordering and generation of topology information.
///
/// Note the impact of the option to generate fullTopologyInLastLevel. Given
/// subsequent levels of uniform refinement typically reguire 4x the data
/// of the previous level, only the minimum amount of data is generated in the
/// last level by default, i.e. a vertex and face-vertex list. If requiring
/// topology traversal of the last level, e.g. inspecting edges or incident
/// faces of vertices, the option to generate full topology in the last
/// level should be enabled.
///
struct UniformOptions {
UniformOptions(int level) :
refinementLevel(level),
orderVerticesFromFacesFirst(false),
fullTopologyInLastLevel(false) { }
unsigned int refinementLevel:4, ///< Number of refinement iterations
orderVerticesFromFacesFirst:1, ///< Order child vertices from faces first
///< instead of child vertices of vertices
fullTopologyInLastLevel:1; ///< Skip topological relationships in the last
///< level of refinement that are not needed for
///< interpolation (keep false if using limit).
};
/// \brief Refine the topology uniformly
///
/// This method applies uniform refinement to the level specified in the
/// given UniformOptions.
///
/// Note the impact of the UniformOption to generate fullTopologyInLastLevel
/// and be sure it is assigned to satisfy the needs of the resulting refinement.
///
/// @param options Options controlling uniform refinement
///
void RefineUniform(UniformOptions options);
/// \brief Returns the options specified on refinement
UniformOptions GetUniformOptions() const { return _uniformOptions; }
//
// Adaptive refinement
//
/// \brief Adaptive refinement options
struct AdaptiveOptions {
AdaptiveOptions(int level) :
isolationLevel(level),
secondaryLevel(15),
useSingleCreasePatch(false),
useInfSharpPatch(false),
considerFVarChannels(false),
orderVerticesFromFacesFirst(false) { }
unsigned int isolationLevel:4; ///< Number of iterations applied to isolate
///< extraordinary vertices and creases
unsigned int secondaryLevel:4; ///< Shallower level to stop isolation of
///< smooth irregular features
unsigned int useSingleCreasePatch:1; ///< Use 'single-crease' patch and stop
///< isolation where applicable
unsigned int useInfSharpPatch:1; ///< Use infinitely sharp patches and stop
///< isolation where applicable
unsigned int considerFVarChannels:1; ///< Inspect face-varying channels and
///< isolate when irregular features present
unsigned int orderVerticesFromFacesFirst:1; ///< Order child vertices from faces first
///< instead of child vertices of vertices
};
/// \brief Feature Adaptive topology refinement
///
/// @param options Options controlling adaptive refinement
///
/// @param selectedFaces Limit adaptive refinement to the specified faces
///
void RefineAdaptive(AdaptiveOptions options,
ConstIndexArray selectedFaces = ConstIndexArray());
/// \brief Returns the options specified on refinement
AdaptiveOptions GetAdaptiveOptions() const { return _adaptiveOptions; }
/// \brief Unrefine the topology, keeping only the base level.
void Unrefine();
//@{
/// @name Number and properties of face-varying channels:
///
/// \brief Returns the number of face-varying channels in the tables
int GetNumFVarChannels() const;
/// \brief Returns the face-varying interpolation rule set for a given channel
Sdc::Options::FVarLinearInterpolation GetFVarLinearInterpolation(int channel = 0) const;
/// \brief Returns the total number of face-varying values in all levels
int GetNumFVarValuesTotal(int channel = 0) const;
//@}
protected:
//
// Lower level protected methods intended strictly for internal use:
//
template <class MESH>
friend class TopologyRefinerFactory;
friend class TopologyRefinerFactoryBase;
friend class PatchTableBuilder;
friend class PatchBuilder;
friend class PtexIndices;
template <typename REAL>
friend class PrimvarRefinerReal;
// Copy constructor exposed via the factory class:
TopologyRefiner(TopologyRefiner const & source);
Vtr::internal::Level & getLevel(int l) { return *_levels[l]; }
Vtr::internal::Level const & getLevel(int l) const { return *_levels[l]; }
Vtr::internal::Refinement & getRefinement(int l) { return *_refinements[l]; }
Vtr::internal::Refinement const & getRefinement(int l) const { return *_refinements[l]; }
private:
// Not default constructible or copyable:
TopologyRefiner() : _uniformOptions(0), _adaptiveOptions(0) { }
TopologyRefiner & operator=(TopologyRefiner const &) { return *this; }
void selectFeatureAdaptiveComponents(Vtr::internal::SparseSelector& selector,
internal::FeatureMask const & mask,
ConstIndexArray selectedFaces);
void selectLinearIrregularFaces(Vtr::internal::SparseSelector& selector,
ConstIndexArray selectedFaces);
void initializeInventory();
void updateInventory(Vtr::internal::Level const & newLevel);
void appendLevel(Vtr::internal::Level & newLevel);
void appendRefinement(Vtr::internal::Refinement & newRefinement);
void assembleFarLevels();
private:
Sdc::SchemeType _subdivType;
Sdc::Options _subdivOptions;
unsigned int _isUniform : 1;
unsigned int _hasHoles : 1;
unsigned int _hasIrregFaces : 1;
unsigned int _regFaceSize : 3;
unsigned int _maxLevel : 4;
// Options assigned on refinement:
UniformOptions _uniformOptions;
AdaptiveOptions _adaptiveOptions;
// Cumulative properties of all levels:
int _totalVertices;
int _totalEdges;
int _totalFaces;
int _totalFaceVertices;
int _maxValence;
// Note the base level may be shared with another instance
bool _baseLevelOwned;
std::vector<Vtr::internal::Level *> _levels;
std::vector<Vtr::internal::Refinement *> _refinements;
std::vector<TopologyLevel> _farLevels;
};
inline int
TopologyRefiner::GetNumFVarChannels() const {
return _levels[0]->getNumFVarChannels();
}
inline Sdc::Options::FVarLinearInterpolation
TopologyRefiner::GetFVarLinearInterpolation(int channel) const {
return _levels[0]->getFVarOptions(channel).GetFVarLinearInterpolation();
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H */
@@ -0,0 +1,710 @@
//
// Copyright 2014 DreamWorks Animation LLC.
//
// 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_FAR_TOPOLOGY_REFINER_FACTORY_H
#define OPENSUBDIV3_FAR_TOPOLOGY_REFINER_FACTORY_H
#include "../version.h"
#include "../far/topologyRefiner.h"
#include "../far/error.h"
#include <cassert>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
///\brief Private base class of Factories for constructing TopologyRefiners
///
/// TopologyRefinerFactoryBase is the base class for subclasses that are intended to
/// construct TopologyRefiners directly from meshes in their native representations.
/// The subclasses are parameterized by the mesh type \<class MESH\> and are expected
/// to inherit the details related to assembly and validation provided here that are
/// independent of the subclass' mesh type.
//
class TopologyRefinerFactoryBase {
protected:
//
// Protected methods invoked by the subclass template to verify and process each
// stage of construction implemented by the subclass:
//
typedef Vtr::internal::Level::ValidationCallback TopologyCallback;
static bool prepareComponentTopologySizing(TopologyRefiner& refiner);
static bool prepareComponentTopologyAssignment(TopologyRefiner& refiner, bool fullValidation,
TopologyCallback callback, void const * callbackData);
static bool prepareComponentTagsAndSharpness(TopologyRefiner& refiner);
static bool prepareFaceVaryingChannels(TopologyRefiner& refiner);
};
///\brief Factory for constructing TopologyRefiners from specific mesh classes.
///
/// TopologyRefinerFactory<MESH> is the factory class template to convert an instance of
/// TopologyRefiner from an arbitrary mesh class. While a class template, the implementation
/// is not (cannot) be complete, so specialization of a few methods is required (it is a
/// stateless factory, so no instance and only static methods).
///
/// This template provides both the interface and high level assembly for the construction
/// of the TopologyRefiner instance. The high level construction executes a specific set
/// of operations to convert the client's MESH into TopologyRefiner. This set of operations
/// combines methods independent of MESH from the base class with those specialized here for
/// class MESH.
///
template <class MESH>
class TopologyRefinerFactory : public TopologyRefinerFactoryBase {
public:
/// \brief Options related to the construction of each TopologyRefiner.
///
struct Options {
Options(Sdc::SchemeType sdcType = Sdc::SCHEME_CATMARK, Sdc::Options sdcOptions = Sdc::Options()) :
schemeType(sdcType),
schemeOptions(sdcOptions),
validateFullTopology(false) { }
Sdc::SchemeType schemeType; ///< The subdivision scheme type identifier
Sdc::Options schemeOptions; ///< The full set of options for the scheme,
///< e.g. boundary interpolation rules...
unsigned int validateFullTopology : 1; ///< Apply more extensive validation of
///< the constructed topology -- intended
///< for debugging.
};
/// \brief Instantiates a TopologyRefiner from client-provided topological
/// representation.
///
/// If only the face-vertices topological relationships are specified
/// with this factory, edge relationships have to be inferred, which
/// requires additional processing. If the client topological rep can
/// provide this information, it is highly recommended to do so.
///
/// @param mesh Client's topological representation (or a converter)
//
/// @param options Options controlling the creation of the TopologyRefiner
///
/// @return A new instance of TopologyRefiner or 0 for failure
///
static TopologyRefiner* Create(MESH const& mesh, Options options = Options());
/// \brief Instantiates a TopologyRefiner from the base level of an
/// existing instance.
///
/// This allows lightweight copies of the same topology to be refined
/// differently for each new instance. As with other classes that refer
/// to an existing TopologyRefiner, it must generally exist for the entire
/// lifetime of the new instance. In this case, the base level of the
/// original instance must be preserved.
///
/// @param baseLevel An existing TopologyRefiner to share base level.
///
/// @return A new instance of TopologyRefiner or 0 for failure
///
static TopologyRefiner* Create(TopologyRefiner const & baseLevel);
protected:
typedef Vtr::internal::Level::TopologyError TopologyError;
//@{
/// @name Methods to be provided to complete assembly of the TopologyRefiner
///
///
/// These methods are to be specialized to implement all details specific to
/// class MESH required to convert MESH data to TopologyRefiner. Note that
/// some of these *must* be specialized in order to complete construction while
/// some are optional.
///
/// There are two minimal construction requirements (to specify the size and
/// content of all topology relations) and three optional (to specify feature
/// tags, face-varying data, and runtime validation and error reporting).
///
/// See comments in the generic stubs, the factory for Far::TopologyDescriptor
/// or the tutorials for more details on writing these.
///
/// \brief Specify the number of vertices, faces, face-vertices, etc.
static bool resizeComponentTopology(TopologyRefiner& newRefiner, MESH const& mesh);
/// \brief Specify the relationships between vertices, faces, etc. ie the
/// face-vertices, vertex-faces, edge-vertices, etc.
static bool assignComponentTopology(TopologyRefiner& newRefiner, MESH const& mesh);
/// \brief (Optional) Specify edge or vertex sharpness or face holes
static bool assignComponentTags(TopologyRefiner& newRefiner, MESH const& mesh);
/// \brief (Optional) Specify face-varying data per face
static bool assignFaceVaryingTopology(TopologyRefiner& newRefiner, MESH const& mesh);
/// \brief (Optional) Control run-time topology validation and error reporting
static void reportInvalidTopology(TopologyError errCode, char const * msg, MESH const& mesh);
//@}
protected:
//@{
/// @name Base level assembly methods to be used within resizeComponentTopology()
///
/// \brief These methods specify sizes of various quantities, e.g. the number of
/// vertices, faces, face-vertices, etc. The number of the primary components
/// (vertices, faces and edges) should be specified prior to anything else that
/// references them (e.g. we need to know the number of faces before specifying
/// the vertices for that face.
///
/// If a full boundary representation with all neighborhood information is not
/// available, e.g. faces and vertices are available but not edges, only the
/// face-vertices should be specified. The remaining topological relationships
/// will be constructed later in the assembly (though at greater cost than if
/// specified directly).
///
/// The sizes for topological relationships between individual components should be
/// specified in order, i.e. the number of face-vertices for each successive face.
///
/// \brief Specify the number of vertices to be accommodated
static void setNumBaseVertices(TopologyRefiner & newRefiner, int count);
/// \brief Specify the number of faces to be accommodated
static void setNumBaseFaces(TopologyRefiner & newRefiner, int count);
/// \brief Specify the number of edges to be accommodated
static void setNumBaseEdges(TopologyRefiner & newRefiner, int count);
/// \brief Specify the number of vertices incident each face
static void setNumBaseFaceVertices(TopologyRefiner & newRefiner, Index f, int count);
/// \brief Specify the number of faces incident each edge
static void setNumBaseEdgeFaces(TopologyRefiner & newRefiner, Index e, int count);
/// \brief Specify the number of faces incident each vertex
static void setNumBaseVertexFaces(TopologyRefiner & newRefiner, Index v, int count);
/// \brief Specify the number of edges incident each vertex
static void setNumBaseVertexEdges(TopologyRefiner & newRefiner, Index v, int count);
static int getNumBaseVertices(TopologyRefiner const & newRefiner);
static int getNumBaseFaces(TopologyRefiner const & newRefiner);
static int getNumBaseEdges(TopologyRefiner const & newRefiner);
//@}
//@{
/// @name Base level assembly methods to be used within assignComponentTopology()
///
/// \brief These methods populate relationships between components -- in much the
/// same manner as they are inspected once the TopologyRefiner is completed.
///
/// An array of fixed size is returned from these methods and its entries are to be
/// populated with the appropriate indices for its neighbors. At minimum, the
/// vertices for each face must be specified. As noted previously, the remaining
/// relationships will be constructed as needed.
///
/// The ordering of entries in these arrays is important -- they are expected to
/// be ordered counter-clockwise for a right-hand orientation.
///
/// Non-manifold components must be explicitly tagged as such and they do not
/// require the ordering expected of manifold components. Special consideration
/// must also be given to certain non-manifold situations, e.g. the same edge
/// cannot appear twice in a face, and a degenerate edge (same vertex at both
/// ends) can only have one incident face. Such considerations are typically
/// achievable by creating multiple instances of an edge. So while there will
/// always be a one-to-one correspondence between vertices and faces, the same
/// is not guaranteed of edges in certain non-manifold circumstances.
///
/// \brief Assign the vertices incident each face
static IndexArray getBaseFaceVertices(TopologyRefiner & newRefiner, Index f);
/// \brief Assign the edges incident each face
static IndexArray getBaseFaceEdges(TopologyRefiner & newRefiner, Index f);
/// \brief Assign the vertices incident each edge
static IndexArray getBaseEdgeVertices(TopologyRefiner & newRefiner, Index e);
/// \brief Assign the faces incident each edge
static IndexArray getBaseEdgeFaces(TopologyRefiner & newRefiner, Index e);
/// \brief Assign the faces incident each vertex
static IndexArray getBaseVertexFaces(TopologyRefiner & newRefiner, Index v);
/// \brief Assign the edges incident each vertex
static IndexArray getBaseVertexEdges(TopologyRefiner & newRefiner, Index v);
/// \brief Assign the local indices of a vertex within each of its incident faces
static LocalIndexArray getBaseVertexFaceLocalIndices(TopologyRefiner & newRefiner, Index v);
/// \brief Assign the local indices of a vertex within each of its incident edges
static LocalIndexArray getBaseVertexEdgeLocalIndices(TopologyRefiner & newRefiner, Index v);
/// \brief Assign the local indices of an edge within each of its incident faces
static LocalIndexArray getBaseEdgeFaceLocalIndices(TopologyRefiner & newRefiner, Index e);
/// \brief Determine all local indices by inspection (only for pure manifold meshes)
static void populateBaseLocalIndices(TopologyRefiner & newRefiner);
/// \brief Tag an edge as non-manifold
static void setBaseEdgeNonManifold(TopologyRefiner & newRefiner, Index e, bool b);
/// \brief Tag a vertex as non-manifold
static void setBaseVertexNonManifold(TopologyRefiner & newRefiner, Index v, bool b);
//@}
//@{
/// @name Base level assembly methods to be used within assignComponentTags()
///
/// These methods are used to assign edge or vertex sharpness, for tagging faces
/// as holes, etc. Unlike topological assignment, only those components that
/// possess a feature of interest need be explicitly assigned.
///
/// Since topological construction is largely complete by this point, a method is
/// available to identify an edge for sharpness assignment given a pair of vertices.
///
/// \brief Identify an edge to be assigned a sharpness value given a vertex pair
static Index findBaseEdge(TopologyRefiner const & newRefiner, Index v0, Index v1);
/// \brief Assign a sharpness value to a given edge
static void setBaseEdgeSharpness(TopologyRefiner & newRefiner, Index e, float sharpness);
/// \brief Assign a sharpness value to a given vertex
static void setBaseVertexSharpness(TopologyRefiner & newRefiner, Index v, float sharpness);
/// \brief Tag a face as a hole
static void setBaseFaceHole(TopologyRefiner & newRefiner, Index f, bool isHole);
//@}
//@{
/// @name Base level assembly methods to be used within assignFaceVaryingTopology()
///
/// Face-varying data is assigned to faces in much the same way as face-vertex
/// topology is assigned -- indices for face-varying values are assigned to the
/// corners of each face just as indices for vertices were assigned.
///
/// Independent sets of face-varying data are stored in channels. The identifier
/// of each channel (an integer) is expected whenever referring to face-varying
/// data in any form.
///
/// \brief Create a new face-varying channel with the given number of values
static int createBaseFVarChannel(TopologyRefiner & newRefiner, int numValues);
/// \brief Create a new face-varying channel with the given number of values and independent interpolation options
static int createBaseFVarChannel(TopologyRefiner & newRefiner, int numValues, Sdc::Options const& fvarOptions);
/// \brief Assign the face-varying values for the corners of each face
static IndexArray getBaseFaceFVarValues(TopologyRefiner & newRefiner, Index face, int channel = 0);
//@}
protected:
//
// Not to be specialized:
//
static bool populateBaseLevel(TopologyRefiner& refiner, MESH const& mesh, Options options);
};
//
// Generic implementations:
//
template <class MESH>
TopologyRefiner*
TopologyRefinerFactory<MESH>::Create(MESH const& mesh, Options options) {
TopologyRefiner * refiner = new TopologyRefiner(options.schemeType, options.schemeOptions);
if (! populateBaseLevel(*refiner, mesh, options)) {
delete refiner;
return 0;
}
// Eventually want to move the Refiner's inventory initialization here. Currently it
// is handled after topology assignment, but if the inventory is to include additional
// features (e.g. holes, etc.) it is better off deferred to here.
return refiner;
}
template <class MESH>
TopologyRefiner*
TopologyRefinerFactory<MESH>::Create(TopologyRefiner const & source) {
return new TopologyRefiner(source);
}
template <class MESH>
bool
TopologyRefinerFactory<MESH>::populateBaseLevel(TopologyRefiner& refiner, MESH const& mesh, Options options) {
//
// Construction of a specialized topology refiner involves four steps, each of which
// involves a method specialized for MESH followed by one that takes an action in
// response to it or in preparation for the next step.
//
// Both the specialized methods and those that follow them may find fault in the
// construction and trigger failure at any time:
//
//
// Sizing of the topology -- this is a required specialization for MESH. This defines
// an inventory of all components and their relations that is used to allocate buffers
// to be efficiently populated in the subsequent topology assignment step.
//
if (! resizeComponentTopology(refiner, mesh)) return false;
if (! prepareComponentTopologySizing(refiner)) return false;
//
// Assignment of the topology -- this is a required specialization for MESH. If edges
// are specified, all other topological relations are expected to be defined for them.
// Otherwise edges and remaining topology will be completed from the face-vertices:
//
bool validate = options.validateFullTopology;
TopologyCallback callback = reinterpret_cast<TopologyCallback>(reportInvalidTopology);
void const * userData = &mesh;
if (! assignComponentTopology(refiner, mesh)) return false;
if (! prepareComponentTopologyAssignment(refiner, validate, callback, userData)) return false;
//
// User assigned and internal tagging of components -- an optional specialization for
// MESH. Allows the specification of sharpness values, holes, etc.
//
if (! assignComponentTags(refiner, mesh)) return false;
if (! prepareComponentTagsAndSharpness(refiner)) return false;
//
// Defining channels of face-varying primvar data -- an optional specialization for MESH.
//
if (! assignFaceVaryingTopology(refiner, mesh)) return false;
if (! prepareFaceVaryingChannels(refiner)) return false;
return true;
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setNumBaseFaces(TopologyRefiner & newRefiner, int count) {
newRefiner._levels[0]->resizeFaces(count);
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setNumBaseEdges(TopologyRefiner & newRefiner, int count) {
newRefiner._levels[0]->resizeEdges(count);
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setNumBaseVertices(TopologyRefiner & newRefiner, int count) {
newRefiner._levels[0]->resizeVertices(count);
}
template <class MESH>
inline int
TopologyRefinerFactory<MESH>::getNumBaseFaces(TopologyRefiner const & newRefiner) {
return newRefiner._levels[0]->getNumFaces();
}
template <class MESH>
inline int
TopologyRefinerFactory<MESH>::getNumBaseEdges(TopologyRefiner const & newRefiner) {
return newRefiner._levels[0]->getNumEdges();
}
template <class MESH>
inline int
TopologyRefinerFactory<MESH>::getNumBaseVertices(TopologyRefiner const & newRefiner) {
return newRefiner._levels[0]->getNumVertices();
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setNumBaseFaceVertices(TopologyRefiner & newRefiner, Index f, int count) {
newRefiner._levels[0]->resizeFaceVertices(f, count);
newRefiner._hasIrregFaces |= (count != newRefiner._regFaceSize);
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setNumBaseEdgeFaces(TopologyRefiner & newRefiner, Index e, int count) {
newRefiner._levels[0]->resizeEdgeFaces(e, count);
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setNumBaseVertexFaces(TopologyRefiner & newRefiner, Index v, int count) {
newRefiner._levels[0]->resizeVertexFaces(v, count);
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setNumBaseVertexEdges(TopologyRefiner & newRefiner, Index v, int count) {
newRefiner._levels[0]->resizeVertexEdges(v, count);
}
template <class MESH>
inline IndexArray
TopologyRefinerFactory<MESH>::getBaseFaceVertices(TopologyRefiner & newRefiner, Index f) {
return newRefiner._levels[0]->getFaceVertices(f);
}
template <class MESH>
inline IndexArray
TopologyRefinerFactory<MESH>::getBaseFaceEdges(TopologyRefiner & newRefiner, Index f) {
return newRefiner._levels[0]->getFaceEdges(f);
}
template <class MESH>
inline IndexArray
TopologyRefinerFactory<MESH>::getBaseEdgeVertices(TopologyRefiner & newRefiner, Index e) {
return newRefiner._levels[0]->getEdgeVertices(e);
}
template <class MESH>
inline IndexArray
TopologyRefinerFactory<MESH>::getBaseEdgeFaces(TopologyRefiner & newRefiner, Index e) {
return newRefiner._levels[0]->getEdgeFaces(e);
}
template <class MESH>
inline IndexArray
TopologyRefinerFactory<MESH>::getBaseVertexFaces(TopologyRefiner & newRefiner, Index v) {
return newRefiner._levels[0]->getVertexFaces(v);
}
template <class MESH>
inline IndexArray
TopologyRefinerFactory<MESH>::getBaseVertexEdges(TopologyRefiner & newRefiner, Index v) {
return newRefiner._levels[0]->getVertexEdges(v);
}
template <class MESH>
inline LocalIndexArray
TopologyRefinerFactory<MESH>::getBaseEdgeFaceLocalIndices(TopologyRefiner & newRefiner, Index e) {
return newRefiner._levels[0]->getEdgeFaceLocalIndices(e);
}
template <class MESH>
inline LocalIndexArray
TopologyRefinerFactory<MESH>::getBaseVertexFaceLocalIndices(TopologyRefiner & newRefiner, Index v) {
return newRefiner._levels[0]->getVertexFaceLocalIndices(v);
}
template <class MESH>
inline LocalIndexArray
TopologyRefinerFactory<MESH>::getBaseVertexEdgeLocalIndices(TopologyRefiner & newRefiner, Index v) {
return newRefiner._levels[0]->getVertexEdgeLocalIndices(v);
}
template <class MESH>
inline Index
TopologyRefinerFactory<MESH>::findBaseEdge(TopologyRefiner const & newRefiner, Index v0, Index v1) {
return newRefiner._levels[0]->findEdge(v0, v1);
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::populateBaseLocalIndices(TopologyRefiner & newRefiner) {
newRefiner._levels[0]->populateLocalIndices();
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setBaseEdgeNonManifold(TopologyRefiner & newRefiner, Index e, bool b) {
newRefiner._levels[0]->setEdgeNonManifold(e, b);
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setBaseVertexNonManifold(TopologyRefiner & newRefiner, Index v, bool b) {
newRefiner._levels[0]->setVertexNonManifold(v, b);
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setBaseEdgeSharpness(TopologyRefiner & newRefiner, Index e, float s) {
newRefiner._levels[0]->getEdgeSharpness(e) = s;
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setBaseVertexSharpness(TopologyRefiner & newRefiner, Index v, float s) {
newRefiner._levels[0]->getVertexSharpness(v) = s;
}
template <class MESH>
inline void
TopologyRefinerFactory<MESH>::setBaseFaceHole(TopologyRefiner & newRefiner, Index f, bool b) {
newRefiner._levels[0]->setFaceHole(f, b);
newRefiner._hasHoles |= b;
}
template <class MESH>
inline int
TopologyRefinerFactory<MESH>::createBaseFVarChannel(TopologyRefiner & newRefiner, int numValues) {
return newRefiner._levels[0]->createFVarChannel(numValues, newRefiner._subdivOptions);
}
template <class MESH>
inline int
TopologyRefinerFactory<MESH>::createBaseFVarChannel(TopologyRefiner & newRefiner, int numValues, Sdc::Options const& fvarOptions) {
Sdc::Options newOptions = newRefiner._subdivOptions;
newOptions.SetFVarLinearInterpolation(fvarOptions.GetFVarLinearInterpolation());
return newRefiner._levels[0]->createFVarChannel(numValues, newOptions);
}
template <class MESH>
inline IndexArray
TopologyRefinerFactory<MESH>::getBaseFaceFVarValues(TopologyRefiner & newRefiner, Index face, int channel) {
return newRefiner._levels[0]->getFaceFVarValues(face, channel);
}
template <class MESH>
bool
TopologyRefinerFactory<MESH>::resizeComponentTopology(TopologyRefiner& /* refiner */, MESH const& /* mesh */) {
Error(FAR_RUNTIME_ERROR,
"Failure in TopologyRefinerFactory<>::resizeComponentTopology() -- no specialization provided.");
//
// Sizing the topology tables:
// This method is for determining the sizes of the various topology tables (and other
// data) associated with the mesh. Once completed, appropriate memory will be allocated
// and an additional method invoked to populate it accordingly.
//
// The following methods should be called -- first those to specify the number of faces,
// edges and vertices in the mesh:
//
// void setBaseFaceCount( TopologyRefiner& newRefiner, int count)
// void setBaseEdgeCount( TopologyRefiner& newRefiner, int count)
// void setBaseVertexCount(TopologyRefiner& newRefiner, int count)
//
// and then for each face, edge and vertex, the number of its incident components:
//
// void setBaseFaceVertexCount(TopologyRefiner& newRefiner, Index face, int count)
// void setBaseEdgeFaceCount( TopologyRefiner& newRefiner, Index edge, int count)
// void setBaseVertexFaceCount(TopologyRefiner& newRefiner, Index vertex, int count)
// void setBaseVertexEdgeCount(TopologyRefiner& newRefiner, Index vertex, int count)
//
// The count/size for a component type must be set before indices associated with that
// component type can be used.
//
// Note that it is only necessary to size 4 of the 6 supported topological relations --
// the number of edge-vertices is fixed at two per edge, and the number of face-edges is
// the same as the number of face-vertices.
//
// So a single pass through your mesh to gather up all of this sizing information will
// allow the Tables to be allocated appropriately once and avoid any dynamic resizing as
// it grows.
//
return false;
}
template <class MESH>
bool
TopologyRefinerFactory<MESH>::assignComponentTopology(TopologyRefiner& /* refiner */, MESH const& /* mesh */) {
Error(FAR_RUNTIME_ERROR,
"Failure in TopologyRefinerFactory<>::assignComponentTopology() -- no specialization provided.");
//
// Assigning the topology tables:
// Once the topology tables have been allocated, the six required topological
// relations can be directly populated using the following methods:
//
// IndexArray setBaseFaceVertices(TopologyRefiner& newRefiner, Index face)
// IndexArray setBaseFaceEdges(TopologyRefiner& newRefiner, Index face)
//
// IndexArray setBaseEdgeVertices(TopologyRefiner& newRefiner, Index edge)
// IndexArray setBaseEdgeFaces(TopologyRefiner& newRefiner, Index edge)
//
// IndexArray setBaseVertexEdges(TopologyRefiner& newRefiner, Index vertex)
// IndexArray setBaseVertexFaces(TopologyRefiner& newRefiner, Index vertex)
//
// For the last two relations -- the faces and edges incident a vertex -- there are
// also "local indices" that must be specified (considering doing this internally),
// where the "local index" of each incident face or edge is the index of the vertex
// within that face or edge, and so ranging from 0-3 for incident quads and 0-1 for
// incident edges. These are assigned through similarly retrieved arrays:
//
// LocalIndexArray setBaseVertexFaceLocalIndices(TopologyRefiner& newRefiner, Index vertex)
// LocalIndexArray setBaseVertexEdgeLocalIndices(TopologyRefiner& newRefiner, Index vertex)
// LocalIndexArray setBaseEdgeFaceLocalIndices( TopologyRefiner& newRefiner, Index edge)
//
// or, if the mesh is manifold, explicit assignment of these can be deferred and
// all can be determined by calling:
//
// void populateBaseLocalIndices(TopologyRefiner& newRefiner)
//
// All components are assumed to be locally manifold and ordering of components in
// the above relations is expected to be counter-clockwise.
//
// For non-manifold components, no ordering/orientation of incident components is
// assumed or required, but be sure to explicitly tag such components (vertices and
// edges) as non-manifold:
//
// void setBaseEdgeNonManifold(TopologyRefiner& newRefiner, Index edge, bool b);
//
// void setBaseVertexNonManifold(TopologyRefiner& newRefiner, Index vertex, bool b);
//
// Also consider using TopologyLevel::ValidateTopology() when debugging to ensure
// that topology has been completely and correctly specified.
//
return false;
}
template <class MESH>
bool
TopologyRefinerFactory<MESH>::assignFaceVaryingTopology(TopologyRefiner& /* refiner */, MESH const& /* mesh */) {
//
// Optional assigning face-varying topology tables:
//
// Create independent face-varying primitive variable channels:
// int createBaseFVarChannel(TopologyRefiner& newRefiner, int numValues)
//
// For each channel, populate the face-vertex values:
// IndexArray setBaseFaceFVarValues(TopologyRefiner& newRefiner, Index face, int channel = 0)
//
return true;
}
template <class MESH>
bool
TopologyRefinerFactory<MESH>::assignComponentTags(TopologyRefiner& /* refiner */, MESH const& /* mesh */) {
//
// Optional tagging:
// This is where any additional feature tags -- sharpness, holes, etc. -- can be
// specified using:
//
// void setBaseEdgeSharpness(TopologyRefiner& newRefiner, Index edge, float sharpness)
// void setBaseVertexSharpness(TopologyRefiner& newRefiner, Index vertex, float sharpness)
//
// void setBaseFaceHole(TopologyRefiner& newRefiner, Index face, bool hole)
//
return true;
}
template <class MESH>
void
TopologyRefinerFactory<MESH>::reportInvalidTopology(
TopologyError /* errCode */, char const * /* msg */, MESH const& /* mesh */) {
//
// Optional topology validation error reporting:
// This method is called whenever the factory encounters topology validation
// errors. By default, nothing is reported
//
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_TOPOLOGY_REFINER_FACTORY_H */
+61
View File
@@ -0,0 +1,61 @@
//
// Copyright 2014 DreamWorks Animation LLC.
//
// 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_FAR_TYPES_H
#define OPENSUBDIV3_FAR_TYPES_H
#include "../version.h"
#include "../vtr/types.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
//
// Typedefs for indices that are inherited from the Vtr level -- eventually
// these primitive Vtr types may be declared at a lower, more public level.
//
typedef Vtr::Index Index;
typedef Vtr::LocalIndex LocalIndex;
typedef Vtr::IndexArray IndexArray;
typedef Vtr::LocalIndexArray LocalIndexArray;
typedef Vtr::ConstIndexArray ConstIndexArray;
typedef Vtr::ConstLocalIndexArray ConstLocalIndexArray;
inline bool IndexIsValid(Index index) { return Vtr::IndexIsValid(index); }
static const Index INDEX_INVALID = Vtr::INDEX_INVALID;
static const int VALENCE_LIMIT = Vtr::VALENCE_LIMIT;
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_FAR_TYPES_H */