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"
38 namespace OpenSubdiv {
39 namespace 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>
429 void EvaluateBasis(PatchHandle
const & handle, REAL u, REAL v,
430 REAL wP[], REAL wDu[] = 0, REAL wDv[] = 0,
431 REAL wDuu[] = 0, REAL wDuv[] = 0, REAL wDvv[] = 0)
const;
435 void EvaluateBasis(PatchHandle
const & handle,
float u,
float v,
436 float wP[],
float wDu[] = 0,
float wDv[] = 0,
437 float wDuu[] = 0,
float wDuv[] = 0,
float wDvv[] = 0)
const;
441 void EvaluateBasis(PatchHandle
const & handle,
double u,
double v,
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;
552 PatchArray & getPatchArray(
Index arrayIndex);
553 PatchArray
const & getPatchArray(
Index arrayIndex)
const;
555 void reservePatchArrays(
int numPatchArrays);
559 IndexArray getPatchArrayVertices(
int arrayIndex);
567 IndexArray getPatchArrayVaryingVertices(
int arrayIndex);
569 void allocateVaryingVertices(
571 void populateVaryingVertices();
577 struct FVarPatchChannel;
578 typedef std::vector<FVarPatchChannel> FVarPatchChannelVector;
580 FVarPatchChannel & getFVarPatchChannel(
int channel);
581 FVarPatchChannel
const & getFVarPatchChannel(
int channel)
const;
583 void allocateFVarPatchChannels(
int numChannels);
584 void allocateFVarPatchChannelValues(
586 int numPatches,
int channel);
589 void setFVarPatchChannelLinearInterpolation(
596 PatchParam getPatchFVarPatchParam(
int patch,
int channel)
const;
606 class StencilTablePtr {
617 StencilTablePtr() { _fPtr = 0; }
618 StencilTablePtr(float_type * ptr) { _fPtr = ptr; }
619 StencilTablePtr(double_type * ptr) { _dPtr = ptr; }
621 operator bool()
const {
return _fPtr != 0; }
623 void Set() { _fPtr = 0; }
624 void Set(float_type * ptr) { _fPtr = ptr; }
625 void Set(double_type * ptr) { _dPtr = ptr; }
627 template <
typename REAL> StencilTableReal<REAL> * Get()
const;
639 PatchArrayVector _patchArrays;
641 std::vector<Index> _patchVerts;
654 StencilTablePtr _localPointStencils;
655 StencilTablePtr _localPointVaryingStencils;
660 PatchDescriptor _varyingDesc;
662 std::vector<Index> _varyingVerts;
667 FVarPatchChannelVector _fvarChannels;
669 std::vector<StencilTablePtr> _localPointFaceVaryingStencils;
674 std::vector<Index> _sharpnessIndices;
675 std::vector<float> _sharpnessValues;
680 unsigned int _isUniformLinear : 1;
685 unsigned int _vertexPrecisionIsDouble : 1;
686 unsigned int _varyingPrecisionIsDouble : 1;
687 unsigned int _faceVaryingPrecisionIsDouble : 1;
694 template <>
inline StencilTableReal<float> *
695 PatchTable::StencilTablePtr::Get<float>()
const {
return _fPtr; }
697 template <>
inline StencilTableReal<double> *
698 PatchTable::StencilTablePtr::Get<double>()
const {
return _dPtr; }
700 template <>
inline bool
701 PatchTable::LocalPointStencilPrecisionMatchesType<float>()
const {
702 return !_vertexPrecisionIsDouble;
704 template <>
inline bool
705 PatchTable::LocalPointVaryingStencilPrecisionMatchesType<float>()
const {
706 return !_varyingPrecisionIsDouble;
708 template <>
inline bool
709 PatchTable::LocalPointFaceVaryingStencilPrecisionMatchesType<float>()
const {
710 return !_faceVaryingPrecisionIsDouble;
713 template <>
inline bool
714 PatchTable::LocalPointStencilPrecisionMatchesType<double>()
const {
715 return _vertexPrecisionIsDouble;
717 template <>
inline bool
718 PatchTable::LocalPointVaryingStencilPrecisionMatchesType<double>()
const {
719 return _varyingPrecisionIsDouble;
721 template <>
inline bool
722 PatchTable::LocalPointFaceVaryingStencilPrecisionMatchesType<double>()
const {
723 return _faceVaryingPrecisionIsDouble;
731 assert(LocalPointStencilPrecisionMatchesType<float>());
732 return static_cast<StencilTable const *
>(_localPointStencils.Get<
float>());
736 assert(LocalPointVaryingStencilPrecisionMatchesType<float>());
738 _localPointVaryingStencils.Get<
float>());
742 assert(LocalPointFaceVaryingStencilPrecisionMatchesType<float>());
743 if (channel >= 0 && channel < (
int)_localPointFaceVaryingStencils.size()) {
745 _localPointFaceVaryingStencils[channel].Get<
float>());
750 template <
typename REAL>
753 assert(LocalPointStencilPrecisionMatchesType<REAL>());
754 return _localPointStencils.Get<REAL>();
756 template <
typename REAL>
759 assert(LocalPointVaryingStencilPrecisionMatchesType<REAL>());
760 return _localPointVaryingStencils.Get<REAL>();
762 template <
typename REAL>
765 assert(LocalPointFaceVaryingStencilPrecisionMatchesType<REAL>());
766 if (channel >= 0 && channel < (
int)_localPointFaceVaryingStencils.size()) {
767 return _localPointFaceVaryingStencils[channel].Get<REAL>();
779 assert(LocalPointStencilPrecisionMatchesType<float>());
780 if (_localPointStencils) {
781 _localPointStencils.Get<
float>()->UpdateValues(src, dst);
788 assert(LocalPointVaryingStencilPrecisionMatchesType<float>());
789 if (_localPointVaryingStencils) {
790 _localPointVaryingStencils.Get<
float>()->UpdateValues(src, dst);
797 assert(LocalPointFaceVaryingStencilPrecisionMatchesType<float>());
798 if (channel >= 0 && channel < (
int)_localPointFaceVaryingStencils.size()) {
799 if (_localPointFaceVaryingStencils[channel]) {
800 _localPointFaceVaryingStencils[channel].Get<
float>()->UpdateValues(src, dst);
811 float wP[],
float wDu[],
float wDv[],
812 float wDuu[],
float wDuv[],
float wDvv[])
const {
814 EvaluateBasis<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
818 double wP[],
double wDu[],
double wDv[],
819 double wDuu[],
double wDuv[],
double wDvv[])
const {
821 EvaluateBasis<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
826 float wP[],
float wDu[],
float wDv[],
827 float wDuu[],
float wDuv[],
float wDvv[])
const {
829 EvaluateBasisVarying<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
833 double wP[],
double wDu[],
double wDv[],
834 double wDuu[],
double wDuv[],
double wDvv[])
const {
836 EvaluateBasisVarying<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv);
841 float wP[],
float wDu[],
float wDv[],
842 float wDuu[],
float wDuv[],
float wDvv[],
int channel)
const {
844 EvaluateBasisFaceVarying<float>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv, channel);
848 double wP[],
double wDu[],
double wDv[],
849 double wDuu[],
double wDuv[],
double wDvv[],
int channel)
const {
851 EvaluateBasisFaceVarying<double>(handle, u, v, wP, wDu, wDv, wDuu, wDuv, wDvv, channel);
857 using namespace OPENSUBDIV_VERSION;
PatchTable(PatchTable const &src)
Copy constructor.
std::vector< Index > const & GetSharpnessIndexTable() const
Returns a sharpness index table for each patch (if exists)
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 ...
std::vector< Index > VertexValenceTable
int GetNumPatches(int array) const
Returns the number of patches in array.
void ComputeLocalPointValuesVarying(T const *src, T *dst) const
Updates local point varying values.
int GetNumPatchesTotal() const
Returns the total number of patches stored in the table.
ConstIndexArray GetPatchFVarValues(PatchHandle const &handle, int channel=0) const
Returns the value indices for a given patch in channel.
QuadOffsetsTable const & GetQuadOffsetsTable() const
Returns the quad-offsets table.
PatchParam GetPatchFVarPatchParam(PatchHandle const &handle, int channel=0) const
Returns the value indices for a given patch in channel.
int GetNumControlVertices(int array) const
Returns the number of control vertices in array.
int GetNumPtexFaces() const
Returns the total number of ptex faces in the mesh.
VertexValenceTable const & GetVertexValenceTable() const
Returns the 'VertexValences' table (vertex neighborhoods table)
StencilTable const * GetLocalPointStencilTable() const
Returns the stencil table to compute local point vertex values.
void ComputeLocalPointValues(T const *src, T *dst) const
Updates local point vertex values.
PatchDescriptor GetFVarPatchDescriptorRegular(int channel=0) const
Returns the regular patch descriptor for channel.
int GetNumPatchArrays() const
Returns the number of patch arrays in the table.
bool IsFeatureAdaptive() const
True if the patches are of feature adaptive types.
PatchParam GetPatchParam(PatchHandle const &handle) const
Returns a PatchParam for the patch identified by handle.
ConstPatchParamArray GetFVarPatchParams(int channel=0) const
Returns an array of face-varying patch param for channel.
std::vector< unsigned int > QuadOffsetsTable
ConstIndexArray GetPatchVertices(PatchHandle const &handle) const
Returns the control vertex indices for the patch identified by handle.
int GetNumLocalPointsFaceVarying(int channel=0) const
Returns the number of local face-varying points for channel.
std::vector< float > const & GetSharpnessValues() const
Returns sharpness values table.
bool LocalPointFaceVaryingStencilPrecisionMatchesType() const
Tests if the precision of the stencil table to compute local point face-varying values matches the gi...
int GetNumLocalPointsVarying() const
Returns the number of local varying points.
An quadtree-based map connecting coarse faces to their sub-patches.
bool LocalPointVaryingStencilPrecisionMatchesType() const
Tests if the precision of the stencil table to compute local point varying values matches the given f...
Sdc::Options::FVarLinearInterpolation GetFVarChannelLinearInterpolation(int channel=0) const
Deprecated.
ConstIndexArray GetPatchArrayVertices(int array) const
Returns the control vertex indices for the patches in array.
int GetMaxValence() const
Returns max vertex valence.
Table of subdivision stencils.
std::vector< Index > PatchVertsTable
PatchParamArray getPatchParams(int arrayIndex)
int GetFVarValueStride(int channel=0) const
Returns the stride between patches in the value index array of channel.
StencilTable const * GetLocalPointVaryingStencilTable() const
Returns the stencil table to compute local point varying values.
PatchParamTable const & GetPatchParamTable() const
Returns the PatchParamTable (PatchParams order matches patch array sorting)
PatchDescriptor GetPatchArrayDescriptor(int array) const
Returns the PatchDescriptor for the patches in array.
std::vector< PatchParam > PatchParamTable
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...
PatchDescriptor GetPatchDescriptor(PatchHandle const &handle) const
Returns the PatchDescriptor for the patch identified by handle.
ConstIndexArray GetPatchArrayVaryingVertices(int array) const
Returns the varying vertex indices for the patches in array.
Container for arrays of parametric patches.
ConstIndexArray GetPatchVaryingVertices(PatchHandle const &handle) const
Returns the varying vertex indices for a given patch.
int GetNumFVarChannels() const
Returns the number of face-varying channels.
PatchVertsTable const & GetPatchControlVerticesTable() const
Get the table of patch control vertices.
ConstIndexArray GetFVarValues(int channel=0) const
Returns an array of value indices for the patches in channel.
void ComputeLocalPointValuesFaceVarying(T const *src, T *dst, int channel=0) const
Updates local point face-varying values.
ConstPatchParamArray const GetPatchParams(int array) const
Returns the PatchParams for the patches in array.
StencilTable const * GetLocalPointFaceVaryingStencilTable(int channel=0) const
Returns the stencil table to compute local point face-varying values.
bool LocalPointStencilPrecisionMatchesType() const
Tests if the precision of the stencil table to compute local point vertex values matches the given fl...
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.
Handle that can be used as unique patch identifier within PatchTable.
float GetSingleCreasePatchSharpnessValue(PatchHandle const &handle) const
Returns the crease sharpness for the patch identified by handle if it is a single-crease patch...
friend class PatchTableBuilder
Index * getSharpnessIndices(Index arrayIndex)
Describes the type of a patch.
std::vector< PatchArray > PatchArrayVector
void print() const
debug helper
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...
Stencil table class wrapping the template for compatibility.
Vtr::ConstArray< unsigned int > ConstQuadOffsetsArray
Accessors for the gregory patch evaluation buffers. These methods will be deprecated.
PatchDescriptor GetFVarPatchDescriptor(int channel=0) const
Returns the default/irregular patch descriptor for channel.
PatchDescriptor GetVaryingPatchDescriptor() const
Returns the varying patch descriptor.
ConstIndexArray GetVaryingVertices() const
Returns an array of varying vertex indices for the patches.
int GetNumControlVerticesTotal() const
Returns the total number of control vertex indices in the table.
int GetNumLocalPoints() const
Returns the number of local vertex points.
Index getPatchIndex(int array, int patch) const
float * getSharpnessValues(Index arrayIndex)
ConstPatchParamArray GetPatchArrayFVarPatchParams(int array, int channel=0) const
Returns the face-varying for a given patch in array in channel.
ConstIndexArray GetPatchArrayFVarValues(int array, int channel=0) const
Returns the value indices for the patches in array in channel.