2014-09-19 00:48:34 +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-22 18:50:01 +00:00
|
|
|
#include "../far/patchTable.h"
|
2015-05-20 22:44:29 +00:00
|
|
|
#include "../far/patchBasis.h"
|
2014-09-19 00:48:34 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
2015-02-26 21:57:47 +00:00
|
|
|
#include <cstdio>
|
2014-09-19 00:48:34 +00:00
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
namespace Far {
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::PatchTable(int maxvalence) :
|
2015-04-23 23:58:45 +00:00
|
|
|
_maxValence(maxvalence),
|
2015-05-22 18:50:01 +00:00
|
|
|
_vertexStencilTable(NULL),
|
|
|
|
_varyingStencilTable(NULL) {
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
2014-11-25 20:41:19 +00:00
|
|
|
|
|
|
|
// Copy constructor
|
|
|
|
// XXXX manuelk we need to eliminate this constructor (C++11 smart pointers)
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::PatchTable(PatchTable const & src) :
|
2014-11-25 20:41:19 +00:00
|
|
|
_maxValence(src._maxValence),
|
|
|
|
_numPtexFaces(src._numPtexFaces),
|
|
|
|
_patchArrays(src._patchArrays),
|
|
|
|
_patchVerts(src._patchVerts),
|
|
|
|
_paramTable(src._paramTable),
|
|
|
|
_quadOffsetsTable(src._quadOffsetsTable),
|
|
|
|
_vertexValenceTable(src._vertexValenceTable),
|
2015-05-22 18:50:01 +00:00
|
|
|
_vertexStencilTable(NULL),
|
|
|
|
_varyingStencilTable(NULL),
|
2015-02-26 21:57:47 +00:00
|
|
|
_fvarChannels(src._fvarChannels),
|
2014-11-25 20:41:19 +00:00
|
|
|
_sharpnessIndices(src._sharpnessIndices),
|
|
|
|
_sharpnessValues(src._sharpnessValues) {
|
2015-04-23 23:58:45 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
if (src._vertexStencilTable) {
|
|
|
|
_vertexStencilTable = new StencilTable(*src._vertexStencilTable);
|
2015-04-23 23:58:45 +00:00
|
|
|
}
|
2015-05-22 18:50:01 +00:00
|
|
|
if (src._varyingStencilTable) {
|
|
|
|
_varyingStencilTable = new StencilTable(*src._varyingStencilTable);
|
2015-04-23 23:58:45 +00:00
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::~PatchTable() {
|
|
|
|
delete _vertexStencilTable;
|
|
|
|
delete _varyingStencilTable;
|
2014-11-11 19:27:25 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
//
|
2014-11-25 20:41:19 +00:00
|
|
|
// PatchArrays
|
2014-10-09 21:48:50 +00:00
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
struct PatchTable::PatchArray {
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray(PatchDescriptor d, int np, Index v, Index p, Index qo) :
|
|
|
|
desc(d), numPatches(np), vertIndex(v),
|
|
|
|
patchIndex(p), quadOffsetIndex (qo) { }
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
void print() const;
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchDescriptor desc; // type of patches in the array
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
int numPatches; // number of patches in the array
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
Index vertIndex, // index to the first control vertex
|
|
|
|
patchIndex, // index of the first patch in the array
|
|
|
|
quadOffsetIndex; // index of the first quad offset entry
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
};
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
// debug helper
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::PatchArray::print() const {
|
2015-02-26 21:57:47 +00:00
|
|
|
desc.print();
|
|
|
|
printf(" numPatches=%d vertIndex=%d patchIndex=%d "
|
|
|
|
"quadOffsetIndex=%d\n", numPatches, vertIndex, patchIndex,
|
|
|
|
quadOffsetIndex);
|
|
|
|
}
|
2015-05-22 18:50:01 +00:00
|
|
|
inline PatchTable::PatchArray &
|
|
|
|
PatchTable::getPatchArray(Index arrayIndex) {
|
2014-11-25 20:41:19 +00:00
|
|
|
assert(arrayIndex<(Index)GetNumPatchArrays());
|
|
|
|
return _patchArrays[arrayIndex];
|
|
|
|
}
|
2015-05-22 18:50:01 +00:00
|
|
|
inline PatchTable::PatchArray const &
|
|
|
|
PatchTable::getPatchArray(Index arrayIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
assert(arrayIndex<(Index)GetNumPatchArrays());
|
|
|
|
return _patchArrays[arrayIndex];
|
2014-10-09 21:48:50 +00:00
|
|
|
}
|
2014-11-25 20:41:19 +00:00
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::reservePatchArrays(int numPatchArrays) {
|
2014-11-25 20:41:19 +00:00
|
|
|
_patchArrays.reserve(numPatchArrays);
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
//
|
|
|
|
// FVarPatchChannel
|
|
|
|
//
|
|
|
|
// Stores a record for each patch in the primitive :
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
// - Each patch in the PatchTable has a corresponding patch in each
|
2015-02-26 21:57:47 +00:00
|
|
|
// face-varying patch channel. Patch vertex indices are sorted in the same
|
2015-05-22 18:50:01 +00:00
|
|
|
// patch-type order as PatchTable::PTables. Face-varying data for a patch
|
2015-02-26 21:57:47 +00:00
|
|
|
// can therefore be quickly accessed by using the patch primitive ID as
|
|
|
|
// index into patchValueOffsets to locate the face-varying control vertex
|
|
|
|
// indices.
|
|
|
|
//
|
|
|
|
// - Face-varying channels can have a different interpolation modes
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
// - Unlike "vertex" PatchTable, there are no "transition" patterns required
|
2015-02-26 21:57:47 +00:00
|
|
|
// for face-varying patches.
|
|
|
|
//
|
|
|
|
// - No transition patterns means vertex indices of face-varying patches can
|
|
|
|
// be pre-rotated in the factory, so we do not store patch rotation
|
|
|
|
//
|
|
|
|
// - Face-varying patches still special variants for boundary and corner cases
|
|
|
|
//
|
|
|
|
// - currently most patches with sharp boundaries but smooth interiors have
|
|
|
|
// to be isolated to level 10 : we need a special type of bicubic patch
|
|
|
|
// similar to single-crease to resolve this condition without requiring
|
|
|
|
// isolation if possible
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
struct PatchTable::FVarPatchChannel {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
// Channel interpolation mode
|
|
|
|
Sdc::Options::FVarLinearInterpolation interpolation;
|
|
|
|
|
|
|
|
// Patch type
|
|
|
|
//
|
|
|
|
// Note : in bilinear interpolation modes, all patches are of the same type,
|
|
|
|
// so we only need a single type (patchesType). In bi-cubic modes, each
|
|
|
|
// patch requires its own type (patchTypes).
|
|
|
|
PatchDescriptor::Type patchesType;
|
|
|
|
std::vector<PatchDescriptor::Type> patchTypes;
|
|
|
|
|
|
|
|
// Patch points values
|
|
|
|
std::vector<Index> patchValuesOffsets; // offset to the first value of each patch
|
|
|
|
std::vector<Index> patchValues; // point values for each patch
|
|
|
|
};
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
inline PatchTable::FVarPatchChannel &
|
|
|
|
PatchTable::getFVarPatchChannel(int channel) {
|
2015-02-26 21:57:47 +00:00
|
|
|
assert(channel<(int)_fvarChannels.size());
|
|
|
|
return _fvarChannels[channel];
|
|
|
|
}
|
2015-05-22 18:50:01 +00:00
|
|
|
inline PatchTable::FVarPatchChannel const &
|
|
|
|
PatchTable::getFVarPatchChannel(int channel) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
assert(channel<(int)_fvarChannels.size());
|
|
|
|
return _fvarChannels[channel];
|
|
|
|
}
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::allocateFVarPatchChannels(int numChannels) {
|
2015-02-26 21:57:47 +00:00
|
|
|
_fvarChannels.resize(numChannels);
|
|
|
|
}
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::allocateChannelValues(int channel,
|
2015-02-26 21:57:47 +00:00
|
|
|
int numPatches, int numVerticesTotal) {
|
|
|
|
|
|
|
|
FVarPatchChannel & c = getFVarPatchChannel(channel);
|
|
|
|
if (c.interpolation==Sdc::Options::FVAR_LINEAR_ALL) {
|
|
|
|
// Allocate bi-linear channels (allows uniform topology to be populated
|
|
|
|
// in a single traversal)
|
|
|
|
c.patchValues.resize(numVerticesTotal);
|
|
|
|
} else {
|
|
|
|
// Allocate per-patch type and offset vectors for bi-cubic patches
|
|
|
|
//
|
|
|
|
// Note : c.patchValues cannot be allocated pre-emptively since we do
|
|
|
|
// not know the type (and size) of each patch yet. These channels
|
|
|
|
// require an extra step to compact the value indices and generate
|
|
|
|
// offsets
|
|
|
|
c.patchesType = PatchDescriptor::NON_PATCH;
|
|
|
|
c.patchTypes.resize(numPatches);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::setFVarPatchChannelLinearInterpolation(int channel,
|
2015-02-26 21:57:47 +00:00
|
|
|
Sdc::Options::FVarLinearInterpolation interpolation) {
|
|
|
|
FVarPatchChannel & c = getFVarPatchChannel(channel);
|
|
|
|
c.interpolation = interpolation;
|
|
|
|
}
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::setFVarPatchChannelPatchesType(int channel, PatchDescriptor::Type type) {
|
2015-02-26 21:57:47 +00:00
|
|
|
FVarPatchChannel & c = getFVarPatchChannel(channel);
|
|
|
|
c.patchesType = type;
|
|
|
|
}
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::setBicubicFVarPatchChannelValues(int channel, int patchSize,
|
2015-02-26 21:57:47 +00:00
|
|
|
std::vector<Index> const & values) {
|
|
|
|
|
|
|
|
// This method populates the sparse array of values held in the patch
|
2015-05-22 18:50:01 +00:00
|
|
|
// table from a non-sparse array of value indices generated during
|
2015-02-26 21:57:47 +00:00
|
|
|
// the second traversal of an adaptive TopologyRefiner.
|
|
|
|
// It is assumed that the patch types have been stored in the channel's
|
|
|
|
// 'patchTypes' vector during the first traversal.
|
|
|
|
|
|
|
|
FVarPatchChannel & c = getFVarPatchChannel(channel);
|
|
|
|
assert(c.interpolation!=Sdc::Options::FVAR_LINEAR_ALL and
|
|
|
|
c.patchTypes.size()*patchSize==values.size());
|
|
|
|
|
|
|
|
int npatches = (int)c.patchTypes.size(),
|
|
|
|
nverts = 0;
|
|
|
|
|
|
|
|
// Generate offsets and count vertices
|
|
|
|
c.patchValuesOffsets.resize(npatches);
|
|
|
|
for (int patch=0; patch<npatches; ++patch) {
|
|
|
|
int nv = PatchDescriptor::GetNumFVarControlVertices(c.patchTypes[patch]);
|
|
|
|
c.patchValuesOffsets[patch] = nverts;
|
|
|
|
nverts += nv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate values
|
|
|
|
Index const * srcValues = &values[0];
|
|
|
|
|
|
|
|
c.patchValues.resize(nverts);
|
|
|
|
Index * dstValues = &c.patchValues[0];
|
|
|
|
|
|
|
|
for (int patch=0; patch<npatches; ++patch) {
|
|
|
|
|
|
|
|
int nv = PatchDescriptor::GetNumFVarControlVertices(c.patchTypes[patch]);
|
|
|
|
|
|
|
|
memcpy(dstValues, srcValues, nv * sizeof(Index));
|
|
|
|
|
|
|
|
srcValues += patchSize;
|
|
|
|
dstValues += nv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
// PatchTable
|
2015-02-26 21:57:47 +00:00
|
|
|
//
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
inline int
|
|
|
|
getPatchSize(PatchDescriptor desc) {
|
2015-04-08 01:34:05 +00:00
|
|
|
return desc.GetNumControlVertices();
|
2014-10-09 21:48:50 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::pushPatchArray(PatchDescriptor desc, int npatches,
|
2014-11-25 20:41:19 +00:00
|
|
|
Index * vidx, Index * pidx, Index * qoidx) {
|
|
|
|
|
|
|
|
if (npatches>0) {
|
|
|
|
_patchArrays.push_back(PatchArray(
|
|
|
|
desc, npatches, *vidx, *pidx, qoidx ? *qoidx : 0));
|
|
|
|
int nverts = getPatchSize(desc);
|
|
|
|
*vidx += npatches * nverts;
|
|
|
|
*pidx += npatches;
|
|
|
|
if (qoidx) {
|
|
|
|
*qoidx += (desc.GetType() == PatchDescriptor::GREGORY) ?
|
|
|
|
npatches*nverts : 0;
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
int
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getPatchIndex(int arrayIndex, int patchIndex) const {
|
2015-01-28 23:50:23 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
|
|
|
assert(patchIndex<pa.numPatches);
|
|
|
|
return pa.patchIndex + patchIndex;
|
|
|
|
}
|
2014-11-25 20:41:19 +00:00
|
|
|
Index *
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getSharpnessIndices(int arrayIndex) {
|
2014-11-25 20:41:19 +00:00
|
|
|
return &_sharpnessIndices[getPatchArray(arrayIndex).patchIndex];
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
float *
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getSharpnessValues(int arrayIndex) {
|
2014-11-25 20:41:19 +00:00
|
|
|
return &_sharpnessValues[getPatchArray(arrayIndex).patchIndex];
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchDescriptor
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetPatchDescriptor(PatchHandle const & handle) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
return getPatchArray(handle.arrayIndex).desc;
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchDescriptor
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetPatchArrayDescriptor(int arrayIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
return getPatchArray(arrayIndex).desc;
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
int
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetNumPatchArrays() const {
|
2014-11-25 20:41:19 +00:00
|
|
|
return (int)_patchArrays.size();
|
|
|
|
}
|
|
|
|
int
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetNumPatches(int arrayIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
return getPatchArray(arrayIndex).numPatches;
|
|
|
|
}
|
|
|
|
int
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetNumPatchesTotal() const {
|
2015-02-26 21:57:47 +00:00
|
|
|
// there is one PatchParam record for each patch in the mesh
|
|
|
|
return (int)_paramTable.size();
|
|
|
|
}
|
|
|
|
int
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetNumControlVertices(int arrayIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
|
|
|
return pa.numPatches * getPatchSize(pa.desc);
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
Index
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::findPatchArray(PatchDescriptor desc) {
|
2015-02-26 21:57:47 +00:00
|
|
|
for (int i=0; i<(int)_patchArrays.size(); ++i) {
|
|
|
|
if (_patchArrays[i].desc==desc)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return Vtr::INDEX_INVALID;
|
|
|
|
}
|
2014-11-25 20:41:19 +00:00
|
|
|
IndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getPatchArrayVertices(int arrayIndex) {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
|
|
|
int size = getPatchSize(pa.desc);
|
|
|
|
assert(pa.vertIndex<(Index)_patchVerts.size());
|
|
|
|
return IndexArray(&_patchVerts[pa.vertIndex], pa.numPatches * size);
|
|
|
|
}
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetPatchArrayVertices(int arrayIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
|
|
|
int size = getPatchSize(pa.desc);
|
|
|
|
assert(pa.vertIndex<(Index)_patchVerts.size());
|
2014-12-15 18:23:13 +00:00
|
|
|
return ConstIndexArray(&_patchVerts[pa.vertIndex], pa.numPatches * size);
|
2014-11-25 20:41:19 +00:00
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetPatchVertices(PatchHandle const & handle) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(handle.arrayIndex);
|
2015-04-08 01:34:05 +00:00
|
|
|
Index vert = pa.vertIndex + handle.vertIndex;
|
2014-12-15 18:23:13 +00:00
|
|
|
return ConstIndexArray(&_patchVerts[vert], getPatchSize(pa.desc));
|
2014-11-25 20:41:19 +00:00
|
|
|
}
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetPatchVertices(int arrayIndex, int patchIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
|
|
|
int size = getPatchSize(pa.desc);
|
|
|
|
assert((pa.vertIndex + patchIndex*size)<(Index)_patchVerts.size());
|
2014-12-15 18:23:13 +00:00
|
|
|
return ConstIndexArray(&_patchVerts[pa.vertIndex + patchIndex*size], size);
|
2014-11-25 20:41:19 +00:00
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchParam
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetPatchParam(PatchHandle const & handle) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
assert(handle.patchIndex < (Index)_paramTable.size());
|
|
|
|
return _paramTable[handle.patchIndex];
|
|
|
|
}
|
|
|
|
PatchParam
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetPatchParam(int arrayIndex, int patchIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
|
|
|
assert((pa.patchIndex + patchIndex) < (int)_paramTable.size());
|
|
|
|
return _paramTable[pa.patchIndex + patchIndex];
|
|
|
|
}
|
|
|
|
PatchParamArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getPatchParams(int arrayIndex) {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
|
|
|
return PatchParamArray(&_paramTable[pa.patchIndex], pa.numPatches);
|
|
|
|
}
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstPatchParamArray const
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetPatchParams(int arrayIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
2014-12-15 18:23:13 +00:00
|
|
|
return ConstPatchParamArray(&_paramTable[pa.patchIndex], pa.numPatches);
|
2014-11-25 20:41:19 +00:00
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
float
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetSingleCreasePatchSharpnessValue(PatchHandle const & handle) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
assert((handle.patchIndex) < (int)_sharpnessIndices.size());
|
|
|
|
Index index = _sharpnessIndices[handle.patchIndex];
|
|
|
|
if (index == Vtr::INDEX_INVALID) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
assert(index < (Index)_sharpnessValues.size());
|
|
|
|
return _sharpnessValues[index];
|
|
|
|
}
|
|
|
|
float
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetSingleCreasePatchSharpnessValue(int arrayIndex, int patchIndex) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(arrayIndex);
|
|
|
|
assert((pa.patchIndex + patchIndex) < (int)_sharpnessIndices.size());
|
|
|
|
Index index = _sharpnessIndices[pa.patchIndex + patchIndex];
|
|
|
|
if (index == Vtr::INDEX_INVALID) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
assert(index < (Index)_sharpnessValues.size());
|
|
|
|
return _sharpnessValues[index];
|
|
|
|
}
|
2014-10-13 15:52:09 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::ConstQuadOffsetsArray
|
|
|
|
PatchTable::GetPatchQuadOffsets(PatchHandle const & handle) const {
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchArray const & pa = getPatchArray(handle.arrayIndex);
|
2014-12-15 18:23:13 +00:00
|
|
|
return Vtr::ConstArray<unsigned int>(&_quadOffsetsTable[pa.quadOffsetIndex + handle.vertIndex], 4);
|
2014-11-25 20:41:19 +00:00
|
|
|
}
|
|
|
|
bool
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::IsFeatureAdaptive() const {
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
// XXX:
|
|
|
|
// revisit this function, since we'll add uniform cubic patches later.
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
for (int i=0; i<GetNumPatchArrays(); ++i) {
|
|
|
|
PatchDescriptor const & desc = _patchArrays[i].desc;
|
|
|
|
if (desc.GetType()>=PatchDescriptor::REGULAR and
|
|
|
|
desc.GetType()<=PatchDescriptor::GREGORY_BASIS) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
}
|
2014-11-25 20:41:19 +00:00
|
|
|
return false;
|
2014-10-09 21:48:50 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
int
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetNumFVarChannels() const {
|
2015-02-26 21:57:47 +00:00
|
|
|
return (int)_fvarChannels.size();
|
|
|
|
}
|
|
|
|
Sdc::Options::FVarLinearInterpolation
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetFVarChannelLinearInterpolation(int channel) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
FVarPatchChannel const & c = getFVarPatchChannel(channel);
|
|
|
|
return c.interpolation;
|
|
|
|
}
|
|
|
|
Vtr::Array<PatchDescriptor::Type>
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getFVarPatchTypes(int channel) {
|
2015-02-26 21:57:47 +00:00
|
|
|
FVarPatchChannel & c = getFVarPatchChannel(channel);
|
|
|
|
return Vtr::Array<PatchDescriptor::Type>(&c.patchTypes[0],
|
2015-02-27 23:52:12 +00:00
|
|
|
(int)c.patchTypes.size());
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
Vtr::ConstArray<PatchDescriptor::Type>
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetFVarPatchTypes(int channel) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
FVarPatchChannel const & c = getFVarPatchChannel(channel);
|
|
|
|
if (c.patchesType!=PatchDescriptor::NON_PATCH) {
|
|
|
|
return Vtr::ConstArray<PatchDescriptor::Type>(&c.patchesType, 1);
|
|
|
|
} else {
|
|
|
|
return Vtr::ConstArray<PatchDescriptor::Type>(&c.patchTypes[0],
|
2015-02-27 23:52:12 +00:00
|
|
|
(int)c.patchTypes.size());
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ConstIndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetFVarPatchesValues(int channel) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
FVarPatchChannel const & c = getFVarPatchChannel(channel);
|
2015-02-27 23:52:12 +00:00
|
|
|
return ConstIndexArray(&c.patchValues[0], (int)c.patchValues.size());
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
IndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getFVarPatchesValues(int channel) {
|
2015-02-26 21:57:47 +00:00
|
|
|
FVarPatchChannel & c = getFVarPatchChannel(channel);
|
2015-02-27 23:52:12 +00:00
|
|
|
return IndexArray(&c.patchValues[0], (int)c.patchValues.size());
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
PatchDescriptor::Type
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getFVarPatchType(int channel, int patch) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
FVarPatchChannel const & c = getFVarPatchChannel(channel);
|
|
|
|
PatchDescriptor::Type type;
|
|
|
|
if (c.patchesType!=PatchDescriptor::NON_PATCH) {
|
|
|
|
assert(c.patchTypes.empty());
|
|
|
|
type = c.patchesType;
|
|
|
|
} else {
|
|
|
|
assert(patch<(int)c.patchTypes.size());
|
|
|
|
type = c.patchTypes[patch];
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
PatchDescriptor::Type
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetFVarPatchType(int channel, PatchHandle const & handle) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
return getFVarPatchType(channel, handle.patchIndex);
|
|
|
|
}
|
|
|
|
PatchDescriptor::Type
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetFVarPatchType(int channel, int arrayIndex, int patchIndex) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
return getFVarPatchType(channel, getPatchIndex(arrayIndex, patchIndex));
|
|
|
|
}
|
|
|
|
ConstIndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::getFVarPatchValues(int channel, int patch) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
FVarPatchChannel const & c = getFVarPatchChannel(channel);
|
|
|
|
|
|
|
|
if (c.patchValuesOffsets.empty()) {
|
|
|
|
int ncvs = PatchDescriptor::GetNumFVarControlVertices(c.patchesType);
|
|
|
|
return ConstIndexArray(&c.patchValues[patch * ncvs], ncvs);
|
|
|
|
} else {
|
|
|
|
assert(patch<(int)c.patchValuesOffsets.size() and
|
|
|
|
patch<(int)c.patchTypes.size());
|
|
|
|
return ConstIndexArray(&c.patchValues[c.patchValuesOffsets[patch]],
|
|
|
|
PatchDescriptor::GetNumFVarControlVertices(c.patchTypes[patch]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConstIndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetFVarPatchValues(int channel, PatchHandle const & handle) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
return getFVarPatchValues(channel, handle.patchIndex);
|
|
|
|
}
|
|
|
|
ConstIndexArray
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::GetFVarPatchValues(int channel, int arrayIndex, int patchIndex) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
return getFVarPatchValues(channel, getPatchIndex(arrayIndex, patchIndex));
|
2014-11-25 20:41:19 +00:00
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::print() const {
|
|
|
|
printf("patchTable (0x%p)\n", this);
|
2015-02-26 21:57:47 +00:00
|
|
|
printf(" numPatches = %d\n", GetNumPatchesTotal());
|
|
|
|
for (int i=0; i<GetNumPatchArrays(); ++i) {
|
|
|
|
printf(" patchArray %d:\n", i);
|
|
|
|
PatchArray const & pa = getPatchArray(i);
|
|
|
|
pa.print();
|
2014-10-09 21:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:44:29 +00:00
|
|
|
//
|
|
|
|
// Evaluate basis functions for position and first derivatives at (s,t):
|
|
|
|
//
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable::EvaluateBasis(PatchHandle const & handle, float s, float t,
|
2015-05-20 22:44:29 +00:00
|
|
|
float wP[], float wDs[], float wDt[]) const {
|
|
|
|
|
|
|
|
PatchDescriptor::Type patchType = GetPatchArrayDescriptor(handle.arrayIndex).GetType();
|
|
|
|
PatchParam::BitField const & patchBits = _paramTable[handle.patchIndex].bitField;
|
|
|
|
|
|
|
|
if (patchType == PatchDescriptor::REGULAR) {
|
|
|
|
internal::GetBSplineWeights(patchBits, s, t, wP, wDs, wDt);
|
|
|
|
} else if (patchType == PatchDescriptor::GREGORY_BASIS) {
|
|
|
|
internal::GetGregoryWeights(patchBits, s, t, wP, wDs, wDt);
|
|
|
|
} else if (patchType == PatchDescriptor::QUADS) {
|
|
|
|
internal::GetBilinearWeights(patchBits, s, t, wP, wDs, wDt);
|
|
|
|
} else {
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-19 00:48:34 +00:00
|
|
|
} // end namespace Far
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|