Sdc::TypeTraits now parameterized by Sdc::Scheme at runtime:

- changed template parameter to runtime method parameter
    - added traits as static methods of all schemes
    - constructed internal table of traits from all schemes
This commit is contained in:
barfowl 2015-01-02 14:57:04 -08:00
parent 881ff6c1e9
commit be7c8fdfd1
11 changed files with 176 additions and 248 deletions

View File

@ -145,37 +145,28 @@ TopologyRefiner::GetNumHoles(int level) const {
//
// Ptex information accessors
//
template <Sdc::Type SCHEME_TYPE> void
computePtexIndices(Vtr::Level const & coarseLevel, std::vector<int> & ptexIndices) {
void
TopologyRefiner::initializePtexIndices() const {
Vtr::Level const & coarseLevel = getLevel(0);
std::vector<int> & ptexIndices = const_cast<std::vector<int> &>(_ptexIndices);
int nfaces = coarseLevel.getNumFaces();
ptexIndices.resize(nfaces+1);
int ptexID=0;
int regFaceSize = Sdc::TypeTraits::GetRegularFaceSize(GetSchemeType());
for (int i = 0; i < nfaces; ++i) {
ptexIndices[i] = ptexID;
Vtr::ConstIndexArray fverts = coarseLevel.getFaceVertices(i);
ptexID += fverts.size()==Sdc::TypeTraits<SCHEME_TYPE>::RegularFaceValence() ? 1 : fverts.size();
ptexID += fverts.size()==regFaceSize ? 1 : fverts.size();
}
// last entry contains the number of ptex texture faces
ptexIndices[nfaces]=ptexID;
}
void
TopologyRefiner::initializePtexIndices() const {
std::vector<int> & indices = const_cast<std::vector<int> &>(_ptexIndices);
switch (GetSchemeType()) {
case Sdc::TYPE_BILINEAR:
computePtexIndices<Sdc::TYPE_BILINEAR>(getLevel(0), indices); break;
case Sdc::TYPE_CATMARK :
computePtexIndices<Sdc::TYPE_CATMARK>(getLevel(0), indices); break;
case Sdc::TYPE_LOOP :
computePtexIndices<Sdc::TYPE_LOOP>(getLevel(0), indices); break;
}
}
int
TopologyRefiner::GetNumPtexFaces() const {
if (_ptexIndices.empty()) {
initializePtexIndices();
}
// see computePtexIndices()
return _ptexIndices.back();
}
int

View File

@ -38,10 +38,8 @@ set(PRIVATE_HEADER_FILES )
#-------------------------------------------------------------------------------
# source & headers
set(SOURCE_FILES
bilinearTraits.cpp
catmarkTraits.cpp
crease.cpp
loopTraits.cpp
typeTraits.cpp
)
set(DOXY_HEADER_FILES ${PUBLIC_HEADER_FILES})

View File

@ -34,7 +34,27 @@ namespace OPENSUBDIV_VERSION {
namespace Sdc {
//
// Current specializations:
// Specializations for Scheme<TYPE_BILINEAR>:
//
//
// Bilinear traits:
//
template <>
inline Split Scheme<TYPE_BILINEAR>::GetTopologicalSplitType() { return SPLIT_TO_QUADS; }
template <>
inline int Scheme<TYPE_BILINEAR>::GetRegularFaceSize() { return 4; }
template <>
inline int Scheme<TYPE_BILINEAR>::GetRegularVertexValence() { return 4; }
template <>
inline int Scheme<TYPE_BILINEAR>::GetLocalNeighborhoodSize() { return 0; }
//
// Refinement masks:
//
template <>
template <typename EDGE, typename MASK>

View File

@ -1,68 +0,0 @@
//
// Copyright 2014 DreamWorks Animation LLC.
//
// 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.
//
#include "../sdc/type.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Sdc {
//
// Specializations for TypeTraits<TYPE_BILINEAR>:
//
template <>
Split
TypeTraits<TYPE_BILINEAR>::TopologicalSplitType() {
return SPLIT_TO_QUADS;
}
template <>
int
TypeTraits<TYPE_BILINEAR>::LocalNeighborhoodSize() {
return 0;
}
template <>
int
TypeTraits<TYPE_BILINEAR>::RegularVertexValence() {
return 0;
}
template <>
int
TypeTraits<TYPE_BILINEAR>::RegularFaceValence() {
return 0;
}
template <>
char const*
TypeTraits<TYPE_BILINEAR>::Label() {
// Might need to declare static here to keep all compilers happy...
return "bilinear";
}
} // end namespace sdc
} // end namespace OPENSUBDIV_VERSION
} // end namespace OpenSubdiv

View File

@ -40,6 +40,22 @@ namespace Sdc {
// Specializations for Scheme<TYPE_CATMARK>:
//
//
// Catmark traits:
//
template <>
inline Split Scheme<TYPE_CATMARK>::GetTopologicalSplitType() { return SPLIT_TO_QUADS; }
template <>
inline int Scheme<TYPE_CATMARK>::GetRegularFaceSize() { return 4; }
template <>
inline int Scheme<TYPE_CATMARK>::GetRegularVertexValence() { return 4; }
template <>
inline int Scheme<TYPE_CATMARK>::GetLocalNeighborhoodSize() { return 1; }
//
// Masks for edge-vertices: the hard Crease mask does not need to be specialized
// (simply the midpoint), so all that is left is the Smooth case:

View File

@ -1,68 +0,0 @@
//
// Copyright 2014 DreamWorks Animation LLC.
//
// 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.
//
#include "../sdc/type.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Sdc {
//
// Specializations for TypeTraits<TYPE_CATMARK>:
//
template <>
Split
TypeTraits<TYPE_CATMARK>::TopologicalSplitType() {
return SPLIT_TO_QUADS;
}
template <>
int
TypeTraits<TYPE_CATMARK>::LocalNeighborhoodSize() {
return 1;
}
template <>
int
TypeTraits<TYPE_CATMARK>::RegularVertexValence() {
return 4;
}
template <>
int
TypeTraits<TYPE_CATMARK>::RegularFaceValence() {
return 4;
}
template <>
char const*
TypeTraits<TYPE_CATMARK>::Label() {
// Might need to declare static here to keep all compilers happy...
return "catmark";
}
} // end namespace sdc
} // end namespace OPENSUBDIV_VERSION
} // end namespace OpenSubdiv

View File

@ -38,7 +38,25 @@ namespace Sdc {
//
// Specializations for Sdc::Scheme<TYPE_LOOP>:
//
//
//
// Loop traits:
//
template <>
inline Split Scheme<TYPE_LOOP>::GetTopologicalSplitType() { return SPLIT_TO_TRIS; }
template <>
inline int Scheme<TYPE_LOOP>::GetRegularFaceSize() { return 3; }
template <>
inline int Scheme<TYPE_LOOP>::GetRegularVertexValence() { return 6; }
template <>
inline int Scheme<TYPE_LOOP>::GetLocalNeighborhoodSize() { return 1; }
//
// Protected methods to assign the two types of masks for an edge-vertex --
// Crease and Smooth.
//

View File

@ -1,68 +0,0 @@
//
// Copyright 2014 DreamWorks Animation LLC.
//
// 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.
//
#include "../sdc/type.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Sdc {
//
// Specializations for TypeTraits<TYPE_LOOP>:
//
template <>
Split
TypeTraits<TYPE_LOOP>::TopologicalSplitType() {
return SPLIT_TO_TRIS;
}
template <>
int
TypeTraits<TYPE_LOOP>::LocalNeighborhoodSize() {
return 1;
}
template <>
int
TypeTraits<TYPE_LOOP>::RegularVertexValence() {
return 6;
}
template <>
int
TypeTraits<TYPE_LOOP>::RegularFaceValence() {
return 3;
}
template <>
char const*
TypeTraits<TYPE_LOOP>::Label() {
// Might need to declare static here to keep all compilers happy...
return "loop";
}
} // end namespace sdc
} // end namespace OPENSUBDIV_VERSION
} // end namespace OpenSubdiv

View File

@ -130,6 +130,15 @@ public:
void ComputeVertexLimitMask(VERTEX const& vertexNeighborhood, MASK& positionMask,
MASK& tangent1Mask,
MASK& tangent2Mask) const;
//
// Static methods defining traits/properties of the scheme:
//
static Split GetTopologicalSplitType();
static int GetRegularFaceSize();
static int GetRegularVertexValence();
static int GetLocalNeighborhoodSize();
protected:
//

View File

@ -51,34 +51,19 @@ enum Split {
};
///
/// \brief Traits associated with all types. These are specialized and instantiated for
/// each of the supported types.
/// \brief Traits associated the types of all subdivision schemes -- parameterized by
/// the scheme type. All traits are also defined on the scheme itself.
///
/// Traits do not vary with the topology or any options applied to the scheme. They
/// are intended to help construct more general queries about a subdivision scheme
/// in a context where its details may be less well understood. They serve little
/// purpose in code specialized to the particular scheme, i.e. in code already
/// specialized for Catmark, the values for these traits for the Catmark scheme are
/// typically known and their usage well understood.
///
// Question:
// Do we really need/want these TypeTraits, or will static methods on another
// class specialized for the type suffice, i.e. Scheme<SCHEME_TYPE>?
// If yes, there will be little in here other than Sdc::Type, which we may want
// to merge into <sdc/options.h>.
//
template <Type SCHEME_TYPE>
struct TypeTraits {
static Type GetType() {
return SCHEME_TYPE;
}
static Type GetType(Type schemeType) { return schemeType; }
static Split TopologicalSplitType();
static int LocalNeighborhoodSize();
static int RegularVertexValence();
static int RegularFaceValence();
static char const* Label();
static Split GetTopologicalSplitType(Type schemeType);
static int GetRegularFaceSize(Type schemeType);
static int GetRegularVertexValence(Type schemeType);
static int GetLocalNeighborhoodSize(Type schemeType);
static char const* GetName(Type schemeType);
};

View File

@ -0,0 +1,95 @@
//
// Copyright 2014 DreamWorks Animation LLC.
//
// 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.
//
#include "../sdc/type.h"
#include "../sdc/bilinearScheme.h"
#include "../sdc/catmarkScheme.h"
#include "../sdc/loopScheme.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Sdc {
struct TypeTraitsEntry {
char const * _name;
Split _splitType;
int _regularFaceSize;
int _regularVertexValence;
int _localNeighborhood;
};
static const TypeTraitsEntry typeTraitsTable[3] = {
{ "bilinear", Scheme<TYPE_BILINEAR>::GetTopologicalSplitType(),
Scheme<TYPE_BILINEAR>::GetRegularFaceSize(),
Scheme<TYPE_BILINEAR>::GetRegularVertexValence(),
Scheme<TYPE_BILINEAR>::GetLocalNeighborhoodSize() },
{ "catmark", Scheme<TYPE_CATMARK>::GetTopologicalSplitType(),
Scheme<TYPE_CATMARK>::GetRegularFaceSize(),
Scheme<TYPE_CATMARK>::GetRegularVertexValence(),
Scheme<TYPE_CATMARK>::GetLocalNeighborhoodSize() },
{ "loop", Scheme<TYPE_LOOP>::GetTopologicalSplitType(),
Scheme<TYPE_LOOP>::GetRegularFaceSize(),
Scheme<TYPE_LOOP>::GetRegularVertexValence(),
Scheme<TYPE_LOOP>::GetLocalNeighborhoodSize() }
};
//
// Static methods for TypeTraits:
//
char const*
TypeTraits::GetName(Type schemeType) {
return typeTraitsTable[schemeType]._name;
}
Split
TypeTraits::GetTopologicalSplitType(Type schemeType) {
return typeTraitsTable[schemeType]._splitType;
}
int
TypeTraits::GetRegularFaceSize(Type schemeType) {
return typeTraitsTable[schemeType]._regularFaceSize;
}
int
TypeTraits::GetRegularVertexValence(Type schemeType) {
return typeTraitsTable[schemeType]._regularVertexValence;
}
int
TypeTraits::GetLocalNeighborhoodSize(Type schemeType) {
return typeTraitsTable[schemeType]._localNeighborhood;
}
} // end namespace sdc
} // end namespace OPENSUBDIV_VERSION
} // end namespace OpenSubdiv