25#ifndef OPENSUBDIV3_FAR_PATCH_TABLE_H
26#define OPENSUBDIV3_FAR_PATCH_TABLE_H
28#include "../version.h"
30#include "../far/patchDescriptor.h"
31#include "../far/patchParam.h"
32#include "../far/stencilTable.h"
34#include "../sdc/options.h"
39namespace OPENSUBDIV_VERSION {
85 return (
int)_patchVerts.size();
167 template <
typename REAL>
186 template <
class T>
void
197 template <
typename REAL>
216 template <
class T>
void
227 template <
typename REAL>
248 template <
class T>
void
268 return _vertexValenceTable;
393 return _quadOffsetsTable;
428 template <
typename REAL>
430 REAL wP[], REAL wDu[] = 0, REAL wDv[] = 0,
431 REAL wDuu[] = 0, REAL wDuv[] = 0, REAL wDvv[] = 0)
const;
436 float wP[],
float wDu[] = 0,
float wDv[] = 0,
437 float wDuu[] = 0,
float wDuv[] = 0,
float wDvv[] = 0)
const;
442 double wP[],
double wDu[] = 0,
double wDv[] = 0,
443 double wDuu[] = 0,
double wDuv[] = 0,
double wDvv[] = 0)
const;
467 template <
typename REAL>
469 REAL wP[], REAL wDu[] = 0, REAL wDv[] = 0,
470 REAL wDuu[] = 0, REAL wDuv[] = 0, REAL wDvv[] = 0)
const;
475 float wP[],
float wDu[] = 0,
float wDv[] = 0,
476 float wDuu[] = 0,
float wDuv[] = 0,
float wDvv[] = 0)
const;
481 double wP[],
double wDu[] = 0,
double wDv[] = 0,
482 double wDuu[] = 0,
double wDuv[] = 0,
double wDvv[] = 0)
const;
508 template <
typename REAL>
510 REAL wP[], REAL wDu[] = 0, REAL wDv[] = 0,
511 REAL wDuu[] = 0, REAL wDuv[] = 0, REAL wDvv[] = 0,
512 int channel = 0)
const;
517 float wP[],
float wDu[] = 0,
float wDv[] = 0,
518 float wDuu[] = 0,
float wDuv[] = 0,
float wDvv[] = 0,
519 int channel = 0)
const;
524 double wP[],
double wDu[] = 0,
double wDv[] = 0,
525 double wDuu[] = 0,
double wDuv[] = 0,
double wDvv[] = 0,
526 int channel = 0)
const;
550 desc(d), numPatches(np), vertIndex(v),
551 patchIndex(p), quadOffsetIndex (qo) { }
564 typedef std::vector<PatchArray> PatchArrayVector;
566 PatchArray & getPatchArray(
Index arrayIndex);
567 PatchArray
const & getPatchArray(
Index arrayIndex)
const;
569 void reservePatchArrays(
int numPatchArrays);
570 void pushPatchArray(PatchDescriptor desc,
int npatches,
573 IndexArray getPatchArrayVertices(
int arrayIndex);
575 Index findPatchArray(PatchDescriptor desc);
581 IndexArray getPatchArrayVaryingVertices(
int arrayIndex);
583 void allocateVaryingVertices(
584 PatchDescriptor desc,
int numPatches);
585 void populateVaryingVertices();
615 struct FVarPatchChannel {
618 PatchDescriptor regDesc;
619 PatchDescriptor irregDesc;
623 std::vector<Index> patchValues;
624 std::vector<PatchParam> patchParam;
626 typedef std::vector<FVarPatchChannel> FVarPatchChannelVector;
628 FVarPatchChannel & getFVarPatchChannel(
int channel);
629 FVarPatchChannel
const & getFVarPatchChannel(
int channel)
const;
631 void allocateFVarPatchChannels(
int numChannels);
632 void allocateFVarPatchChannelValues(
633 PatchDescriptor regDesc, PatchDescriptor irregDesc,
634 int numPatches,
int channel);
637 void setFVarPatchChannelLinearInterpolation(
644 PatchParam getPatchFVarPatchParam(
int patch,
int channel)
const;
654 class StencilTablePtr {
656 typedef StencilTableReal<float> float_type;
657 typedef StencilTableReal<double> double_type;
665 StencilTablePtr() { _fPtr = 0; }
666 StencilTablePtr(float_type * ptr) { _fPtr = ptr; }
667 StencilTablePtr(double_type * ptr) { _dPtr = ptr; }
669 operator bool()
const {
return _fPtr != 0; }
671 void Set() { _fPtr = 0; }
672 void Set(float_type * ptr) { _fPtr = ptr; }
673 void Set(double_type * ptr) { _dPtr = ptr; }
675 template <
typename REAL> StencilTableReal<REAL> * Get()
const;
689 std::vector<Index> _patchVerts;
702 StencilTablePtr _localPointStencils;
703 StencilTablePtr _localPointVaryingStencils;
708 PatchDescriptor _varyingDesc;
710 std::vector<Index> _varyingVerts;
715 FVarPatchChannelVector _fvarChannels;
717 std::vector<StencilTablePtr> _localPointFaceVaryingStencils;
722 std::vector<Index> _sharpnessIndices;
723 std::vector<float> _sharpnessValues;
728 unsigned int _isUniformLinear : 1;
733 unsigned int _vertexPrecisionIsDouble : 1;
734 unsigned int _varyingPrecisionIsDouble : 1;
735 unsigned int _faceVaryingPrecisionIsDouble : 1;
742template <>
inline StencilTableReal<float> *
743PatchTable::StencilTablePtr::Get<float>()
const {
return _fPtr; }
745template <>
inline StencilTableReal<double> *
746PatchTable::StencilTablePtr::Get<double>()
const {
return _dPtr; }
748template <>
inline bool
749PatchTable::LocalPointStencilPrecisionMatchesType<float>()
const {
750 return !_vertexPrecisionIsDouble;
752template <>
inline bool
753PatchTable::LocalPointVaryingStencilPrecisionMatchesType<float>()
const {
754 return !_varyingPrecisionIsDouble;
756template <>
inline bool
757PatchTable::LocalPointFaceVaryingStencilPrecisionMatchesType<float>()
const {
758 return !_faceVaryingPrecisionIsDouble;
761template <>
inline bool
762PatchTable::LocalPointStencilPrecisionMatchesType<double>()
const {
763 return _vertexPrecisionIsDouble;
765template <>
inline bool
766PatchTable::LocalPointVaryingStencilPrecisionMatchesType<double>()
const {
767 return _varyingPrecisionIsDouble;
769template <>
inline bool
770PatchTable::LocalPointFaceVaryingStencilPrecisionMatchesType<double>()
const {
771 return _faceVaryingPrecisionIsDouble;
779 assert(LocalPointStencilPrecisionMatchesType<float>());
780 return static_cast<StencilTable const *
>(_localPointStencils.Get<
float>());
784 assert(LocalPointVaryingStencilPrecisionMatchesType<float>());
786 _localPointVaryingStencils.Get<
float>());
790 assert(LocalPointFaceVaryingStencilPrecisionMatchesType<float>());
791 if (channel >= 0 && channel < (
int)_localPointFaceVaryingStencils.size()) {
793 _localPointFaceVaryingStencils[channel].Get<
float>());
798template <
typename REAL>
801 assert(LocalPointStencilPrecisionMatchesType<REAL>());
802 return _localPointStencils.Get<REAL>();
804template <
typename REAL>
807 assert(LocalPointVaryingStencilPrecisionMatchesType<REAL>());
808 return _localPointVaryingStencils.Get<REAL>();
810template <
typename REAL>
813 assert(LocalPointFaceVaryingStencilPrecisionMatchesType<REAL>());
814 if (channel >= 0 && channel < (
int)_localPointFaceVaryingStencils.size()) {
815 return _localPointFaceVaryingStencils[channel].Get<REAL>();
827 assert(LocalPointStencilPrecisionMatchesType<float>());
828 if (_localPointStencils) {
829 _localPointStencils.Get<
float>()->UpdateValues(src, dst);
836 assert(LocalPointVaryingStencilPrecisionMatchesType<float>());
837 if (_localPointVaryingStencils) {
838 _localPointVaryingStencils.Get<
float>()->UpdateValues(src, dst);
845 assert(LocalPointFaceVaryingStencilPrecisionMatchesType<float>());
846 if (channel >= 0 && channel < (
int)_localPointFaceVaryingStencils.size()) {
847 if (_localPointFaceVaryingStencils[channel]) {
848 _localPointFaceVaryingStencils[channel].Get<
float>()->UpdateValues(src, dst);
859 float wP[],
float wDu[],
float wDv[],
860 float wDuu[],
float wDuv[],
float wDvv[])
const {
862 EvaluateBasis<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
866 double wP[],
double wDu[],
double wDv[],
867 double wDuu[],
double wDuv[],
double wDvv[])
const {
869 EvaluateBasis<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
874 float wP[],
float wDu[],
float wDv[],
875 float wDuu[],
float wDuv[],
float wDvv[])
const {
877 EvaluateBasisVarying<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
881 double wP[],
double wDu[],
double wDv[],
882 double wDuu[],
double wDuv[],
double wDvv[])
const {
884 EvaluateBasisVarying<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
889 float wP[],
float wDu[],
float wDv[],
890 float wDuu[],
float wDuv[],
float wDvv[],
int channel)
const {
892 EvaluateBasisFaceVarying<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv, channel);
896 double wP[],
double wDu[],
double wDv[],
897 double wDuu[],
double wDuv[],
double wDvv[],
int channel)
const {
899 EvaluateBasisFaceVarying<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv, channel);
905using namespace OPENSUBDIV_VERSION;
Vtr::ConstIndexArray ConstIndexArray
std::vector< PatchParam > PatchParamTable
Vtr::IndexArray IndexArray
Vtr::Array< PatchParam > PatchParamArray
std::vector< PatchArray > PatchArrayVector
Describes the type of a patch.
An quadtree-based map connecting coarse faces to their sub-patches.
Container for arrays of parametric patches.
ConstIndexArray GetPatchArrayVaryingVertices(int array) const
Returns the varying vertex indices for the patches in array.
float * getSharpnessValues(Index arrayIndex)
PatchVertsTable const & GetPatchControlVerticesTable() const
Get the table of patch control vertices.
void ComputeLocalPointValuesFaceVarying(T const *src, T *dst, int channel=0) const
Updates local point face-varying values.
ConstIndexArray GetVaryingVertices() const
Returns an array of varying vertex indices for the patches.
void ComputeLocalPointValuesVarying(T const *src, T *dst) const
Updates local point varying values.
ConstIndexArray GetPatchVaryingVertices(PatchHandle const &handle) const
Returns the varying vertex indices for a given patch.
bool IsFeatureAdaptive() const
True if the patches are of feature adaptive types.
int GetMaxValence() const
Returns max vertex valence.
StencilTableReal< REAL > const * GetLocalPointStencilTable() const
Returns the stencil table to compute local point vertex values.
StencilTable const * GetLocalPointStencilTable() const
Returns the stencil table to compute local point vertex values.
PatchParamArray getPatchParams(int arrayIndex)
ConstIndexArray GetPatchArrayFVarValues(int array, int channel=0) const
Returns the value indices for the patches in array in channel.
std::vector< float > const & GetSharpnessValues() const
Returns sharpness values table.
std::vector< Index > VertexValenceTable
PatchParam GetPatchFVarPatchParam(int array, int patch, int channel=0) const
Returns the face-varying params for a given patch channel.
ConstIndexArray GetPatchVaryingVertices(int array, int patch) const
Returns the varying vertex indices for a given patch.
PatchTable(PatchTable const &src)
Copy constructor.
int GetNumPatchArrays() const
Returns the number of patch arrays in the table.
ConstIndexArray GetPatchVertices(PatchHandle const &handle) const
Returns the control vertex indices for the patch identified by handle.
PatchTable(int maxvalence)
bool LocalPointFaceVaryingStencilPrecisionMatchesType() const
Tests if the precision of the stencil table to compute local point face-varying values matches the gi...
PatchParamTable const & GetPatchParamTable() const
Returns the PatchParamTable (PatchParams order matches patch array sorting)
VertexValenceTable const & GetVertexValenceTable() const
Returns the 'VertexValences' table (vertex neighborhoods table)
StencilTable const * GetLocalPointFaceVaryingStencilTable(int channel=0) const
Returns the stencil table to compute local point face-varying values.
int GetNumControlVertices(int array) const
Returns the number of control vertices in array.
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
Evaluate basis functions for a face-varying value and derivatives at a given (u,v) parametric locatio...
ConstQuadOffsetsArray GetPatchQuadOffsets(PatchHandle const &handle) const
Returns the 'QuadOffsets' for the Gregory patch identified by handle.
PatchDescriptor GetFVarPatchDescriptorIrregular(int channel=0) const
Returns the irregular patch descriptor for channel.
float GetSingleCreasePatchSharpnessValue(int array, int patch) const
Returns the crease sharpness for the patch in array if it is a single-crease patch,...
Index * getSharpnessIndices(Index arrayIndex)
void ComputeLocalPointValues(T const *src, T *dst) const
Updates local point vertex values.
float GetSingleCreasePatchSharpnessValue(PatchHandle const &handle) const
Returns the crease sharpness for the patch identified by handle if it is a single-crease patch,...
PatchParam GetPatchParam(int array, int patch) const
Returns the PatchParam for patch in array.
ConstIndexArray GetPatchFVarValues(int array, int patch, int channel=0) const
Returns the value indices for a given patch in channel.
PatchDescriptor GetFVarPatchDescriptorRegular(int channel=0) const
Returns the regular patch descriptor for channel.
PatchDescriptor GetPatchDescriptor(PatchHandle const &handle) const
Returns the PatchDescriptor for the patch identified by handle.
std::vector< Index > PatchVertsTable
QuadOffsetsTable const & GetQuadOffsetsTable() const
Returns the quad-offsets table.
int GetNumPatches(int array) const
Returns the number of patches in array.
PatchDescriptor GetVaryingPatchDescriptor() const
Returns the varying patch descriptor.
ConstIndexArray GetPatchFVarValues(PatchHandle const &handle, int channel=0) const
Returns the value indices for a given patch in channel.
ConstPatchParamArray const GetPatchParams(int array) const
Returns the PatchParams for the patches in array.
int GetNumControlVerticesTotal() const
Returns the total number of control vertex indices in the table.
int GetNumFVarChannels() const
Returns the number of face-varying channels.
ConstPatchParamArray GetPatchArrayFVarPatchParams(int array, int channel=0) const
Returns the face-varying for a given patch in array in channel.
Index getPatchIndex(int array, int patch) const
int GetNumLocalPoints() const
Returns the number of local vertex points.
bool LocalPointVaryingStencilPrecisionMatchesType() const
Tests if the precision of the stencil table to compute local point varying values matches the given f...
ConstIndexArray GetPatchArrayVertices(int array) const
Returns the control vertex indices for the patches in array.
int GetNumPtexFaces() const
Returns the total number of ptex faces in the mesh.
ConstIndexArray GetFVarValues(int channel=0) const
Returns an array of value indices for the patches in channel.
Vtr::ConstArray< unsigned int > ConstQuadOffsetsArray
Accessors for the gregory patch evaluation buffers. These methods will be deprecated.
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
Evaluate basis functions for position and derivatives at a given (u,v) parametric location of a patch...
StencilTableReal< REAL > const * GetLocalPointFaceVaryingStencilTable(int channel=0) const
Returns the stencil table to compute local point face-varying values.
int GetNumPatchesTotal() const
Returns the total number of patches stored in the table.
PatchParam GetPatchParam(PatchHandle const &handle) const
Returns a PatchParam for the patch identified by handle.
void print() const
debug helper
Sdc::Options::FVarLinearInterpolation GetFVarChannelLinearInterpolation(int channel=0) const
Deprecated.
std::vector< Index > const & GetSharpnessIndexTable() const
Returns a sharpness index table for each patch (if exists)
PatchDescriptor GetPatchArrayDescriptor(int array) const
Returns the PatchDescriptor for the patches in array.
friend class PatchTableBuilder
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
Evaluate basis functions for a varying value and derivatives at a given (u,v) parametric location of ...
StencilTable const * GetLocalPointVaryingStencilTable() const
Returns the stencil table to compute local point varying values.
std::vector< unsigned int > QuadOffsetsTable
ConstIndexArray GetPatchVertices(int array, int patch) const
Returns the control vertex indices for patch in array.
PatchParam GetPatchFVarPatchParam(PatchHandle const &handle, int channel=0) const
Returns the value indices for a given patch in channel.
int GetFVarValueStride(int channel=0) const
Returns the stride between patches in the value index array of channel.
ConstPatchParamArray GetFVarPatchParams(int channel=0) const
Returns an array of face-varying patch param for channel.
PatchDescriptor GetFVarPatchDescriptor(int channel=0) const
Returns the default/irregular patch descriptor for channel.
int GetNumLocalPointsVarying() const
Returns the number of local varying points.
bool LocalPointStencilPrecisionMatchesType() const
Tests if the precision of the stencil table to compute local point vertex values matches the given fl...
StencilTableReal< REAL > const * GetLocalPointVaryingStencilTable() const
Returns the stencil table to compute local point varying values.
int GetNumLocalPointsFaceVarying(int channel=0) const
Returns the number of local face-varying points for channel.
Handle that can be used as unique patch identifier within PatchTable.
Table of subdivision stencils.
Stencil table class wrapping the template for compatibility.