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
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
#include "../far/patchParam.h"
|
2013-05-17 16:47:44 +00:00
|
|
|
#include "../far/patchParam.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#include "../far/types.h"
|
2013-05-17 16:47:44 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
#include "../sdc/type.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 {
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
namespace Far {
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
/// \brief Container for patch vertex indices tables
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
/// PatchTables contain the lists of vertices for each patch of an adaptive
|
2012-12-11 01:15:13 +00:00
|
|
|
/// mesh representation.
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
class PatchTables {
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
public:
|
2014-10-09 21:48:50 +00:00
|
|
|
|
|
|
|
typedef std::vector<Index> PTable;
|
|
|
|
typedef std::vector<Index> VertexValenceTable;
|
|
|
|
typedef std::vector<Index> QuadOffsetTable;
|
2014-09-05 22:07:46 +00:00
|
|
|
typedef std::vector<PatchParam> PatchParamTable;
|
2013-05-09 00:06:59 +00:00
|
|
|
|
|
|
|
enum Type {
|
2013-07-11 01:51:43 +00:00
|
|
|
NON_PATCH = 0, ///< undefined
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
POINTS, ///< points (useful for cage drawing)
|
|
|
|
LINES, ///< lines (useful for cage drawing)
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
QUADS, ///< bilinear quads-only patches
|
|
|
|
TRIANGLES, ///< bilinear triangles-only mesh
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
LOOP, ///< Loop patch (currently unsupported)
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
REGULAR, ///< feature-adaptive bicubic patches
|
2014-10-13 15:52:09 +00:00
|
|
|
SINGLE_CREASE,
|
2013-05-09 00:06:59 +00:00
|
|
|
BOUNDARY,
|
|
|
|
CORNER,
|
|
|
|
GREGORY,
|
|
|
|
GREGORY_BOUNDARY
|
|
|
|
};
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
enum TransitionPattern {
|
|
|
|
NON_TRANSITION = 0,
|
|
|
|
PATTERN0,
|
|
|
|
PATTERN1,
|
|
|
|
PATTERN2,
|
|
|
|
PATTERN3,
|
2014-05-16 01:03:44 +00:00
|
|
|
PATTERN4
|
2013-05-09 00:06:59 +00:00
|
|
|
};
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
public:
|
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
/// \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.
|
|
|
|
///
|
2013-05-09 00:06:59 +00:00
|
|
|
class Descriptor {
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
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) {}
|
2014-02-25 01:12:39 +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()) { }
|
2014-02-25 01:12:39 +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
|
|
|
}
|
2014-02-25 01:12:39 +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
|
|
|
}
|
2014-02-25 01:12:39 +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 {
|
2014-05-16 01:03:44 +00:00
|
|
|
return (unsigned char)_rotation;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
2014-02-25 01:12:39 +00:00
|
|
|
|
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
|
2014-05-16 01:03:44 +00:00
|
|
|
static inline short GetNumControlVertices( Type t );
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static inline short GetNumFVarControlVertices( Type t );
|
|
|
|
|
2014-02-25 01:12:39 +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() );
|
|
|
|
}
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// \brief Returns the number of control vertices expected for a patch of the
|
|
|
|
/// type described
|
|
|
|
short GetNumFVarControlVertices() const {
|
|
|
|
return GetNumFVarControlVertices( this->GetType() );
|
|
|
|
}
|
|
|
|
|
2014-02-25 01:12:39 +00:00
|
|
|
/// \brief Allows ordering of patches by type
|
2014-05-16 01:03:44 +00:00
|
|
|
inline bool operator < ( Descriptor const other ) const;
|
2014-02-25 01:12:39 +00:00
|
|
|
|
|
|
|
/// \brief True if the descriptors are identical
|
2014-05-16 01:03:44 +00:00
|
|
|
inline bool operator == ( Descriptor const other ) const;
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
private:
|
2014-09-05 22:07:46 +00:00
|
|
|
friend class PatchTablesFactory;
|
2014-02-25 01:12:39 +00:00
|
|
|
|
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
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
typedef std::vector<Descriptor> DescriptorVector;
|
2013-05-17 16:06:40 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
/// \brief Returns a vector of all the legal patch descriptors for the
|
|
|
|
/// given adaptive subdivision scheme
|
|
|
|
static DescriptorVector const & GetAdaptiveDescriptors(Sdc::Type type);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-17 16:06:40 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/// \brief Array of patches of the same type
|
2013-05-09 00:06:59 +00:00
|
|
|
class PatchArray {
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
public:
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Constructor.
|
2013-05-10 17:44:03 +00:00
|
|
|
///
|
2014-02-25 01:12:39 +00:00
|
|
|
/// @param desc descriptor information for the patches in
|
2013-05-17 21:07:53 +00:00
|
|
|
/// 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
|
|
|
|
///
|
2014-02-25 01:12:39 +00:00
|
|
|
/// @param patchIndex absolute index of the first patch in the
|
2013-05-10 17:44:03 +00:00
|
|
|
/// array
|
|
|
|
///
|
|
|
|
/// @param npatches number of patches in the array
|
|
|
|
///
|
|
|
|
/// @param quadOffsetIndex absolute index of the first quad offset
|
|
|
|
/// entry
|
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
PatchArray( Descriptor desc, Index vertIndex, Index patchIndex,
|
|
|
|
Index npatches, Index quadOffsetIndex ) :
|
|
|
|
_desc(desc), _range(vertIndex, patchIndex, npatches, quadOffsetIndex) { }
|
2013-05-10 17:44:03 +00:00
|
|
|
|
|
|
|
/// 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 {
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Constructor
|
2013-05-10 17:44:03 +00:00
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
/// @param vIndex absolute index to the first control vertex
|
|
|
|
/// of the first patch in the PTable
|
2013-05-10 17:44:03 +00:00
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
/// @param pIndex absolute index of the first patch in the
|
|
|
|
/// array
|
2013-05-10 17:44:03 +00:00
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
/// @param npatches number of patches in the array
|
2013-05-10 17:44:03 +00:00
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
/// @param qoIndex absolute index of the first quad offset
|
|
|
|
/// entry
|
2013-05-10 17:44:03 +00:00
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
ArrayRange( Index vIndex, Index pIndex, int npatches, Index qoIndex ) :
|
|
|
|
npatches(npatches), vertIndex(vIndex), patchIndex(pIndex),
|
|
|
|
quadOffsetIndex(qoIndex) { }
|
2013-05-09 20:14:02 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
int npatches; ///< number of patches in the array
|
|
|
|
|
|
|
|
Index 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
|
|
|
|
quadOffsetIndex; ///< absolute index of the first quad offset entry
|
2013-05-09 20:14:02 +00:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-25 01:12:39 +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
|
2014-10-09 21:48:50 +00:00
|
|
|
Index GetVertIndex() const {
|
2013-05-09 20:14:02 +00:00
|
|
|
return _range.vertIndex;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
2014-02-25 01:12:39 +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)
|
2014-10-09 21:48:50 +00:00
|
|
|
Index GetPatchIndex() const {
|
2013-05-09 20:14:02 +00:00
|
|
|
return _range.patchIndex;
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the number of patches in the array
|
2014-10-09 21:48:50 +00:00
|
|
|
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
|
2014-10-09 21:48:50 +00:00
|
|
|
Index GetQuadOffsetIndex() const {
|
2013-05-09 20:14:02 +00:00
|
|
|
return _range.quadOffsetIndex;
|
2013-05-09 16:23:01 +00:00
|
|
|
}
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
private:
|
2014-09-05 22:07:46 +00:00
|
|
|
friend class PatchTablesFactory;
|
2014-02-25 01:12:39 +00:00
|
|
|
|
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
|
|
|
};
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
typedef std::vector<PatchArray> PatchArrayVector;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-19 00:48:34 +00:00
|
|
|
/// \brief Handle that can be used as unique patch identifier within PatchTables
|
|
|
|
struct PatchHandle {
|
2014-10-09 21:48:50 +00:00
|
|
|
Index patchArrayIdx, ///< OsdPatchArray containing the patch
|
|
|
|
patchIdx, ///< Index of the patch in the OsdPatchArray
|
|
|
|
vertexOffset; ///< Relative offset to the first CV of the patch in the patch array
|
2014-09-19 00:48:34 +00:00
|
|
|
};
|
|
|
|
|
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
|
2014-02-25 01:12:39 +00:00
|
|
|
PatchArray const * GetPatchArray( Descriptor desc ) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
return const_cast<PatchTables *>(this)->findPatchArray( desc );
|
2013-05-09 00:06:59 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// brief Returns a pointer to the PatchArry of uniformly subdivided faces at 'level'
|
|
|
|
///
|
|
|
|
/// @param level the level of subdivision of the faces (returns the highest
|
|
|
|
/// level by default)
|
|
|
|
///
|
|
|
|
/// @return a pointer to the PatchArray or NULL if the mesh is not uniformly
|
|
|
|
/// subdivided or the level cannot be found.
|
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
PatchArray const * GetUniformPatchArray(int level=0) const;
|
2014-09-05 22:07:46 +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
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
/// In uniform mode the PatchTablesFactory can be set to generate either a
|
2013-07-26 17:38:49 +00:00
|
|
|
/// 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
|
2014-09-05 22:07:46 +00:00
|
|
|
/// factories to convert the coarse mesh to PatchTables.
|
2013-07-26 17:38:49 +00:00
|
|
|
///
|
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.
|
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
Index const * GetUniformFaceVertices(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
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
/// In uniform mode the PatchTablesFactory can be set to generate either a
|
2013-07-26 17:38:49 +00:00
|
|
|
/// 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
|
2014-09-05 22:07:46 +00:00
|
|
|
/// factories to convert the coarse mesh to PatchTables.
|
2013-07-26 17:38:49 +00:00
|
|
|
///
|
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
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
int GetNumUniformFaces(int level=0) const;
|
2014-02-25 01:12:39 +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
|
|
|
|
2014-10-13 15:52:09 +00:00
|
|
|
/// \brief Returns a sharpness index table for each type of patch (if exists)
|
|
|
|
std::vector<int> const &GetSharpnessIndexTable() const { return _sharpnessIndexTable; }
|
|
|
|
|
|
|
|
/// \brief Returns sharpness values (if exists)
|
|
|
|
std::vector<float> const &GetSharpnessValues() const { return _sharpnessValues; }
|
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
/// \brief Number of control vertices of Regular Patches in table.
|
|
|
|
static short GetRegularPatchSize() { return 16; }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
/// \brief Number of control vertices of Boundary Patches in table.
|
|
|
|
static short GetBoundaryPatchSize() { return 12; }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
/// \brief Number of control vertices of Boundary Patches in table.
|
|
|
|
static short GetCornerPatchSize() { return 9; }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
/// \brief Number of control vertices of Gregory (and Gregory Boundary) Patches in table.
|
|
|
|
static short GetGregoryPatchSize() { return 4; }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the total number of patches stored in the tables
|
2014-10-09 21:48:50 +00:00
|
|
|
int GetNumPatchesTotal() const;
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2013-07-11 01:51:43 +00:00
|
|
|
/// \brief Returns the total number of control vertex indices in the tables
|
2014-10-09 21:48:50 +00:00
|
|
|
int GetNumControlVerticesTotal() 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; }
|
2014-02-25 01:12:39 +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;
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-03-25 02:13:40 +00:00
|
|
|
/// \brief Returns the total number of vertices in the mesh across across all depths
|
|
|
|
int GetNumPtexFaces() const { return _numPtexFaces; }
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// \brief Face-varying patch vertex indices tables
|
|
|
|
///
|
|
|
|
/// FVarPatchTables contain the topology for face-varying primvar data
|
|
|
|
/// channels. The patch ordering matches that of PatchTables PatchArrays.
|
|
|
|
///
|
|
|
|
class FVarPatchTables {
|
2014-04-05 02:10:34 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// \brief Returns the number of face-varying primvar channels
|
|
|
|
int GetNumChannels() const {
|
|
|
|
return (int)_channels.size();
|
2014-04-05 02:10:34 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// \brief Returns the face-varying patches vertex indices
|
|
|
|
///
|
|
|
|
/// @param channel Then face-varying primvar channel index
|
|
|
|
///
|
2014-10-09 21:48:50 +00:00
|
|
|
std::vector<Index> const & GetPatchVertices(int channel) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
return _channels[channel].patchVertIndices;
|
2014-04-05 02:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-09-05 22:07:46 +00:00
|
|
|
friend class PatchTablesFactory;
|
2014-04-05 02:10:34 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
struct Channel {
|
|
|
|
friend class PatchTablesFactory;
|
2014-04-05 02:10:34 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
std::vector<Index> patchVertIndices; // face-varying vertex indices
|
2014-09-05 22:07:46 +00:00
|
|
|
};
|
2014-04-05 02:10:34 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
std::vector<Channel> _channels; // face-varying primvar channels
|
2014-04-05 02:10:34 +00:00
|
|
|
};
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Returns the face-varying patches
|
|
|
|
FVarPatchTables const * GetFVarPatchTables() const { return _fvarPatchTables; }
|
|
|
|
|
|
|
|
/// \brief Public constructor
|
|
|
|
///
|
|
|
|
/// @param patchArrays Vector of descriptors and ranges for arrays of patches
|
|
|
|
///
|
|
|
|
/// @param patches Indices of the control vertices of the patches
|
|
|
|
///
|
|
|
|
/// @param vertexValences Vertex valance table
|
|
|
|
///
|
|
|
|
/// @param quadOffsets Quad offset table
|
|
|
|
///
|
|
|
|
/// @param fvarPatchTables Indices of the face-varying control vertices of the patches
|
|
|
|
///
|
|
|
|
/// @param patchParams Local patch parameterization
|
|
|
|
///
|
|
|
|
/// @param maxValence Highest vertex valence allowed in the mesh
|
|
|
|
///
|
|
|
|
PatchTables(PatchArrayVector const & patchArrays,
|
2014-09-19 00:48:34 +00:00
|
|
|
PTable const & patches,
|
|
|
|
VertexValenceTable const * vertexValences,
|
|
|
|
QuadOffsetTable const * quadOffsets,
|
|
|
|
PatchParamTable const * patchParams,
|
|
|
|
FVarPatchTables const * fvarPatchTables,
|
|
|
|
int maxValence);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Destructor
|
|
|
|
~PatchTables() { delete _fvarPatchTables; }
|
2014-04-05 02:10:34 +00:00
|
|
|
|
2014-10-02 23:09:17 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
//
|
|
|
|
// Interpolation methods
|
|
|
|
//
|
|
|
|
|
|
|
|
/// \brief Interpolate the (s,t) parametric location of a *bilinear* patch
|
|
|
|
///
|
|
|
|
/// \note This method can only be used on uniform PatchTables of quads (see
|
|
|
|
/// IsFeatureAdaptive() method)
|
2014-09-19 00:48:34 +00:00
|
|
|
///
|
|
|
|
/// @param handle A patch handle indentifying the sub-patch containing the
|
|
|
|
/// (s,t) location
|
|
|
|
///
|
|
|
|
/// @param s Patch coordinate (in coarse face normalized space)
|
|
|
|
///
|
|
|
|
/// @param t Patch coordinate (in coarse face normalized space)
|
|
|
|
///
|
|
|
|
/// @param src Source primvar buffer (control vertices data)
|
|
|
|
///
|
|
|
|
/// @param dst Destination primvar buffer (limit surface data)
|
|
|
|
///
|
2014-10-02 23:09:17 +00:00
|
|
|
template <class T, class U> void Interpolate(PatchHandle const & handle,
|
2014-09-24 22:15:22 +00:00
|
|
|
float s, float t, T const & src, U * dst) const;
|
2014-09-19 00:48:34 +00:00
|
|
|
|
2014-10-02 23:09:17 +00:00
|
|
|
/// \brief Interpolate the (s,t) parametric location of a bilinear (quad)
|
|
|
|
/// patch
|
|
|
|
///
|
|
|
|
template <class T, class U> static void
|
2014-10-09 21:48:50 +00:00
|
|
|
InterpolateBilinear(Index const * cvs, float s, float t,
|
2014-10-02 23:09:17 +00:00
|
|
|
T const & src, U * dst);
|
|
|
|
|
|
|
|
/// \brief Interpolate the (s,t) parametric location of a regular bicubic
|
|
|
|
/// patch
|
|
|
|
///
|
|
|
|
/// @param cvs Array of 16 control vertex indices
|
|
|
|
///
|
|
|
|
/// @param Q Array of 16 bicubic weights for the control vertices
|
|
|
|
///
|
|
|
|
/// @param Qd1 Array of 16 bicubic 's' tangent weights for the control
|
|
|
|
/// vertices
|
|
|
|
///
|
|
|
|
/// @param Qd2 Array of 16 bicubic 't' tangent weights for the control
|
|
|
|
/// vertices
|
|
|
|
///
|
|
|
|
/// @param src Source primvar buffer (control vertices data)
|
|
|
|
///
|
|
|
|
/// @param dst Destination primvar buffer (limit surface data)
|
|
|
|
///
|
|
|
|
template <class T, class U> static void
|
2014-10-09 21:48:50 +00:00
|
|
|
InterpolateRegularPatch(Index const * cvs,
|
2014-10-02 23:09:17 +00:00
|
|
|
float const * Q, float const *Qd1, float const *Qd2, T const & src, U * dst);
|
|
|
|
|
|
|
|
/// \brief Interpolate the (s,t) parametric location of a boundary bicubic
|
|
|
|
/// patch
|
|
|
|
///
|
|
|
|
/// @param cvs Array of 12 control vertex indices
|
|
|
|
///
|
|
|
|
/// @param Q Array of 12 bicubic weights for the control vertices
|
|
|
|
///
|
|
|
|
/// @param Qd1 Array of 12 bicubic 's' tangent weights for the control
|
|
|
|
/// vertices
|
|
|
|
///
|
|
|
|
/// @param Qd2 Array of 12 bicubic 't' tangent weights for the control
|
|
|
|
/// vertices
|
|
|
|
///
|
|
|
|
/// @param src Source primvar buffer (control vertices data)
|
|
|
|
///
|
|
|
|
/// @param dst Destination primvar buffer (limit surface data)
|
|
|
|
///
|
|
|
|
template <class T, class U> static void
|
2014-10-09 21:48:50 +00:00
|
|
|
InterpolateBoundaryPatch(Index const * cvs,
|
2014-10-02 23:09:17 +00:00
|
|
|
float const * Q, float const *Qd1, float const *Qd2, T const & src, U * dst);
|
|
|
|
|
|
|
|
/// \brief Interpolate the (s,t) parametric location of a corner bicubic
|
|
|
|
/// patch
|
|
|
|
///
|
|
|
|
/// @param cvs Array of 9 control vertex indices
|
|
|
|
///
|
|
|
|
/// @param Q Array of 9 bicubic weights for the control vertices
|
|
|
|
///
|
|
|
|
/// @param Qd1 Array of 9 bicubic 's' tangent weights for the control
|
|
|
|
/// vertices
|
|
|
|
///
|
|
|
|
/// @param Qd2 Array of 9 bicubic 't' tangent weights for the control
|
|
|
|
/// vertices
|
|
|
|
///
|
|
|
|
/// @param src Source primvar buffer (control vertices data)
|
|
|
|
///
|
|
|
|
/// @param dst Destination primvar buffer (limit surface data)
|
|
|
|
///
|
|
|
|
template <class T, class U> static void
|
2014-10-09 21:48:50 +00:00
|
|
|
InterpolateCornerPatch(Index const * cvs,
|
2014-10-02 23:09:17 +00:00
|
|
|
float const * Q, float const *Qd1, float const *Qd2, T const & src, U * dst);
|
|
|
|
|
|
|
|
/// \brief Interpolate the (s,t) parametric location of a *bicubic* patch
|
|
|
|
///
|
|
|
|
/// \note This method can only be used on feature adaptive PatchTables (ie.
|
|
|
|
/// IsFeatureAdaptive() is false)
|
|
|
|
///
|
|
|
|
/// @param handle A patch handle indentifying the sub-patch containing the
|
|
|
|
/// (s,t) location
|
|
|
|
///
|
|
|
|
/// @param s Patch coordinate (in coarse face normalized space)
|
|
|
|
///
|
|
|
|
/// @param t Patch coordinate (in coarse face normalized space)
|
|
|
|
///
|
|
|
|
/// @param src Source primvar buffer (control vertices data)
|
|
|
|
///
|
|
|
|
/// @param dst Destination primvar buffer (limit surface data)
|
|
|
|
///
|
|
|
|
template <class T, class U> void Limit(PatchHandle const & handle,
|
|
|
|
float s, float t, T const & src, U * dst) const;
|
2014-09-19 00:48:34 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
private:
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
friend class PatchTablesFactory;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-19 00:48:34 +00:00
|
|
|
// Returns bi-cubic interpolation coefficients for a given (u,v) location
|
|
|
|
// on a b-spline patch
|
|
|
|
static void getBSplineWeightsAtUV(PatchParam::BitField bits, float s, float t,
|
|
|
|
float point[16], float deriv1[16], float deriv2[16]);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
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
|
2014-10-09 21:48:50 +00:00
|
|
|
PatchArray * findPatchArray( Descriptor desc );
|
|
|
|
|
|
|
|
static DescriptorVector const & getBilinearDescriptors();
|
|
|
|
static DescriptorVector const & getAdaptiveCatmarkDescriptors();
|
|
|
|
static DescriptorVector const & getAdaptiveLoopDescriptors();
|
2013-05-09 00:06:59 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// Private constructor
|
2014-09-05 22:07:46 +00:00
|
|
|
PatchTables( int maxvalence ) : _fvarPatchTables(0), _maxValence(maxvalence) { }
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
PatchArrayVector _patchArrays; // Vector of descriptors for arrays of patches
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
PTable _patches; // Indices of the control vertices of the patches
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
VertexValenceTable _vertexValenceTable; // Vertex valence table (for Gregory patches)
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
QuadOffsetTable _quadOffsetTable; // Quad offsets table (for Gregory patches)
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
PatchParamTable _paramTable; // PatchParam bitfields (one per patch)
|
2014-02-25 01:12:39 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
FVarPatchTables const * _fvarPatchTables; // sparse face-varying patch table (one per patch)
|
2013-03-08 01:50:15 +00:00
|
|
|
|
2014-10-13 15:52:09 +00:00
|
|
|
std::vector<int> _sharpnessIndexTable;// Indices of single-crease sharpness (one per patch)
|
|
|
|
|
|
|
|
std::vector<float> _sharpnessValues; // Sharpness values.
|
|
|
|
|
2014-02-25 01:12:39 +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;
|
2014-03-25 02:13:40 +00:00
|
|
|
|
|
|
|
// number of total ptex faces in quads or triangles(loop)
|
|
|
|
int _numPtexFaces;
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
// Returns the number of control vertices expected for a patch of this type
|
2014-02-25 01:12:39 +00:00
|
|
|
inline short
|
2014-09-05 22:07:46 +00:00
|
|
|
PatchTables::Descriptor::GetNumControlVertices( PatchTables::Type type ) {
|
2013-05-09 00:06:59 +00:00
|
|
|
switch (type) {
|
2014-10-09 21:48:50 +00:00
|
|
|
case REGULAR : return PatchTables::GetRegularPatchSize();
|
2014-10-13 15:52:09 +00:00
|
|
|
case SINGLE_CREASE : return PatchTables::GetRegularPatchSize();
|
2013-05-09 00:06:59 +00:00
|
|
|
case QUADS : return 4;
|
|
|
|
case GREGORY :
|
2014-10-09 21:48:50 +00:00
|
|
|
case GREGORY_BOUNDARY : return PatchTables::GetGregoryPatchSize();
|
|
|
|
case BOUNDARY : return PatchTables::GetBoundaryPatchSize();
|
|
|
|
case CORNER : return PatchTables::GetCornerPatchSize();
|
2013-05-09 00:06:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// Returns the number of face-varying control vertices expected for a patch of this type
|
|
|
|
inline short
|
|
|
|
PatchTables::Descriptor::GetNumFVarControlVertices( PatchTables::Type type ) {
|
|
|
|
switch (type) {
|
|
|
|
case REGULAR : // We only support bilinear interpolation for now,
|
2014-10-13 15:52:09 +00:00
|
|
|
case SINGLE_CREASE :
|
2014-09-05 22:07:46 +00:00
|
|
|
case QUADS : // so all these patches only carry 4 CVs.
|
|
|
|
case GREGORY :
|
|
|
|
case GREGORY_BOUNDARY :
|
|
|
|
case BOUNDARY :
|
|
|
|
case CORNER : return 4;
|
|
|
|
case TRIANGLES : return 3;
|
|
|
|
case LINES : return 2;
|
|
|
|
case POINTS : return 1;
|
|
|
|
default : return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:06:59 +00:00
|
|
|
// Allows ordering of patches by type
|
2014-02-25 01:12:39 +00:00
|
|
|
inline bool
|
2014-09-05 22:07:46 +00:00
|
|
|
PatchTables::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
|
2014-09-05 22:07:46 +00:00
|
|
|
PatchTables::Descriptor::operator == ( Descriptor const other ) const {
|
2013-05-09 16:23:01 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-19 00:48:34 +00:00
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-09 21:48:50 +00:00
|
|
|
PatchTables::InterpolateBilinear(Index const * cvs, float s, float t,
|
2014-10-02 23:09:17 +00:00
|
|
|
T const & src, U * dst) {
|
|
|
|
|
|
|
|
float os = 1.0f - s,
|
|
|
|
ot = 1.0f - t,
|
|
|
|
Q[4] = { os*ot, s*ot, s*t, os*t },
|
|
|
|
dQ1[4] = { t-1.0f, ot, t, -t },
|
|
|
|
dQ2[4] = { s-1.0f, -s, s, os };
|
|
|
|
|
|
|
|
for (int k=0; k<4; ++k) {
|
|
|
|
dst->AddWithWeight(src[cvs[k]], Q[k], dQ1[k], dQ2[k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-09 21:48:50 +00:00
|
|
|
PatchTables::InterpolateRegularPatch(Index const * cvs,
|
2014-09-19 00:48:34 +00:00
|
|
|
float const * Q, float const *Qd1, float const *Qd2,
|
2014-09-24 22:15:22 +00:00
|
|
|
T const & src, U * dst) {
|
2014-09-19 00:48:34 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// v0 -- v1 -- v2 -- v3
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// v4 -- v5 -- v6 -- v7
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// v8 -- v9 -- v10-- v11
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// v12-- v13-- v14-- v15
|
|
|
|
//
|
|
|
|
for (int k=0; k<16; ++k) {
|
|
|
|
dst->AddWithWeight(src[cvs[k]], Q[k], Qd1[k], Qd2[k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-09 21:48:50 +00:00
|
|
|
PatchTables::InterpolateBoundaryPatch(Index const * cvs,
|
2014-09-19 00:48:34 +00:00
|
|
|
float const * Q, float const *Qd1, float const *Qd2,
|
2014-09-24 22:15:22 +00:00
|
|
|
T const & src, U * dst) {
|
2014-09-19 00:48:34 +00:00
|
|
|
|
|
|
|
// mirror the missing vertices (M)
|
|
|
|
//
|
|
|
|
// M0 -- M1 -- M2 -- M3 (corner)
|
|
|
|
// | | | |
|
|
|
|
// | | | |
|
|
|
|
// v0 -- v1 -- v2 -- v3 M : mirrored
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// v4 -- v5 -- v6 -- v7 v : original Cv
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// |.....|.....|.....|
|
|
|
|
// v8 -- v9 -- v10-- v11
|
|
|
|
//
|
|
|
|
for (int k=0; k<4; ++k) { // M0 - M3
|
|
|
|
dst->AddWithWeight(src[cvs[k]], 2.0f*Q[k], 2.0f*Qd1[k], 2.0f*Qd2[k]);
|
|
|
|
dst->AddWithWeight(src[cvs[k+4]], -1.0f*Q[k], -1.0f*Qd1[k], -1.0f*Qd2[k]);
|
|
|
|
}
|
|
|
|
for (int k=0; k<12; ++k) {
|
|
|
|
dst->AddWithWeight(src[cvs[k]], Q[k+4], Qd1[k+4], Qd2[k+4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-09 21:48:50 +00:00
|
|
|
PatchTables::InterpolateCornerPatch(Index const * cvs,
|
2014-09-19 00:48:34 +00:00
|
|
|
float const * Q, float const *Qd1, float const *Qd2,
|
2014-09-24 22:15:22 +00:00
|
|
|
T const & src, U * dst) {
|
2014-09-19 00:48:34 +00:00
|
|
|
|
|
|
|
// mirror the missing vertices (M)
|
|
|
|
//
|
|
|
|
// M0 -- M1 -- M2 -- M3 (corner)
|
|
|
|
// | | | |
|
|
|
|
// | | | |
|
|
|
|
// v0 -- v1 -- v2 -- M4 M : mirrored
|
|
|
|
// |.....|.....| |
|
|
|
|
// |.....|.....| |
|
|
|
|
// v3.--.v4.--.v5 -- M5 v : original Cv
|
|
|
|
// |.....|.....| |
|
|
|
|
// |.....|.....| |
|
|
|
|
// v6 -- v7 -- v8 -- M6
|
|
|
|
//
|
|
|
|
for (int k=0; k<3; ++k) { // M0 - M2
|
|
|
|
dst->AddWithWeight(src[cvs[k ]], 2.0f*Q[k], 2.0f*Qd1[k], 2.0f*Qd2[k]);
|
|
|
|
dst->AddWithWeight(src[cvs[k+3]], -1.0f*Q[k], -1.0f*Qd1[k], -1.0f*Qd2[k]);
|
|
|
|
}
|
|
|
|
for (int k=0; k<3; ++k) { // M4 - M6
|
|
|
|
int idx = (k+1)*4 + 3;
|
|
|
|
dst->AddWithWeight(src[cvs[k*3+2]], 2.0f*Q[idx], 2.0f*Qd1[idx], 2.0f*Qd2[idx]);
|
|
|
|
dst->AddWithWeight(src[cvs[k*3+1]], -1.0f*Q[idx], -1.0f*Qd1[idx], -1.0f*Qd2[idx]);
|
|
|
|
}
|
|
|
|
// M3 = -2.v1 + 4.v2 + v4 - 2.v5
|
|
|
|
dst->AddWithWeight(src[cvs[1]], -2.0f*Q[3], -2.0f*Qd1[3], -2.0f*Qd2[3]);
|
|
|
|
dst->AddWithWeight(src[cvs[2]], 4.0f*Q[3], 4.0f*Qd1[3], 4.0f*Qd2[3]);
|
|
|
|
dst->AddWithWeight(src[cvs[4]], 1.0f*Q[3], 1.0f*Qd1[3], 1.0f*Qd2[3]);
|
|
|
|
dst->AddWithWeight(src[cvs[5]], -2.0f*Q[3], -2.0f*Qd1[3], -2.0f*Qd2[3]);
|
|
|
|
for (int y=0; y<3; ++y) { // v0 - v8
|
|
|
|
for (int x=0; x<3; ++x) {
|
|
|
|
int idx = y*4+x+4;
|
|
|
|
dst->AddWithWeight(src[cvs[y*3+x]], Q[idx], Qd1[idx], Qd2[idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 23:09:17 +00:00
|
|
|
// Interpolates the limit position of a parametric location on a patch
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
|
|
|
PatchTables::Interpolate(PatchHandle const & handle, float s, float t,
|
|
|
|
T const & src, U * dst) const {
|
|
|
|
|
|
|
|
assert(dst and (not IsFeatureAdaptive()));
|
|
|
|
|
|
|
|
PatchTables::PatchArray const & parray =
|
|
|
|
_patchArrays[handle.patchArrayIdx];
|
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
Index const * cvs =
|
2014-10-02 23:09:17 +00:00
|
|
|
&_patches[parray.GetVertIndex() + handle.vertexOffset];
|
|
|
|
|
|
|
|
PatchParam::BitField const & bits =
|
|
|
|
_paramTable[handle.patchIdx].bitField;
|
|
|
|
|
|
|
|
bits.Normalize(s,t);
|
|
|
|
|
|
|
|
Type ptype = parray.GetDescriptor().GetType();
|
|
|
|
assert(ptype==QUADS);
|
|
|
|
|
|
|
|
dst->Clear();
|
|
|
|
|
|
|
|
InterpolateBilinear(cvs, s, t, src, dst);
|
|
|
|
}
|
|
|
|
|
2014-09-19 00:48:34 +00:00
|
|
|
// Interpolates the limit position of a parametric location on a patch
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-09-20 00:22:35 +00:00
|
|
|
PatchTables::Limit(PatchHandle const & handle, float s, float t,
|
2014-09-24 22:15:22 +00:00
|
|
|
T const & src, U * dst) const {
|
2014-09-19 00:48:34 +00:00
|
|
|
|
2014-10-02 23:09:17 +00:00
|
|
|
assert(dst and IsFeatureAdaptive());
|
2014-09-19 00:48:34 +00:00
|
|
|
|
|
|
|
PatchTables::PatchArray const & parray =
|
|
|
|
_patchArrays[handle.patchArrayIdx];
|
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
Index const * cvs =
|
2014-09-19 00:48:34 +00:00
|
|
|
&_patches[parray.GetVertIndex() + handle.vertexOffset];
|
|
|
|
|
|
|
|
PatchParam::BitField const & bits =
|
|
|
|
_paramTable[handle.patchIdx].bitField;
|
|
|
|
|
|
|
|
bits.Normalize(s,t);
|
|
|
|
|
|
|
|
Type ptype = parray.GetDescriptor().GetType();
|
|
|
|
|
|
|
|
if (ptype>=REGULAR and ptype<=CORNER) {
|
|
|
|
|
|
|
|
float Q[16], Qd1[16], Qd2[16];
|
|
|
|
|
|
|
|
getBSplineWeightsAtUV(bits, s, t, Q, Qd1, Qd2);
|
|
|
|
|
|
|
|
float scale = float(1 << bits.GetDepth());
|
|
|
|
for (int k=0; k<16; ++k) {
|
|
|
|
Qd1[k] *= scale;
|
|
|
|
Qd2[k] *= scale;
|
|
|
|
}
|
2014-09-22 17:34:46 +00:00
|
|
|
|
2014-09-19 00:48:34 +00:00
|
|
|
dst->Clear();
|
|
|
|
|
|
|
|
switch (ptype) {
|
|
|
|
case REGULAR:
|
|
|
|
InterpolateRegularPatch(cvs, Q, Qd1, Qd2, src, dst);
|
|
|
|
break;
|
2014-10-13 15:52:09 +00:00
|
|
|
case SINGLE_CREASE:
|
|
|
|
// TODO: implement InterpolateSingleCreasePatch().
|
|
|
|
//InterpolateRegularPatch(cvs, Q, Qd1, Qd2, src, dst);
|
|
|
|
break;
|
2014-09-19 00:48:34 +00:00
|
|
|
case BOUNDARY:
|
|
|
|
InterpolateBoundaryPatch(cvs, Q, Qd1, Qd2, src, dst);
|
|
|
|
break;
|
|
|
|
case CORNER:
|
|
|
|
InterpolateCornerPatch(cvs, Q, Qd1, Qd2, src, dst);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
} else if (ptype>=GREGORY and ptype<=GREGORY_BOUNDARY) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
} // end namespace Far
|
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 */
|