2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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:
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
|
|
|
|
2013-03-23 01:20:50 +00:00
|
|
|
#ifndef FAR_PATCH_TABLES_H
|
|
|
|
#define FAR_PATCH_TABLES_H
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
#include "../version.h"
|
2013-03-25 14:32:17 +00:00
|
|
|
|
2013-05-17 16:47:44 +00:00
|
|
|
#include "../far/patchParam.h"
|
|
|
|
|
2013-05-09 16:23:01 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cassert>
|
2013-06-11 22:59:43 +00:00
|
|
|
#include <algorithm>
|
2013-03-08 01:50:15 +00:00
|
|
|
#include <vector>
|
2013-05-17 22:46:29 +00:00
|
|
|
#include <map>
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
/// \brief Container for patch vertex indices tables
|
|
|
|
///
|
|
|
|
/// FarPatchTables contain the lists of vertices for each patch of an adaptive
|
|
|
|
/// mesh representation.
|
|
|
|
///
|
|
|
|
class FarPatchTables {
|
|
|
|
|
|
|
|
public:
|
2013-05-09 00:06:59 +00:00
|
|
|
typedef std::vector<unsigned int> PTable;
|
|
|
|
typedef std::vector<int> VertexValenceTable;
|
|
|
|
typedef std::vector<unsigned int> QuadOffsetTable;
|
2013-05-17 16:47:44 +00:00
|
|
|
typedef std::vector<FarPatchParam> PatchParamTable;
|
2013-05-09 00:06:59 +00:00
|
|
|
typedef std::vector<float> FVarDataTable;
|
|
|
|
|
|
|
|
enum Type {
|
2013-07-11 01:51:43 +00:00
|
|
|
NON_PATCH = 0, ///< undefined
|
2013-05-09 01:47:36 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
POINTS, ///< points (useful for cage drawing)
|
|
|
|
LINES, ///< lines (useful for cage drawing)
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
QUADS, ///< bilinear quads-only patches
|
|
|
|
TRIANGLES, ///< bilinear triangles-only mesh
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
LOOP, ///< Loop patch (unsupported)
|
|
|
|
|
|
|
|
REGULAR, ///< feature-adaptive bicubic patches
|
2013-05-09 00:06:59 +00:00
|
|
|
BOUNDARY,
|
|
|
|
CORNER,
|
|
|
|
GREGORY,
|
|
|
|
GREGORY_BOUNDARY
|
|
|
|
};
|
2013-03-23 01:20:50 +00:00
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
enum TransitionPattern {
|
|
|
|
NON_TRANSITION = 0,
|
|
|
|
PATTERN0,
|
|
|
|
PATTERN1,
|
|
|
|
PATTERN2,
|
|
|
|
PATTERN3,
|
|
|
|
PATTERN4,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Describes the type of a patch
|
2013-05-09 01:47:36 +00:00
|
|
|
///
|
|
|
|
/// Uniquely identifies all the types of patches in a mesh :
|
|
|
|
///
|
|
|
|
/// * Raw polygon meshes are identified as POLYGONS and can contain faces
|
|
|
|
/// with arbitrary number of vertices
|
|
|
|
///
|
|
|
|
/// * Uniformly subdivided meshes contain bilinear patches of either QUADS
|
|
|
|
/// or TRIANGLES
|
|
|
|
///
|
|
|
|
/// * Adaptively subdivided meshes contain bicubic patches of types REGULAR,
|
|
|
|
/// BOUNDARY, CORNER, GREGORY, GREGORY_BOUNDARY. These bicubic patches are
|
|
|
|
/// also further distinguished by a transition pattern as well as a rotational
|
|
|
|
/// orientation.
|
|
|
|
///
|
|
|
|
/// An iterator class is provided as a convenience to enumerate over the set
|
|
|
|
/// of valid feature adaptive patch descriptors.
|
|
|
|
///
|
2013-05-09 00:06:59 +00:00
|
|
|
class Descriptor {
|
|
|
|
|
|
|
|
public:
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Default constructor.
|
2013-05-09 00:06:59 +00:00
|
|
|
Descriptor() :
|
2013-05-09 20:14:02 +00:00
|
|
|
_type(NON_PATCH), _pattern(NON_TRANSITION), _rotation(0) {}
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Constructor
|
2013-05-09 20:14:02 +00:00
|
|
|
Descriptor(int type, int pattern, unsigned char rotation) :
|
2013-05-14 01:43:05 +00:00
|
|
|
_type(type), _pattern(pattern), _rotation(rotation) { }
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Copy Constructor
|
2013-05-09 00:06:59 +00:00
|
|
|
Descriptor( Descriptor const & d ) :
|
2013-05-09 20:14:02 +00:00
|
|
|
_type(d.GetType()), _pattern(d.GetPattern()), _rotation(d.GetRotation()) { }
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the type of the patch
|
2013-05-09 00:06:59 +00:00
|
|
|
Type GetType() const {
|
2013-05-14 01:43:05 +00:00
|
|
|
return (Type)_type;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the transition pattern of the patch if any (5 types)
|
2013-05-09 00:06:59 +00:00
|
|
|
TransitionPattern GetPattern() const {
|
2013-05-14 01:43:05 +00:00
|
|
|
return (TransitionPattern)_pattern;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the rotation of the patch (4 rotations)
|
2013-05-09 00:06:59 +00:00
|
|
|
unsigned char GetRotation() const {
|
|
|
|
return _rotation;
|
|
|
|
}
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the number of control vertices expected for a patch of the
|
2013-05-09 01:47:36 +00:00
|
|
|
/// type described
|
2013-05-09 00:06:59 +00:00
|
|
|
static short GetNumControlVertices( Type t );
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the number of control vertices expected for a patch of the
|
2013-05-09 01:47:36 +00:00
|
|
|
/// type described
|
2013-05-09 00:06:59 +00:00
|
|
|
short GetNumControlVertices() const {
|
|
|
|
return GetNumControlVertices( this->GetType() );
|
|
|
|
}
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Iterates through the patches in the following preset order
|
|
|
|
///
|
|
|
|
/// Order:
|
2013-05-09 00:06:59 +00:00
|
|
|
///
|
2013-07-11 01:51:43 +00:00
|
|
|
/// NON_TRANSITION ( REGULAR
|
|
|
|
/// BOUNDARY
|
|
|
|
/// CORNER
|
|
|
|
/// GREGORY
|
|
|
|
/// GREGORY_BOUNDARY )
|
2013-05-09 00:06:59 +00:00
|
|
|
///
|
2013-07-11 01:51:43 +00:00
|
|
|
/// PATTERN0 ( REGULAR
|
|
|
|
/// BOUNDARY ROT0 ROT1 ROT2 ROT3
|
|
|
|
/// CORNER ROT0 ROT1 ROT2 ROT3 )
|
2013-05-09 00:06:59 +00:00
|
|
|
///
|
2013-07-11 01:51:43 +00:00
|
|
|
/// PATTERN1 ( REGULAR
|
|
|
|
/// BOUNDARY ROT0 ROT1 ROT2 ROT3
|
|
|
|
/// CORNER ROT0 ROT1 ROT2 ROT3 )
|
|
|
|
/// ...
|
2013-05-09 00:06:59 +00:00
|
|
|
///
|
2013-07-11 01:51:43 +00:00
|
|
|
/// NON_TRANSITION NON_PATCH ROT0 (end)
|
2013-05-09 00:06:59 +00:00
|
|
|
///
|
|
|
|
Descriptor & operator ++ ();
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Allows ordering of patches by type
|
2013-05-09 16:23:01 +00:00
|
|
|
bool operator < ( Descriptor const other ) const;
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief True if the descriptors are identical
|
2013-05-09 16:23:01 +00:00
|
|
|
bool operator == ( Descriptor const other ) const;
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Descriptor Iterator
|
2013-05-09 00:06:59 +00:00
|
|
|
class iterator;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns an iterator to the first type of patch (REGULAR NON_TRANSITION ROT0)
|
2013-06-24 23:59:49 +00:00
|
|
|
static iterator begin();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns an iterator to the end of the list of patch types (NON_PATCH)
|
2013-06-24 23:59:49 +00:00
|
|
|
static iterator end();
|
2013-05-09 00:06:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
template <class T> friend class FarPatchTablesFactory;
|
|
|
|
friend class iterator;
|
|
|
|
|
2013-05-14 01:43:05 +00:00
|
|
|
unsigned int _type:4;
|
|
|
|
unsigned int _pattern:3;
|
|
|
|
unsigned int _rotation:2;
|
2013-05-09 00:06:59 +00:00
|
|
|
};
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-17 16:06:40 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-17 16:06:40 +00:00
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
/// \brief Describes an array of patches of the same type
|
|
|
|
class PatchArray {
|
|
|
|
|
|
|
|
public:
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Constructor.
|
2013-05-10 17:44:03 +00:00
|
|
|
///
|
2013-05-17 21:07:53 +00:00
|
|
|
/// @param desc descriptor information for the patches in
|
|
|
|
/// the array
|
|
|
|
///
|
2013-05-10 17:44:03 +00:00
|
|
|
/// @param vertIndex absolute index to the first control vertex
|
|
|
|
/// of the first patch in the PTable
|
|
|
|
///
|
|
|
|
/// @param patchIndex absolute index of the first patch in the
|
|
|
|
/// array
|
|
|
|
///
|
|
|
|
/// @param npatches number of patches in the array
|
|
|
|
///
|
|
|
|
/// @param quadOffsetIndex absolute index of the first quad offset
|
|
|
|
/// entry
|
|
|
|
///
|
|
|
|
PatchArray( Descriptor desc, unsigned int vertIndex, unsigned int patchIndex, unsigned int npatches, unsigned int quadOffsetIndex ) :
|
|
|
|
_desc(desc), _range(vertIndex, patchIndex, npatches, quadOffsetIndex) { }
|
|
|
|
|
|
|
|
/// Returns a patch descriptor defining the type of patches in the array
|
|
|
|
Descriptor GetDescriptor() const {
|
|
|
|
return _desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Describes the range of patches in a PatchArray
|
2013-05-09 20:14:02 +00:00
|
|
|
struct ArrayRange {
|
2013-05-10 17:44:03 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Constructor
|
2013-05-10 17:44:03 +00:00
|
|
|
///
|
|
|
|
/// @param vertIndex absolute index to the first control vertex
|
|
|
|
/// of the first patch in the PTable
|
|
|
|
///
|
|
|
|
/// @param patchIndex absolute index of the first patch in the
|
|
|
|
/// array
|
|
|
|
///
|
|
|
|
/// @param npatches number of patches in the array
|
|
|
|
///
|
|
|
|
/// @param quadOffsetIndex absolute index of the first quad offset
|
|
|
|
/// entry
|
|
|
|
///
|
2013-05-09 20:14:02 +00:00
|
|
|
ArrayRange( unsigned int vertIndex, unsigned int patchIndex, unsigned int npatches, unsigned int quadOffsetIndex ) :
|
|
|
|
vertIndex(vertIndex), patchIndex(patchIndex), npatches(npatches), quadOffsetIndex(quadOffsetIndex) { }
|
|
|
|
|
|
|
|
unsigned int vertIndex, // absolute index to the first control vertex of the first patch in the PTable
|
|
|
|
patchIndex, // absolute index of the first patch in the array
|
|
|
|
npatches, // number of patches in the array
|
|
|
|
quadOffsetIndex; // absolute index of the first quad offset entry
|
|
|
|
};
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns a array range struct
|
2013-05-09 20:14:02 +00:00
|
|
|
ArrayRange const & GetArrayRange() const {
|
|
|
|
return _range;
|
|
|
|
}
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the index of the first control vertex of the first patch
|
2013-05-09 01:47:36 +00:00
|
|
|
/// of this array in the global PTable
|
2013-05-09 00:06:59 +00:00
|
|
|
unsigned int GetVertIndex() const {
|
2013-05-09 20:14:02 +00:00
|
|
|
return _range.vertIndex;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the global index of the first patch in this array (Used to
|
2013-05-17 16:47:44 +00:00
|
|
|
/// access param / fvar table data)
|
2013-05-09 00:06:59 +00:00
|
|
|
unsigned int GetPatchIndex() const {
|
2013-05-09 20:14:02 +00:00
|
|
|
return _range.patchIndex;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the number of patches in the array
|
2013-05-09 00:06:59 +00:00
|
|
|
unsigned int GetNumPatches() const {
|
2013-05-09 20:14:02 +00:00
|
|
|
return _range.npatches;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
2013-05-09 16:23:01 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the index to the first entry in the QuadOffsetTable
|
2013-05-09 16:23:01 +00:00
|
|
|
unsigned int GetQuadOffsetIndex() const {
|
2013-05-09 20:14:02 +00:00
|
|
|
return _range.quadOffsetIndex;
|
2013-05-09 16:23:01 +00:00
|
|
|
}
|
2013-05-09 00:06:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
template <class T> friend class FarPatchTablesFactory;
|
|
|
|
|
2013-05-09 20:14:02 +00:00
|
|
|
Descriptor _desc; // type of patches in the array
|
|
|
|
|
|
|
|
ArrayRange _range; // index locators in the array
|
2013-05-09 00:06:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<PatchArray> PatchArrayVector;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Constructor
|
2013-05-17 19:49:57 +00:00
|
|
|
///
|
|
|
|
/// @param patchArrays Vector of descriptors and ranges for arrays of patches
|
|
|
|
///
|
2013-05-17 21:39:07 +00:00
|
|
|
/// @param patches Indices of the control vertices of the patches
|
2013-05-17 19:49:57 +00:00
|
|
|
///
|
|
|
|
/// @param vertexValences Vertex valance table
|
|
|
|
///
|
|
|
|
/// @param quadOffsets Quad offset table
|
|
|
|
///
|
2013-05-17 21:39:07 +00:00
|
|
|
/// @param patchParams Local patch parameterization
|
2013-05-17 19:49:57 +00:00
|
|
|
///
|
|
|
|
/// @param fvarData Face varying data table
|
|
|
|
///
|
|
|
|
/// @param maxValence Highest vertex valence allowed in the mesh
|
|
|
|
///
|
|
|
|
FarPatchTables(PatchArrayVector const & patchArrays,
|
|
|
|
PTable const & patches,
|
|
|
|
VertexValenceTable const * vertexValences,
|
|
|
|
QuadOffsetTable const * quadOffsets,
|
|
|
|
PatchParamTable const * patchParams,
|
|
|
|
FVarDataTable const * fvarData,
|
|
|
|
int maxValence);
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Get the table of patch control vertices
|
2013-05-09 00:06:59 +00:00
|
|
|
PTable const & GetPatchTable() const { return _patches; }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns a pointer to the array of patches matching the descriptor
|
2013-05-09 01:47:36 +00:00
|
|
|
PatchArray const * GetPatchArray( Descriptor desc ) const {
|
2013-05-09 00:06:59 +00:00
|
|
|
return const_cast<FarPatchTables *>(this)->findPatchArray( desc );
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns all arrays of patches
|
2013-05-16 00:53:40 +00:00
|
|
|
PatchArrayVector const & GetPatchArrayVector() const {
|
2013-05-09 16:23:01 +00:00
|
|
|
return _patchArrays;
|
|
|
|
}
|
2013-05-16 00:53:40 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns a pointer to the vertex indices of uniformly subdivided faces
|
2013-05-16 00:53:40 +00:00
|
|
|
///
|
2013-07-26 17:38:49 +00:00
|
|
|
/// In uniform mode the FarPatchTablesFactory can be set to generate either a
|
|
|
|
/// patch array containing the faces at the highest level of subdivision, or
|
|
|
|
/// a range of arrays, corresponding to multiple successive levels of subdivision.
|
|
|
|
///
|
|
|
|
/// Note : level '0' is not the coarse mesh. Currently there is no path in the
|
|
|
|
/// factories to convert the coarse mesh to FarPatchTables.
|
|
|
|
///
|
2013-06-19 23:31:06 +00:00
|
|
|
/// @param level the level of subdivision of the faces (returns the highest
|
|
|
|
/// level by default)
|
2013-05-16 00:53:40 +00:00
|
|
|
///
|
|
|
|
/// @return a pointer to the first vertex index or NULL if the mesh
|
|
|
|
/// is not uniformly subdivided or the level cannot be found.
|
|
|
|
///
|
2013-06-19 23:31:06 +00:00
|
|
|
unsigned int const * GetFaceVertices(int level=0) const;
|
2013-05-09 16:23:01 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the number of faces in a uniformly subdivided mesh at a given level
|
2013-05-16 00:53:40 +00:00
|
|
|
///
|
2013-07-26 17:38:49 +00:00
|
|
|
/// In uniform mode the FarPatchTablesFactory can be set to generate either a
|
|
|
|
/// patch array containing the faces at the highest level of subdivision, or
|
|
|
|
/// a range of arrays, corresponding to multiple successive levels of subdivision.
|
|
|
|
///
|
|
|
|
/// Note : level '0' is not the coarse mesh. Currently there is no path in the
|
|
|
|
/// factories to convert the coarse mesh to FarPatchTables.
|
|
|
|
///
|
2013-06-19 23:31:06 +00:00
|
|
|
/// @param level the level of subdivision of the faces (returns the highest
|
|
|
|
/// level by default)
|
2013-05-16 00:53:40 +00:00
|
|
|
///
|
|
|
|
/// @return the number of faces in the mesh given the subdivision level
|
2013-06-19 23:31:06 +00:00
|
|
|
/// or -1 if the mesh is not uniform or the level is incorrect.
|
2013-05-16 00:53:40 +00:00
|
|
|
///
|
2013-06-19 23:31:06 +00:00
|
|
|
int GetNumFaces(int level=0) const;
|
2013-05-16 00:53:40 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns a vertex valence table used by Gregory patches
|
2012-12-11 01:15:13 +00:00
|
|
|
VertexValenceTable const & GetVertexValenceTable() const { return _vertexValenceTable; }
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns a quad offsets table used by Gregory patches
|
2012-12-11 01:15:13 +00:00
|
|
|
QuadOffsetTable const & GetQuadOffsetTable() const { return _quadOffsetTable; }
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns a PatchParamTable for each type of patch
|
2013-05-17 16:47:44 +00:00
|
|
|
PatchParamTable const & GetPatchParamTable() const { return _paramTable; }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns an FVarDataTable for each type of patch
|
2013-05-16 00:53:40 +00:00
|
|
|
/// The data is stored as a run of totalFVarWidth floats per-vertex per-face
|
|
|
|
/// e.g.: for UV data it has the structure of float[p][4][2] where
|
|
|
|
/// p=primitiveID and totalFVarWidth=2:
|
|
|
|
/// [ [ uv uv uv uv ] [ uv uv uv uv ] [ ... ] ]
|
|
|
|
/// prim 0 prim 1
|
2013-05-09 16:23:01 +00:00
|
|
|
FVarDataTable const & GetFVarDataTable() const { return _fvarTable; }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Ringsize of Regular Patches in table.
|
2012-12-11 01:15:13 +00:00
|
|
|
static int GetRegularPatchRingsize() { return 16; }
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Ringsize of Boundary Patches in table.
|
2012-12-11 01:15:13 +00:00
|
|
|
static int GetBoundaryPatchRingsize() { return 12; }
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Ringsize of Boundary Patches in table.
|
2012-12-11 01:15:13 +00:00
|
|
|
static int GetCornerPatchRingsize() { return 9; }
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Ringsize of Gregory (and Gregory Boundary) Patches in table.
|
2012-12-11 01:15:13 +00:00
|
|
|
static int GetGregoryPatchRingsize() { return 4; }
|
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the total number of patches stored in the tables
|
2013-05-09 00:06:59 +00:00
|
|
|
int GetNumPatches() const;
|
2013-03-23 01:20:50 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the total number of control vertex indices in the tables
|
2013-05-09 00:06:59 +00:00
|
|
|
int GetNumControlVertices() const;
|
2013-03-23 01:20:50 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns max vertex valence
|
2012-12-11 01:15:13 +00:00
|
|
|
int GetMaxValence() const { return _maxValence; }
|
2013-05-16 00:53:40 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief True if the patches are of feature adaptive types
|
2013-05-16 00:53:40 +00:00
|
|
|
bool IsFeatureAdaptive() const;
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
template <class T> friend class FarPatchTablesFactory;
|
2013-03-08 01:50:15 +00:00
|
|
|
template <class T, class U> friend class FarMultiMeshFactory;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-09 01:47:36 +00:00
|
|
|
// Returns the array of patches of type "desc", or NULL if there aren't any in the primitive
|
2013-05-09 00:06:59 +00:00
|
|
|
PatchArray * findPatchArray( Descriptor desc );
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// Private constructor
|
2013-03-08 01:50:15 +00:00
|
|
|
FarPatchTables( int maxvalence ) : _maxValence(maxvalence) { }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-16 00:53:40 +00:00
|
|
|
|
|
|
|
PatchArrayVector _patchArrays; // Vector of descriptors for arrays of patches
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-05-09 01:47:36 +00:00
|
|
|
PTable _patches; // Indices of the control vertices of the patches
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-09 01:47:36 +00:00
|
|
|
VertexValenceTable _vertexValenceTable; // vertex valence table (for Gregory patches)
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-05-09 01:47:36 +00:00
|
|
|
QuadOffsetTable _quadOffsetTable; // quad offsets table (for Gregory patches)
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2013-05-17 16:47:44 +00:00
|
|
|
PatchParamTable _paramTable;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-09 01:47:36 +00:00
|
|
|
FVarDataTable _fvarTable;
|
2013-03-08 01:50:15 +00:00
|
|
|
|
2013-03-23 01:20:50 +00:00
|
|
|
// highest vertex valence allowed in the mesh (used for Gregory
|
2013-05-09 16:23:01 +00:00
|
|
|
// vertexValance & quadOffset tables)
|
2013-03-23 01:20:50 +00:00
|
|
|
int _maxValence;
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
|
|
|
|
2013-06-24 23:59:49 +00:00
|
|
|
/// \brief Descriptor iterator class
|
|
|
|
class FarPatchTables::Descriptor::iterator {
|
|
|
|
public:
|
|
|
|
/// Constructor
|
|
|
|
iterator() {}
|
|
|
|
|
|
|
|
/// Copy Constructor
|
|
|
|
iterator(Descriptor desc) : pos(desc) { }
|
|
|
|
|
|
|
|
/// Iteration increment operator
|
|
|
|
iterator & operator ++ () { ++pos; return *this; }
|
|
|
|
|
|
|
|
/// True of the two descriptors are identical
|
|
|
|
bool operator == ( iterator const & other ) const { return (pos==other.pos); }
|
|
|
|
|
|
|
|
/// True if the two descriptors are different
|
|
|
|
bool operator != ( iterator const & other ) const { return not (*this==other); }
|
|
|
|
|
|
|
|
/// Dereferencing operator
|
|
|
|
Descriptor * operator -> () { return &pos; }
|
|
|
|
|
|
|
|
/// Dereferencing operator
|
|
|
|
Descriptor & operator * () { return pos; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Descriptor pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns an iterator to the first type of patch (REGULAR NON_TRANSITION ROT0)
|
|
|
|
inline FarPatchTables::Descriptor::iterator
|
|
|
|
FarPatchTables::Descriptor::begin() {
|
|
|
|
return iterator( Descriptor(REGULAR, NON_TRANSITION, 0) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns an iterator to the end of the list of patch types (NON_PATCH)
|
|
|
|
inline FarPatchTables::Descriptor::iterator
|
|
|
|
FarPatchTables::Descriptor::end() {
|
|
|
|
return iterator( Descriptor() );
|
|
|
|
}
|
|
|
|
|
2013-05-17 19:49:57 +00:00
|
|
|
// Constructor
|
|
|
|
inline
|
|
|
|
FarPatchTables::FarPatchTables(PatchArrayVector const & patchArrays,
|
|
|
|
PTable const & patches,
|
|
|
|
VertexValenceTable const * vertexValences,
|
|
|
|
QuadOffsetTable const * quadOffsets,
|
|
|
|
PatchParamTable const * patchParams,
|
|
|
|
FVarDataTable const * fvarData,
|
|
|
|
int maxValence) :
|
|
|
|
_patchArrays(patchArrays),
|
|
|
|
_patches(patches),
|
|
|
|
_maxValence(maxValence) {
|
|
|
|
|
|
|
|
// copy other tables if exist
|
|
|
|
if (vertexValences)
|
|
|
|
_vertexValenceTable = *vertexValences;
|
|
|
|
if (quadOffsets)
|
|
|
|
_quadOffsetTable = *quadOffsets;
|
|
|
|
if (patchParams)
|
|
|
|
_paramTable = *patchParams;
|
|
|
|
if (fvarData)
|
|
|
|
_fvarTable = *fvarData;
|
|
|
|
}
|
|
|
|
|
2013-05-16 00:53:40 +00:00
|
|
|
inline bool
|
|
|
|
FarPatchTables::IsFeatureAdaptive() const {
|
2013-06-10 21:36:25 +00:00
|
|
|
|
|
|
|
// the vertex valence table is only used by Gregory patches, so the PatchTables
|
|
|
|
// contain feature adaptive patches if this is not empty.
|
|
|
|
if (not _vertexValenceTable.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
PatchArrayVector const & parrays = GetPatchArrayVector();
|
|
|
|
|
|
|
|
// otherwise, we have to check each patch array
|
|
|
|
for (int i=0; i<(int)parrays.size(); ++i) {
|
|
|
|
|
|
|
|
if (parrays[i].GetDescriptor().GetType() >= REGULAR and
|
|
|
|
parrays[i].GetDescriptor().GetType() <= GREGORY_BOUNDARY)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
2013-05-16 00:53:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
// Returns the number of control vertices expected for a patch of this type
|
|
|
|
inline short
|
|
|
|
FarPatchTables::Descriptor::GetNumControlVertices( FarPatchTables::Type type ) {
|
|
|
|
switch (type) {
|
|
|
|
case REGULAR : return FarPatchTables::GetRegularPatchRingsize();
|
|
|
|
case QUADS : return 4;
|
|
|
|
case GREGORY :
|
|
|
|
case GREGORY_BOUNDARY : return FarPatchTables::GetGregoryPatchRingsize();
|
|
|
|
case BOUNDARY : return FarPatchTables::GetBoundaryPatchRingsize();
|
|
|
|
case CORNER : return FarPatchTables::GetCornerPatchRingsize();
|
|
|
|
case TRIANGLES : return 3;
|
2013-05-17 19:49:57 +00:00
|
|
|
case LINES : return 2;
|
|
|
|
case POINTS : return 1;
|
2013-05-09 00:06:59 +00:00
|
|
|
default : return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterates in order through the patch types, patterns and rotation in a preset order
|
|
|
|
inline FarPatchTables::Descriptor &
|
|
|
|
FarPatchTables::Descriptor::operator ++ () {
|
|
|
|
|
|
|
|
if (GetPattern()==NON_TRANSITION) {
|
|
|
|
if (GetType()==GREGORY_BOUNDARY) {
|
|
|
|
_type=REGULAR;
|
|
|
|
++_pattern;
|
|
|
|
} else
|
|
|
|
++_type;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
switch (GetType()) {
|
|
|
|
case REGULAR : ++_type;
|
|
|
|
_rotation=0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOUNDARY : if (GetRotation()==3) {
|
|
|
|
++_type;
|
|
|
|
_rotation=0;
|
|
|
|
} else {
|
|
|
|
++_rotation;
|
|
|
|
}; break;
|
|
|
|
|
|
|
|
case CORNER : if (GetRotation()==3) {
|
|
|
|
if (GetPattern()!=PATTERN4) {
|
|
|
|
_type=REGULAR;
|
|
|
|
_rotation=0;
|
|
|
|
++_pattern;
|
|
|
|
} else {
|
|
|
|
*this = Descriptor();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++_rotation;
|
|
|
|
}; break;
|
|
|
|
|
|
|
|
case NON_PATCH : break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-05-16 00:53:40 +00:00
|
|
|
// Returns a pointer to the vertex indices of uniformly subdivided faces
|
|
|
|
inline unsigned int const *
|
|
|
|
FarPatchTables::GetFaceVertices(int level) const {
|
|
|
|
|
|
|
|
if (IsFeatureAdaptive())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
PatchArrayVector const & parrays = GetPatchArrayVector();
|
|
|
|
|
2013-06-19 23:31:06 +00:00
|
|
|
if (parrays.empty())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (level < 1) {
|
|
|
|
return &GetPatchTable()[ parrays.rbegin()->GetVertIndex() ];
|
|
|
|
} else if ((level-1) < (int)parrays.size() ) {
|
2013-05-16 00:53:40 +00:00
|
|
|
return &GetPatchTable()[ parrays[level-1].GetVertIndex() ];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of faces in a uniformly subdivided mesh at a given level
|
|
|
|
inline int
|
|
|
|
FarPatchTables::GetNumFaces(int level) const {
|
|
|
|
|
|
|
|
if (IsFeatureAdaptive())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
PatchArrayVector const & parrays = GetPatchArrayVector();
|
|
|
|
|
2013-06-19 23:31:06 +00:00
|
|
|
if (parrays.empty())
|
2013-06-27 17:10:28 +00:00
|
|
|
return -1;
|
2013-06-19 23:31:06 +00:00
|
|
|
|
|
|
|
if (level < 1) {
|
|
|
|
return parrays.rbegin()->GetNumPatches();
|
|
|
|
} else if ( (level-1) < (int)parrays.size() ) {
|
2013-05-16 00:53:40 +00:00
|
|
|
return parrays[level-1].GetNumPatches();
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
// Allows ordering of patches by type
|
|
|
|
inline bool
|
2013-05-09 16:23:01 +00:00
|
|
|
FarPatchTables::Descriptor::operator < ( Descriptor const other ) const {
|
2013-05-09 17:53:22 +00:00
|
|
|
return _pattern < other._pattern or ((_pattern == other._pattern) and
|
|
|
|
(_type < other._type or ((_type == other._type) and
|
2013-05-09 20:14:02 +00:00
|
|
|
(_rotation < other._rotation))));
|
|
|
|
}
|
2013-05-09 00:06:59 +00:00
|
|
|
|
|
|
|
// True if the descriptors are identical
|
2013-05-09 16:23:01 +00:00
|
|
|
inline bool
|
|
|
|
FarPatchTables::Descriptor::operator == ( Descriptor const other ) const {
|
|
|
|
return _pattern == other._pattern and
|
|
|
|
_type == other._type and
|
2013-05-09 20:14:02 +00:00
|
|
|
_rotation == other._rotation;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a pointer to the array of patches matching the descriptor
|
|
|
|
inline FarPatchTables::PatchArray *
|
|
|
|
FarPatchTables::findPatchArray( FarPatchTables::Descriptor desc ) {
|
|
|
|
|
|
|
|
for (int i=0; i<(int)_patchArrays.size(); ++i) {
|
|
|
|
if (_patchArrays[i].GetDescriptor()==desc)
|
|
|
|
return &_patchArrays[i];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-23 01:20:50 +00:00
|
|
|
// Returns the total number of patches stored in the tables
|
2013-05-09 00:06:59 +00:00
|
|
|
inline int
|
2013-03-23 01:20:50 +00:00
|
|
|
FarPatchTables::GetNumPatches() const {
|
2013-06-11 22:59:43 +00:00
|
|
|
// there is one PatchParam record for each patch in the mesh
|
|
|
|
return (int)GetPatchParamTable().size();
|
2013-03-23 01:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the total number of control vertex indices in the tables
|
2013-05-09 00:06:59 +00:00
|
|
|
inline int
|
2013-03-23 01:20:50 +00:00
|
|
|
FarPatchTables::GetNumControlVertices() const {
|
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
int result=0;
|
|
|
|
for (int i=0; i<(int)_patchArrays.size(); ++i) {
|
|
|
|
result += _patchArrays[i].GetDescriptor().GetNumControlVertices() *
|
|
|
|
_patchArrays[i].GetNumPatches();
|
2013-03-23 01:20:50 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
return result;
|
2013-03-23 01:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2013-03-23 01:20:50 +00:00
|
|
|
#endif /* FAR_PATCH_TABLES */
|