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"
|
2015-04-10 16:19:08 +00:00
|
|
|
#include "../far/error.h"
|
2015-06-01 07:14:19 +00:00
|
|
|
#include "../vtr/fvarLevel.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#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
|
|
|
|
//
|
2015-01-07 01:40:11 +00:00
|
|
|
TopologyRefiner::TopologyRefiner(Sdc::SchemeType schemeType, Sdc::Options schemeOptions) :
|
2014-09-05 22:07:46 +00:00
|
|
|
_subdivType(schemeType),
|
|
|
|
_subdivOptions(schemeOptions),
|
|
|
|
_isUniform(true),
|
2014-10-24 20:52:40 +00:00
|
|
|
_hasHoles(false),
|
2015-04-02 03:44:33 +00:00
|
|
|
_maxLevel(0),
|
|
|
|
_uniformOptions(0),
|
|
|
|
_adaptiveOptions(0),
|
|
|
|
_totalVertices(0),
|
|
|
|
_totalEdges(0),
|
|
|
|
_totalFaces(0),
|
|
|
|
_totalFaceVertices(0),
|
|
|
|
_maxValence(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);
|
2015-05-26 03:34:50 +00:00
|
|
|
_levels.push_back(new Vtr::internal::Level);
|
2015-05-19 22:06:41 +00:00
|
|
|
_farLevels.reserve(10);
|
|
|
|
assembleFarLevels();
|
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);
|
2015-04-02 03:44:33 +00:00
|
|
|
initializeInventory();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
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();
|
2015-05-19 22:06:41 +00:00
|
|
|
|
|
|
|
assembleFarLevels();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2015-04-02 03:44:33 +00:00
|
|
|
// Intializing and updating the component inventory:
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-04-02 03:44:33 +00:00
|
|
|
void
|
|
|
|
TopologyRefiner::initializeInventory() {
|
|
|
|
|
|
|
|
if (_levels.size()) {
|
|
|
|
assert(_levels.size() == 1);
|
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level const & baseLevel = *_levels[0];
|
2015-04-02 03:44:33 +00:00
|
|
|
|
|
|
|
_totalVertices = baseLevel.getNumVertices();
|
|
|
|
_totalEdges = baseLevel.getNumEdges();
|
|
|
|
_totalFaces = baseLevel.getNumFaces();
|
|
|
|
_totalFaceVertices = baseLevel.getNumFaceVerticesTotal();
|
|
|
|
|
|
|
|
_maxValence = baseLevel.getMaxValence();
|
|
|
|
} else {
|
|
|
|
_totalVertices = 0;
|
|
|
|
_totalEdges = 0;
|
|
|
|
_totalFaces = 0;
|
|
|
|
_totalFaceVertices = 0;
|
|
|
|
|
|
|
|
_maxValence = 0;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-02 03:44:33 +00:00
|
|
|
|
|
|
|
void
|
2015-05-26 03:34:50 +00:00
|
|
|
TopologyRefiner::updateInventory(Vtr::internal::Level const & newLevel) {
|
2015-04-02 03:44:33 +00:00
|
|
|
|
|
|
|
_totalVertices += newLevel.getNumVertices();
|
|
|
|
_totalEdges += newLevel.getNumEdges();
|
|
|
|
_totalFaces += newLevel.getNumFaces();
|
|
|
|
_totalFaceVertices += newLevel.getNumFaceVerticesTotal();
|
|
|
|
|
|
|
|
_maxValence = std::max(_maxValence, newLevel.getMaxValence());
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-04-02 03:44:33 +00:00
|
|
|
|
|
|
|
void
|
2015-05-26 03:34:50 +00:00
|
|
|
TopologyRefiner::appendLevel(Vtr::internal::Level & newLevel) {
|
2015-04-02 03:44:33 +00:00
|
|
|
|
|
|
|
_levels.push_back(&newLevel);
|
|
|
|
|
|
|
|
updateInventory(newLevel);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-04-02 03:44:33 +00:00
|
|
|
|
|
|
|
void
|
2015-05-26 03:34:50 +00:00
|
|
|
TopologyRefiner::appendRefinement(Vtr::internal::Refinement & newRefinement) {
|
2015-04-02 03:44:33 +00:00
|
|
|
|
|
|
|
_refinements.push_back(&newRefinement);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-04-02 03:44:33 +00:00
|
|
|
|
2015-05-19 22:06:41 +00:00
|
|
|
void
|
|
|
|
TopologyRefiner::assembleFarLevels() {
|
|
|
|
|
|
|
|
_farLevels.resize(_levels.size());
|
|
|
|
|
|
|
|
_farLevels[0]._refToParent = 0;
|
|
|
|
_farLevels[0]._level = _levels[0];
|
|
|
|
_farLevels[0]._refToChild = 0;
|
|
|
|
|
|
|
|
int nRefinements = (int)_refinements.size();
|
|
|
|
if (nRefinements) {
|
|
|
|
_farLevels[0]._refToChild = _refinements[0];
|
|
|
|
|
|
|
|
for (int i = 1; i < nRefinements; ++i) {
|
|
|
|
_farLevels[i]._refToParent = _refinements[i - 1];
|
|
|
|
_farLevels[i]._level = _levels[i];
|
|
|
|
_farLevels[i]._refToChild = _refinements[i];;
|
|
|
|
}
|
|
|
|
|
|
|
|
_farLevels[nRefinements]._refToParent = _refinements[nRefinements - 1];
|
|
|
|
_farLevels[nRefinements]._level = _levels[nRefinements];
|
|
|
|
_farLevels[nRefinements]._refToChild = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 03:44:33 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors to the topology information:
|
|
|
|
//
|
2014-09-05 22:07:46 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2015-04-10 04:08:26 +00:00
|
|
|
if (_levels[0]->getNumVertices() == 0) {
|
|
|
|
Error(FAR_RUNTIME_ERROR,
|
2015-07-31 19:47:49 +00:00
|
|
|
"Failure in TopologyRefiner::RefineUniform() -- base level is uninitialized.");
|
2015-04-10 04:08:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_refinements.size()) {
|
|
|
|
Error(FAR_RUNTIME_ERROR,
|
2015-07-31 19:47:49 +00:00
|
|
|
"Failure in TopologyRefiner::RefineUniform() -- previous refinements already applied.");
|
2015-04-10 04:08:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate the stack of levels and the refinements between them:
|
|
|
|
//
|
2015-04-02 03:44:33 +00:00
|
|
|
_uniformOptions = options;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_isUniform = true;
|
2014-12-30 22:07:24 +00:00
|
|
|
_maxLevel = options.refinementLevel;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 01:21:55 +00:00
|
|
|
Sdc::Split splitType = Sdc::SchemeTypeTraits::GetTopologicalSplitType(_subdivType);
|
2014-11-18 01:19:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Initialize refinement options for Vtr -- adjusting full-topology for the last level:
|
|
|
|
//
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Refinement::Options refineOptions;
|
2015-04-02 04:00:29 +00:00
|
|
|
refineOptions._sparse = false;
|
|
|
|
refineOptions._faceVertsFirst = options.orderVerticesFromFacesFirst;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-01-05 20:44:29 +00:00
|
|
|
for (int i = 1; i <= (int)options.refinementLevel; ++i) {
|
2015-04-02 03:44:33 +00:00
|
|
|
refineOptions._minimalTopology =
|
2015-06-26 05:24:56 +00:00
|
|
|
options.fullTopologyInLastLevel ? false : (i == (int)options.refinementLevel);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level& parentLevel = getLevel(i-1);
|
|
|
|
Vtr::internal::Level& childLevel = *(new Vtr::internal::Level);
|
2014-10-15 18:22:32 +00:00
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Refinement* refinement = 0;
|
2014-11-18 01:19:30 +00:00
|
|
|
if (splitType == Sdc::SPLIT_TO_QUADS) {
|
2015-05-26 03:34:50 +00:00
|
|
|
refinement = new Vtr::internal::QuadRefinement(parentLevel, childLevel, _subdivOptions);
|
2014-11-18 01:19:30 +00:00
|
|
|
} else {
|
2015-05-26 03:34:50 +00:00
|
|
|
refinement = new Vtr::internal::TriRefinement(parentLevel, childLevel, _subdivOptions);
|
2014-11-18 01:19:30 +00:00
|
|
|
}
|
|
|
|
refinement->refine(refineOptions);
|
2014-10-15 18:22:32 +00:00
|
|
|
|
2015-04-02 03:44:33 +00:00
|
|
|
appendLevel(childLevel);
|
|
|
|
appendRefinement(*refinement);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-05-19 22:06:41 +00:00
|
|
|
assembleFarLevels();
|
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
|
|
|
|
2015-04-10 04:08:26 +00:00
|
|
|
if (_levels[0]->getNumVertices() == 0) {
|
|
|
|
Error(FAR_RUNTIME_ERROR,
|
2015-07-31 19:47:49 +00:00
|
|
|
"Failure in TopologyRefiner::RefineAdaptive() -- base level is uninitialized.");
|
2015-04-10 04:08:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_refinements.size()) {
|
|
|
|
Error(FAR_RUNTIME_ERROR,
|
2015-07-31 19:47:49 +00:00
|
|
|
"Failure in TopologyRefiner::RefineAdaptive() -- previous refinements already applied.");
|
2015-04-10 04:08:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-02 01:21:55 +00:00
|
|
|
if (_subdivType != Sdc::SCHEME_CATMARK) {
|
|
|
|
Error(FAR_RUNTIME_ERROR,
|
2015-07-31 19:47:49 +00:00
|
|
|
"Failure in TopologyRefiner::RefineAdaptive() -- currently only supported for Catmark scheme.");
|
2015-06-02 01:21:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate the stack of levels and the refinements between them:
|
|
|
|
//
|
2015-04-02 03:44:33 +00:00
|
|
|
_adaptiveOptions = options;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
_isUniform = false;
|
2014-12-30 22:07:24 +00:00
|
|
|
_maxLevel = options.isolationLevel;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
2015-04-02 03:44:33 +00:00
|
|
|
// Initialize refinement options for Vtr -- full topology is always generated in
|
|
|
|
// the last level as expected usage is for patch retrieval:
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Refinement::Options refineOptions;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-04-02 04:00:29 +00:00
|
|
|
refineOptions._sparse = true;
|
|
|
|
refineOptions._minimalTopology = false;
|
|
|
|
refineOptions._faceVertsFirst = options.orderVerticesFromFacesFirst;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 01:21:55 +00:00
|
|
|
Sdc::Split splitType = Sdc::SchemeTypeTraits::GetTopologicalSplitType(_subdivType);
|
2014-11-18 01:19:30 +00:00
|
|
|
|
2015-01-05 20:44:29 +00:00
|
|
|
for (int i = 1; i <= (int)options.isolationLevel; ++i) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level& parentLevel = getLevel(i-1);
|
|
|
|
Vtr::internal::Level& childLevel = *(new Vtr::internal::Level);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Refinement* refinement = 0;
|
2014-11-18 01:19:30 +00:00
|
|
|
if (splitType == Sdc::SPLIT_TO_QUADS) {
|
2015-05-26 03:34:50 +00:00
|
|
|
refinement = new Vtr::internal::QuadRefinement(parentLevel, childLevel, _subdivOptions);
|
2014-11-18 01:19:30 +00:00
|
|
|
} else {
|
2015-05-26 03:34:50 +00:00
|
|
|
refinement = new Vtr::internal::TriRefinement(parentLevel, childLevel, _subdivOptions);
|
2014-11-18 01:19:30 +00:00
|
|
|
}
|
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.
|
|
|
|
//
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::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
|
|
|
|
2015-04-02 03:44:33 +00:00
|
|
|
appendLevel(childLevel);
|
|
|
|
appendRefinement(*refinement);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-05-19 22:06:41 +00:00
|
|
|
assembleFarLevels();
|
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
|
|
|
//
|
2015-05-26 03:34:50 +00:00
|
|
|
// It assumes we have a freshly initialized SparseSelector (i.e. nothing already selected)
|
2014-09-05 22:07:46 +00:00
|
|
|
// 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
|
2015-05-26 03:34:50 +00:00
|
|
|
TopologyRefiner::selectFeatureAdaptiveComponents(Vtr::internal::SparseSelector& selector) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level const& level = selector.getRefinement().parent();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-01 01:26:13 +00:00
|
|
|
int regularFaceSize = selector.getRefinement().getRegularFaceSize();
|
2015-04-02 03:44:33 +00:00
|
|
|
bool considerSingleCreasePatch = _adaptiveOptions.useSingleCreasePatch && (regularFaceSize == 4);
|
2014-11-18 01:19:30 +00:00
|
|
|
|
2015-02-10 01:41:19 +00:00
|
|
|
//
|
|
|
|
// Face-varying consideration when isolating features:
|
|
|
|
// - there must obviously be face-varying channels for any consideration
|
|
|
|
// - we can ignore all purely linear face-varying channels -- a common case that
|
|
|
|
// will allow us to avoid the repeated per-face inspection of FVar data
|
|
|
|
// - may allow a subset of face-varying channels to be considered in future:
|
|
|
|
//
|
|
|
|
// Note that some of this consideration can be given at the highest level and then
|
|
|
|
// reflected potentially in the Selector, e.g. when all FVar channels are linear,
|
|
|
|
// any request to inspect them can be overridden for all levels and not repeatedly
|
|
|
|
// reassessed here for each level.
|
|
|
|
//
|
|
|
|
int numFVarChannels = level.getNumFVarChannels();
|
2015-05-01 02:37:53 +00:00
|
|
|
bool considerFVarChannels = false;
|
2015-02-10 01:41:19 +00:00
|
|
|
|
|
|
|
if (considerFVarChannels) {
|
|
|
|
considerFVarChannels = false;
|
|
|
|
|
|
|
|
for (int channel = 0; channel < numFVarChannels; ++channel) {
|
2015-06-01 01:26:13 +00:00
|
|
|
if (not level.getFVarLevel(channel).isLinear()) {
|
2015-02-10 01:41:19 +00:00
|
|
|
considerFVarChannels = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Inspect each face and the properties tagged at all of its corners:
|
|
|
|
//
|
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
|
|
|
|
2015-04-02 03:44:33 +00:00
|
|
|
if (level.isFaceHole(face)) {
|
2014-10-24 20:52:40 +00:00
|
|
|
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.):
|
|
|
|
//
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level::VTag compFaceVTag = level.getFaceCompositeVTag(faceVerts);
|
2014-12-20 02:18:13 +00:00
|
|
|
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._nonManifold) {
|
2015-02-08 23:20:46 +00:00
|
|
|
// Warrants further inspection in future -- isolate for now
|
2014-09-24 01:24:29 +00:00
|
|
|
// - will want to defer inf-sharp treatment to below
|
|
|
|
selectFace = true;
|
2015-02-08 23:20:46 +00:00
|
|
|
} else if (compFaceVTag._rule == Sdc::Crease::RULE_SMOOTH) {
|
|
|
|
// Avoid isolation when ALL vertices are Smooth. All vertices must be regular by
|
|
|
|
// now and all vertices Smooth implies they are all interior vertices. (If any
|
|
|
|
// adjacent faces are not regular, this face will have been previously selected).
|
|
|
|
selectFace = false;
|
|
|
|
} else if (compFaceVTag._rule & Sdc::Crease::RULE_DART) {
|
|
|
|
// Any occurrence of a Dart vertex requires isolation
|
|
|
|
selectFace = true;
|
|
|
|
} else if (not (compFaceVTag._rule & Sdc::Crease::RULE_SMOOTH)) {
|
|
|
|
// 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, i.e. with one or more
|
|
|
|
// smooth interior vertices.
|
2014-09-24 01:24:29 +00:00
|
|
|
selectFace = true;
|
2015-02-26 04:02:10 +00:00
|
|
|
} else if (compFaceVTag._semiSharp || compFaceVTag._semiSharpEdges) {
|
2015-02-08 23:20:46 +00:00
|
|
|
// Any semi-sharp feature at or around the vertex warrants isolation -- unless we
|
|
|
|
// optimize for the single-crease patch, i.e. only edge sharpness of a constant value
|
|
|
|
// along the entire regular patch boundary (quickly exclude the Corner case first):
|
|
|
|
if (considerSingleCreasePatch && not (compFaceVTag._rule & Sdc::Crease::RULE_CORNER)) {
|
2014-12-20 02:18:13 +00:00
|
|
|
selectFace = not level.isSingleCreasePatch(face);
|
2014-10-13 15:52:09 +00:00
|
|
|
} else {
|
|
|
|
selectFace = true;
|
|
|
|
}
|
2015-02-08 23:20:46 +00:00
|
|
|
} else if (not compFaceVTag._boundary) {
|
|
|
|
// At this point we are left with a mix of smooth and inf-sharp features. If not
|
|
|
|
// on a boundary, the interior inf-sharp features need isolation -- unless we are
|
|
|
|
// again optimizing for the single-crease patch, infinitely sharp in this case.
|
2014-09-24 01:24:29 +00:00
|
|
|
//
|
2015-02-08 23:20:46 +00:00
|
|
|
// Note this case of detecting a single-crease patch, while similar to the above,
|
|
|
|
// is kept separate for the inf-sharp case: a separate and much more efficient
|
|
|
|
// test can be made for the inf-sharp case, and there are other opportunities here
|
|
|
|
// to optimize for regular patches at infinitely sharp corners.
|
|
|
|
if (considerSingleCreasePatch && not (compFaceVTag._rule & Sdc::Crease::RULE_CORNER)) {
|
|
|
|
selectFace = not level.isSingleCreasePatch(face);
|
|
|
|
} else {
|
|
|
|
selectFace = true;
|
|
|
|
}
|
|
|
|
} else if (not (compFaceVTag._rule & Sdc::Crease::RULE_CORNER)) {
|
|
|
|
// We are now left with boundary faces -- if no Corner vertex, we have a mix of both
|
|
|
|
// regular Smooth and Crease vertices on a boundary face, which can only be a regular
|
|
|
|
// boundary patch, so don't isolate.
|
|
|
|
selectFace = false;
|
|
|
|
} else {
|
2015-02-26 04:02:10 +00:00
|
|
|
// The last case with at least one Corner vertex and one Smooth (interior) vertex --
|
|
|
|
// distinguish the regular corner case from others:
|
|
|
|
if (not compFaceVTag._corner) {
|
|
|
|
// We may consider interior sharp corners as regular in future, but for now we
|
|
|
|
// only accept a topological corner for the regular corner case:
|
|
|
|
selectFace = true;
|
|
|
|
} else if (level.getDepth() > 0) {
|
|
|
|
// A true corner at a subdivided level -- adjacent verts must be Crease and the
|
|
|
|
// opposite Smooth so we must have a regular corner:
|
|
|
|
selectFace = false;
|
|
|
|
} else {
|
|
|
|
// Make sure the adjacent boundary vertices were not sharpened, or equivalently,
|
|
|
|
// that only one corner is sharp:
|
2015-06-01 01:26:13 +00:00
|
|
|
unsigned int infSharpCount = level.getVertexTag(faceVerts[0])._infSharp;
|
2015-02-26 04:02:10 +00:00
|
|
|
for (int i = 1; i < faceVerts.size(); ++i) {
|
2015-06-01 01:26:13 +00:00
|
|
|
infSharpCount += level.getVertexTag(faceVerts[i])._infSharp;
|
2015-02-26 04:02:10 +00:00
|
|
|
}
|
|
|
|
selectFace = (infSharpCount != 1);
|
2014-12-20 02:18:13 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2014-12-20 02:18:13 +00:00
|
|
|
|
2015-02-10 01:41:19 +00:00
|
|
|
//
|
2015-02-12 04:51:00 +00:00
|
|
|
// If still not selected, inspect the face-varying channels (when present) for similar
|
|
|
|
// irregular features requiring isolation:
|
2015-02-10 01:41:19 +00:00
|
|
|
//
|
|
|
|
if (not selectFace and considerFVarChannels) {
|
2015-02-12 04:51:00 +00:00
|
|
|
for (int channel = 0; not selectFace && (channel < numFVarChannels); ++channel) {
|
2015-06-01 01:26:13 +00:00
|
|
|
Vtr::internal::FVarLevel const & fvarLevel = level.getFVarLevel(channel);
|
2015-02-10 01:41:19 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Retrieve the counterpart to the face-vertices composite tag for the face-values
|
|
|
|
// for this channel. We can make some quick accept/reject tests but eventually we
|
|
|
|
// will need to combine the face-vertex and face-varying topology to determine the
|
|
|
|
// regularity of faces along face-varying boundaries.
|
|
|
|
//
|
|
|
|
Vtr::ConstIndexArray faceValues = fvarLevel.getFaceValues(face);
|
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::FVarLevel::ValueTag compFVarFaceTag =
|
2015-02-25 03:57:56 +00:00
|
|
|
fvarLevel.getFaceCompositeValueTag(faceValues, faceVerts);
|
2015-02-10 01:41:19 +00:00
|
|
|
|
|
|
|
// No mismatch in topology -> no need to further isolate...
|
|
|
|
if (not compFVarFaceTag._mismatch) continue;
|
|
|
|
|
|
|
|
if (compFVarFaceTag._xordinary) {
|
|
|
|
// An xordinary boundary value always requires isolation:
|
|
|
|
selectFace = true;
|
|
|
|
} else {
|
2015-02-12 04:51:00 +00:00
|
|
|
// Combine the FVar topology tags (ValueTags) at corners with the vertex topology
|
|
|
|
// tags (VTags), then make similar inferences from the combined tags as was done
|
|
|
|
// for the face.
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level::VTag fvarVTags[4];
|
|
|
|
Vtr::internal::Level::VTag compFVarVTag =
|
2015-02-25 03:57:56 +00:00
|
|
|
fvarLevel.getFaceCompositeValueAndVTag(faceValues, faceVerts, fvarVTags);
|
2015-02-12 04:51:00 +00:00
|
|
|
|
|
|
|
if (not (compFVarVTag._rule & Sdc::Crease::RULE_SMOOTH)) {
|
|
|
|
// No Smooth corners so too many boundaries/corners -- need to isolate:
|
|
|
|
selectFace = true;
|
|
|
|
} else if (not (compFVarVTag._rule & Sdc::Crease::RULE_CORNER)) {
|
|
|
|
// A mix of Smooth and Crease corners -- must be regular so don't isolate:
|
|
|
|
selectFace = false;
|
|
|
|
} else {
|
|
|
|
// Since FVar boundaries can be "sharpened" based on the linear interpolation
|
|
|
|
// rules, we again have to inspect more closely (as we did with the original
|
|
|
|
// face) to ensure we have a regular corner and not a sharpened crease:
|
|
|
|
unsigned int boundaryCount = fvarVTags[0]._boundary,
|
|
|
|
infSharpCount = fvarVTags[0]._infSharp;
|
|
|
|
for (int i = 1; i < faceVerts.size(); ++i) {
|
|
|
|
boundaryCount += fvarVTags[i]._boundary;
|
|
|
|
infSharpCount += fvarVTags[i]._infSharp;
|
|
|
|
}
|
|
|
|
selectFace = (boundaryCount != 3) || (infSharpCount != 1);
|
2015-02-26 01:35:48 +00:00
|
|
|
|
|
|
|
// There is a possibility of a false positive at level 0 -- Smooth interior
|
|
|
|
// vertex with adjacent Corner and two opposite boundary Crease vertices
|
|
|
|
// (the topological corner tag catches this above). Verify that the corner
|
|
|
|
// vertex is opposite the smooth vertex (and consider doing this above)...
|
|
|
|
//
|
|
|
|
if (not selectFace && (level.getDepth() == 0)) {
|
|
|
|
if (fvarVTags[0]._infSharp && fvarVTags[2]._boundary) selectFace = true;
|
|
|
|
if (fvarVTags[1]._infSharp && fvarVTags[3]._boundary) selectFace = true;
|
|
|
|
if (fvarVTags[2]._infSharp && fvarVTags[0]._boundary) selectFace = true;
|
|
|
|
if (fvarVTags[3]._infSharp && fvarVTags[1]._boundary) selectFace = true;
|
|
|
|
}
|
2015-02-12 04:51:00 +00:00
|
|
|
}
|
2015-02-10 01:41:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, select the face for further refinement:
|
2014-09-05 22:07:46 +00:00
|
|
|
if (selectFace) {
|
|
|
|
selector.selectFace(face);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace Far
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|