8#ifndef OPENSUBDIV3_FAR_STENCILTABLE_H
9#define OPENSUBDIV3_FAR_STENCILTABLE_H
11#include "../version.h"
21namespace OPENSUBDIV_VERSION {
26class PatchTableBuilder;
28template <
typename REAL>
class StencilTableFactoryReal;
29template <
typename REAL>
class LimitStencilTableFactoryReal;
35template <
typename REAL>
123template <
typename REAL>
124class StencilTableReal {
127 std::vector<int>
const& offsets,
128 std::vector<int>
const& sizes,
129 std::vector<int>
const& sources,
130 std::vector<REAL>
const& weights,
131 bool includeCoarseVerts,
140 return (
int)
_sizes.size();
187 template <
class T,
class U>
192 template <
class T1,
class T2,
class U>
194 U &dstValues,
Index start=-1,
Index end=-1)
const {
195 this->
update(srcBase, numBase, srcRef, dstValues,
_weights, start, end);
199 template <
class T,
class U>
203 template <
class T1,
class T2,
class U>
206 this->
update(srcBase, numBase, srcRef, dst,
_weights, start, end);
215 template <
class T,
class U>
216 void update( T
const &srcValues, U &dstValues,
217 std::vector<REAL>
const & valueWeights,
Index start,
Index end)
const;
218 template <
class T1,
class T2,
class U>
219 void update( T1
const &srcBase,
int numBase, T2
const &srcRef, U &dstValues,
220 std::vector<REAL>
const & valueWeights,
Index start,
Index end)
const;
272 std::vector<int>
const& offsets,
273 std::vector<int>
const& sizes,
274 std::vector<int>
const& sources,
275 std::vector<float>
const& weights,
276 bool includeCoarseVerts,
279 sizes, sources, weights, includeCoarseVerts, firstOffset) { }
285template <
typename REAL>
286class LimitStencilReal :
public StencilReal<REAL> {
316 _duWeights(duWeights),
317 _dvWeights(dvWeights),
318 _duuWeights(duuWeights),
319 _duvWeights(duvWeights),
320 _dvvWeights(dvvWeights) {
350 int stride = *this->
_size;
354 if (_duWeights) _duWeights += stride;
355 if (_dvWeights) _dvWeights += stride;
356 if (_duuWeights) _duuWeights += stride;
357 if (_duvWeights) _duvWeights += stride;
358 if (_dvvWeights) _dvvWeights += stride;
382 float * duWeights=0,
float * dvWeights=0,
383 float * duuWeights=0,
float * duvWeights=0,
float * dvvWeights=0)
385 duWeights, dvWeights, duuWeights, duvWeights, dvvWeights) { }
391template <
typename REAL>
392class LimitStencilTableReal :
public StencilTableReal<REAL> {
396 std::vector<int>
const& offsets,
397 std::vector<int>
const& sizes,
398 std::vector<int>
const& sources,
399 std::vector<REAL>
const& weights,
400 std::vector<REAL>
const& duWeights,
401 std::vector<REAL>
const& dvWeights,
402 std::vector<REAL>
const& duuWeights,
403 std::vector<REAL>
const& duvWeights,
404 std::vector<REAL>
const& dvvWeights,
405 bool includeCoarseVerts,
458 template <
class T,
class U>
460 int start=-1,
int end=-1)
const {
462 this->
update(srcValues, uderivs, _duWeights, start, end);
463 this->
update(srcValues, vderivs, _dvWeights, start, end);
466 template <
class T1,
class T2,
class U>
468 U & uderivs, U & vderivs,
int start=-1,
int end=-1)
const {
470 this->
update(srcBase, numBase, srcRef, uderivs, _duWeights, start, end);
471 this->
update(srcBase, numBase, srcRef, vderivs, _dvWeights, start, end);
475 template <
class T,
class U>
477 int start=-1,
int end=-1)
const {
479 this->
update(src, uderivs, _duWeights, start, end);
480 this->
update(src, vderivs, _dvWeights, start, end);
482 template <
class T1,
class T2,
class U>
484 U *uderivs, U *vderivs,
int start=-1,
int end=-1)
const {
486 this->
update(srcBase, numBase, srcRef, uderivs, _duWeights, start, end);
487 this->
update(srcBase, numBase, srcRef, vderivs, _dvWeights, start, end);
510 template <
class T,
class U>
512 U & uuderivs, U & uvderivs, U & vvderivs,
513 int start=-1,
int end=-1)
const {
515 this->
update(srcValues, uuderivs, _duuWeights, start, end);
516 this->
update(srcValues, uvderivs, _duvWeights, start, end);
517 this->
update(srcValues, vvderivs, _dvvWeights, start, end);
520 template <
class T1,
class T2,
class U>
522 U & uuderivs, U & uvderivs, U & vvderivs,
int start=-1,
int end=-1)
const {
524 this->
update(srcBase, numBase, srcRef, uuderivs, _duuWeights, start, end);
525 this->
update(srcBase, numBase, srcRef, uvderivs, _duvWeights, start, end);
526 this->
update(srcBase, numBase, srcRef, vvderivs, _dvvWeights, start, end);
530 template <
class T,
class U>
532 int start=-1,
int end=-1)
const {
534 this->
update(src, uuderivs, _duuWeights, start, end);
535 this->
update(src, uvderivs, _duvWeights, start, end);
536 this->
update(src, vvderivs, _dvvWeights, start, end);
538 template <
class T1,
class T2,
class U>
540 U *uuderivs, U *uvderivs, U *vvderivs,
int start=-1,
int end=-1)
const {
542 this->
update(srcBase, numBase, srcRef, uuderivs, _duuWeights, start, end);
543 this->
update(srcBase, numBase, srcRef, uvderivs, _duvWeights, start, end);
544 this->
update(srcBase, numBase, srcRef, vvderivs, _dvvWeights, start, end);
554 void resize(
int nstencils,
int nelems);
557 std::vector<REAL> _duWeights,
580 std::vector<int>
const& offsets,
581 std::vector<int>
const& sizes,
582 std::vector<int>
const& sources,
583 std::vector<float>
const& weights,
584 std::vector<float>
const& duWeights,
585 std::vector<float>
const& dvWeights,
586 std::vector<float>
const& duuWeights,
587 std::vector<float>
const& duvWeights,
588 std::vector<float>
const& dvvWeights,
589 bool includeCoarseVerts,
592 offsets, sizes, sources, weights,
593 duWeights, dvWeights, duuWeights, duvWeights, dvvWeights,
594 includeCoarseVerts, firstOffset) { }
599template <
typename REAL>
600template <
class T1,
class T2,
class U>
void
602 T2
const &srcRef, U &dstValues,
603 std::vector<REAL>
const &valueWeights,
Index start,
Index end)
const {
605 int const * sizes = &_sizes.at(0);
606 Index const * indices = &_indices.at(0);
607 REAL
const * weights = &valueWeights.at(0);
610 assert(start < (
Index)_offsets.size());
612 indices += _offsets[start];
613 weights += _offsets[start];
618 int nstencils = ((end < start) ? GetNumStencils() : end) - start;
620 for (
int i = 0; i < nstencils; ++i, ++sizes) {
621 dstValues[start + i].Clear();
622 for (
int j = 0; j < *sizes; ++j, ++indices, ++weights) {
623 if (*indices < numBase) {
624 dstValues[start + i].AddWithWeight(srcBase[*indices], *weights);
626 dstValues[start + i].AddWithWeight(srcRef[*indices - numBase], *weights);
631template <
typename REAL>
632template <
class T,
class U>
void
634 std::vector<REAL>
const &valueWeights,
Index start,
Index end)
const {
636 int const * sizes = &_sizes.at(0);
637 Index const * indices = &_indices.at(0);
638 REAL
const * weights = &valueWeights.at(0);
641 assert(start < (
Index)_offsets.size());
643 indices += _offsets[start];
644 weights += _offsets[start];
649 int nstencils = ((end < start) ? GetNumStencils() : end) - start;
651 for (
int i = 0; i < nstencils; ++i, ++sizes) {
652 dstValues[start + i].Clear();
653 for (
int j = 0; j < *sizes; ++j, ++indices, ++weights) {
654 dstValues[start + i].AddWithWeight(srcValues[*indices], *weights);
659template <
typename REAL>
663 int noffsets = (int)_sizes.size();
664 _offsets.resize(noffsets);
665 for (
int i=0; i<(int)_sizes.size(); ++i ) {
671template <
typename REAL>
674 _sizes.resize(nstencils);
675 _indices.resize(nelems);
676 _weights.resize(nelems);
679template <
typename REAL>
682 _sizes.reserve(nstencils);
683 _indices.reserve(nelems);
684 _weights.reserve(nelems);
687template <
typename REAL>
690 std::vector<int>(_sizes).swap(_sizes);
691 std::vector<Index>(_indices).swap(_indices);
692 std::vector<REAL>(_weights).swap(_weights);
695template <
typename REAL>
703template <
typename REAL>
706 assert((! _offsets.empty()) && i<(
int)_offsets.size());
708 Index ofs = _offsets[i];
711 const_cast<Index*
>(&_indices[ofs]),
712 const_cast<REAL*
>(&_weights[ofs]));
715template <
typename REAL>
718 return GetStencil(index);
721template <
typename REAL>
725 _duWeights.resize(nelems);
726 _dvWeights.resize(nelems);
730template <
typename REAL>
731inline LimitStencilReal<REAL>
733 assert((! this->GetOffsets().empty()) && i<(
int)this->GetOffsets().size());
735 Index ofs = this->GetOffsets()[i];
737 if (!_duWeights.empty() && !_dvWeights.empty() &&
738 !_duuWeights.empty() && !_duvWeights.empty() && !_dvvWeights.empty()) {
740 const_cast<int *
>(&this->GetSizes()[i]),
741 const_cast<Index *
>(&this->GetControlIndices()[ofs]),
742 const_cast<REAL *
>(&this->GetWeights()[ofs]),
743 const_cast<REAL *
>(&GetDuWeights()[ofs]),
744 const_cast<REAL *
>(&GetDvWeights()[ofs]),
745 const_cast<REAL *
>(&GetDuuWeights()[ofs]),
746 const_cast<REAL *
>(&GetDuvWeights()[ofs]),
747 const_cast<REAL *
>(&GetDvvWeights()[ofs]) );
748 }
else if (!_duWeights.empty() && !_dvWeights.empty()) {
750 const_cast<int *
>(&this->GetSizes()[i]),
751 const_cast<Index *
>(&this->GetControlIndices()[ofs]),
752 const_cast<REAL *
>(&this->GetWeights()[ofs]),
753 const_cast<REAL *
>(&GetDuWeights()[ofs]),
754 const_cast<REAL *
>(&GetDvWeights()[ofs]) );
757 const_cast<int *
>(&this->GetSizes()[i]),
758 const_cast<Index *
>(&this->GetControlIndices()[ofs]),
759 const_cast<REAL *
>(&this->GetWeights()[ofs]) );
763template <
typename REAL>
766 return GetLimitStencil(index);
772using namespace OPENSUBDIV_VERSION;
A specialized factory for StencilTable.
A specialized factory for LimitStencilTable.
Vertex stencil descriptor.
StencilReal()
Default constructor.
StencilReal(int *size, Index *indices, REAL *weights)
Constructor.
void Next()
Advance to the next stencil in the table.
StencilReal(StencilReal const &other)
Copy constructor.
Index const * GetVertexIndices() const
Returns the control vertices' indices.
int GetSize() const
Returns the size of the stencil.
int * GetSizePtr() const
Returns the size of the stencil as a pointer.
REAL const * GetWeights() const
Returns the interpolation weights.
Vertex stencil class wrapping the template for compatibility.
Stencil(BaseStencil const &other)
Stencil(int *size, Index *indices, float *weights)
StencilReal< float > BaseStencil
Table of subdivision stencils.
int GetNumControlVertices() const
Returns the number of control vertices indexed in the table.
std::vector< int > _sizes
friend class Far::PatchTableBuilder
void update(T1 const &srcBase, int numBase, T2 const &srcRef, U &dstValues, std::vector< REAL > const &valueWeights, Index start, Index end) const
void UpdateValues(T1 const &srcBase, int numBase, T2 const &srcRef, U &dstValues, Index start=-1, Index end=-1) const
std::vector< Index > const & GetControlIndices() const
Returns the indices of the control vertices.
StencilReal< REAL > operator[](Index index) const
Returns the stencil at index i in the table.
void update(T const &srcValues, U &dstValues, std::vector< REAL > const &valueWeights, Index start, Index end) const
std::vector< int > const & GetSizes() const
Returns the number of control vertices of each stencil in the table.
int GetNumStencils() const
Returns the number of stencils in the table.
virtual ~StencilTableReal()
std::vector< Index > const & GetOffsets() const
Returns the offset to a given stencil (factory may leave empty)
StencilReal< REAL > GetStencil(Index i) const
Returns a Stencil at index i in the table.
void Clear()
Clears the stencils from the table.
std::vector< Index > _offsets
std::vector< REAL > _weights
void resize(int nstencils, int nelems)
std::vector< REAL > const & GetWeights() const
Returns the stencil interpolation weights.
void UpdateValues(T1 const *srcBase, int numBase, T2 const *srcRef, U *dst, Index start=-1, Index end=-1) const
StencilTableReal(int numControlVerts, std::vector< int > const &offsets, std::vector< int > const &sizes, std::vector< int > const &sources, std::vector< REAL > const &weights, bool includeCoarseVerts, size_t firstOffset)
std::vector< Index > _indices
void reserve(int nstencils, int nelems)
void UpdateValues(T const *src, U *dst, Index start=-1, Index end=-1) const
void UpdateValues(T const &srcValues, U &dstValues, Index start=-1, Index end=-1) const
Updates point values based on the control values.
Stencil table class wrapping the template for compatibility.
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)
StencilTable(int numControlVerts)
Stencil GetStencil(Index index) const
Stencil operator[](Index index) const
StencilTableReal< float > BaseTable
Limit point stencil descriptor.
REAL const * GetDuvWeights() const
Returns the uv derivative weights.
REAL const * GetDvWeights() const
Returns the v derivative weights.
void Next()
Advance to the next stencil in the table.
REAL const * GetDvvWeights() const
Returns the vv derivative weights.
LimitStencilReal(int *size, Index *indices, REAL *weights, REAL *duWeights=0, REAL *dvWeights=0, REAL *duuWeights=0, REAL *duvWeights=0, REAL *dvvWeights=0)
Constructor.
REAL const * GetDuWeights() const
Returns the u derivative weights.
REAL const * GetDuuWeights() const
Returns the uu derivative weights.
Limit point stencil class wrapping the template for compatibility.
LimitStencil(BaseStencil const &other)
LimitStencil(int *size, Index *indices, float *weights, float *duWeights=0, float *dvWeights=0, float *duuWeights=0, float *duvWeights=0, float *dvvWeights=0)
LimitStencilReal< float > BaseStencil
Table of limit subdivision stencils.
std::vector< REAL > const & GetDuuWeights() const
Returns the 'uu' derivative stencil interpolation weights.
LimitStencilReal< REAL > operator[](Index index) const
Returns the limit stencil at index i in the table.
std::vector< REAL > const & GetDvvWeights() const
Returns the 'vv' derivative stencil interpolation weights.
void UpdateDerivs(T const *src, U *uderivs, U *vderivs, int start=-1, int end=-1) const
void Update2ndDerivs(T const *src, T *uuderivs, U *uvderivs, U *vvderivs, int start=-1, int end=-1) const
std::vector< REAL > const & GetDvWeights() const
Returns the 'v' derivative stencil interpolation weights.
void Update2ndDerivs(T1 const *srcBase, int numBase, T2 const *srcRef, U *uuderivs, U *uvderivs, U *vvderivs, int start=-1, int end=-1) 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.
LimitStencilReal< REAL > GetLimitStencil(Index i) const
Returns a LimitStencil at index i in the table.
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 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.
std::vector< REAL > const & GetDuWeights() const
Returns the 'u' derivative stencil interpolation weights.
void Clear()
Clears the stencils from the table.
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< REAL > const & GetDuvWeights() const
Returns the 'uv' derivative stencil interpolation weights.
void UpdateDerivs(T1 const &srcBase, int numBase, T2 const &srcRef, U &uderivs, U &vderivs, int start=-1, int end=-1) const
void UpdateDerivs(T1 const *srcBase, int numBase, T2 const *srcRef, U *uderivs, U *vderivs, int start=-1, int end=-1) const
Limit stencil table class wrapping the template for compatibility.
LimitStencil GetLimitStencil(Index index) const
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)
LimitStencil operator[](Index index) const
LimitStencilTableReal< float > BaseTable