25 #ifndef OPENSUBDIV3_FAR_STENCILTABLE_H 26 #define OPENSUBDIV3_FAR_STENCILTABLE_H 28 #include "../version.h" 30 #include "../far/types.h" 38 namespace OPENSUBDIV_VERSION {
127 std::vector<int>
const& offsets,
128 std::vector<int>
const& sizes,
129 std::vector<int>
const& sources,
130 std::vector<float>
const& weights,
131 bool includeCoarseVerts,
140 return (
int)_sizes.size();
145 return _numControlVertices;
190 update(controlValues, values,
_weights, start, end);
199 template <
class T>
void update( T
const *controlValues, T *values,
200 std::vector<float>
const & valueWeights,
Index start,
Index end)
const;
203 void generateOffsets();
206 void resize(
int nstencils,
int nelems);
209 void reserve(
int nstencils,
int nelems);
220 : _numControlVertices(numControlVerts)
226 friend class GregoryBasis;
228 friend class EndCapBSplineBasisPatchFactory;
229 friend class EndCapGregoryBasisPatchFactory;
269 float * duuWeights=0,
270 float * duvWeights=0,
271 float * dvvWeights=0)
272 :
Stencil(size, indices, weights),
273 _duWeights(duWeights),
274 _dvWeights(dvWeights),
275 _duuWeights(duuWeights),
276 _duvWeights(duvWeights),
277 _dvvWeights(dvvWeights) {
311 if (_duWeights) _duWeights += stride;
312 if (_dvWeights) _dvWeights += stride;
313 if (_duuWeights) _duuWeights += stride;
314 if (_duvWeights) _duvWeights += stride;
315 if (_dvvWeights) _dvvWeights += stride;
335 std::vector<int>
const& offsets,
336 std::vector<int>
const& sizes,
337 std::vector<int>
const& sources,
338 std::vector<float>
const& weights,
339 std::vector<float>
const& duWeights,
340 std::vector<float>
const& dvWeights,
341 std::vector<float>
const& duuWeights,
342 std::vector<float>
const& duvWeights,
343 std::vector<float>
const& dvvWeights,
344 bool includeCoarseVerts,
399 int start=-1,
int end=-1)
const {
401 update(controlValues, uderivs, _duWeights, start, end);
402 update(controlValues, vderivs, _dvWeights, start, end);
427 int start=-1,
int end=-1)
const {
429 update(controlValues, uuderivs, _duuWeights, start, end);
430 update(controlValues, uvderivs, _duvWeights, start, end);
431 update(controlValues, vvderivs, _dvvWeights, start, end);
441 void resize(
int nstencils,
int nelems);
444 std::vector<float> _duWeights,
453 template <
class T>
void 455 std::vector<float>
const &valueWeights,
Index start,
Index end)
const {
457 int const * sizes = &_sizes.at(0);
459 float const * weights = &valueWeights.at(0);
462 assert(start<(
Index)_offsets.size());
464 indices += _offsets[start];
465 weights += _offsets[start];
469 if (end<start || end<0) {
470 end = GetNumStencils();
473 int nstencils = end - std::max(0, start);
474 for (
int i=0; i<nstencils; ++i, ++sizes) {
480 for (
int j=0; j<*sizes; ++j, ++indices, ++weights) {
481 values[i].AddWithWeight( controlValues[*indices], *weights );
489 int noffsets = (int)_sizes.size();
490 _offsets.resize(noffsets);
491 for (
int i=0; i<(int)_sizes.size(); ++i ) {
499 _sizes.resize(nstencils);
506 _sizes.reserve(nstencils);
513 std::vector<int>(_sizes).swap(_sizes);
527 assert((! _offsets.empty()) && i<(
int)_offsets.size());
529 Index ofs = _offsets[i];
531 return Stencil( const_cast<int*>(&_sizes[i]),
532 const_cast<Index *>(&
_indices[ofs]),
533 const_cast<float *>(&
_weights[ofs]) );
538 return GetStencil(index);
542 LimitStencilTable::resize(
int nstencils,
int nelems) {
544 _duWeights.resize(nelems);
545 _dvWeights.resize(nelems);
551 assert((! GetOffsets().empty()) && i<(
int)GetOffsets().size());
553 Index ofs = GetOffsets()[i];
555 if (!_duWeights.empty() && !_dvWeights.empty() &&
556 !_duuWeights.empty() && !_duvWeights.empty() && !_dvvWeights.empty()) {
558 const_cast<Index *>(&GetControlIndices()[ofs]),
560 const_cast<float *>(&GetDuWeights()[ofs]),
561 const_cast<float *>(&GetDvWeights()[ofs]),
562 const_cast<float *>(&GetDuuWeights()[ofs]),
563 const_cast<float *>(&GetDuvWeights()[ofs]),
564 const_cast<float *>(&GetDvvWeights()[ofs]) );
565 }
else if (!_duWeights.empty() && !_dvWeights.empty()) {
567 const_cast<Index *>(&GetControlIndices()[ofs]),
569 const_cast<float *>(&GetDuWeights()[ofs]),
570 const_cast<float *>(&GetDvWeights()[ofs]) );
573 const_cast<Index *>(&GetControlIndices()[ofs]),
580 return GetLimitStencil(index);
587 using namespace OPENSUBDIV_VERSION;
591 #endif // OPENSUBDIV3_FAR_STENCILTABLE_H int GetSize() const
Returns the size of the stencil.
std::vector< float > const & GetWeights() const
Returns the stencil interpolation weights.
std::vector< Index > const & GetOffsets() const
Returns the offset to a given stencil (factory may leave empty)
std::vector< float > _weights
A specialized factory for StencilTable.
Stencil(Stencil const &other)
Copy constructor.
Table of subdivision stencils.
LimitStencil operator[](Index index) const
Returns the limit stencil at index i in the table.
void Next()
Advance to the next stencil in the table.
int * GetSizePtr() const
Returns the size of the stencil as a pointer.
A specialized factory for LimitStencilTable.
Table of limit subdivision stencils.
Vertex stencil descriptor.
float const * GetDvWeights() const
Returns the v derivative weights.
std::vector< float > const & GetDuuWeights() const
Returns the 'uu' derivative stencil interpolation weights.
std::vector< float > const & GetDuvWeights() const
Returns the 'uv' derivative stencil interpolation weights.
void Update2ndDerivs(T const *controlValues, T *uuderivs, T *uvderivs, T *vvderivs, int start=-1, int end=-1) const
Updates 2nd derivative values based on the control values.
Factory for constructing a PatchTable from a TopologyRefiner.
float const * GetDvvWeights() const
Returns the vv derivative weights.
Stencil operator[](Index index) const
Returns the stencil at index i in the table.
Stencil GetStencil(Index i) const
Returns a Stencil at index i in the table.
void UpdateDerivs(T const *controlValues, T *uderivs, T *vderivs, int start=-1, int end=-1) const
Updates derivative values based on the control values.
Stencil(int *size, Index *indices, float *weights)
Constructor.
void Next()
Advance to the next stencil in the table.
void update(T const *controlValues, T *values, std::vector< float > const &valueWeights, Index start, Index end) const
LimitStencil GetLimitStencil(Index i) const
Returns a LimitStencil at index i in the table.
float const * GetDuuWeights() const
Returns the uu derivative weights.
Stencil()
Default constructor.
std::vector< float > const & GetDvWeights() const
Returns the 'v' derivative stencil interpolation weights.
std::vector< float > const & GetDvvWeights() const
Returns the 'vv' derivative stencil interpolation weights.
std::vector< int > _sizes
std::vector< float > const & GetDuWeights() const
Returns the 'u' derivative stencil interpolation weights.
Index const * GetVertexIndices() const
Returns the control vertices indices.
float const * GetDuWeights() const
Returns the u derivative weights.
float const * GetDuvWeights() const
Returns the uv derivative weights.
void reserve(int nstencils, int nelems)
std::vector< Index > const & GetControlIndices() const
Returns the indices of the control vertices.
std::vector< Index > _offsets
Limit point stencil descriptor.
std::vector< int > const & GetSizes() const
Returns the number of control vertices of each stencil in the table.
StencilTable(int numControlVerts)
void resize(int nstencils, int nelems)
void UpdateValues(T const *controlValues, T *values, Index start=-1, Index end=-1) const
Updates point values based on the control values.
int GetNumControlVertices() const
Returns the number of control vertices indexed in the table.
LimitStencil(int *size, Index *indices, float *weights, float *duWeights=0, float *dvWeights=0, float *duuWeights=0, float *duvWeights=0, float *dvvWeights=0)
Constructor.
float const * GetWeights() const
Returns the interpolation weights.
int GetNumStencils() const
Returns the number of stencils in the table.