2014-11-01 00:07:45 +00:00
|
|
|
//
|
|
|
|
// Copyright 2013 Pixar
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
|
|
|
//
|
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
|
|
|
//
|
|
|
|
// You may obtain a copy of the Apache License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
|
|
|
//
|
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#ifndef OPENSUBDIV3_FAR_GREGORY_BASIS_H
|
|
|
|
#define OPENSUBDIV3_FAR_GREGORY_BASIS_H
|
2014-11-01 00:07:45 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
#include "../vtr/level.h"
|
2015-09-11 21:26:51 +00:00
|
|
|
#include "../vtr/stackBuffer.h"
|
2015-05-22 20:07:54 +00:00
|
|
|
#include "../far/types.h"
|
|
|
|
#include "../far/stencilTable.h"
|
2015-04-18 00:36:55 +00:00
|
|
|
#include <cstring>
|
2014-11-01 00:07:45 +00:00
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
namespace Far {
|
|
|
|
|
|
|
|
class TopologyRefiner;
|
|
|
|
|
|
|
|
/// \brief Container for gregory basis stencils
|
|
|
|
///
|
2015-04-23 23:58:45 +00:00
|
|
|
/// XXXtakahito: Currently these classes are being used by EndPatch factories.
|
|
|
|
/// These classes will likely go away once we get limit masks
|
|
|
|
/// from SchemeWorker.
|
|
|
|
///
|
2014-11-01 00:07:45 +00:00
|
|
|
class GregoryBasis {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-11-04 19:14:21 +00:00
|
|
|
/// \brief Updates point values based on the control values
|
|
|
|
///
|
|
|
|
/// \note The destination buffers are assumed to have allocated at least
|
|
|
|
/// \c GetNumStencils() elements.
|
|
|
|
///
|
|
|
|
/// @param controlValues Buffer with primvar data for the control vertices
|
|
|
|
///
|
|
|
|
/// @param values Destination buffer for the interpolated primvar
|
|
|
|
/// data
|
|
|
|
///
|
|
|
|
template <class T, class U>
|
|
|
|
void Evaluate(T const & controlValues, U values[20]) const {
|
2014-11-01 00:07:45 +00:00
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
Vtr::Index const * indices = &_indices.at(0);
|
2014-11-01 00:07:45 +00:00
|
|
|
float const * weights = &_weights.at(0);
|
|
|
|
|
|
|
|
for (int i=0; i<20; ++i) {
|
|
|
|
values[i].Clear();
|
|
|
|
for (int j=0; j<_sizes[i]; ++j, ++indices, ++weights) {
|
|
|
|
values[i].AddWithWeight(controlValues[*indices], *weights);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
//
|
|
|
|
// Basis point
|
|
|
|
//
|
|
|
|
// Implements arithmetic operators to manipulate the influence of the
|
|
|
|
// 1-ring control vertices supporting the patch basis
|
|
|
|
//
|
|
|
|
class Point {
|
|
|
|
public:
|
2015-09-15 16:11:41 +00:00
|
|
|
// 40 means up to valence=10 is on stack
|
|
|
|
static const int RESERVED_STENCIL_SIZE = 40;
|
2014-11-01 00:07:45 +00:00
|
|
|
|
2015-09-11 21:26:51 +00:00
|
|
|
Point(int stencilCapacity=RESERVED_STENCIL_SIZE) : _size(0) {
|
|
|
|
_stencils.SetSize(stencilCapacity);
|
2015-05-21 17:59:40 +00:00
|
|
|
}
|
2014-11-01 00:07:45 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
Point(Point const & other) {
|
2015-09-11 21:26:51 +00:00
|
|
|
_stencils.SetSize(other._stencils.GetSize());
|
2015-04-18 00:36:55 +00:00
|
|
|
*this = other;
|
|
|
|
}
|
2014-11-01 00:07:45 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
int GetSize() const {
|
|
|
|
return _size;
|
|
|
|
}
|
2014-11-04 19:14:21 +00:00
|
|
|
|
2015-09-11 21:26:51 +00:00
|
|
|
int GetCapacity() const {
|
|
|
|
return _stencils.GetSize();
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
2014-11-01 00:07:45 +00:00
|
|
|
|
2015-09-11 21:26:51 +00:00
|
|
|
void Clear(int capacity) {
|
|
|
|
_size = 0;
|
|
|
|
if ((int)_stencils.GetSize() < capacity) {
|
|
|
|
_stencils.SetSize(capacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddWithWeight(Vtr::Index idx, float weight) {
|
2015-09-15 16:11:41 +00:00
|
|
|
for (int i = 0; i < _size; ++i) {
|
|
|
|
if (_stencils[i].index == idx) {
|
|
|
|
_stencils[i].weight += weight;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(_size < (int)_stencils.GetSize());
|
|
|
|
_stencils[_size].index = idx;
|
|
|
|
_stencils[_size].weight = weight;
|
|
|
|
++_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddWithWeight(Point const &src, float weight) {
|
|
|
|
for (int i = 0; i < src._size; ++i) {
|
|
|
|
AddWithWeight(src._stencils[i].index,
|
|
|
|
src._stencils[i].weight * weight);
|
|
|
|
}
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
2014-11-04 19:14:21 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
Point & operator = (Point const & other) {
|
2015-09-11 21:26:51 +00:00
|
|
|
Clear(other.GetCapacity());
|
2015-04-18 00:36:55 +00:00
|
|
|
_size = other._size;
|
2015-09-11 21:26:51 +00:00
|
|
|
assert(_size <= (int)_stencils.GetSize());
|
|
|
|
for (int i = 0; i < _size; ++i) {
|
|
|
|
_stencils[i] = other._stencils[i];
|
|
|
|
}
|
2015-04-18 00:36:55 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2014-11-04 19:14:21 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
Point & operator *= (float f) {
|
|
|
|
for (int i=0; i<_size; ++i) {
|
2015-09-11 21:26:51 +00:00
|
|
|
_stencils[i].weight *= f;
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
void OffsetIndices(Vtr::Index offset) {
|
2015-04-18 00:36:55 +00:00
|
|
|
for (int i=0; i<_size; ++i) {
|
2015-09-11 21:26:51 +00:00
|
|
|
_stencils[i].index += offset;
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
void Copy(int ** size, Vtr::Index ** indices, float ** weights) const {
|
2015-09-11 21:26:51 +00:00
|
|
|
for (int i = 0; i < _size; ++i) {
|
|
|
|
**indices = _stencils[i].index;
|
|
|
|
**weights = _stencils[i].weight;
|
|
|
|
++(*indices);
|
|
|
|
++(*weights);
|
|
|
|
}
|
2015-04-18 00:36:55 +00:00
|
|
|
**size = _size;
|
|
|
|
++(*size);
|
|
|
|
}
|
|
|
|
|
2015-10-08 01:53:02 +00:00
|
|
|
Vtr::Index GetStencilIndex(int index) const {
|
|
|
|
return _stencils[index].index;
|
|
|
|
}
|
|
|
|
float GetStencilWeight(int index) const {
|
|
|
|
return _stencils[index].weight;
|
|
|
|
}
|
2015-04-18 00:36:55 +00:00
|
|
|
|
2015-10-08 01:53:02 +00:00
|
|
|
private:
|
2015-04-18 00:36:55 +00:00
|
|
|
int _size;
|
2015-09-11 21:26:51 +00:00
|
|
|
|
|
|
|
struct Stencil {
|
|
|
|
Vtr::Index index;
|
|
|
|
float weight;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vtr::internal::StackBuffer<Stencil, RESERVED_STENCIL_SIZE> _stencils;
|
2015-04-18 00:36:55 +00:00
|
|
|
};
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2014-11-04 19:14:21 +00:00
|
|
|
//
|
2015-04-18 00:36:55 +00:00
|
|
|
// ProtoBasis
|
2014-11-04 19:14:21 +00:00
|
|
|
//
|
2015-05-20 20:24:48 +00:00
|
|
|
// Given a Vtr::Level and a face index, gathers all the influences of the
|
|
|
|
// 1-ring that supports the 20 CVs of a Gregory patch basis.
|
2015-04-18 00:36:55 +00:00
|
|
|
//
|
|
|
|
struct ProtoBasis {
|
|
|
|
|
2015-05-29 19:41:11 +00:00
|
|
|
ProtoBasis(Vtr::internal::Level const & level,
|
|
|
|
Vtr::Index faceIndex,
|
2016-07-13 17:02:01 +00:00
|
|
|
Vtr::internal::Level::VSpan const cornerSpans[],
|
2015-05-29 19:41:11 +00:00
|
|
|
int levelVertOffset,
|
|
|
|
int fvarChannel);
|
2015-04-18 00:36:55 +00:00
|
|
|
|
|
|
|
int GetNumElements() const;
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
void Copy(int * sizes, Vtr::Index * indices, float * weights) const;
|
2015-05-20 20:24:48 +00:00
|
|
|
void Copy(GregoryBasis* dest) const;
|
2015-04-18 00:36:55 +00:00
|
|
|
|
|
|
|
// Control Vertices based on :
|
2015-05-20 20:24:48 +00:00
|
|
|
// "Approximating Subdivision Surfaces with Gregory Patches for Hardware
|
2015-05-21 00:39:06 +00:00
|
|
|
// Tessellation" Loop, Schaefer, Ni, Castano (ACM ToG Siggraph Asia
|
2015-05-20 20:24:48 +00:00
|
|
|
// 2009)
|
2015-04-18 00:36:55 +00:00
|
|
|
//
|
|
|
|
// P3 e3- e2+ P2
|
|
|
|
// O--------O--------O--------O
|
|
|
|
// | | | |
|
|
|
|
// | | | |
|
|
|
|
// | | f3- | f2+ |
|
|
|
|
// | O O |
|
|
|
|
// e3+ O------O O------O e2-
|
|
|
|
// | f3+ f2- |
|
|
|
|
// | |
|
|
|
|
// | |
|
|
|
|
// | f0- f1+ |
|
|
|
|
// e0- O------O O------O e1+
|
|
|
|
// | O O |
|
|
|
|
// | | f0+ | f1- |
|
|
|
|
// | | | |
|
|
|
|
// | | | |
|
|
|
|
// O--------O--------O--------O
|
|
|
|
// P0 e0+ e1- P1
|
|
|
|
//
|
|
|
|
|
|
|
|
Point P[4], Ep[4], Em[4], Fp[4], Fm[4];
|
|
|
|
|
|
|
|
// for varying interpolation
|
2015-10-08 01:53:02 +00:00
|
|
|
Vtr::Index varyingIndex[4];
|
2015-04-18 00:36:55 +00:00
|
|
|
};
|
2014-11-04 19:14:21 +00:00
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
typedef std::vector<GregoryBasis::Point> PointsVector;
|
|
|
|
|
2015-10-08 01:53:02 +00:00
|
|
|
// for basis point stencil
|
|
|
|
static void AppendToStencilTable(GregoryBasis::Point const &p,
|
|
|
|
StencilTable *table) {
|
|
|
|
int size = p.GetSize();
|
|
|
|
table->_sizes.push_back(size);
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
table->_indices.push_back(p.GetStencilIndex(i));
|
|
|
|
table->_weights.push_back(p.GetStencilWeight(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// for varying stencil (just copy)
|
|
|
|
static void AppendToStencilTable(int index, StencilTable *table) {
|
|
|
|
table->_sizes.push_back(1);
|
|
|
|
table->_indices.push_back(index);
|
|
|
|
table->_weights.push_back(1.f);
|
|
|
|
}
|
2015-04-23 23:58:45 +00:00
|
|
|
|
2014-11-04 19:14:21 +00:00
|
|
|
private:
|
2014-11-01 00:07:45 +00:00
|
|
|
|
2015-05-20 20:24:48 +00:00
|
|
|
int _sizes[20];
|
2014-11-11 19:27:25 +00:00
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
std::vector<Vtr::Index> _indices;
|
2015-04-18 00:36:55 +00:00
|
|
|
std::vector<float> _weights;
|
2014-11-01 00:07:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Far
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#endif /* OPENSUBDIV3_FAR_GREGORY_BASIS_H */
|