25 #ifndef OPENSUBDIV3_FAR_STENCILTABLE_H 
   26 #define OPENSUBDIV3_FAR_STENCILTABLE_H 
   28 #include "../version.h" 
   30 #include "../far/types.h" 
   37 namespace OpenSubdiv {
 
   38 namespace OPENSUBDIV_VERSION {
 
   43 class PatchTableBuilder;
 
   52 template <
typename REAL>
 
  140 template <
typename REAL>
 
  144                     std::vector<int> 
const& offsets,
 
  145                     std::vector<int> 
const& sizes,
 
  146                     std::vector<int> 
const& sources,
 
  147                     std::vector<REAL> 
const& weights,
 
  148                     bool includeCoarseVerts,
 
  157         return (
int)
_sizes.size();
 
  204     template <
class T, 
class U>
 
  209     template <
class T1, 
class T2, 
class U>
 
  211         U &dstValues, 
Index start=-1, 
Index end=-1)
 const {
 
  212         this->
update(srcBase, numBase, srcRef, dstValues, 
_weights, start, end);
 
  216     template <
class T, 
class U>
 
  220     template <
class T1, 
class T2, 
class U>
 
  223         this->
update(srcBase, numBase, srcRef, dst, 
_weights, start, end);
 
  232     template <
class T, 
class U>
 
  233     void update( T 
const &srcValues, U &dstValues,
 
  234         std::vector<REAL> 
const & valueWeights, 
Index start, 
Index end) 
const;
 
  235     template <
class T1, 
class T2, 
class U>
 
  236     void update( T1 
const &srcBase, 
int numBase, T2 
const &srcRef, U &dstValues,
 
  237         std::vector<REAL> 
const & valueWeights, 
Index start, 
Index end) 
const;
 
  243     void resize(
int nstencils, 
int nelems);
 
  246     void reserve(
int nstencils, 
int nelems);
 
  261     friend class Far::PatchTableBuilder;
 
  289                  std::vector<int> 
const& offsets,
 
  290                  std::vector<int> 
const& sizes,
 
  291                  std::vector<int> 
const& sources,
 
  292                  std::vector<float> 
const& weights,
 
  293                  bool includeCoarseVerts,
 
  296                 sizes, sources, weights, includeCoarseVerts, firstOffset) { }
 
  302 template <
typename REAL>
 
  333           _duWeights(duWeights),
 
  334           _dvWeights(dvWeights),
 
  335           _duuWeights(duuWeights),
 
  336           _duvWeights(duvWeights),
 
  337           _dvvWeights(dvvWeights) {
 
  367        int stride = *this->
_size;
 
  371        if (_duWeights) _duWeights += stride;
 
  372        if (_dvWeights) _dvWeights += stride;
 
  373        if (_duuWeights) _duuWeights += stride;
 
  374        if (_duvWeights) _duvWeights += stride;
 
  375        if (_dvvWeights) _dvvWeights += stride;
 
  399                  float * duWeights=0, 
float * dvWeights=0,
 
  400                  float * duuWeights=0, 
float * duvWeights=0, 
float * dvvWeights=0)
 
  402                  duWeights, dvWeights, duuWeights, duvWeights, dvvWeights) { }
 
  408 template <
typename REAL>
 
  413                     std::vector<int> 
const& offsets,
 
  414                     std::vector<int> 
const& sizes,
 
  415                     std::vector<int> 
const& sources,
 
  416                     std::vector<REAL> 
const& weights,
 
  417                     std::vector<REAL> 
const& duWeights,
 
  418                     std::vector<REAL> 
const& dvWeights,
 
  419                     std::vector<REAL> 
const& duuWeights,
 
  420                     std::vector<REAL> 
const& duvWeights,
 
  421                     std::vector<REAL> 
const& dvvWeights,
 
  422                     bool includeCoarseVerts,
 
  475     template <
class T, 
class U>
 
  477         int start=-1, 
int end=-1)
 const {
 
  479         this->
update(srcValues, uderivs, _duWeights, start, end);
 
  480         this->
update(srcValues, vderivs, _dvWeights, start, end);
 
  483     template <
class T1, 
class T2, 
class U>
 
  485         U & uderivs, U & vderivs, 
int start=-1, 
int end=-1)
 const {
 
  487         this->
update(srcBase, numBase, srcRef, uderivs, _duWeights, start, end);
 
  488         this->
update(srcBase, numBase, srcRef, vderivs, _dvWeights, start, end);
 
  492     template <
class T, 
class U>
 
  494         int start=-1, 
int end=-1)
 const {
 
  496         this->
update(src, uderivs, _duWeights, start, end);
 
  497         this->
update(src, vderivs, _dvWeights, start, end);
 
  499     template <
class T1, 
class T2, 
class U>
 
  501         U *uderivs, U *vderivs, 
int start=-1, 
int end=-1)
 const {
 
  503         this->
update(srcBase, numBase, srcRef, uderivs, _duWeights, start, end);
 
  504         this->
update(srcBase, numBase, srcRef, vderivs, _dvWeights, start, end);
 
  527     template <
class T, 
class U>
 
  529         U & uuderivs, U & uvderivs, U & vvderivs,
 
  530         int start=-1, 
int end=-1)
 const {
 
  532         this->
update(srcValues, uuderivs, _duuWeights, start, end);
 
  533         this->
update(srcValues, uvderivs, _duvWeights, start, end);
 
  534         this->
update(srcValues, vvderivs, _dvvWeights, start, end);
 
  537     template <
class T1, 
class T2, 
class U>
 
  539         U & uuderivs, U & uvderivs, U & vvderivs, 
int start=-1, 
int end=-1)
 const {
 
  541         this->
update(srcBase, numBase, srcRef, uuderivs, _duuWeights, start, end);
 
  542         this->
update(srcBase, numBase, srcRef, uvderivs, _duvWeights, start, end);
 
  543         this->
update(srcBase, numBase, srcRef, vvderivs, _dvvWeights, start, end);
 
  547     template <
class T, 
class U>
 
  549         int start=-1, 
int end=-1)
 const {
 
  551         this->
update(src, uuderivs, _duuWeights, start, end);
 
  552         this->
update(src, uvderivs, _duvWeights, start, end);
 
  553         this->
update(src, vvderivs, _dvvWeights, start, end);
 
  555     template <
class T1, 
class T2, 
class U>
 
  557         U *uuderivs, U *uvderivs, U *vvderivs, 
int start=-1, 
int end=-1)
 const {
 
  559         this->
update(srcBase, numBase, srcRef, uuderivs, _duuWeights, start, end);
 
  560         this->
update(srcBase, numBase, srcRef, uvderivs, _duvWeights, start, end);
 
  561         this->
update(srcBase, numBase, srcRef, vvderivs, _dvvWeights, start, end);
 
  571     void resize(
int nstencils, 
int nelems);
 
  574     std::vector<REAL>   _duWeights,   
 
  597                     std::vector<int> 
const& offsets,
 
  598                     std::vector<int> 
const& sizes,
 
  599                     std::vector<int> 
const& sources,
 
  600                     std::vector<float> 
const& weights,
 
  601                     std::vector<float> 
const& duWeights,
 
  602                     std::vector<float> 
const& dvWeights,
 
  603                     std::vector<float> 
const& duuWeights,
 
  604                     std::vector<float> 
const& duvWeights,
 
  605                     std::vector<float> 
const& dvvWeights,
 
  606                     bool includeCoarseVerts,
 
  609                     offsets, sizes, sources, weights,
 
  610                     duWeights, dvWeights, duuWeights, duvWeights, dvvWeights,
 
  611                     includeCoarseVerts, firstOffset) { }
 
  616 template <
typename REAL>
 
  617 template <
class T1, 
class T2, 
class U> 
void 
  619     T2 
const &srcRef, U &dstValues,
 
  620     std::vector<REAL> 
const &valueWeights, 
Index start, 
Index end)
 const {
 
  622     int const * sizes = &_sizes.at(0);
 
  623     Index const * indices = &_indices.at(0);
 
  624     REAL 
const * weights = &valueWeights.at(0);
 
  627         assert(start < (
Index)_offsets.size());
 
  629         indices += _offsets[start];
 
  630         weights += _offsets[start];
 
  635     int nstencils = ((end < start) ? GetNumStencils() : end) - start;
 
  637     for (
int i = 0; i < nstencils; ++i, ++sizes) {
 
  638         dstValues[start + i].Clear();
 
  639         for (
int j = 0; j < *sizes; ++j, ++indices, ++weights) {
 
  640             if (*indices < numBase) {
 
  641                 dstValues[start + i].AddWithWeight(srcBase[*indices], *weights);
 
  643                 dstValues[start + i].AddWithWeight(srcRef[*indices - numBase], *weights);
 
  648 template <
typename REAL>
 
  649 template <
class T, 
class U> 
void 
  651     std::vector<REAL> 
const &valueWeights, 
Index start, 
Index end)
 const {
 
  653     int const * sizes = &_sizes.at(0);
 
  654     Index const * indices = &_indices.at(0);
 
  655     REAL 
const * weights = &valueWeights.at(0);
 
  658         assert(start < (
Index)_offsets.size());
 
  660         indices += _offsets[start];
 
  661         weights += _offsets[start];
 
  666     int nstencils = ((end < start) ? GetNumStencils() : end) - start;
 
  668     for (
int i = 0; i < nstencils; ++i, ++sizes) {
 
  669         dstValues[start + i].Clear();
 
  670         for (
int j = 0; j < *sizes; ++j, ++indices, ++weights) {
 
  671             dstValues[start + i].AddWithWeight(srcValues[*indices], *weights);
 
  676 template <
typename REAL>
 
  680     int noffsets = (int)_sizes.size();
 
  681     _offsets.resize(noffsets);
 
  682     for (
int i=0; i<(int)_sizes.size(); ++i ) {
 
  688 template <
typename REAL>
 
  691     _sizes.resize(nstencils);
 
  692     _indices.resize(nelems);
 
  693     _weights.resize(nelems);
 
  696 template <
typename REAL>
 
  699     _sizes.reserve(nstencils);
 
  700     _indices.reserve(nelems);
 
  701     _weights.reserve(nelems);
 
  704 template <
typename REAL>
 
  707     std::vector<int>(_sizes).swap(_sizes);
 
  708     std::vector<Index>(_indices).swap(_indices);
 
  709     std::vector<REAL>(_weights).swap(_weights);
 
  712 template <
typename REAL>
 
  720 template <
typename REAL>
 
  723     assert((! _offsets.empty()) && i<(
int)_offsets.size());
 
  725     Index ofs = _offsets[i];
 
  728                              const_cast<Index*>(&_indices[ofs]),
 
  729                              const_cast<REAL*
>(&_weights[ofs]));
 
  732 template <
typename REAL>
 
  735     return GetStencil(index);
 
  738 template <
typename REAL>
 
  742     _duWeights.resize(nelems);
 
  743     _dvWeights.resize(nelems);
 
  747 template <
typename REAL>
 
  748 inline LimitStencilReal<REAL>
 
  750     assert((! this->GetOffsets().empty()) && i<(
int)this->GetOffsets().size());
 
  752     Index ofs = this->GetOffsets()[i];
 
  754     if (!_duWeights.empty() && !_dvWeights.empty() &&
 
  755         !_duuWeights.empty() && !_duvWeights.empty() && !_dvvWeights.empty()) {
 
  757                              const_cast<int *
>(&this->GetSizes()[i]),
 
  758                              const_cast<Index *>(&this->GetControlIndices()[ofs]),
 
  759                              const_cast<REAL *>(&this->GetWeights()[ofs]),
 
  760                              const_cast<REAL *>(&GetDuWeights()[ofs]),
 
  761                              const_cast<REAL *>(&GetDvWeights()[ofs]),
 
  762                              const_cast<REAL *>(&GetDuuWeights()[ofs]),
 
  763                              const_cast<REAL *>(&GetDuvWeights()[ofs]),
 
  764                              const_cast<REAL *>(&GetDvvWeights()[ofs]) );
 
  765     } 
else if (!_duWeights.empty() && !_dvWeights.empty()) {
 
  767                              const_cast<int *
>(&this->GetSizes()[i]),
 
  768                              const_cast<Index *>(&this->GetControlIndices()[ofs]),
 
  769                              const_cast<REAL *>(&this->GetWeights()[ofs]),
 
  770                              const_cast<REAL *>(&GetDuWeights()[ofs]),
 
  771                              const_cast<REAL *>(&GetDvWeights()[ofs]) );
 
  774                              const_cast<int *
>(&this->GetSizes()[i]),
 
  775                              const_cast<Index *>(&this->GetControlIndices()[ofs]),
 
  776                              const_cast<REAL *>(&this->GetWeights()[ofs]) );
 
  780 template <
typename REAL>
 
  783     return GetLimitStencil(index);
 
  789 using namespace OPENSUBDIV_VERSION;
 
  793 #endif // OPENSUBDIV3_FAR_STENCILTABLE_H 
StencilTableReal(int numControlVerts)
REAL const * GetDvvWeights() const 
Returns the vv derivative weights. 
std::vector< REAL > const & GetDuWeights() const 
Returns the 'u' derivative stencil interpolation weights. 
REAL const * GetWeights() const 
Returns the interpolation weights. 
StencilReal(StencilReal const &other)
Copy constructor. 
std::vector< REAL > const & GetDuvWeights() const 
Returns the 'uv' derivative stencil interpolation weights. 
LimitStencilTable(int numControlVerts, std::vector< int > const &offsets, std::vector< int > const &sizes, std::vector< int > const &sources, std::vector< float > const &weights, std::vector< float > const &duWeights, std::vector< float > const &dvWeights, std::vector< float > const &duuWeights, std::vector< float > const &duvWeights, std::vector< float > const &dvvWeights, bool includeCoarseVerts, size_t firstOffset)
Vertex stencil descriptor. 
std::vector< int > _sizes
void UpdateDerivs(T1 const *srcBase, int numBase, T2 const *srcRef, U *uderivs, U *vderivs, int start=-1, int end=-1) const 
StencilReal(int *size, Index *indices, REAL *weights)
Constructor. 
void UpdateValues(T const &srcValues, U &dstValues, Index start=-1, Index end=-1) const 
Updates point values based on the control values. 
void UpdateValues(T const *src, U *dst, Index start=-1, Index end=-1) const 
Stencil(BaseStencil const &other)
Stencil operator[](Index index) const 
void UpdateDerivs(T const &srcValues, U &uderivs, U &vderivs, int start=-1, int end=-1) const 
Updates derivative values based on the control values. 
std::vector< Index > _offsets
LimitStencilReal< float > BaseStencil
StencilTable(int numControlVerts, std::vector< int > const &offsets, std::vector< int > const &sizes, std::vector< int > const &sources, std::vector< float > const &weights, bool includeCoarseVerts, size_t firstOffset)
Limit stencil table class wrapping the template for compatibility. 
void UpdateDerivs(T const *src, U *uderivs, U *vderivs, int start=-1, int end=-1) const 
void Clear()
Clears the stencils from the table. 
LimitStencil GetLimitStencil(Index index) const 
StencilReal()
Default constructor. 
StencilReal< REAL > GetStencil(Index i) const 
Returns a Stencil at index i in the table. 
std::vector< REAL > const & GetDvvWeights() const 
Returns the 'vv' derivative stencil interpolation weights. 
std::vector< Index > const & GetOffsets() const 
Returns the offset to a given stencil (factory may leave empty) 
std::vector< REAL > _weights
void update(T const &srcValues, U &dstValues, std::vector< REAL > const &valueWeights, Index start, Index end) const 
void Next()
Advance to the next stencil in the table. 
std::vector< REAL > const & GetWeights() const 
Returns the stencil interpolation weights. 
Vertex stencil class wrapping the template for compatibility. 
std::vector< Index > _indices
Table of subdivision stencils. 
LimitStencilReal(int *size, Index *indices, REAL *weights, REAL *duWeights=0, REAL *dvWeights=0, REAL *duuWeights=0, REAL *duvWeights=0, REAL *dvvWeights=0)
Constructor. 
int GetNumControlVertices() const 
Returns the number of control vertices indexed in the table. 
int * GetSizePtr() const 
Returns the size of the stencil as a pointer. 
LimitStencil(BaseStencil const &other)
int GetNumStencils() const 
Returns the number of stencils in the table. 
LimitStencilTableReal< float > BaseTable
REAL const * GetDuuWeights() const 
Returns the uu derivative weights. 
void Update2ndDerivs(T const *src, T *uuderivs, U *uvderivs, U *vvderivs, int start=-1, int end=-1) const 
StencilTable(int numControlVerts)
REAL const * GetDvWeights() const 
Returns the v derivative weights. 
Limit point stencil descriptor. 
LimitStencilReal< REAL > operator[](Index index) const 
Returns the limit stencil at index i in the table. 
Stencil(int *size, Index *indices, float *weights)
LimitStencilTableReal(int numControlVerts, std::vector< int > const &offsets, std::vector< int > const &sizes, std::vector< int > const &sources, std::vector< REAL > const &weights, std::vector< REAL > const &duWeights, std::vector< REAL > const &dvWeights, std::vector< REAL > const &duuWeights, std::vector< REAL > const &duvWeights, std::vector< REAL > const &dvvWeights, bool includeCoarseVerts, size_t firstOffset)
void Clear()
Clears the stencils from the table. 
A specialized factory for LimitStencilTable. 
std::vector< Index > const & GetControlIndices() const 
Returns the indices of the control vertices. 
LimitStencil operator[](Index index) const 
LimitStencilReal< REAL > GetLimitStencil(Index i) const 
Returns a LimitStencil at index i in the table. 
StencilReal< float > BaseStencil
void reserve(int nstencils, int nelems)
void Update2ndDerivs(T1 const &srcBase, int numBase, T2 const &srcRef, U &uuderivs, U &uvderivs, U &vvderivs, int start=-1, int end=-1) const 
void resize(int nstencils, int nelems)
REAL const * GetDuvWeights() const 
Returns the uv derivative weights. 
std::vector< REAL > const & GetDvWeights() const 
Returns the 'v' derivative stencil interpolation weights. 
void Next()
Advance to the next stencil in the table. 
virtual ~StencilTableReal()
REAL const * GetDuWeights() const 
Returns the u derivative weights. 
StencilTableReal< float > BaseTable
void UpdateValues(T1 const *srcBase, int numBase, T2 const *srcRef, U *dst, Index start=-1, Index end=-1) const 
LimitStencil(int *size, Index *indices, float *weights, float *duWeights=0, float *dvWeights=0, float *duuWeights=0, float *duvWeights=0, float *dvvWeights=0)
void UpdateValues(T1 const &srcBase, int numBase, T2 const &srcRef, U &dstValues, Index start=-1, Index end=-1) const 
std::vector< REAL > const & GetDuuWeights() const 
Returns the 'uu' derivative stencil interpolation weights. 
int GetSize() const 
Returns the size of the stencil. 
A specialized factory for StencilTable. 
void Update2ndDerivs(T const &srcValues, U &uuderivs, U &uvderivs, U &vvderivs, int start=-1, int end=-1) const 
Updates 2nd derivative values based on the control values. 
Stencil table class wrapping the template for compatibility. 
Table of limit subdivision stencils. 
Index const * GetVertexIndices() const 
Returns the control vertices' indices. 
void Update2ndDerivs(T1 const *srcBase, int numBase, T2 const *srcRef, U *uuderivs, U *uvderivs, U *vvderivs, int start=-1, int end=-1) const 
std::vector< int > const & GetSizes() const 
Returns the number of control vertices of each stencil in the table. 
Stencil GetStencil(Index index) const 
Limit point stencil class wrapping the template for compatibility. 
StencilReal< REAL > operator[](Index index) const 
Returns the stencil at index i in the table. 
void UpdateDerivs(T1 const &srcBase, int numBase, T2 const &srcRef, U &uderivs, U &vderivs, int start=-1, int end=-1) const