2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// 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 "../far/topologyRefiner.h"
|
|
|
|
#include "../vtr/sparseSelector.h"
|
2014-11-18 01:19:30 +00:00
|
|
|
#include "../vtr/quadRefinement.h"
|
|
|
|
#include "../vtr/triRefinement.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
namespace Far {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Relatively trivial construction/destruction -- the base level (level[0]) needs
|
|
|
|
// to be explicitly initialized after construction and refinement then applied
|
|
|
|
//
|
|
|
|
TopologyRefiner::TopologyRefiner(Sdc::Type schemeType, Sdc::Options schemeOptions) :
|
|
|
|
_subdivType(schemeType),
|
|
|
|
_subdivOptions(schemeOptions),
|
|
|
|
_isUniform(true),
|
2014-10-24 20:52:40 +00:00
|
|
|
_hasHoles(false),
|
|
|
|
_useSingleCreasePatch(false),
|
|
|
|
_maxLevel(0) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// Need to revisit allocation scheme here -- want to use smart-ptrs for these
|
|
|
|
// but will probably have to settle for explicit new/delete...
|
2014-10-15 01:59:05 +00:00
|
|
|
_levels.reserve(10);
|
|
|
|
_levels.push_back(new Vtr::Level);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
TopologyRefiner::~TopologyRefiner() {
|
|
|
|
|
|
|
|
for (int i=0; i<(int)_levels.size(); ++i) {
|
|
|
|
delete _levels[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<(int)_refinements.size(); ++i) {
|
|
|
|
delete _refinements[i];
|
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
TopologyRefiner::Unrefine() {
|
2014-10-15 01:59:05 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (_levels.size()) {
|
2014-10-15 01:59:05 +00:00
|
|
|
for (int i=1; i<(int)_levels.size(); ++i) {
|
|
|
|
delete _levels[i];
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
_levels.resize(1);
|
|
|
|
}
|
2014-10-15 01:59:05 +00:00
|
|
|
for (int i=0; i<(int)_refinements.size(); ++i) {
|
|
|
|
delete _refinements[i];
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
_refinements.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TopologyRefiner::Clear() {
|
|
|
|
_levels.clear();
|
|
|
|
_refinements.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors to the topology information:
|
|
|
|
//
|
|
|
|
int
|
|
|
|
TopologyRefiner::GetNumVerticesTotal() const {
|
|
|
|
int sum = 0;
|
|
|
|
for (int i = 0; i < (int)_levels.size(); ++i) {
|
2014-10-15 01:59:05 +00:00
|
|
|
sum += _levels[i]->getNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
int
|
|
|
|
TopologyRefiner::GetNumEdgesTotal() const {
|
|
|
|
int sum = 0;
|
|
|
|
for (int i = 0; i < (int)_levels.size(); ++i) {
|
2014-10-15 01:59:05 +00:00
|
|
|
sum += _levels[i]->getNumEdges();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
int
|
|
|
|
TopologyRefiner::GetNumFacesTotal() const {
|
|
|
|
int sum = 0;
|
|
|
|
for (int i = 0; i < (int)_levels.size(); ++i) {
|
2014-10-15 01:59:05 +00:00
|
|
|
sum += _levels[i]->getNumFaces();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
int
|
|
|
|
TopologyRefiner::GetNumFaceVerticesTotal() const {
|
|
|
|
int sum = 0;
|
|
|
|
for (int i = 0; i < (int)_levels.size(); ++i) {
|
2014-10-15 01:59:05 +00:00
|
|
|
sum += _levels[i]->getNumFaceVerticesTotal();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
int
|
|
|
|
TopologyRefiner::GetNumFVarValuesTotal(int channel) const {
|
|
|
|
int sum = 0;
|
|
|
|
for (int i = 0; i < (int)_levels.size(); ++i) {
|
2014-10-15 01:59:05 +00:00
|
|
|
sum += _levels[i]->getNumFVarValues(channel);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2014-10-24 20:52:40 +00:00
|
|
|
int
|
|
|
|
TopologyRefiner::GetNumHoles(int level) const {
|
|
|
|
int sum = 0;
|
|
|
|
Vtr::Level const & lvl = getLevel(level);
|
|
|
|
for (Index face = 0; face < lvl.getNumFaces(); ++face) {
|
|
|
|
if (lvl.isHole(face)) {
|
|
|
|
++sum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2014-09-26 22:10:57 +00:00
|
|
|
//
|
|
|
|
// Ptex information accessors
|
|
|
|
//
|
2014-09-05 22:07:46 +00:00
|
|
|
template <Sdc::Type SCHEME_TYPE> void
|
|
|
|
computePtexIndices(Vtr::Level const & coarseLevel, std::vector<int> & ptexIndices) {
|
|
|
|
int nfaces = coarseLevel.getNumFaces();
|
|
|
|
ptexIndices.resize(nfaces+1);
|
|
|
|
int ptexID=0;
|
|
|
|
for (int i = 0; i < nfaces; ++i) {
|
|
|
|
ptexIndices[i] = ptexID;
|
2014-12-15 18:23:13 +00:00
|
|
|
Vtr::ConstIndexArray fverts = coarseLevel.getFaceVertices(i);
|
2014-09-05 22:07:46 +00:00
|
|
|
ptexID += fverts.size()==Sdc::TypeTraits<SCHEME_TYPE>::RegularFaceValence() ? 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:
|
2014-10-15 01:59:05 +00:00
|
|
|
computePtexIndices<Sdc::TYPE_BILINEAR>(getLevel(0), indices); break;
|
2014-09-05 22:07:46 +00:00
|
|
|
case Sdc::TYPE_CATMARK :
|
2014-10-15 01:59:05 +00:00
|
|
|
computePtexIndices<Sdc::TYPE_CATMARK>(getLevel(0), indices); break;
|
2014-09-05 22:07:46 +00:00
|
|
|
case Sdc::TYPE_LOOP :
|
2014-10-15 01:59:05 +00:00
|
|
|
computePtexIndices<Sdc::TYPE_LOOP>(getLevel(0), indices); break;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int
|
|
|
|
TopologyRefiner::GetNumPtexFaces() const {
|
|
|
|
if (_ptexIndices.empty()) {
|
|
|
|
initializePtexIndices();
|
|
|
|
}
|
|
|
|
// see computePtexIndices()
|
|
|
|
return _ptexIndices.back();
|
|
|
|
}
|
|
|
|
int
|
|
|
|
TopologyRefiner::GetPtexIndex(Index f) const {
|
|
|
|
if (_ptexIndices.empty()) {
|
|
|
|
initializePtexIndices();
|
|
|
|
}
|
2014-09-26 22:10:57 +00:00
|
|
|
assert(f<(int)_ptexIndices.size());
|
|
|
|
return _ptexIndices[f];
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// Returns the face adjacent to 'face' along edge 'edge'
|
|
|
|
inline Index
|
|
|
|
getAdjacentFace(Vtr::Level const & level, Index edge, Index face) {
|
2014-12-15 18:23:13 +00:00
|
|
|
Far::ConstIndexArray adjFaces = level.getEdgeFaces(edge);
|
2014-09-26 22:10:57 +00:00
|
|
|
if (adjFaces.size()!=2) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (adjFaces[0]==face) ? adjFaces[1] : adjFaces[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TopologyRefiner::GetPtexAdjacency(int face, int quadrant,
|
|
|
|
int adjFaces[4], int adjEdges[4]) const {
|
|
|
|
|
|
|
|
assert(GetSchemeType()==Sdc::TYPE_CATMARK);
|
|
|
|
|
|
|
|
if (_ptexIndices.empty()) {
|
|
|
|
initializePtexIndices();
|
|
|
|
}
|
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
Vtr::Level const & level = getLevel(0);
|
2014-09-26 22:10:57 +00:00
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray fedges = level.getFaceEdges(face);
|
2014-09-26 22:10:57 +00:00
|
|
|
|
|
|
|
if (fedges.size()==4) {
|
|
|
|
|
|
|
|
// Regular ptex quad face
|
|
|
|
for (int i=0; i<4; ++i) {
|
|
|
|
int edge = fedges[i];
|
|
|
|
Index adjface = getAdjacentFace(level, edge, face);
|
|
|
|
if (adjface==-1) {
|
|
|
|
adjFaces[i] = -1; // boundary or non-manifold
|
|
|
|
adjEdges[i] = 0;
|
|
|
|
} else {
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray aedges = level.getFaceEdges(adjface);
|
2014-09-26 22:10:57 +00:00
|
|
|
if (aedges.size()==4) {
|
|
|
|
adjFaces[i] = _ptexIndices[adjface];
|
|
|
|
adjEdges[i] = aedges.FindIndexIn4Tuple(edge);
|
|
|
|
assert(adjEdges[i]!=-1);
|
|
|
|
} else {
|
|
|
|
// neighbor is a sub-face
|
|
|
|
adjFaces[i] = _ptexIndices[adjface] +
|
|
|
|
(aedges.FindIndex(edge)+1)%aedges.size();
|
|
|
|
adjEdges[i] = 3;
|
|
|
|
}
|
|
|
|
assert(adjFaces[i]!=-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Ptex sub-face 'quadrant' (non-quad)
|
|
|
|
//
|
|
|
|
// Ptex adjacency pattern for non-quads:
|
|
|
|
//
|
|
|
|
// v2
|
|
|
|
/* o
|
|
|
|
// / \
|
|
|
|
// / \
|
|
|
|
// /0 3\
|
|
|
|
// / \
|
|
|
|
// o_ 1 2 _o
|
|
|
|
// / -_ _- \
|
|
|
|
// / 2 -o- 1 \
|
|
|
|
// /3 | 0\
|
|
|
|
// / 1|2 \
|
|
|
|
// / 0 | 3 \
|
|
|
|
// o----------o----------o
|
|
|
|
// v0 v1
|
|
|
|
*/
|
|
|
|
assert(quadrant>=0 and quadrant<fedges.size());
|
|
|
|
|
|
|
|
int nextQuadrant = (quadrant+1) % fedges.size(),
|
|
|
|
prevQuadrant = (quadrant+fedges.size()-1) % fedges.size();
|
|
|
|
|
|
|
|
{ // resolve neighbors within the sub-face (edges 1 & 2)
|
|
|
|
adjFaces[1] = _ptexIndices[face] + nextQuadrant;
|
|
|
|
adjEdges[1] = 2;
|
|
|
|
|
|
|
|
adjFaces[2] = _ptexIndices[face] + prevQuadrant;
|
|
|
|
adjEdges[2] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // resolve neighbor outisde the sub-face (edge 0)
|
|
|
|
int edge0 = fedges[quadrant];
|
|
|
|
Index adjface0 = getAdjacentFace(level, edge0, face);
|
|
|
|
if (adjface0==-1) {
|
|
|
|
adjFaces[0] = -1; // boundary or non-manifold
|
|
|
|
adjEdges[0] = 0;
|
|
|
|
} else {
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray afedges = level.getFaceEdges(adjface0);
|
2014-09-26 22:10:57 +00:00
|
|
|
if (afedges.size()==4) {
|
|
|
|
adjFaces[0] = _ptexIndices[adjface0];
|
|
|
|
adjEdges[0] = afedges.FindIndexIn4Tuple(edge0);
|
|
|
|
} else {
|
|
|
|
int subedge = (afedges.FindIndex(edge0)+1)%afedges.size();
|
|
|
|
adjFaces[0] = _ptexIndices[adjface0] + subedge;
|
|
|
|
adjEdges[0] = 3;
|
|
|
|
}
|
|
|
|
assert(adjFaces[0]!=-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// resolve neighbor outisde the sub-face (edge 3)
|
|
|
|
int edge3 = fedges[prevQuadrant];
|
|
|
|
Index adjface3 = getAdjacentFace(level, edge3, face);
|
|
|
|
if (adjface3==-1) {
|
|
|
|
adjFaces[3]=-1; // boundary or non-manifold
|
|
|
|
adjEdges[3]=0;
|
|
|
|
} else {
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray afedges = level.getFaceEdges(adjface3);
|
2014-09-26 22:10:57 +00:00
|
|
|
if (afedges.size()==4) {
|
|
|
|
adjFaces[3] = _ptexIndices[adjface3];
|
|
|
|
adjEdges[3] = afedges.FindIndexIn4Tuple(edge3);
|
|
|
|
} else {
|
|
|
|
int subedge = afedges.FindIndex(edge3);
|
|
|
|
adjFaces[3] = _ptexIndices[adjface3] + subedge;
|
|
|
|
adjEdges[3] = 0;
|
|
|
|
}
|
|
|
|
assert(adjFaces[3]!=-1);
|
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Main refinement method -- allocating and initializing levels and refinements:
|
|
|
|
//
|
|
|
|
void
|
2014-12-30 22:07:24 +00:00
|
|
|
TopologyRefiner::RefineUniform(UniformOptions options) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
assert(_levels[0]->getNumVertices() > 0); // Make sure the base level has been initialized
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate the stack of levels and the refinements between them:
|
|
|
|
//
|
|
|
|
_isUniform = true;
|
2014-12-30 22:07:24 +00:00
|
|
|
_maxLevel = options.refinementLevel;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Sdc::Split splitType = (_subdivType == Sdc::TYPE_LOOP) ? Sdc::SPLIT_TO_TRIS : Sdc::SPLIT_TO_QUADS;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Initialize refinement options for Vtr -- adjusting full-topology for the last level:
|
|
|
|
//
|
|
|
|
Vtr::Refinement::Options refineOptions;
|
|
|
|
refineOptions._sparse = false;
|
|
|
|
|
2014-12-30 22:07:24 +00:00
|
|
|
for (int i = 1; i <= options.refinementLevel; ++i) {
|
2014-12-23 18:07:24 +00:00
|
|
|
refineOptions._faceTopologyOnly =
|
2014-12-30 22:07:24 +00:00
|
|
|
options.fullTopologyInLastLevel ? false : (i == options.refinementLevel);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Vtr::Level& parentLevel = getLevel(i-1);
|
|
|
|
Vtr::Level& childLevel = *(new Vtr::Level);
|
2014-10-15 18:22:32 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Vtr::Refinement* refinement = 0;
|
|
|
|
if (splitType == Sdc::SPLIT_TO_QUADS) {
|
|
|
|
refinement = new Vtr::QuadRefinement(parentLevel, childLevel, _subdivOptions);
|
|
|
|
} else {
|
|
|
|
refinement = new Vtr::TriRefinement(parentLevel, childLevel, _subdivOptions);
|
|
|
|
}
|
|
|
|
refinement->refine(refineOptions);
|
2014-10-15 18:22:32 +00:00
|
|
|
|
|
|
|
_levels.push_back(&childLevel);
|
2014-11-18 01:19:30 +00:00
|
|
|
_refinements.push_back(refinement);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2014-12-30 22:07:24 +00:00
|
|
|
TopologyRefiner::RefineAdaptive(AdaptiveOptions options) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
assert(_levels[0]->getNumVertices() > 0); // Make sure the base level has been initialized
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate the stack of levels and the refinements between them:
|
|
|
|
//
|
|
|
|
_isUniform = false;
|
2014-12-30 22:07:24 +00:00
|
|
|
_maxLevel = options.isolationLevel;
|
2014-12-23 18:07:24 +00:00
|
|
|
_useSingleCreasePatch = options.useSingleCreasePatch;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize refinement options for Vtr:
|
|
|
|
//
|
|
|
|
Vtr::Refinement::Options refineOptions;
|
|
|
|
|
|
|
|
refineOptions._sparse = true;
|
2014-12-23 18:07:24 +00:00
|
|
|
refineOptions._faceTopologyOnly = not options.fullTopologyInLastLevel;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Sdc::Split splitType = (_subdivType == Sdc::TYPE_LOOP) ? Sdc::SPLIT_TO_TRIS : Sdc::SPLIT_TO_QUADS;
|
|
|
|
|
2014-12-30 22:07:24 +00:00
|
|
|
for (int i = 1; i <= options.isolationLevel; ++i) {
|
2014-09-05 22:07:46 +00:00
|
|
|
// Keeping full topology on for debugging -- may need to go back a level and "prune"
|
|
|
|
// its topology if we don't use the full depth
|
|
|
|
refineOptions._faceTopologyOnly = false;
|
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
Vtr::Level& parentLevel = getLevel(i-1);
|
2014-10-15 18:22:32 +00:00
|
|
|
Vtr::Level& childLevel = *(new Vtr::Level);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Vtr::Refinement* refinement = 0;
|
|
|
|
if (splitType == Sdc::SPLIT_TO_QUADS) {
|
|
|
|
refinement = new Vtr::QuadRefinement(parentLevel, childLevel, _subdivOptions);
|
|
|
|
} else {
|
|
|
|
refinement = new Vtr::TriRefinement(parentLevel, childLevel, _subdivOptions);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
2014-10-15 18:22:32 +00:00
|
|
|
// Initialize a Selector to mark a sparse set of components for refinement. If
|
|
|
|
// nothing was selected, discard the new refinement and child level, trim the
|
|
|
|
// maximum level and stop refinining any further. Otherwise, refine and append
|
|
|
|
// the new refinement and child.
|
|
|
|
//
|
|
|
|
// Note that if we support the "full topology at last level" option properly,
|
|
|
|
// we should prune the previous level generated, as it is now the last...
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2014-11-18 01:19:30 +00:00
|
|
|
Vtr::SparseSelector selector(*refinement);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
selectFeatureAdaptiveComponents(selector);
|
2014-10-15 18:22:32 +00:00
|
|
|
if (selector.isSelectionEmpty()) {
|
|
|
|
_maxLevel = i - 1;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
delete refinement;
|
2014-10-15 18:22:32 +00:00
|
|
|
delete &childLevel;
|
2014-09-05 22:07:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-10-15 18:22:32 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
refinement->refine(refineOptions);
|
2014-10-15 18:22:32 +00:00
|
|
|
|
|
|
|
_levels.push_back(&childLevel);
|
2014-11-18 01:19:30 +00:00
|
|
|
_refinements.push_back(refinement);
|
2014-10-15 18:22:32 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
//childLevel.print(refinement);
|
2014-10-15 18:22:32 +00:00
|
|
|
//assert(childLevel.validateTopology());
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2014-11-18 01:19:30 +00:00
|
|
|
// Method for selecting components for sparse refinement based on the feature-adaptive needs
|
|
|
|
// of patch generation.
|
2014-09-24 01:24:29 +00:00
|
|
|
//
|
2014-09-05 22:07:46 +00:00
|
|
|
// It assumes we have a freshly initialized Vtr::SparseSelector (i.e. nothing already selected)
|
|
|
|
// and will select all relevant topological features for inclusion in the subsequent sparse
|
|
|
|
// refinement.
|
|
|
|
//
|
2014-11-18 01:19:30 +00:00
|
|
|
// This was originally written specific to the quad-centric Catmark scheme and was since
|
|
|
|
// generalized to support Loop given the enhanced tagging of components based on the scheme.
|
|
|
|
// Any further enhancements here, e.g. new approaches for dealing with infinitely sharp
|
2014-12-20 02:18:13 +00:00
|
|
|
// creases, should be aware of the intended generality. Ultimately it may not be worth
|
2014-11-18 01:19:30 +00:00
|
|
|
// trying to keep this general and we will be better off specializing it for each scheme.
|
|
|
|
// The fact that this method is intimately tied to patch generation also begs for it to
|
|
|
|
// become part of a class that encompasses both the feature adaptive tagging and the
|
|
|
|
// identification of the intended patch that result from it.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
void
|
2014-11-18 01:19:30 +00:00
|
|
|
TopologyRefiner::selectFeatureAdaptiveComponents(Vtr::SparseSelector& selector) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vtr::Level const& level = selector.getRefinement().parent();
|
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
int regularFaceSize = selector.getRefinement()._regFaceSize;
|
|
|
|
bool considerSingleCreasePatch = _useSingleCreasePatch && (regularFaceSize == 4);
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
for (Vtr::Index face = 0; face < level.getNumFaces(); ++face) {
|
2014-12-20 02:18:13 +00:00
|
|
|
|
2014-10-24 20:52:40 +00:00
|
|
|
if (level.isHole(face)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-12-20 02:18:13 +00:00
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
Vtr::ConstIndexArray faceVerts = level.getFaceVertices(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-09-24 01:24:29 +00:00
|
|
|
//
|
|
|
|
// Testing irregular faces is only necessary at level 0, and potentially warrants
|
2014-11-18 01:19:30 +00:00
|
|
|
// separating out as the caller can detect these:
|
2014-09-24 01:24:29 +00:00
|
|
|
//
|
2014-11-18 01:19:30 +00:00
|
|
|
if (faceVerts.size() != regularFaceSize) {
|
2014-09-26 22:10:57 +00:00
|
|
|
//
|
2014-09-24 01:24:29 +00:00
|
|
|
// We need to also ensure that all adjacent faces to this are selected, so we
|
|
|
|
// select every face incident every vertex of the face. This is the only place
|
|
|
|
// where other faces are selected as a side effect and somewhat undermines the
|
|
|
|
// whole intent of the per-face traversal.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2014-12-15 18:23:13 +00:00
|
|
|
Vtr::ConstIndexArray fVerts = level.getFaceVertices(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int i = 0; i < fVerts.size(); ++i) {
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray fVertFaces = level.getVertexFaces(fVerts[i]);
|
2014-09-24 01:24:29 +00:00
|
|
|
for (int j = 0; j < fVertFaces.size(); ++j) {
|
|
|
|
selector.selectFace(fVertFaces[j]);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2014-09-24 01:24:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Combine the tags for all vertices of the face and quickly accept/reject based on
|
|
|
|
// the presence/absence of properties where we can (further inspection is likely to
|
|
|
|
// be necessary in some cases, particularly when we start trying to be clever about
|
|
|
|
// minimizing refinement for inf-sharp creases, etc.):
|
|
|
|
//
|
2014-12-20 02:18:13 +00:00
|
|
|
Vtr::Level::VTag compFaceVTag = level.getFaceCompositeVTag(faceVerts);
|
|
|
|
if (compFaceVTag._incomplete) {
|
2014-09-24 01:24:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool selectFace = false;
|
2014-12-20 02:18:13 +00:00
|
|
|
if (compFaceVTag._xordinary) {
|
2014-09-24 01:24:29 +00:00
|
|
|
selectFace = true;
|
2014-12-20 02:18:13 +00:00
|
|
|
} else if (compFaceVTag._rule & Sdc::Crease::RULE_DART) {
|
2014-09-24 01:24:29 +00:00
|
|
|
// Get this case out of the way before testing hard features
|
|
|
|
selectFace = true;
|
2014-12-20 02:18:13 +00:00
|
|
|
} else if (compFaceVTag._nonManifold) {
|
2014-09-24 01:24:29 +00:00
|
|
|
// Warrants further inspection -- isolate for now
|
|
|
|
// - will want to defer inf-sharp treatment to below
|
|
|
|
selectFace = true;
|
2014-12-20 02:18:13 +00:00
|
|
|
} else if (!(compFaceVTag._rule & Sdc::Crease::RULE_SMOOTH)) {
|
2014-09-24 01:24:29 +00:00
|
|
|
// None of the vertices is Smooth, so we have all vertices either Crease or Corner,
|
|
|
|
// though some may be regular patches, this currently warrants isolation as we only
|
|
|
|
// support regular patches with one corner or one boundary.
|
|
|
|
selectFace = true;
|
2014-12-20 02:18:13 +00:00
|
|
|
} else if (compFaceVTag._semiSharp) {
|
2014-10-13 15:52:09 +00:00
|
|
|
// if this is regular and the adjacent edges have same sharpness
|
|
|
|
// and no vertex corner sharpness,
|
|
|
|
// we can stop refinning and use single-crease patch.
|
2014-11-18 01:19:30 +00:00
|
|
|
if (considerSingleCreasePatch) {
|
2014-12-20 02:18:13 +00:00
|
|
|
selectFace = not level.isSingleCreasePatch(face);
|
2014-10-13 15:52:09 +00:00
|
|
|
} else {
|
|
|
|
selectFace = true;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
2014-09-24 01:24:29 +00:00
|
|
|
// This leaves us with at least one Smooth vertex (and so two smooth adjacent edges
|
|
|
|
// of the quad) and the rest hard Creases or Corners. This includes the regular
|
|
|
|
// corner and boundary cases that we don't want to isolate, but leaves a few others
|
|
|
|
// that do warrant isolation -- needing further inspection.
|
|
|
|
//
|
|
|
|
// For now go with the boundary cases and don't isolate...
|
2014-12-20 02:18:13 +00:00
|
|
|
//selectFace = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not selectFace) {
|
|
|
|
// Infinitely sharp edges do not influence vertex flags, but they need to
|
|
|
|
// isolated unless they can be treated as 'single-crease' cases.
|
|
|
|
// XXXX manuelk this will probably have to be revisited once infinitely
|
|
|
|
// sharp creases are handled correctly.
|
|
|
|
Vtr::ConstIndexArray faceEdges = level.getFaceEdges(face);
|
|
|
|
Vtr::Level::ETag compFaceETag = level.getFaceCompositeETag(faceEdges);
|
|
|
|
if (compFaceETag._infSharp and not compFaceETag._boundary) {
|
|
|
|
// XXXX manuelk we are testing an 'and' aggregate of flags for all
|
|
|
|
// edges : this should be safe, because if the sharp edge is not
|
|
|
|
// the edge on the boundary, this face would have been selected
|
|
|
|
// with one of the previous tests
|
|
|
|
selectFace = considerSingleCreasePatch ?
|
|
|
|
not level.isSingleCreasePatch(face) : true;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2014-12-20 02:18:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (selectFace) {
|
|
|
|
selector.selectFace(face);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace Far
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|