Internal refactoring to support multiple precision:

- overloaded PatchBuilder to populate SparseMatrix as float or double
    - simplified PatchTableBuilder handling of matrices and Varying stencils
This commit is contained in:
barry 2018-07-23 11:00:35 -07:00
parent aa7eba45bc
commit f15d4ae02f
9 changed files with 165 additions and 83 deletions

View File

@ -73,10 +73,11 @@ BilinearPatchBuilder::patchTypeFromBasis(BasisType basis) const {
return patchTypeFromBasisArray[(int)basis];
}
template <typename REAL>
int
BilinearPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
BilinearPatchBuilder::convertSourcePatch(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const {
SparseMatrix<REAL> & matrix) const {
assert("Conversion from Bilinear patches to other bases not yet supported" == 0);
@ -87,6 +88,19 @@ BilinearPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
return -1;
}
int
BilinearPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const {
return convertSourcePatch(sourcePatch, patchType, matrix);
}
int
BilinearPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<double> & matrix) const {
return convertSourcePatch(sourcePatch, patchType, matrix);
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION

View File

@ -53,6 +53,14 @@ protected:
virtual int convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const;
virtual int convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<double> & matrix) const;
private:
template <typename REAL>
int convertSourcePatch(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<REAL> & matrix) const;
};
} // end namespace Far

View File

@ -1898,10 +1898,11 @@ namespace {
};
}
template <typename REAL>
int
CatmarkPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
CatmarkPatchBuilder::convertSourcePatch(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const {
SparseMatrix<REAL> & matrix) const {
assert(_schemeType == Sdc::SCHEME_CATMARK);
@ -1912,17 +1913,30 @@ CatmarkPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
//
if (patchType == PatchDescriptor::GREGORY_BASIS) {
GregoryConverter<float>(sourcePatch, matrix);
GregoryConverter<REAL>(sourcePatch, matrix);
} else if (patchType == PatchDescriptor::REGULAR) {
BSplineConverter<float>(sourcePatch, matrix);
BSplineConverter<REAL>(sourcePatch, matrix);
} else if (patchType == PatchDescriptor::QUADS) {
LinearConverter<float>(sourcePatch, matrix);
LinearConverter<REAL>(sourcePatch, matrix);
} else {
assert("Unknown or unsupported patch type" == 0);
}
return matrix.GetNumRows();
}
int
CatmarkPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const {
return convertSourcePatch(sourcePatch, patchType, matrix);
}
int
CatmarkPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<double> & matrix) const {
return convertSourcePatch(sourcePatch, patchType, matrix);
}
CatmarkPatchBuilder::CatmarkPatchBuilder(
TopologyRefiner const& refiner, Options const& options) :
PatchBuilder(refiner, options) {

View File

@ -53,9 +53,17 @@ protected:
virtual int convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const;
virtual int convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<double> & matrix) const;
private:
typedef SparseMatrix<float> ConversionMatrix;
template <typename REAL>
int convertSourcePatch(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<REAL> & matrix) const;
};
} // end namespace Far

View File

@ -72,10 +72,11 @@ LoopPatchBuilder::patchTypeFromBasis(BasisType basis) const {
return patchTypeFromBasisArray[(int)basis];
}
template <typename REAL>
int
LoopPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const {
LoopPatchBuilder::convertSourcePatch(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<REAL> & matrix) const {
assert("Non-linear patches for Loop not yet supported" == 0);
@ -86,6 +87,20 @@ LoopPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
return -1;
}
int
LoopPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const {
return convertSourcePatch(sourcePatch, patchType, matrix);
}
int
LoopPatchBuilder::convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<double> & matrix) const {
return convertSourcePatch(sourcePatch, patchType, matrix);
}
} // end namespace Far
} // end namespace OPENSUBDIV_VERSION

View File

@ -53,6 +53,14 @@ protected:
virtual int convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const;
virtual int convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<double> & matrix) const;
private:
template <typename REAL>
int convertSourcePatch(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<REAL> & matrix) const;
};
} // end namespace Far

View File

@ -798,11 +798,16 @@ PatchBuilder::GetIrregularPatchSourcePoints(
cornerSpans, sourcePatch, sourcePoints, fvarChannel);
}
//
// Template conversion methods for the matrix type -- explicit instantiation
// for float and double is required and follows the definition:
//
template <typename REAL>
int
PatchBuilder::GetIrregularPatchConversionMatrix(
int levelIndex, Index faceIndex,
Level::VSpan const cornerSpans[],
SparseMatrix<float> & conversionMatrix) const {
SparseMatrix<REAL> & conversionMatrix) const {
assertTriangularPatchesNotYetSupportedHere();
@ -813,6 +818,12 @@ PatchBuilder::GetIrregularPatchConversionMatrix(
return convertToPatchType(
sourcePatch, GetIrregularPatchType(), conversionMatrix);
}
template int PatchBuilder::GetIrregularPatchConversionMatrix<float>(
int levelIndex, Index faceIndex, Level::VSpan const cornerSpans[],
SparseMatrix<float> & conversionMatrix) const;
template int PatchBuilder::GetIrregularPatchConversionMatrix<double>(
int levelIndex, Index faceIndex, Level::VSpan const cornerSpans[],
SparseMatrix<double> & conversionMatrix) const;
bool

View File

@ -226,9 +226,10 @@ public:
Index patchPoints[],
int fvc = -1) const;
template <typename REAL>
int GetIrregularPatchConversionMatrix(int level, Index face,
Vtr::internal::Level::VSpan const cornerSpans[],
SparseMatrix<float> & matrix) const;
SparseMatrix<REAL> & matrix) const;
int GetIrregularPatchSourcePoints(int level, Index face,
Vtr::internal::Level::VSpan const cornerSpans[],
@ -293,9 +294,13 @@ protected:
//
virtual PatchDescriptor::Type patchTypeFromBasis(BasisType basis) const = 0;
// Note overloading of the conversion for SparseMatrix<REAL>:
virtual int convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<float> & matrix) const = 0;
virtual int convertToPatchType(SourcePatch const & sourcePatch,
PatchDescriptor::Type patchType,
SparseMatrix<double> & matrix) const = 0;
protected:
TopologyRefiner const& _refiner;

View File

@ -123,7 +123,6 @@ private:
// Struct comprising a collection of topological properties for a patch that
// may be shared (between vertex and face-varying patches):
typedef SparseMatrix<float> Matrix;
struct PatchInfo {
PatchInfo() : isRegular(false), isRegSingleCrease(false),
regBoundaryMask(0), regSharpness(0.0f),
@ -135,7 +134,8 @@ private:
float regSharpness;
Level::VSpan irregCornerSpans[4];
int paramBoundaryMask;
Matrix matrix;
SparseMatrix<float> matrix;
};
private:
@ -160,11 +160,13 @@ private:
struct Options {
Options() : shareLocalPoints(false),
reuseSourcePoints(false),
createStencilTable(true) { }
createStencilTable(true),
createVaryingTable(false) { }
unsigned int shareLocalPoints : 1;
unsigned int reuseSourcePoints : 1;
unsigned int createStencilTable : 1;
unsigned int createVaryingTable : 1;
};
public:
@ -178,11 +180,11 @@ private:
int GetNumLocalPoints() const { return _numLocalPoints; }
int AppendLocalPatchPoints(int levelIndex, Index faceIndex,
Matrix const & conversionMatrix,
PatchDescriptor::Type patchType,
Index const sourcePoints[],
int sourcePointOffset,
Index patchPoints[]);
SparseMatrix<float> const & conversionMatrix,
PatchDescriptor::Type patchType,
Index const sourcePoints[],
int sourcePointOffset,
Index patchPoints[]);
StencilTable * AcquireStencilTable() {
return acquireStencilTable(&_stencilTable);
@ -190,14 +192,14 @@ private:
private:
// Internal methods:
void appendLocalPointStencil(Matrix const & conversionMatrix,
int stencilRow,
Index const sourcePoints[],
int sourcePointOffset);
void appendLocalPointStencil(SparseMatrix<float> const & conversionMatrix,
int stencilRow,
Index const sourcePoints[],
int sourcePointOffset);
void appendLocalPointStencils(Matrix const & conversionMatrix,
Index const sourcePoints[],
int sourcePointOffset);
void appendLocalPointStencils(SparseMatrix<float> const & conversionMatrix,
Index const sourcePoints[],
int sourcePointOffset);
// Methods for local point Varying stencils
// XXXX -- hope to get rid of these...
@ -206,11 +208,6 @@ private:
Index const sourcePoints[],
int sourcePointOffset);
void appendLocalPointVaryingStencils(int const * varyingIndices,
Matrix const & conversionMatrix,
Index const sourcePoints[],
int sourcePointOffset);
StencilTable * acquireStencilTable(StencilTable **stencilTableMember);
Index findSharedCornerPoint(int levelIndex, Index valueIndex,
@ -1043,16 +1040,18 @@ PatchTableBuilder::populateAdaptivePatches() {
}
//
// Initializing StencilTable and other helpers:
// Initializing StencilTable and other helpers. Note Varying local points
// are managed by the LocalPointHelper for Vertex patches (as Varying local
// points are tightly coupled to their local points)
//
LocalPointHelper * vertexLocalPointHelper = 0;
LocalPointHelper * varyingLocalPointHelper = 0;
StackBuffer<LocalPointHelper*,4> fvarLocalPointHelpers;
if (_requiresLocalPoints) {
LocalPointHelper::Options opts;
opts.createStencilTable = true;
opts.createVaryingTable = _requiresVaryingLocalPoints;
opts.shareLocalPoints = _options.shareEndCapPatchPoints;
opts.reuseSourcePoints = (_patchBuilder->GetIrregularPatchType() ==
_patchBuilder->GetNativePatchType() );
@ -1061,6 +1060,9 @@ PatchTableBuilder::populateAdaptivePatches() {
_refiner, opts, -1, estimateLocalPointCount(opts, -1));
if (_requiresFVarPatches) {
opts.createStencilTable = true;
opts.createVaryingTable = false;
fvarLocalPointHelpers.SetSize((int)_fvarChannelIndices.size());
for (int fvc = 0; fvc < (int)_fvarChannelIndices.size(); ++fvc) {
@ -1172,15 +1174,12 @@ PatchTableBuilder::populateAdaptivePatches() {
// Finalizing and destroying StencilTable and other helpers:
//
if (_requiresLocalPoints) {
if (_requiresVaryingPatches) {
// XXXX (barfowl) - note this is still managed by the vertex helper
_table->_localPointVaryingStencils =
vertexLocalPointHelper->AcquireStencilTableVarying();
delete varyingLocalPointHelper;
}
_table->_localPointStencils =
vertexLocalPointHelper->AcquireStencilTable();
if (_requiresVaryingLocalPoints) {
_table->_localPointVaryingStencils =
vertexLocalPointHelper->AcquireStencilTableVarying();
}
delete vertexLocalPointHelper;
if (_requiresFVarPatches) {
@ -1307,7 +1306,7 @@ PatchTableBuilder::LocalPointHelper::LocalPointHelper(
if (_options.createStencilTable) {
_stencilTable = new StencilTable(0);
if (_stencilTable && (_fvarChannel < 0)) {
if (_options.createVaryingTable) {
_stencilTableVarying = new StencilTable(0);
}
}
@ -1415,10 +1414,10 @@ PatchTableBuilder::LocalPointHelper::findSharedEdgePoint(int levelIndex,
void
PatchTableBuilder::LocalPointHelper::appendLocalPointStencil(
Matrix const & conversionMatrix,
int stencilRow,
Index const sourcePoints[],
int sourcePointOffset) {
SparseMatrix<float> const & conversionMatrix,
int stencilRow,
Index const sourcePoints[],
int sourcePointOffset) {
int stencilSize = conversionMatrix.GetRowSize(stencilRow);
ConstArray<int> matrixColumns = conversionMatrix.GetRowColumns(stencilRow);
@ -1434,9 +1433,9 @@ PatchTableBuilder::LocalPointHelper::appendLocalPointStencil(
void
PatchTableBuilder::LocalPointHelper::appendLocalPointStencils(
Matrix const & conversionMatrix,
Index const sourcePoints[],
int sourcePointOffset) {
SparseMatrix<float> const & conversionMatrix,
Index const sourcePoints[],
int sourcePointOffset) {
//
// Resize the StencilTable members to accomodate all rows and elements from
@ -1519,20 +1518,6 @@ PatchTableBuilder::LocalPointHelper::appendLocalPointVaryingStencil(
_stencilTableVarying->_weights.push_back(1.0f);
}
void
PatchTableBuilder::LocalPointHelper::appendLocalPointVaryingStencils(
int const * varyingIndices, Matrix const & conversionMatrix,
Index const sourcePoints[], int sourcePointOffset) {
for (int i = 0; i < conversionMatrix.GetNumRows(); ++i) {
Index varyingPoint = sourcePoints[varyingIndices[i]] + sourcePointOffset;
_stencilTableVarying->_sizes.push_back(1);
_stencilTableVarying->_indices.push_back(varyingPoint);
_stencilTableVarying->_weights.push_back(1.0f);
}
}
namespace {
typedef short ShareBits;
@ -1565,11 +1550,11 @@ namespace {
int
PatchTableBuilder::LocalPointHelper::AppendLocalPatchPoints(
int levelIndex, Index faceIndex,
Matrix const & matrix,
PatchDescriptor::Type patchType,
Index const sourcePoints[],
int sourcePointOffset,
Index patchPoints[]) {
SparseMatrix<float> const & matrix,
PatchDescriptor::Type patchType,
Index const sourcePoints[],
int sourcePointOffset,
Index patchPoints[]) {
//
// If sharing local points, verify the type of this patch supports
@ -1585,8 +1570,13 @@ PatchTableBuilder::LocalPointHelper::AppendLocalPatchPoints(
bool shareLocalPointsForThisPatch = (shareBitsPerPoint != 0);
int const * varyingIndices =
_stencilTableVarying ? GetVaryingIndicesPerType(patchType) : 0;
int const * varyingIndices = 0;
if (_stencilTableVarying) {
varyingIndices = GetVaryingIndicesPerType(patchType);
}
bool applyVertexStencils = (_stencilTable != 0);
bool applyVaryingStencils = (varyingIndices != 0);
//
// When point-sharing is not enabled, all patch points are generally
@ -1597,10 +1587,15 @@ PatchTableBuilder::LocalPointHelper::AppendLocalPatchPoints(
//
if (!shareLocalPointsForThisPatch) {
if (!_options.reuseSourcePoints) {
appendLocalPointStencils(matrix, sourcePoints, sourcePointOffset);
if (varyingIndices) {
appendLocalPointVaryingStencils(
varyingIndices, matrix, sourcePoints, sourcePointOffset);
if (applyVertexStencils) {
appendLocalPointStencils(
matrix, sourcePoints, sourcePointOffset);
if (applyVaryingStencils) {
for (int i = 0; i < numPatchPoints; ++i) {
appendLocalPointVaryingStencil(
varyingIndices, i, sourcePoints, sourcePointOffset);
}
}
}
for (int i = 0; i < numPatchPoints; ++i) {
patchPoints[i] = nextNewLocalPoint ++;
@ -1612,12 +1607,13 @@ PatchTableBuilder::LocalPointHelper::AppendLocalPatchPoints(
+ sourcePointOffset;
continue;
}
appendLocalPointStencil(
if (applyVertexStencils) {
appendLocalPointStencil(
matrix, i, sourcePoints, sourcePointOffset);
if (varyingIndices) {
appendLocalPointVaryingStencil(
varyingIndices, i, sourcePoints, sourcePointOffset);
if (applyVaryingStencils) {
appendLocalPointVaryingStencil(
varyingIndices, i, sourcePoints, sourcePointOffset);
}
}
patchPoints[i] = nextNewLocalPoint ++;
}
@ -1682,10 +1678,13 @@ PatchTableBuilder::LocalPointHelper::AppendLocalPatchPoints(
}
}
if (patchPoint == nextNewLocalPoint) {
appendLocalPointStencil(matrix, i, sourcePoints, sourcePointOffset);
if (varyingIndices) {
appendLocalPointVaryingStencil(
varyingIndices, i, sourcePoints, sourcePointOffset);
if (applyVertexStencils) {
appendLocalPointStencil(
matrix, i, sourcePoints, sourcePointOffset);
if (applyVaryingStencils) {
appendLocalPointVaryingStencil(
varyingIndices, i, sourcePoints, sourcePointOffset);
}
}
nextNewLocalPoint ++;
}