2014-09-05 22:07:46 +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/patchTableFactory.h"
|
2015-04-18 00:36:55 +00:00
|
|
|
#include "../far/error.h"
|
2015-04-20 06:25:43 +00:00
|
|
|
#include "../far/ptexIndices.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#include "../far/topologyRefiner.h"
|
|
|
|
#include "../vtr/level.h"
|
2015-06-01 07:14:19 +00:00
|
|
|
#include "../vtr/fvarLevel.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#include "../vtr/refinement.h"
|
2016-07-22 01:47:44 +00:00
|
|
|
#include "../vtr/stackBuffer.h"
|
2015-04-23 23:58:45 +00:00
|
|
|
#include "../far/endCapBSplineBasisPatchFactory.h"
|
|
|
|
#include "../far/endCapGregoryBasisPatchFactory.h"
|
|
|
|
#include "../far/endCapLegacyGregoryPatchFactory.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 18:48:37 +00:00
|
|
|
#include <algorithm>
|
2014-09-05 22:07:46 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
2016-09-03 03:53:24 +00:00
|
|
|
namespace Far {
|
|
|
|
|
|
|
|
using Vtr::internal::Refinement;
|
|
|
|
using Vtr::internal::Level;
|
|
|
|
using Vtr::internal::FVarLevel;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
namespace {
|
2015-07-10 23:54:12 +00:00
|
|
|
|
2015-07-21 00:56:00 +00:00
|
|
|
// Helpers for compiler warnings and floating point equality tests
|
|
|
|
#ifdef __INTEL_COMPILER
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning disable 1572
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline bool isSharpnessEqual(float s1, float s2) { return (s1 == s2); }
|
|
|
|
|
|
|
|
#ifdef __INTEL_COMPILER
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
//
|
|
|
|
// Local helper functions for identifying the subset of a ring around a
|
2016-09-09 04:18:11 +00:00
|
|
|
// corner that contributes to a patch -- parameterized by a mask that
|
|
|
|
// indicates what kind of edge is to delimit the span.
|
2016-09-03 03:53:24 +00:00
|
|
|
//
|
2016-09-09 04:18:11 +00:00
|
|
|
// Note that the two main methods need both face-verts and face-edges for
|
|
|
|
// each corner, and that we don't really need the face-index once we have
|
2016-09-03 03:53:24 +00:00
|
|
|
// them -- consider passing the fVerts and fEdges as arguments as they
|
|
|
|
// will otherwise be retrieved repeatedly for each corner.
|
|
|
|
//
|
2016-09-09 04:18:11 +00:00
|
|
|
// (As these mature it is likely they will be moved to Vtr, as a method
|
|
|
|
// to identify a VSpan would complement the existing method to gather
|
|
|
|
// the vertex/values associated with it. The manifold vs non-manifold
|
|
|
|
// choice would then also be encapsulated -- provided both remain free
|
|
|
|
// of PatchTable-specific logic.)
|
|
|
|
//
|
|
|
|
inline Level::ETag
|
|
|
|
getSingularEdgeMask(bool includeAllInfSharpEdges = false) {
|
|
|
|
|
|
|
|
Level::ETag eTagMask;
|
|
|
|
eTagMask.clear();
|
|
|
|
eTagMask._boundary = true;
|
|
|
|
eTagMask._nonManifold = true;
|
|
|
|
eTagMask._infSharp = includeAllInfSharpEdges;
|
|
|
|
return eTagMask;
|
|
|
|
}
|
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
inline bool
|
|
|
|
isEdgeSingular(Level const & level, FVarLevel const * fvarLevel, Index eIndex,
|
|
|
|
Level::ETag eTagMask)
|
|
|
|
{
|
|
|
|
Level::ETag eTag = level.getEdgeTag(eIndex);
|
|
|
|
if (fvarLevel) {
|
|
|
|
eTag = fvarLevel->getEdgeTag(eIndex).combineWithLevelETag(eTag);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Level::ETag::ETagSize * iTag = reinterpret_cast<Level::ETag::ETagSize*>(&eTag);
|
|
|
|
Level::ETag::ETagSize * iMask = reinterpret_cast<Level::ETag::ETagSize*>(&eTagMask);
|
|
|
|
return (*iTag & *iMask) > 0;
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-03 03:53:24 +00:00
|
|
|
identifyManifoldCornerSpan(Level const & level, Index fIndex,
|
|
|
|
int fCorner, Level::ETag eTagMask,
|
|
|
|
Level::VSpan & vSpan, int fvc = -1)
|
|
|
|
{
|
|
|
|
FVarLevel const * fvarLevel = (fvc < 0) ? 0 : &level.getFVarLevel(fvc);
|
|
|
|
|
|
|
|
ConstIndexArray fVerts = level.getFaceVertices(fIndex);
|
|
|
|
ConstIndexArray fEdges = level.getFaceEdges(fIndex);
|
|
|
|
|
|
|
|
ConstIndexArray vEdges = level.getVertexEdges(fVerts[fCorner]);
|
|
|
|
int nEdges = vEdges.size();
|
|
|
|
|
|
|
|
int iLeadingStart = vEdges.FindIndex(fEdges[fCorner]);
|
|
|
|
int iTrailingStart = (iLeadingStart + 1) % nEdges;
|
|
|
|
|
2016-09-19 21:18:51 +00:00
|
|
|
vSpan.clear();
|
2016-09-03 03:53:24 +00:00
|
|
|
vSpan._numFaces = 1;
|
|
|
|
|
|
|
|
int iLeading = iLeadingStart;
|
|
|
|
while (! isEdgeSingular(level, fvarLevel, vEdges[iLeading], eTagMask)) {
|
|
|
|
++vSpan._numFaces;
|
|
|
|
iLeading = (iLeading + nEdges - 1) % nEdges;
|
|
|
|
if (iLeading == iTrailingStart) break;
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
2016-09-03 03:53:24 +00:00
|
|
|
|
|
|
|
int iTrailing = iTrailingStart;
|
|
|
|
while (! isEdgeSingular(level, fvarLevel, vEdges[iTrailing], eTagMask)) {
|
|
|
|
++vSpan._numFaces;
|
|
|
|
iTrailing = (iTrailing + 1) % nEdges;
|
|
|
|
if (iTrailing == iLeadingStart) break;
|
|
|
|
}
|
2016-09-19 21:18:51 +00:00
|
|
|
vSpan._startFace = (LocalIndex) iLeading;
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
void
|
2016-09-03 03:53:24 +00:00
|
|
|
identifyNonManifoldCornerSpan(Level const & level, Index fIndex,
|
|
|
|
int fCorner, Level::ETag /* eTagMask */,
|
|
|
|
Level::VSpan & vSpan, int /* fvc */ = -1)
|
|
|
|
{
|
|
|
|
// For now, non-manifold patches revert to regular patches -- just identify
|
2016-09-19 21:18:51 +00:00
|
|
|
// the single face now for a sharp corner patch.
|
|
|
|
//
|
|
|
|
// Remember that the face may be incident the vertex multiple times when
|
|
|
|
// non-manifold, so make sure the local index of the corner vertex in the
|
|
|
|
// face identified additionally matches the corner.
|
2015-04-18 00:36:55 +00:00
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
//FVarLevel const * fvarLevel = (fvc < 0) ? 0 : &level.getFVarChannel(fvc);
|
|
|
|
|
2016-09-19 21:18:51 +00:00
|
|
|
Index vIndex = level.getFaceVertices(fIndex)[fCorner];
|
2016-09-03 03:53:24 +00:00
|
|
|
|
2016-09-19 21:18:51 +00:00
|
|
|
ConstIndexArray vFaces = level.getVertexFaces(vIndex);
|
|
|
|
ConstLocalIndexArray vInFace = level.getVertexFaceLocalIndices(vIndex);
|
2016-09-03 03:53:24 +00:00
|
|
|
|
2016-09-19 21:18:51 +00:00
|
|
|
vSpan.clear();
|
|
|
|
for (int i = 0; i < vFaces.size(); ++i) {
|
|
|
|
if ((vFaces[i] == fIndex) && ((int)vInFace[i] == fCorner)) {
|
|
|
|
vSpan._startFace = (LocalIndex) i;
|
|
|
|
vSpan._numFaces = 1;
|
|
|
|
vSpan._sharp = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(vSpan._numFaces == 1);
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
// Additional anonymous helper functions:
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-04-18 00:36:55 +00:00
|
|
|
static inline void
|
2015-02-26 21:57:47 +00:00
|
|
|
offsetAndPermuteIndices(Far::Index const indices[], int count,
|
|
|
|
Far::Index offset, int const permutation[],
|
|
|
|
Far::Index result[]) {
|
|
|
|
|
2015-04-24 20:18:03 +00:00
|
|
|
// The patch vertices for boundary and corner patches
|
|
|
|
// are assigned index values even though indices will
|
|
|
|
// be undefined along boundary and corner edges.
|
2015-05-22 18:50:01 +00:00
|
|
|
// When the resulting patch table is going to be used
|
2015-04-24 20:18:03 +00:00
|
|
|
// as indices for drawing, it is convenient for invalid
|
|
|
|
// indices to be replaced with known good values, such
|
|
|
|
// as the first un-permuted index, which is the index
|
|
|
|
// of the first vertex of the patch face.
|
|
|
|
Far::Index knownGoodIndex = indices[0];
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
if (permutation) {
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2015-04-27 19:40:18 +00:00
|
|
|
if (permutation[i] < 0) {
|
|
|
|
result[i] = offset + knownGoodIndex;
|
|
|
|
} else {
|
|
|
|
result[i] = offset + indices[permutation[i]];
|
2015-04-17 14:42:53 +00:00
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2015-04-27 19:40:18 +00:00
|
|
|
} else if (offset) {
|
2015-02-26 21:57:47 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
2015-04-27 19:40:18 +00:00
|
|
|
result[i] = offset + indices[i];
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2015-04-27 19:40:18 +00:00
|
|
|
} else {
|
|
|
|
std::memcpy(result, indices, count * sizeof(Far::Index));
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
inline int
|
|
|
|
assignSharpnessIndex(float sharpness, std::vector<float> & sharpnessValues) {
|
|
|
|
|
|
|
|
// linear search
|
|
|
|
for (int i=0; i<(int)sharpnessValues.size(); ++i) {
|
|
|
|
if (isSharpnessEqual(sharpnessValues[i], sharpness)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sharpnessValues.push_back(sharpness);
|
|
|
|
return (int)sharpnessValues.size()-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
// Builder Context
|
2015-02-26 21:57:47 +00:00
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
// Helper class aggregating transient contextual data structures during
|
|
|
|
// the creation of a patch table.
|
|
|
|
// This helps keeping the factory class stateless.
|
2015-02-26 21:57:47 +00:00
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
// Note : struct members are not re-entrant nor are they intended to be !
|
|
|
|
//
|
|
|
|
struct PatchTableFactory::BuilderContext {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
public:
|
2016-09-03 03:53:24 +00:00
|
|
|
// Simple struct to store <level,face> (and more?) info for a patch:
|
2016-07-22 01:47:44 +00:00
|
|
|
struct PatchTuple {
|
|
|
|
PatchTuple()
|
2016-09-03 03:53:24 +00:00
|
|
|
: faceIndex(Vtr::INDEX_INVALID), levelIndex(-1) { }
|
2016-07-22 01:47:44 +00:00
|
|
|
PatchTuple(PatchTuple const & p)
|
2016-09-03 03:53:24 +00:00
|
|
|
: faceIndex(p.faceIndex), levelIndex(p.levelIndex) { }
|
2017-04-20 01:48:15 +00:00
|
|
|
PatchTuple(Index faceIndexArg, int levelIndexArg)
|
|
|
|
: faceIndex(faceIndexArg), levelIndex(levelIndexArg) { }
|
2016-07-22 01:47:44 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Index faceIndex;
|
|
|
|
int levelIndex;
|
2016-07-22 01:47:44 +00:00
|
|
|
};
|
2016-08-06 02:00:51 +00:00
|
|
|
typedef std::vector<PatchTuple> PatchTupleVector;
|
2016-07-22 01:47:44 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
public:
|
|
|
|
BuilderContext(TopologyRefiner const & refiner, Options options);
|
|
|
|
|
|
|
|
// Methods to query patch properties for classification and construction.
|
|
|
|
bool IsPatchEligible(int levelIndex, Index faceIndex) const;
|
|
|
|
|
2016-10-12 20:08:35 +00:00
|
|
|
bool IsPatchSmoothCorner(int levelIndex, Index faceIndex,
|
|
|
|
int fvcFactory = -1) const;
|
2016-09-03 03:53:24 +00:00
|
|
|
|
|
|
|
bool IsPatchRegular(int levelIndex, Index faceIndex,
|
|
|
|
int fvcFactory = -1) const;
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
int GetRegularPatchBoundaryMask(int levelIndex, Index faceIndex,
|
|
|
|
int fvcFactory = -1) const;
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
void GetIrregularPatchCornerSpans(int levelIndex, Index faceIndex,
|
|
|
|
Level::VSpan cornerSpans[4],
|
|
|
|
int fvcFactory = -1) const;
|
2016-07-22 01:47:44 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Methods to gather points associated with the different patch types
|
|
|
|
int GatherLinearPatchPoints(Index * iptrs,
|
|
|
|
PatchTuple const & patch,
|
|
|
|
int fvcFactory = -1) const;
|
|
|
|
int GatherRegularPatchPoints(Index * iptrs,
|
|
|
|
PatchTuple const & patch,
|
|
|
|
int boundaryMask,
|
|
|
|
int fvcFactory = -1) const;
|
|
|
|
template <class END_CAP_FACTORY_TYPE>
|
|
|
|
int GatherIrregularPatchPoints(END_CAP_FACTORY_TYPE *endCapFactory,
|
|
|
|
Index * iptrs,
|
|
|
|
PatchTuple const & patch,
|
|
|
|
Level::VSpan cornerSpans[4],
|
|
|
|
int fvcFactory = -1) const;
|
|
|
|
|
|
|
|
// Additional simple queries -- most regarding face-varying channels that hide
|
|
|
|
// the mapping between channels in the source Refiner and corresponding channels
|
|
|
|
// in the Factory and PatchTable
|
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
// True if face-varying patches need to be generated for this topology
|
|
|
|
bool RequiresFVarPatches() const {
|
|
|
|
return (! fvarChannelIndices.empty());
|
|
|
|
}
|
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
int GetRefinerFVarChannel(int fvcFactory) const {
|
|
|
|
return (fvcFactory >= 0) ? fvarChannelIndices[fvcFactory] : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DoesFaceVaryingPatchMatch(int levelIndex, Index faceIndex, int fvcFactory) const {
|
|
|
|
return refiner.getLevel(levelIndex).doesFaceFVarTopologyMatch(faceIndex,
|
|
|
|
GetRefinerFVarChannel(fvcFactory));
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetDistinctRefinerFVarChannel(int levelIndex, int faceIndex, int fvcFactory) const {
|
|
|
|
return ((fvcFactory >= 0) &&
|
|
|
|
!DoesFaceVaryingPatchMatch(levelIndex, faceIndex, fvcFactory)) ?
|
|
|
|
GetRefinerFVarChannel(fvcFactory) : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetTransitionMask(int levelIndex, Index faceIndex) const {
|
|
|
|
return (levelIndex == refiner.GetMaxLevel()) ? 0 :
|
|
|
|
refiner.getRefinement(levelIndex).
|
|
|
|
getParentFaceSparseTag(faceIndex)._transitional;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
TopologyRefiner const & refiner;
|
|
|
|
|
|
|
|
Options const options;
|
|
|
|
|
|
|
|
PtexIndices const ptexIndices;
|
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
// Counters accumulating each type of patch during topology traversal
|
|
|
|
int numRegularPatches;
|
|
|
|
int numIrregularPatches;
|
|
|
|
int numIrregularBoundaryPatches;
|
|
|
|
|
|
|
|
// Tuple for each patch identified during topology traversal
|
2016-08-06 02:00:51 +00:00
|
|
|
PatchTupleVector patches;
|
2016-07-22 01:47:44 +00:00
|
|
|
|
|
|
|
std::vector<int> levelVertOffsets;
|
|
|
|
std::vector< std::vector<int> > levelFVarValueOffsets;
|
|
|
|
|
|
|
|
// These are the indices of face-varying channels in the refiner
|
|
|
|
// or empty if we are not populating face-varying data.
|
|
|
|
std::vector<int> fvarChannelIndices;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
PatchTableFactory::BuilderContext::BuilderContext(
|
|
|
|
TopologyRefiner const & ref, Options opts) :
|
|
|
|
refiner(ref), options(opts), ptexIndices(refiner),
|
|
|
|
numRegularPatches(0), numIrregularPatches(0),
|
|
|
|
numIrregularBoundaryPatches(0) {
|
|
|
|
|
|
|
|
if (options.generateFVarTables) {
|
|
|
|
// If client-code does not select specific channels, default to all
|
|
|
|
// the channels in the refiner.
|
|
|
|
if (options.numFVarChannels==-1) {
|
|
|
|
fvarChannelIndices.resize(refiner.GetNumFVarChannels());
|
|
|
|
for (int fvc=0;fvc<(int)fvarChannelIndices.size(); ++fvc) {
|
|
|
|
fvarChannelIndices[fvc] = fvc; // std::iota
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-07-22 01:47:44 +00:00
|
|
|
fvarChannelIndices.assign(
|
|
|
|
options.fvarChannelIndices,
|
|
|
|
options.fvarChannelIndices+options.numFVarChannels);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-22 01:47:44 +00:00
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
int
|
2016-09-03 03:53:24 +00:00
|
|
|
PatchTableFactory::BuilderContext::GatherLinearPatchPoints(
|
|
|
|
Index * iptrs, PatchTuple const & patch, int fvcFactory) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Level const & level = refiner.getLevel(patch.levelIndex);
|
|
|
|
|
|
|
|
int levelVertOffset = (fvcFactory < 0)
|
2016-07-22 01:47:44 +00:00
|
|
|
? levelVertOffsets[patch.levelIndex]
|
2016-09-03 03:53:24 +00:00
|
|
|
: levelFVarValueOffsets[fvcFactory][patch.levelIndex];
|
|
|
|
|
|
|
|
int fvcRefiner = GetRefinerFVarChannel(fvcFactory);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
ConstIndexArray cvs = (fvcRefiner < 0)
|
|
|
|
? level.getFaceVertices(patch.faceIndex)
|
|
|
|
: level.getFaceFVarValues(patch.faceIndex, fvcRefiner);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
for (int i = 0; i < cvs.size(); ++i) iptrs[i] = levelVertOffset + cvs[i];
|
|
|
|
return cvs.size();
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
int
|
2016-09-03 03:53:24 +00:00
|
|
|
PatchTableFactory::BuilderContext::GatherRegularPatchPoints(
|
|
|
|
Index * iptrs, PatchTuple const & patch, int boundaryMask,
|
|
|
|
int fvcFactory) const {
|
2016-07-22 01:47:44 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Level const & level = refiner.getLevel(patch.levelIndex);
|
|
|
|
|
|
|
|
int levelVertOffset = (fvcFactory < 0)
|
2016-07-22 01:47:44 +00:00
|
|
|
? levelVertOffsets[patch.levelIndex]
|
2016-09-03 03:53:24 +00:00
|
|
|
: levelFVarValueOffsets[fvcFactory][patch.levelIndex];
|
|
|
|
|
|
|
|
int fvcRefiner = GetRefinerFVarChannel(fvcFactory);
|
2016-07-22 01:47:44 +00:00
|
|
|
|
|
|
|
Index patchVerts[16];
|
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
int bType = 0;
|
|
|
|
int bIndex = 0;
|
|
|
|
if (boundaryMask) {
|
|
|
|
static int const boundaryEdgeMaskToType[16] =
|
|
|
|
{ 0, 1, 1, 2, 1, -1, 2, -1, 1, 2, -1, -1, 2, -1, -1, -1 };
|
|
|
|
static int const boundaryEdgeMaskToFeature[16] =
|
|
|
|
{ -1, 0, 1, 1, 2, -1, 2, -1, 3, 0, -1, -1, 3, -1, -1,-1 };
|
|
|
|
|
|
|
|
bType = boundaryEdgeMaskToType[boundaryMask];
|
|
|
|
bIndex = boundaryEdgeMaskToFeature[boundaryMask];
|
|
|
|
}
|
2016-07-22 01:47:44 +00:00
|
|
|
|
|
|
|
int const * permutation = 0;
|
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
if (bType == 0) {
|
2016-07-22 01:47:44 +00:00
|
|
|
static int const permuteRegular[16] =
|
|
|
|
{ 5, 6, 7, 8, 4, 0, 1, 9, 15, 3, 2, 10, 14, 13, 12, 11 };
|
|
|
|
permutation = permuteRegular;
|
2016-09-03 03:53:24 +00:00
|
|
|
level.gatherQuadRegularInteriorPatchPoints(
|
|
|
|
patch.faceIndex, patchVerts, /*rotation=*/0, fvcRefiner);
|
|
|
|
} else if (bType == 1) {
|
2016-07-22 01:47:44 +00:00
|
|
|
// Expand boundary patch vertices and rotate to
|
|
|
|
// restore correct orientation.
|
|
|
|
static int const permuteBoundary[4][16] = {
|
|
|
|
{ -1, -1, -1, -1, 11, 3, 0, 4, 10, 2, 1, 5, 9, 8, 7, 6 },
|
|
|
|
{ 9, 10, 11, -1, 8, 2, 3, -1, 7, 1, 0, -1, 6, 5, 4, -1 },
|
|
|
|
{ 6, 7, 8, 9, 5, 1, 2, 10, 4, 0, 3, 11, -1, -1, -1, -1 },
|
|
|
|
{ -1, 4, 5, 6, -1, 0, 1, 7, -1, 3, 2, 8, -1, 11, 10, 9 } };
|
|
|
|
permutation = permuteBoundary[bIndex];
|
2016-09-03 03:53:24 +00:00
|
|
|
level.gatherQuadRegularBoundaryPatchPoints(
|
|
|
|
patch.faceIndex, patchVerts, bIndex, fvcRefiner);
|
|
|
|
} else if (bType == 2) {
|
2016-07-22 01:47:44 +00:00
|
|
|
// Expand corner patch vertices and rotate to
|
|
|
|
// restore correct orientation.
|
|
|
|
static int const permuteCorner[4][16] = {
|
|
|
|
{ -1, -1, -1, -1, -1, 0, 1, 4, -1, 3, 2, 5, -1, 8, 7, 6 },
|
|
|
|
{ -1, -1, -1, -1, 8, 3, 0, -1, 7, 2, 1, -1, 6, 5, 4, -1 },
|
|
|
|
{ 6, 7, 8, -1, 5, 2, 3, -1, 4, 1, 0, -1, -1, -1, -1, -1 },
|
|
|
|
{ -1, 4, 5, 6, -1, 1, 2, 7, -1, 0, 3, 8, -1, -1, -1, -1 } };
|
|
|
|
permutation = permuteCorner[bIndex];
|
2016-09-03 03:53:24 +00:00
|
|
|
level.gatherQuadRegularCornerPatchPoints(
|
|
|
|
patch.faceIndex, patchVerts, bIndex, fvcRefiner);
|
2016-07-22 01:47:44 +00:00
|
|
|
} else {
|
2016-09-03 03:53:24 +00:00
|
|
|
assert(bType <= 2);
|
2016-07-22 01:47:44 +00:00
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
offsetAndPermuteIndices( patchVerts, 16, levelVertOffset, permutation, iptrs);
|
2016-07-22 01:47:44 +00:00
|
|
|
return 16;
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
template <class END_CAP_FACTORY_TYPE>
|
|
|
|
int
|
2016-09-03 03:53:24 +00:00
|
|
|
PatchTableFactory::BuilderContext::GatherIrregularPatchPoints(
|
2016-07-22 01:47:44 +00:00
|
|
|
END_CAP_FACTORY_TYPE *endCapFactory,
|
2016-08-19 00:21:59 +00:00
|
|
|
Index * iptrs, PatchTuple const & patch,
|
2016-09-03 03:53:24 +00:00
|
|
|
Level::VSpan cornerSpans[4],
|
|
|
|
int fvcFactory) const {
|
2016-07-22 01:47:44 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Level const & level = refiner.getLevel(patch.levelIndex);
|
|
|
|
|
|
|
|
int levelVertOffset = (fvcFactory < 0)
|
2016-07-22 01:47:44 +00:00
|
|
|
? levelVertOffsets[patch.levelIndex]
|
2016-09-03 03:53:24 +00:00
|
|
|
: levelFVarValueOffsets[fvcFactory][patch.levelIndex];
|
|
|
|
|
|
|
|
int fvcRefiner = GetRefinerFVarChannel(fvcFactory);
|
2016-07-22 01:47:44 +00:00
|
|
|
|
|
|
|
ConstIndexArray cvs = endCapFactory->GetPatchPoints(
|
2016-09-03 03:53:24 +00:00
|
|
|
&level, patch.faceIndex, cornerSpans, levelVertOffset, fvcRefiner);
|
2016-07-22 01:47:44 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < cvs.size(); ++i) iptrs[i] = cvs[i];
|
|
|
|
return cvs.size();
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
bool
|
2016-09-03 03:53:24 +00:00
|
|
|
PatchTableFactory::BuilderContext::IsPatchEligible(
|
|
|
|
int levelIndex, Index faceIndex) const {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
//
|
|
|
|
// Patches that are not eligible correpond to the following faces:
|
|
|
|
// - holes
|
|
|
|
// - those in intermediate levels that are further refined (not leaves)
|
|
|
|
// - those without complete neighborhoods that supporting other patches
|
|
|
|
//
|
|
|
|
Level const & level = refiner.getLevel(levelIndex);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
if (level.isFaceHole(faceIndex)) {
|
2016-07-22 01:47:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
if (levelIndex < refiner.GetMaxLevel()) {
|
|
|
|
if (refiner.getRefinement(levelIndex).getParentFaceSparseTag(faceIndex)._selected) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
// Faces that exist solely to support faces intended for patches will not have
|
|
|
|
// their full neighborhood available and so are considered "incomplete":
|
2015-02-26 21:57:47 +00:00
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
Vtr::ConstIndexArray fVerts = level.getFaceVertices(faceIndex);
|
|
|
|
assert(fVerts.size() == 4);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
if (level.getFaceCompositeVTag(fVerts)._incomplete) {
|
2016-07-22 01:47:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-03 03:53:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
bool
|
|
|
|
PatchTableFactory::BuilderContext::IsPatchSmoothCorner(
|
2016-10-12 20:08:35 +00:00
|
|
|
int levelIndex, Index faceIndex, int fvcFactory) const
|
2016-09-03 03:53:24 +00:00
|
|
|
{
|
|
|
|
Level const & level = refiner.getLevel(levelIndex);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-10-12 20:08:35 +00:00
|
|
|
// Ignore the face-varying channel if the topology for the face is not distinct
|
|
|
|
int fvcRefiner = GetDistinctRefinerFVarChannel(levelIndex, faceIndex, fvcFactory);
|
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Vtr::ConstIndexArray fVerts = level.getFaceVertices(faceIndex);
|
|
|
|
if (fVerts.size() != 4) return false;
|
|
|
|
|
|
|
|
Level::VTag vTags[4];
|
2016-10-12 20:08:35 +00:00
|
|
|
level.getFaceVTags(faceIndex, vTags, fvcRefiner);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
// Test the subdivision rules for the corners, rather than just the boundary/interior
|
|
|
|
// tags, to ensure that inf-sharp vertices or edges are properly accounted for (and
|
|
|
|
// the cases appropriately excluded) if inf-sharp patches are enabled:
|
2016-07-22 01:47:44 +00:00
|
|
|
//
|
2016-10-12 20:08:35 +00:00
|
|
|
int boundaryCount = 0;
|
|
|
|
if (options.useInfSharpPatch) {
|
|
|
|
boundaryCount = (vTags[0]._infSharpEdges && (vTags[0]._rule == Sdc::Crease::RULE_CREASE))
|
|
|
|
+ (vTags[1]._infSharpEdges && (vTags[1]._rule == Sdc::Crease::RULE_CREASE))
|
|
|
|
+ (vTags[2]._infSharpEdges && (vTags[2]._rule == Sdc::Crease::RULE_CREASE))
|
|
|
|
+ (vTags[3]._infSharpEdges && (vTags[3]._rule == Sdc::Crease::RULE_CREASE));
|
|
|
|
} else {
|
|
|
|
boundaryCount = (vTags[0]._boundary && (vTags[0]._rule == Sdc::Crease::RULE_CREASE))
|
2016-09-03 03:53:24 +00:00
|
|
|
+ (vTags[1]._boundary && (vTags[1]._rule == Sdc::Crease::RULE_CREASE))
|
|
|
|
+ (vTags[2]._boundary && (vTags[2]._rule == Sdc::Crease::RULE_CREASE))
|
|
|
|
+ (vTags[3]._boundary && (vTags[3]._rule == Sdc::Crease::RULE_CREASE));
|
2016-10-12 20:08:35 +00:00
|
|
|
}
|
2016-09-03 03:53:24 +00:00
|
|
|
int xordinaryCount = vTags[0]._xordinary
|
|
|
|
+ vTags[1]._xordinary
|
|
|
|
+ vTags[2]._xordinary
|
|
|
|
+ vTags[3]._xordinary;
|
|
|
|
|
|
|
|
if ((boundaryCount == 3) && (xordinaryCount == 1)) {
|
|
|
|
// This must be an isolated xordinary corner above level 1, otherwise we still
|
|
|
|
// need to assure the xordinary vertex is opposite a smooth interior vertex:
|
|
|
|
//
|
|
|
|
if (levelIndex > 1) return true;
|
|
|
|
|
|
|
|
if (vTags[0]._xordinary) return (vTags[2]._rule == Sdc::Crease::RULE_SMOOTH);
|
|
|
|
if (vTags[1]._xordinary) return (vTags[3]._rule == Sdc::Crease::RULE_SMOOTH);
|
|
|
|
if (vTags[2]._xordinary) return (vTags[0]._rule == Sdc::Crease::RULE_SMOOTH);
|
|
|
|
if (vTags[3]._xordinary) return (vTags[1]._rule == Sdc::Crease::RULE_SMOOTH);
|
2016-07-22 01:47:44 +00:00
|
|
|
}
|
2016-09-03 03:53:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
bool
|
|
|
|
PatchTableFactory::BuilderContext::IsPatchRegular(
|
|
|
|
int levelIndex, Index faceIndex, int fvcFactory) const
|
|
|
|
{
|
|
|
|
Level const & level = refiner.getLevel(levelIndex);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Ignore the face-varying channel if the topology for the face is not distinct
|
|
|
|
int fvcRefiner = GetDistinctRefinerFVarChannel(levelIndex, faceIndex, fvcFactory);
|
|
|
|
|
|
|
|
// Retrieve the composite VTag for the four corners:
|
|
|
|
Level::VTag fCompVTag = level.getFaceCompositeVTag(faceIndex, fvcRefiner);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
// Patches around non-manifold features are currently regular -- will need to revise
|
|
|
|
// this when infinitely sharp patches are introduced later:
|
2016-07-22 01:47:44 +00:00
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
bool isRegular = ! fCompVTag._xordinary || fCompVTag._nonManifold;
|
|
|
|
|
2016-09-09 04:18:11 +00:00
|
|
|
// Reconsider when using inf-sharp patches in presence of inf-sharp features:
|
2016-09-29 23:59:33 +00:00
|
|
|
if (options.useInfSharpPatch && (fCompVTag._infSharp || fCompVTag._infSharpEdges)) {
|
|
|
|
if (fCompVTag._nonManifold || !fCompVTag._infIrregular) {
|
2016-09-09 04:18:11 +00:00
|
|
|
isRegular = true;
|
2016-09-29 23:59:33 +00:00
|
|
|
} else if (!fCompVTag._infSharpEdges) {
|
|
|
|
isRegular = false;
|
2016-09-09 04:18:11 +00:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// This is unfortunately a relatively complex case to determine... if a corner
|
|
|
|
// vertex has been tagged has having an inf-sharp irregularity about it, the
|
|
|
|
// neighborhood of the corner is partitioned into both regular and irregular
|
|
|
|
// regions and the face must be more closely inspected to determine in which
|
|
|
|
// it lies.
|
|
|
|
//
|
|
|
|
// There could be a simpler test here to quickly accept/reject regularity given
|
|
|
|
// how local it is -- involving no more than one or two (in the case of Loop)
|
|
|
|
// adjacent faces -- but it will likely be messy and will need to inspect
|
|
|
|
// adjacent faces and/or edges. In the meantime, gathering and inspecting the
|
|
|
|
// subset of the neighborhood delimited by inf-sharp edges will suffice (and
|
|
|
|
// be comparable in all but cases of high valence)
|
|
|
|
//
|
|
|
|
Level::VTag vTags[4];
|
|
|
|
level.getFaceVTags(faceIndex, vTags, fvcRefiner);
|
|
|
|
|
|
|
|
Level::VSpan vSpan;
|
|
|
|
Level::ETag eMask = getSingularEdgeMask(true);
|
|
|
|
|
|
|
|
isRegular = true;
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (vTags[i]._infIrregular) {
|
|
|
|
identifyManifoldCornerSpan(level, faceIndex, i, eMask, vSpan, fvcRefiner);
|
|
|
|
|
|
|
|
isRegular = (vSpan._numFaces == (vTags[i]._infSharpCrease ? 2 : 1));
|
|
|
|
if (!isRegular) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 02:14:42 +00:00
|
|
|
|
|
|
|
// When inf-sharp and extra-ordinary features are not isolated, need to inspect more
|
|
|
|
// closely -- any smooth extra-ordinary corner makes the patch irregular:
|
|
|
|
if (fCompVTag._xordinary && (levelIndex < 2)) {
|
|
|
|
Level::VTag vTags[4];
|
|
|
|
level.getFaceVTags(faceIndex, vTags, fvcRefiner);
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (vTags[i]._xordinary && (vTags[i]._rule == Sdc::Crease::RULE_SMOOTH)) {
|
|
|
|
isRegular = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-09 04:18:11 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 20:08:35 +00:00
|
|
|
// Legacy option -- reinterpret an irregular smooth corner as sharp if specified:
|
2017-01-28 00:22:04 +00:00
|
|
|
if (!isRegular && options.generateLegacySharpCornerPatches) {
|
2016-09-03 03:53:24 +00:00
|
|
|
if (fCompVTag._xordinary && fCompVTag._boundary && !fCompVTag._nonManifold) {
|
2016-10-12 20:08:35 +00:00
|
|
|
isRegular = IsPatchSmoothCorner(levelIndex, faceIndex, fvcRefiner);
|
2016-07-22 01:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-03 03:53:24 +00:00
|
|
|
return isRegular;
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
int
|
|
|
|
PatchTableFactory::BuilderContext::GetRegularPatchBoundaryMask(
|
|
|
|
int levelIndex, Index faceIndex, int fvcFactory) const
|
|
|
|
{
|
|
|
|
Level const & level = refiner.getLevel(levelIndex);
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Ignore the face-varying channel if the topology for the face is not distinct
|
|
|
|
int fvcRefiner = GetDistinctRefinerFVarChannel(levelIndex, faceIndex, fvcFactory);
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Gather the VTags for the four corners. Regardless of the options for
|
|
|
|
// treating non-manifold or inf-sharp patches, for a regular patch we can
|
|
|
|
// infer all that we need need from tags for the corner vertices:
|
2016-08-19 00:21:59 +00:00
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
Level::VTag vTags[4];
|
|
|
|
level.getFaceVTags(faceIndex, vTags, fvcRefiner);
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Level::VTag fTag = Level::VTag::BitwiseOr(vTags);
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-09 04:18:11 +00:00
|
|
|
//
|
|
|
|
// Identify vertex tags for inf-sharp edges and/or boundaries, depending on
|
|
|
|
// whether or not inf-sharp patches are in use:
|
|
|
|
//
|
|
|
|
int vBoundaryMask = 0;
|
|
|
|
if (fTag._infSharpEdges) {
|
2016-09-29 22:05:59 +00:00
|
|
|
if (options.useInfSharpPatch) {
|
2016-09-09 04:18:11 +00:00
|
|
|
vBoundaryMask |= (vTags[0]._infSharpEdges << 0) |
|
|
|
|
(vTags[1]._infSharpEdges << 1) |
|
|
|
|
(vTags[2]._infSharpEdges << 2) |
|
|
|
|
(vTags[3]._infSharpEdges << 3);
|
|
|
|
} else if (fTag._boundary) {
|
|
|
|
vBoundaryMask |= (vTags[0]._boundary << 0) |
|
|
|
|
(vTags[1]._boundary << 1) |
|
|
|
|
(vTags[2]._boundary << 2) |
|
|
|
|
(vTags[3]._boundary << 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-19 00:21:59 +00:00
|
|
|
//
|
2016-09-03 03:53:24 +00:00
|
|
|
// Non-manifold patches have been historically represented as regular in all
|
|
|
|
// cases -- when a non-manifold vertex is sharp, it requires a regular corner
|
|
|
|
// patch, and so both of its neighboring corners need to be re-interpreted as
|
2016-09-09 04:18:11 +00:00
|
|
|
// boundaries.
|
2016-08-19 00:21:59 +00:00
|
|
|
//
|
2016-12-15 20:33:36 +00:00
|
|
|
// With the introduction of sharp irregular patches, we are now better off
|
|
|
|
// using irregular patches where appropriate, which will simplify the following
|
|
|
|
// when this patch was already determined to be regular...
|
2016-08-19 00:21:59 +00:00
|
|
|
//
|
2016-12-15 20:33:36 +00:00
|
|
|
if (fTag._nonManifold) {
|
2016-09-03 03:53:24 +00:00
|
|
|
if (vTags[0]._nonManifold) vBoundaryMask |= (1 << 0) | (vTags[0]._infSharp ? 10 : 0);
|
|
|
|
if (vTags[1]._nonManifold) vBoundaryMask |= (1 << 1) | (vTags[1]._infSharp ? 5 : 0);
|
|
|
|
if (vTags[2]._nonManifold) vBoundaryMask |= (1 << 2) | (vTags[2]._infSharp ? 10 : 0);
|
|
|
|
if (vTags[3]._nonManifold) vBoundaryMask |= (1 << 3) | (vTags[3]._infSharp ? 5 : 0);
|
2016-12-15 20:33:36 +00:00
|
|
|
|
|
|
|
// Force adjacent edges as boundaries if only one vertex in the resulting mask
|
|
|
|
// (which would be an irregular boundary for Catmark, but not Loop):
|
|
|
|
if ((vBoundaryMask == (1 << 0)) || (vBoundaryMask == (1 << 2))) {
|
|
|
|
vBoundaryMask |= 10;
|
|
|
|
} else if ((vBoundaryMask == (1 << 1)) || (vBoundaryMask == (1 << 3))) {
|
|
|
|
vBoundaryMask |= 5;
|
|
|
|
}
|
2016-09-03 03:53:24 +00:00
|
|
|
}
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Convert directly from a vertex- to edge-mask (no need to inspect edges):
|
|
|
|
int eBoundaryMask = 0;
|
|
|
|
if (vBoundaryMask) {
|
|
|
|
static int const vBoundaryMaskToEMask[16] =
|
|
|
|
{ 0, -1, -1, 1, -1, -1, 2, 3, -1, 8, -1, 9, 4, 12, 6, -1 };
|
|
|
|
eBoundaryMask = vBoundaryMaskToEMask[vBoundaryMask];
|
|
|
|
assert(eBoundaryMask != -1);
|
|
|
|
}
|
|
|
|
return eBoundaryMask;
|
|
|
|
}
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
void
|
|
|
|
PatchTableFactory::BuilderContext::GetIrregularPatchCornerSpans(
|
|
|
|
int levelIndex, Index faceIndex,
|
|
|
|
Level::VSpan cornerSpans[4],
|
|
|
|
int fvcFactory) const
|
|
|
|
{
|
|
|
|
Level const & level = refiner.getLevel(levelIndex);
|
|
|
|
|
|
|
|
// Ignore the face-varying channel if the topology for the face is not distinct
|
|
|
|
int fvcRefiner = GetDistinctRefinerFVarChannel(levelIndex, faceIndex, fvcFactory);
|
|
|
|
|
|
|
|
// Retrieve tags and identify other information for the corner vertices:
|
|
|
|
Level::VTag vTags[4];
|
|
|
|
level.getFaceVTags(faceIndex, vTags, fvcRefiner);
|
|
|
|
|
|
|
|
FVarLevel::ValueTag fvarTags[4];
|
|
|
|
if (fvcRefiner >= 0) {
|
2016-09-09 04:18:11 +00:00
|
|
|
level.getFVarLevel(fvcRefiner).getFaceValueTags(faceIndex, fvarTags);
|
2016-09-03 03:53:24 +00:00
|
|
|
}
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
//
|
2016-09-09 04:18:11 +00:00
|
|
|
// For each corner vertex, use the complete neighborhood when possible (which
|
|
|
|
// does not require a search, otherwise identify the span of interest around
|
|
|
|
// the vertex:
|
2016-09-03 03:53:24 +00:00
|
|
|
//
|
|
|
|
ConstIndexArray fVerts = level.getFaceVertices(faceIndex);
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-29 22:05:59 +00:00
|
|
|
Level::ETag singularEdgeMask = getSingularEdgeMask(options.useInfSharpPatch);
|
2016-09-09 04:18:11 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
for (int i = 0; i < fVerts.size(); ++i) {
|
2016-09-09 04:18:11 +00:00
|
|
|
bool noFVarMisMatch = (fvcRefiner < 0) || !fvarTags[i]._mismatch;
|
2016-09-29 22:05:59 +00:00
|
|
|
bool testInfSharp = options.useInfSharpPatch &&
|
2016-09-09 04:18:11 +00:00
|
|
|
(vTags[i]._infSharpEdges && (vTags[i]._rule != Sdc::Crease::RULE_DART));
|
|
|
|
|
|
|
|
if (noFVarMisMatch && !testInfSharp) {
|
2016-09-19 21:18:51 +00:00
|
|
|
cornerSpans[i].clear();
|
2016-09-03 03:53:24 +00:00
|
|
|
} else {
|
2016-09-27 02:14:42 +00:00
|
|
|
if (!vTags[i]._nonManifold) {
|
|
|
|
identifyManifoldCornerSpan(
|
|
|
|
level, faceIndex, i, singularEdgeMask, cornerSpans[i], fvcRefiner);
|
|
|
|
} else {
|
|
|
|
identifyNonManifoldCornerSpan(
|
|
|
|
level, faceIndex, i, singularEdgeMask, cornerSpans[i], fvcRefiner);
|
|
|
|
}
|
2016-09-29 22:05:59 +00:00
|
|
|
}
|
2016-10-14 03:28:13 +00:00
|
|
|
if (vTags[i]._corner) {
|
|
|
|
cornerSpans[i]._sharp = true;
|
|
|
|
} else if (options.useInfSharpPatch) {
|
2016-09-29 22:05:59 +00:00
|
|
|
cornerSpans[i]._sharp = vTags[i]._infIrregular && (vTags[i]._rule == Sdc::Crease::RULE_CORNER);
|
2016-08-19 00:21:59 +00:00
|
|
|
}
|
2016-10-13 22:00:34 +00:00
|
|
|
|
|
|
|
// Legacy option -- reinterpret an irregular smooth corner as sharp if specified:
|
2017-01-28 00:22:04 +00:00
|
|
|
if (!cornerSpans[i]._sharp && options.generateLegacySharpCornerPatches) {
|
2016-10-13 22:00:34 +00:00
|
|
|
if (vTags[i]._xordinary && vTags[i]._boundary && !vTags[i]._nonManifold) {
|
|
|
|
int nFaces = cornerSpans[i].isAssigned() ? cornerSpans[i]._numFaces
|
|
|
|
: level.getVertexFaces(fVerts[i]).size();
|
|
|
|
cornerSpans[i]._sharp = (nFaces == 1);
|
|
|
|
}
|
|
|
|
}
|
2016-08-19 00:21:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
// Reserves tables based on the contents of the PatchArrayVector in the PatchTable:
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
void
|
2016-07-22 01:47:44 +00:00
|
|
|
PatchTableFactory::allocateVertexTables(
|
2016-08-24 21:02:57 +00:00
|
|
|
BuilderContext const & context, PatchTable * table) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 18:48:37 +00:00
|
|
|
int ncvs = 0, npatches = 0;
|
2015-05-22 18:50:01 +00:00
|
|
|
for (int i=0; i<table->GetNumPatchArrays(); ++i) {
|
|
|
|
npatches += table->GetNumPatches(i);
|
|
|
|
ncvs += table->GetNumControlVertices(i);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 09:02:07 +00:00
|
|
|
if (ncvs==0 || npatches==0)
|
2014-09-05 22:07:46 +00:00
|
|
|
return;
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
table->_patchVerts.resize( ncvs );
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
table->_paramTable.resize( npatches );
|
2014-10-13 15:52:09 +00:00
|
|
|
|
2016-08-24 21:02:57 +00:00
|
|
|
if (! context.refiner.IsUniform()) {
|
|
|
|
table->allocateVaryingVertices(
|
|
|
|
PatchDescriptor(PatchDescriptor::QUADS), npatches);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context.options.useSingleCreasePatch) {
|
2015-05-22 18:50:01 +00:00
|
|
|
table->_sharpnessIndices.resize( npatches, Vtr::INDEX_INVALID );
|
2014-10-13 15:52:09 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
//
|
|
|
|
// Allocate face-varying tables
|
|
|
|
//
|
|
|
|
void
|
2016-07-22 01:47:44 +00:00
|
|
|
PatchTableFactory::allocateFVarChannels(
|
|
|
|
BuilderContext const & context, PatchTable * table) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
TopologyRefiner const & refiner = context.refiner;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
int npatches = table->GetNumPatchesTotal();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
table->allocateFVarPatchChannels((int)context.fvarChannelIndices.size());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
// Initialize each channel
|
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
int refinerChannel = context.fvarChannelIndices[fvc];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
Sdc::Options::FVarLinearInterpolation interpolation =
|
2016-07-22 01:47:44 +00:00
|
|
|
refiner.GetFVarLinearInterpolation(refinerChannel);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
table->setFVarPatchChannelLinearInterpolation(interpolation, fvc);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-08-19 00:21:59 +00:00
|
|
|
if (refiner.IsUniform()) {
|
|
|
|
PatchDescriptor::Type uniformType = context.options.triangulateQuads
|
|
|
|
? PatchDescriptor::TRIANGLES
|
|
|
|
: PatchDescriptor::QUADS;
|
|
|
|
|
|
|
|
table->allocateFVarPatchChannelValues(
|
|
|
|
PatchDescriptor(uniformType), npatches, fvc);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
bool allLinear = context.options.generateFVarLegacyLinearPatches ||
|
|
|
|
(interpolation == Sdc::Options::FVAR_LINEAR_ALL);
|
2015-06-02 21:58:35 +00:00
|
|
|
|
2016-08-19 00:21:59 +00:00
|
|
|
PatchDescriptor::Type adaptiveType = allLinear
|
|
|
|
? PatchDescriptor::QUADS
|
|
|
|
: ((context.options.GetEndCapType() == Options::ENDCAP_GREGORY_BASIS)
|
|
|
|
? PatchDescriptor::GREGORY_BASIS
|
|
|
|
: PatchDescriptor::REGULAR);
|
|
|
|
|
|
|
|
table->allocateFVarPatchChannelValues(
|
|
|
|
PatchDescriptor(adaptiveType), npatches, fvc);
|
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-06-11 20:18:25 +00:00
|
|
|
// Populates the PatchParam for the given face, returning
|
|
|
|
// a pointer to the next entry
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
PatchParam
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::computePatchParam(
|
2016-07-22 01:47:44 +00:00
|
|
|
BuilderContext const & context,
|
2016-09-29 16:38:32 +00:00
|
|
|
int depth, Index faceIndex,
|
|
|
|
int boundaryMask, int transitionMask) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
TopologyRefiner const & refiner = context.refiner;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// Move up the hierarchy accumulating u,v indices to the coarse level:
|
|
|
|
int childIndexInParent = 0,
|
|
|
|
u = 0,
|
|
|
|
v = 0,
|
|
|
|
ofs = 1;
|
|
|
|
|
2015-05-22 04:26:41 +00:00
|
|
|
bool nonquad = (refiner.GetLevel(depth).GetFaceVertices(faceIndex).size() != 4);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int i = depth; i > 0; --i) {
|
2016-09-03 03:53:24 +00:00
|
|
|
Refinement const& refinement = refiner.getRefinement(i-1);
|
|
|
|
Level const& parentLevel = refiner.getLevel(i-1);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Index parentFaceIndex = refinement.getChildFaceParentFace(faceIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
if (parentLevel.getFaceVertices(parentFaceIndex).size() == 4) {
|
2016-09-03 03:53:24 +00:00
|
|
|
childIndexInParent = refinement.getChildFaceInParentFace(faceIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
switch ( childIndexInParent ) {
|
|
|
|
case 0 : break;
|
|
|
|
case 1 : { u+=ofs; } break;
|
|
|
|
case 2 : { u+=ofs; v+=ofs; } break;
|
|
|
|
case 3 : { v+=ofs; } break;
|
|
|
|
}
|
|
|
|
ofs = (unsigned short)(ofs << 1);
|
|
|
|
} else {
|
|
|
|
nonquad = true;
|
|
|
|
// If the root face is not a quad, we need to offset the ptex index
|
|
|
|
// CCW to match the correct child face
|
2014-12-15 18:23:13 +00:00
|
|
|
Vtr::ConstIndexArray children = refinement.getFaceChildFaces(parentFaceIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int j=0; j<children.size(); ++j) {
|
|
|
|
if (children[j]==faceIndex) {
|
|
|
|
childIndexInParent = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
faceIndex = parentFaceIndex;
|
|
|
|
}
|
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Index ptexIndex = context.ptexIndices.GetFaceId(faceIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(ptexIndex!=-1);
|
|
|
|
|
|
|
|
if (nonquad) {
|
|
|
|
ptexIndex+=childIndexInParent;
|
|
|
|
}
|
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
PatchParam param;
|
|
|
|
param.Set(ptexIndex, (short)u, (short)v, (unsigned short) depth, nonquad,
|
2016-09-29 16:38:32 +00:00
|
|
|
(unsigned short) boundaryMask, (unsigned short) transitionMask);
|
2016-07-22 01:47:44 +00:00
|
|
|
return param;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
//
|
|
|
|
// We should be able to use a single Create() method for both the adaptive and uniform
|
|
|
|
// cases. In the past, more additional arguments were passed to the uniform version,
|
|
|
|
// but that may no longer be necessary (see notes in the uniform version below)...
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable *
|
|
|
|
PatchTableFactory::Create(TopologyRefiner const & refiner, Options options) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
if (refiner.IsUniform()) {
|
|
|
|
return createUniform(refiner, options);
|
|
|
|
} else {
|
2015-04-23 23:58:45 +00:00
|
|
|
return createAdaptive(refiner, options);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable *
|
|
|
|
PatchTableFactory::createUniform(TopologyRefiner const & refiner, Options options) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
assert(refiner.IsUniform());
|
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
BuilderContext context(refiner, options);
|
|
|
|
|
2014-09-17 18:17:25 +00:00
|
|
|
// ensure that triangulateQuads is only set for quadrilateral schemes
|
2016-02-19 09:02:07 +00:00
|
|
|
options.triangulateQuads &= (refiner.GetSchemeType()==Sdc::SCHEME_BILINEAR ||
|
2015-01-07 01:40:11 +00:00
|
|
|
refiner.GetSchemeType()==Sdc::SCHEME_CATMARK);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-07-29 21:42:03 +00:00
|
|
|
// level=0 may contain n-gons, which are not supported in PatchTable.
|
|
|
|
// even if generateAllLevels = true, we start from level 1.
|
|
|
|
|
2015-04-02 03:44:33 +00:00
|
|
|
int maxvalence = refiner.GetMaxValence(),
|
2014-09-05 22:07:46 +00:00
|
|
|
maxlevel = refiner.GetMaxLevel(),
|
2015-07-29 21:42:03 +00:00
|
|
|
firstlevel = options.generateAllLevels ? 1 : maxlevel,
|
2014-11-25 20:41:19 +00:00
|
|
|
nlevels = maxlevel-firstlevel+1;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
PatchDescriptor::Type ptype = PatchDescriptor::NON_PATCH;
|
2014-09-11 23:55:39 +00:00
|
|
|
if (options.triangulateQuads) {
|
2014-11-25 20:41:19 +00:00
|
|
|
ptype = PatchDescriptor::TRIANGLES;
|
2014-09-11 23:55:39 +00:00
|
|
|
} else {
|
|
|
|
switch (refiner.GetSchemeType()) {
|
2015-01-07 01:40:11 +00:00
|
|
|
case Sdc::SCHEME_BILINEAR :
|
|
|
|
case Sdc::SCHEME_CATMARK : ptype = PatchDescriptor::QUADS; break;
|
|
|
|
case Sdc::SCHEME_LOOP : ptype = PatchDescriptor::TRIANGLES; break;
|
2014-09-11 23:55:39 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2014-11-25 20:41:19 +00:00
|
|
|
assert(ptype!=PatchDescriptor::NON_PATCH);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
// Create the instance of the table and allocate and initialize its members.
|
|
|
|
PatchTable * table = new PatchTable(maxvalence);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
table->_numPtexFaces = context.ptexIndices.GetNumFaces();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
table->reservePatchArrays(nlevels);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-04-17 14:42:53 +00:00
|
|
|
PatchDescriptor desc(ptype);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// generate patch arrays
|
|
|
|
for (int level=firstlevel, poffset=0, voffset=0; level<=maxlevel; ++level) {
|
|
|
|
|
2015-05-22 04:26:41 +00:00
|
|
|
TopologyLevel const & refLevel = refiner.GetLevel(level);
|
|
|
|
|
|
|
|
int npatches = refLevel.GetNumFaces();
|
2014-10-24 20:52:40 +00:00
|
|
|
if (refiner.HasHoles()) {
|
2015-05-22 04:26:41 +00:00
|
|
|
for (int i = npatches - 1; i >= 0; --i) {
|
|
|
|
npatches -= refLevel.IsFaceHole(i);
|
|
|
|
}
|
2014-10-24 20:52:40 +00:00
|
|
|
}
|
|
|
|
assert(npatches>=0);
|
2014-11-11 19:27:25 +00:00
|
|
|
|
2014-09-11 23:55:39 +00:00
|
|
|
if (options.triangulateQuads)
|
2014-09-05 22:07:46 +00:00
|
|
|
npatches *= 2;
|
2014-09-11 23:55:39 +00:00
|
|
|
|
2015-07-29 21:42:03 +00:00
|
|
|
table->pushPatchArray(desc, npatches, &voffset, &poffset, 0);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate various tables
|
2016-08-24 21:02:57 +00:00
|
|
|
allocateVertexTables(context, table);
|
2016-07-22 01:47:44 +00:00
|
|
|
|
|
|
|
if (context.RequiresFVarPatches()) {
|
|
|
|
allocateFVarChannels(context, table);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now populate the patches:
|
|
|
|
//
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
Index * iptr = &table->_patchVerts[0];
|
|
|
|
PatchParam * pptr = &table->_paramTable[0];
|
2014-10-09 21:48:50 +00:00
|
|
|
Index ** fptr = 0;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-07-29 21:42:03 +00:00
|
|
|
// we always skip level=0 vertices (control cages)
|
|
|
|
Index levelVertOffset = refiner.GetLevel(0).GetNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
Index * levelFVarVertOffsets = 0;
|
2016-07-22 01:47:44 +00:00
|
|
|
if (context.RequiresFVarPatches()) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
levelFVarVertOffsets = (Index *)alloca(context.fvarChannelIndices.size()*sizeof(Index));
|
|
|
|
memset(levelFVarVertOffsets, 0, context.fvarChannelIndices.size()*sizeof(Index));
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
fptr = (Index **)alloca(context.fvarChannelIndices.size()*sizeof(Index *));
|
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
fptr[fvc] = table->getFVarValues(fvc).begin();
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int level=1; level<=maxlevel; ++level) {
|
|
|
|
|
2015-05-22 04:26:41 +00:00
|
|
|
TopologyLevel const & refLevel = refiner.GetLevel(level);
|
|
|
|
|
|
|
|
int nfaces = refLevel.GetNumFaces();
|
2014-09-05 22:07:46 +00:00
|
|
|
if (level>=firstlevel) {
|
|
|
|
for (int face=0; face<nfaces; ++face) {
|
2014-11-11 19:27:25 +00:00
|
|
|
|
2016-02-19 09:02:07 +00:00
|
|
|
if (refiner.HasHoles() && refLevel.IsFaceHole(face)) {
|
2014-10-24 20:52:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 04:26:41 +00:00
|
|
|
ConstIndexArray fverts = refLevel.GetFaceVertices(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int vert=0; vert<fverts.size(); ++vert) {
|
|
|
|
*iptr++ = levelVertOffset + fverts[vert];
|
|
|
|
}
|
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
*pptr++ = computePatchParam(context, level, face, /*boundary*/0, /*transition*/0);
|
|
|
|
|
|
|
|
if (context.RequiresFVarPatches()) {
|
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
int refinerChannel = context.fvarChannelIndices[fvc];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
ConstIndexArray fvalues = refLevel.GetFaceFVarValues(face, refinerChannel);
|
2015-03-05 21:09:27 +00:00
|
|
|
for (int vert=0; vert<fvalues.size(); ++vert) {
|
2016-07-22 01:47:44 +00:00
|
|
|
assert((levelVertOffset + fvalues[vert]) < (int)table->getFVarValues(fvc).size());
|
|
|
|
fptr[fvc][vert] = levelFVarVertOffsets[fvc] + fvalues[vert];
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2016-07-22 01:47:44 +00:00
|
|
|
fptr[fvc]+=fvalues.size();
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 23:55:39 +00:00
|
|
|
if (options.triangulateQuads) {
|
2014-09-05 22:07:46 +00:00
|
|
|
// Triangulate the quadrilateral: {v0,v1,v2,v3} -> {v0,v1,v2},{v3,v0,v2}.
|
|
|
|
*iptr = *(iptr - 4); // copy v0 index
|
|
|
|
++iptr;
|
|
|
|
*iptr = *(iptr - 3); // copy v2 index
|
|
|
|
++iptr;
|
|
|
|
|
|
|
|
*pptr = *(pptr - 1); // copy first patch param
|
|
|
|
++pptr;
|
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
if (context.RequiresFVarPatches()) {
|
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
*fptr[fvc] = *(fptr[fvc]-4); // copy fv0 index
|
|
|
|
++fptr[fvc];
|
|
|
|
*fptr[fvc] = *(fptr[fvc]-3); // copy fv2 index
|
|
|
|
++fptr[fvc];
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.generateAllLevels) {
|
2015-05-22 04:26:41 +00:00
|
|
|
levelVertOffset += refiner.GetLevel(level).GetNumVertices();
|
2016-07-22 01:47:44 +00:00
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
int refinerChannel = context.fvarChannelIndices[fvc];
|
|
|
|
levelFVarVertOffsets[fvc] += refiner.GetLevel(level).GetNumFVarValues(refinerChannel);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-22 18:50:01 +00:00
|
|
|
return table;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable *
|
|
|
|
PatchTableFactory::createAdaptive(TopologyRefiner const & refiner, Options options) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-02-19 09:02:07 +00:00
|
|
|
assert(! refiner.IsUniform());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
BuilderContext context(refiner, options);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
// First identify the patches -- accumulating an inventory of
|
|
|
|
// information about each resulting patch:
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-04-23 23:58:45 +00:00
|
|
|
identifyAdaptivePatches(context);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
// Create and initialize the instance of the table:
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-04-02 03:44:33 +00:00
|
|
|
int maxValence = refiner.GetMaxValence();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
PatchTable * table = new PatchTable(maxValence);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
table->_numPtexFaces = context.ptexIndices.GetNumFaces();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Now populate the patches:
|
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
populateAdaptivePatches(context, table);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
return table;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Identify all patches required for faces at all levels -- accumulating the number of patches
|
|
|
|
// for each type, and retaining enough information for the patch for each face to populate it
|
|
|
|
// later with no additional analysis.
|
|
|
|
//
|
|
|
|
void
|
2016-07-22 01:47:44 +00:00
|
|
|
PatchTableFactory::identifyAdaptivePatches(BuilderContext & context) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
TopologyRefiner const & refiner = context.refiner;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Iterate through the levels of refinement to inspect and tag components with information
|
|
|
|
// relative to patch generation. We allocate all of the tags locally and use them to
|
|
|
|
// populate the patches once a complete inventory has been taken and all tables appropriately
|
|
|
|
// allocated and initialized:
|
|
|
|
//
|
|
|
|
// The first Level may have no Refinement if it is the only level -- similarly the last Level
|
|
|
|
// has no Refinement, so a single level is effectively the last, but with less information
|
|
|
|
// available in some cases, as it was not generated by refinement.
|
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
int reservePatches = refiner.GetNumFacesTotal();
|
|
|
|
context.patches.reserve(reservePatches);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
context.levelVertOffsets.push_back(0);
|
|
|
|
context.levelFVarValueOffsets.resize(context.fvarChannelIndices.size());
|
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
context.levelFVarValueOffsets[fvc].push_back(0);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
for (int levelIndex=0; levelIndex<refiner.GetNumLevels(); ++levelIndex) {
|
2016-09-03 03:53:24 +00:00
|
|
|
Level const & level = refiner.getLevel(levelIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
context.levelVertOffsets.push_back(
|
2016-09-03 03:53:24 +00:00
|
|
|
context.levelVertOffsets.back() + level.getNumVertices());
|
2016-07-22 01:47:44 +00:00
|
|
|
|
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
int refinerChannel = context.fvarChannelIndices[fvc];
|
|
|
|
context.levelFVarValueOffsets[fvc].push_back(
|
|
|
|
context.levelFVarValueOffsets[fvc].back()
|
2016-09-03 03:53:24 +00:00
|
|
|
+ level.getNumFVarValues(refinerChannel));
|
2015-03-26 17:42:32 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
for (int faceIndex = 0; faceIndex < level.getNumFaces(); ++faceIndex) {
|
2014-11-11 19:27:25 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
if (context.IsPatchEligible(levelIndex, faceIndex)) {
|
2015-03-26 17:42:32 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
context.patches.push_back(BuilderContext::PatchTuple(faceIndex, levelIndex));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Count the patches here to simplify subsequent allocation.
|
|
|
|
if (context.IsPatchRegular(levelIndex, faceIndex)) {
|
|
|
|
++context.numRegularPatches;
|
|
|
|
} else {
|
|
|
|
++context.numIrregularPatches;
|
2015-03-26 17:42:32 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// For legacy gregory patches we need to know how many
|
|
|
|
// irregular patches are also boundary patches.
|
|
|
|
if (context.options.GetEndCapType() == Options::ENDCAP_LEGACY_GREGORY) {
|
|
|
|
bool isBoundaryPatch = level.getFaceCompositeVTag(faceIndex)._boundary;
|
2016-09-30 02:10:28 +00:00
|
|
|
context.numIrregularBoundaryPatches += isBoundaryPatch;
|
2016-09-03 03:53:24 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2016-07-22 01:47:44 +00:00
|
|
|
// Populate adaptive patches that we've previously identified.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::populateAdaptivePatches(
|
2016-07-22 01:47:44 +00:00
|
|
|
BuilderContext & context, PatchTable * table) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
TopologyRefiner const & refiner = context.refiner;
|
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
// State needed to populate an array in the patch table.
|
|
|
|
// Pointers in this structure are initialized after the patch array
|
|
|
|
// data buffers have been allocated and are then incremented as we
|
|
|
|
// populate data into the patch table. Currently, we'll have at
|
|
|
|
// most 3 patch arrays: Regular, Irregular, and IrregularBoundary.
|
|
|
|
struct PatchArrayBuilder {
|
|
|
|
PatchArrayBuilder()
|
|
|
|
: patchType(PatchDescriptor::REGULAR), numPatches(0)
|
|
|
|
, iptr(NULL), pptr(NULL), sptr(NULL) { }
|
|
|
|
|
|
|
|
PatchDescriptor::Type patchType;
|
|
|
|
int numPatches;
|
|
|
|
|
|
|
|
Far::Index *iptr;
|
|
|
|
Far::PatchParam *pptr;
|
|
|
|
Far::Index *sptr;
|
|
|
|
Vtr::internal::StackBuffer<Far::Index*,1> fptr;
|
2016-09-29 16:38:32 +00:00
|
|
|
Vtr::internal::StackBuffer<Far::PatchParam*,1> fpptr;
|
2016-07-22 01:47:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Non-copyable
|
|
|
|
PatchArrayBuilder(PatchArrayBuilder const &) {}
|
|
|
|
PatchArrayBuilder & operator=(PatchArrayBuilder const &) {return *this;}
|
|
|
|
|
|
|
|
} arrayBuilders[3];
|
|
|
|
int R = 0, IR = 1, IRB = 2; // Regular, Irregular, IrregularBoundary
|
|
|
|
|
2016-08-06 02:00:51 +00:00
|
|
|
// Regular patches patches will be packed into the first patch array
|
2016-07-22 01:47:44 +00:00
|
|
|
arrayBuilders[R].patchType = PatchDescriptor::REGULAR;
|
|
|
|
arrayBuilders[R].numPatches = context.numRegularPatches;
|
2016-08-06 02:00:51 +00:00
|
|
|
int numPatchArrays = (arrayBuilders[R].numPatches > 0);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
|
|
|
// Irregular patches are converted to bspline basis and
|
|
|
|
// will be packed into the same patch array as regular patches
|
|
|
|
IR = IRB = R;
|
|
|
|
arrayBuilders[R].numPatches += context.numIrregularPatches;
|
2016-08-06 02:00:51 +00:00
|
|
|
// Make sure we've counted this array even when
|
|
|
|
// there are no regular patches.
|
|
|
|
numPatchArrays = (arrayBuilders[R].numPatches > 0);
|
2016-07-22 01:47:44 +00:00
|
|
|
break;
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
|
|
|
// Irregular patches (both interior and boundary) are converted
|
|
|
|
// to Gregory basis and will be packed into an additional patch array
|
|
|
|
IR = IRB = numPatchArrays;
|
|
|
|
arrayBuilders[IR].patchType = PatchDescriptor::GREGORY_BASIS;
|
|
|
|
arrayBuilders[IR].numPatches += context.numIrregularPatches;
|
|
|
|
numPatchArrays += (arrayBuilders[IR].numPatches > 0);
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_LEGACY_GREGORY:
|
|
|
|
// Irregular interior and irregular boundary patches each will be
|
|
|
|
// packed into separate additional patch arrays.
|
|
|
|
IR = numPatchArrays;
|
|
|
|
arrayBuilders[IR].patchType = PatchDescriptor::GREGORY;
|
|
|
|
arrayBuilders[IR].numPatches = context.numIrregularPatches
|
|
|
|
- context.numIrregularBoundaryPatches;
|
|
|
|
numPatchArrays += (arrayBuilders[IR].numPatches > 0);
|
|
|
|
|
|
|
|
IRB = numPatchArrays;
|
|
|
|
arrayBuilders[IRB].patchType = PatchDescriptor::GREGORY_BOUNDARY;
|
|
|
|
arrayBuilders[IRB].numPatches = context.numIrregularBoundaryPatches;
|
|
|
|
numPatchArrays += (arrayBuilders[IRB].numPatches > 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
// Create patch arrays
|
|
|
|
table->reservePatchArrays(numPatchArrays);
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
int voffset=0, poffset=0, qoffset=0;
|
|
|
|
for (int arrayIndex=0; arrayIndex<numPatchArrays; ++arrayIndex) {
|
|
|
|
PatchArrayBuilder & arrayBuilder = arrayBuilders[arrayIndex];
|
|
|
|
table->pushPatchArray(PatchDescriptor(arrayBuilder.patchType),
|
|
|
|
arrayBuilder.numPatches, &voffset, &poffset, &qoffset );
|
|
|
|
}
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
// Allocate patch array data buffers
|
|
|
|
bool hasSharpness = context.options.useSingleCreasePatch;
|
2016-08-24 21:02:57 +00:00
|
|
|
allocateVertexTables(context, table);
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
if (context.RequiresFVarPatches()) {
|
|
|
|
allocateFVarChannels(context, table);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
// Initialize pointers used while populating patch array data buffers
|
|
|
|
for (int arrayIndex=0; arrayIndex<numPatchArrays; ++arrayIndex) {
|
|
|
|
PatchArrayBuilder & arrayBuilder = arrayBuilders[arrayIndex];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
arrayBuilder.iptr = table->getPatchArrayVertices(arrayIndex).begin();
|
|
|
|
arrayBuilder.pptr = table->getPatchParams(arrayIndex).begin();
|
|
|
|
if (hasSharpness) {
|
|
|
|
arrayBuilder.sptr = table->getSharpnessIndices(arrayIndex);
|
2014-10-13 15:52:09 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
if (context.RequiresFVarPatches()) {
|
2016-07-22 01:47:44 +00:00
|
|
|
arrayBuilder.fptr.SetSize((int)context.fvarChannelIndices.size());
|
2016-08-19 00:21:59 +00:00
|
|
|
arrayBuilder.fpptr.SetSize((int)context.fvarChannelIndices.size());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2016-10-15 02:50:21 +00:00
|
|
|
PatchDescriptor desc = table->GetFVarPatchDescriptor(fvc);
|
2016-09-03 03:53:24 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
Index pidx = table->getPatchIndex(arrayIndex, 0);
|
2016-09-03 03:53:24 +00:00
|
|
|
int ofs = pidx * desc.GetNumControlVertices();
|
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
arrayBuilder.fptr[fvc] = &table->getFVarValues(fvc)[ofs];
|
2016-10-12 00:07:14 +00:00
|
|
|
arrayBuilder.fpptr[fvc] = &table->getFVarPatchParams(fvc)[pidx];
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
// endcap factories
|
|
|
|
// XXX
|
|
|
|
EndCapBSplineBasisPatchFactory *endCapBSpline = NULL;
|
|
|
|
EndCapGregoryBasisPatchFactory *endCapGregoryBasis = NULL;
|
|
|
|
EndCapLegacyGregoryPatchFactory *endCapLegacyGregory = NULL;
|
2016-08-19 00:21:59 +00:00
|
|
|
Vtr::internal::StackBuffer<EndCapBSplineBasisPatchFactory*,1> fvarEndCapBSpline;
|
|
|
|
Vtr::internal::StackBuffer<EndCapGregoryBasisPatchFactory*,1> fvarEndCapGregoryBasis;
|
|
|
|
|
2015-10-08 01:53:02 +00:00
|
|
|
StencilTable *localPointStencils = NULL;
|
|
|
|
StencilTable *localPointVaryingStencils = NULL;
|
2016-08-19 00:21:59 +00:00
|
|
|
Vtr::internal::StackBuffer<StencilTable*,1> localPointFVarStencils;
|
2015-04-23 23:58:45 +00:00
|
|
|
|
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
2015-10-08 01:53:02 +00:00
|
|
|
localPointStencils = new StencilTable(0);
|
|
|
|
localPointVaryingStencils = new StencilTable(0);
|
2015-04-23 23:58:45 +00:00
|
|
|
endCapGregoryBasis = new EndCapGregoryBasisPatchFactory(
|
2015-10-08 01:53:02 +00:00
|
|
|
refiner,
|
|
|
|
localPointStencils,
|
|
|
|
localPointVaryingStencils,
|
|
|
|
context.options.shareEndCapPatchPoints);
|
2015-04-23 23:58:45 +00:00
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
2015-10-08 01:53:02 +00:00
|
|
|
localPointStencils = new StencilTable(0);
|
|
|
|
localPointVaryingStencils = new StencilTable(0);
|
|
|
|
endCapBSpline = new EndCapBSplineBasisPatchFactory(
|
|
|
|
refiner,
|
|
|
|
localPointStencils,
|
|
|
|
localPointVaryingStencils);
|
2015-04-23 23:58:45 +00:00
|
|
|
break;
|
|
|
|
case Options::ENDCAP_LEGACY_GREGORY:
|
|
|
|
endCapLegacyGregory = new EndCapLegacyGregoryPatchFactory(refiner);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-19 00:21:59 +00:00
|
|
|
if (context.RequiresFVarPatches()) {
|
|
|
|
fvarEndCapBSpline.SetSize((int)context.fvarChannelIndices.size());
|
|
|
|
fvarEndCapGregoryBasis.SetSize((int)context.fvarChannelIndices.size());
|
|
|
|
localPointFVarStencils.SetSize((int)context.fvarChannelIndices.size());
|
|
|
|
|
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
|
|
|
localPointFVarStencils[fvc] = new StencilTable(0);
|
|
|
|
fvarEndCapGregoryBasis[fvc] = new EndCapGregoryBasisPatchFactory(
|
|
|
|
refiner,
|
|
|
|
localPointFVarStencils[fvc],
|
|
|
|
NULL,
|
2016-09-04 00:27:50 +00:00
|
|
|
context.options.shareEndCapPatchPoints);
|
2016-08-19 00:21:59 +00:00
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
|
|
|
localPointFVarStencils[fvc] = new StencilTable(0);
|
|
|
|
fvarEndCapBSpline[fvc] = new EndCapBSplineBasisPatchFactory(
|
|
|
|
refiner,
|
|
|
|
localPointFVarStencils[fvc],
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
// Populate patch data buffers
|
|
|
|
for (int patchIndex=0; patchIndex<(int)context.patches.size(); ++patchIndex) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
BuilderContext::PatchTuple const & patch = context.patches[patchIndex];
|
2015-04-27 19:40:18 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
Level const & level = refiner.getLevel(patch.levelIndex);
|
|
|
|
|
|
|
|
Level::VTag faceVTags = level.getFaceCompositeVTag(patch.faceIndex);
|
|
|
|
|
|
|
|
PatchArrayBuilder * arrayBuilder = 0;
|
|
|
|
|
|
|
|
// Properties to potentially be shared across vertex and face-varying patches:
|
|
|
|
int regBoundaryMask = 0;
|
|
|
|
bool isRegSingleCrease = false;
|
|
|
|
Level::VSpan irregCornerSpans[4];
|
|
|
|
float sharpness = 0.0f;
|
|
|
|
|
|
|
|
bool isRegular = context.IsPatchRegular(patch.levelIndex, patch.faceIndex);
|
|
|
|
if (isRegular) {
|
|
|
|
// Build the regular patch array
|
|
|
|
arrayBuilder = &arrayBuilders[R];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
regBoundaryMask = context.GetRegularPatchBoundaryMask(patch.levelIndex, patch.faceIndex);
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Test regular interior patches for a single-crease patch when specified:
|
|
|
|
if (hasSharpness && (regBoundaryMask == 0) && (faceVTags._semiSharpEdges ||
|
|
|
|
faceVTags._infSharpEdges)) {
|
|
|
|
float edgeSharpness = 0.0f;
|
|
|
|
int edgeInFace = 0;
|
|
|
|
if (level.isSingleCreasePatch(patch.faceIndex, &edgeSharpness, &edgeInFace)) {
|
|
|
|
// cap sharpness to the max isolation level
|
|
|
|
edgeSharpness = std::min(edgeSharpness,
|
|
|
|
float(context.options.maxIsolationLevel - patch.levelIndex));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
if (edgeSharpness > 0.0f) {
|
|
|
|
isRegSingleCrease = true;
|
|
|
|
regBoundaryMask = (1 << edgeInFace);
|
|
|
|
sharpness = edgeSharpness;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The single-crease patch is an interior patch so ignore boundary mask when gathering:
|
|
|
|
if (isRegSingleCrease) {
|
|
|
|
arrayBuilder->iptr +=
|
|
|
|
context.GatherRegularPatchPoints(arrayBuilder->iptr, patch, 0);
|
|
|
|
} else {
|
|
|
|
arrayBuilder->iptr +=
|
|
|
|
context.GatherRegularPatchPoints(arrayBuilder->iptr, patch, regBoundaryMask);
|
|
|
|
}
|
2016-07-22 01:47:44 +00:00
|
|
|
} else {
|
2016-09-03 03:53:24 +00:00
|
|
|
// Build the irregular patch array
|
2016-07-22 01:47:44 +00:00
|
|
|
arrayBuilder = &arrayBuilders[IR];
|
|
|
|
|
2016-10-14 03:28:13 +00:00
|
|
|
context.GetIrregularPatchCornerSpans(patch.levelIndex, patch.faceIndex, irregCornerSpans);
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2015-08-12 19:36:58 +00:00
|
|
|
// switch endcap patch type by option
|
2016-07-22 01:47:44 +00:00
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
|
|
|
arrayBuilder->iptr +=
|
2016-09-03 03:53:24 +00:00
|
|
|
context.GatherIrregularPatchPoints(
|
|
|
|
endCapGregoryBasis, arrayBuilder->iptr, patch, irregCornerSpans);
|
2016-07-22 01:47:44 +00:00
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
|
|
|
arrayBuilder->iptr +=
|
2016-09-03 03:53:24 +00:00
|
|
|
context.GatherIrregularPatchPoints(
|
|
|
|
endCapBSpline, arrayBuilder->iptr, patch, irregCornerSpans);
|
2016-07-22 01:47:44 +00:00
|
|
|
break;
|
|
|
|
case Options::ENDCAP_LEGACY_GREGORY:
|
|
|
|
// For legacy gregory patches we may need to switch to
|
|
|
|
// the irregular boundary patch array.
|
2016-09-30 02:10:28 +00:00
|
|
|
if (!faceVTags._boundary) {
|
2016-07-22 01:47:44 +00:00
|
|
|
arrayBuilder->iptr +=
|
2016-09-03 03:53:24 +00:00
|
|
|
context.GatherIrregularPatchPoints(
|
|
|
|
endCapLegacyGregory, arrayBuilder->iptr, patch, irregCornerSpans);
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
2016-07-22 01:47:44 +00:00
|
|
|
arrayBuilder = &arrayBuilders[IRB];
|
|
|
|
arrayBuilder->iptr +=
|
2016-09-03 03:53:24 +00:00
|
|
|
context.GatherIrregularPatchPoints(
|
|
|
|
endCapLegacyGregory, arrayBuilder->iptr, patch, irregCornerSpans);
|
2015-06-02 04:18:35 +00:00
|
|
|
}
|
2016-07-22 01:47:44 +00:00
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BILINEAR_BASIS:
|
|
|
|
// not implemented yet
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// no endcap
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Assign the patch param (why is transition mask 0 if not regular?)
|
|
|
|
int paramBoundaryMask = regBoundaryMask;
|
|
|
|
int paramTransitionMask = isRegular ?
|
|
|
|
context.GetTransitionMask(patch.levelIndex, patch.faceIndex) : 0;
|
|
|
|
|
2016-08-19 00:21:59 +00:00
|
|
|
PatchParam patchParam =
|
2016-07-22 01:47:44 +00:00
|
|
|
computePatchParam(context,
|
|
|
|
patch.levelIndex, patch.faceIndex,
|
2016-09-03 03:53:24 +00:00
|
|
|
paramBoundaryMask, paramTransitionMask);
|
2016-08-19 00:21:59 +00:00
|
|
|
*arrayBuilder->pptr++ = patchParam;
|
2015-04-17 23:26:57 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
if (hasSharpness) {
|
|
|
|
*arrayBuilder->sptr++ =
|
|
|
|
assignSharpnessIndex(sharpness, table->_sharpnessValues);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2016-07-22 01:47:44 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
if (context.RequiresFVarPatches()) {
|
2016-07-22 01:47:44 +00:00
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-07-22 01:47:44 +00:00
|
|
|
BuilderContext::PatchTuple fvarPatch(patch);
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-10-15 02:50:21 +00:00
|
|
|
PatchDescriptor desc = table->GetFVarPatchDescriptor(fvc);
|
2016-08-31 20:05:55 +00:00
|
|
|
|
2016-09-29 16:38:32 +00:00
|
|
|
PatchParam fvarPatchParam = patchParam;
|
2016-08-19 00:21:59 +00:00
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
// Deal with the linear cases trivially first
|
|
|
|
if (desc.GetType() == PatchDescriptor::QUADS) {
|
|
|
|
arrayBuilder->fptr[fvc] +=
|
|
|
|
context.GatherLinearPatchPoints(
|
2016-08-31 20:05:55 +00:00
|
|
|
arrayBuilder->fptr[fvc], fvarPatch, fvc);
|
2016-09-03 03:53:24 +00:00
|
|
|
*arrayBuilder->fpptr[fvc]++ = fvarPatchParam;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For non-linear patches, reuse patch information when the topology
|
|
|
|
// of the face in face-varying space matches the original patch:
|
|
|
|
//
|
|
|
|
bool fvarTopologyMatches = context.DoesFaceVaryingPatchMatch(
|
|
|
|
patch.levelIndex, patch.faceIndex, fvc);
|
|
|
|
|
|
|
|
bool fvarIsRegular = fvarTopologyMatches ? isRegular :
|
|
|
|
context.IsPatchRegular(patch.levelIndex, patch.faceIndex, fvc);
|
|
|
|
|
|
|
|
int fvarBoundaryMask = 0;
|
|
|
|
if (fvarIsRegular) {
|
|
|
|
fvarBoundaryMask = fvarTopologyMatches ? regBoundaryMask :
|
|
|
|
context.GetRegularPatchBoundaryMask(patch.levelIndex, patch.faceIndex, fvc);
|
|
|
|
|
|
|
|
if (isRegSingleCrease && fvarTopologyMatches) {
|
|
|
|
context.GatherRegularPatchPoints(
|
|
|
|
arrayBuilder->fptr[fvc], fvarPatch, 0, fvc);
|
2016-08-19 00:21:59 +00:00
|
|
|
} else {
|
2016-09-03 03:53:24 +00:00
|
|
|
context.GatherRegularPatchPoints(
|
|
|
|
arrayBuilder->fptr[fvc], fvarPatch, fvarBoundaryMask, fvc);
|
2016-08-19 00:21:59 +00:00
|
|
|
}
|
2016-09-03 03:53:24 +00:00
|
|
|
} else {
|
|
|
|
Level::VSpan localCornerSpans[4];
|
|
|
|
Level::VSpan* fvarCornerSpans = localCornerSpans;
|
|
|
|
if (fvarTopologyMatches) {
|
|
|
|
fvarCornerSpans = irregCornerSpans;
|
2016-08-31 20:05:55 +00:00
|
|
|
} else {
|
2016-09-03 03:53:24 +00:00
|
|
|
context.GetIrregularPatchCornerSpans(
|
|
|
|
patch.levelIndex, patch.faceIndex, fvarCornerSpans, fvc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc.GetType() == PatchDescriptor::REGULAR) {
|
|
|
|
context.GatherIrregularPatchPoints(
|
|
|
|
fvarEndCapBSpline[fvc],
|
|
|
|
arrayBuilder->fptr[fvc], fvarPatch, fvarCornerSpans, fvc);
|
|
|
|
} else if (desc.GetType() == PatchDescriptor::GREGORY_BASIS) {
|
|
|
|
context.GatherIrregularPatchPoints(
|
|
|
|
fvarEndCapGregoryBasis[fvc],
|
|
|
|
arrayBuilder->fptr[fvc], fvarPatch, fvarCornerSpans, fvc);
|
|
|
|
} else {
|
|
|
|
assert("Unknown Descriptor for FVar patch" == 0);
|
2016-08-31 20:05:55 +00:00
|
|
|
}
|
2016-08-19 00:21:59 +00:00
|
|
|
}
|
2016-08-31 20:05:55 +00:00
|
|
|
arrayBuilder->fptr[fvc] += desc.GetNumControlVertices();
|
2016-09-03 03:53:24 +00:00
|
|
|
|
|
|
|
fvarPatchParam.Set(
|
2016-09-29 16:38:32 +00:00
|
|
|
patchParam.GetFaceId(),
|
2016-09-03 03:53:24 +00:00
|
|
|
patchParam.GetU(), patchParam.GetV(),
|
|
|
|
patchParam.GetDepth(),
|
|
|
|
patchParam.NonQuadRoot(),
|
|
|
|
(fvarIsRegular ? fvarBoundaryMask : 0),
|
2016-09-29 16:38:32 +00:00
|
|
|
patchParam.GetTransition(),
|
2016-09-03 03:53:24 +00:00
|
|
|
fvarIsRegular);
|
2016-08-19 00:21:59 +00:00
|
|
|
*arrayBuilder->fpptr[fvc]++ = fvarPatchParam;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:02:57 +00:00
|
|
|
table->populateVaryingVertices();
|
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
// finalize end patches
|
2016-02-19 09:02:07 +00:00
|
|
|
if (localPointStencils && localPointStencils->GetNumStencils() > 0) {
|
2016-03-15 18:36:34 +00:00
|
|
|
localPointStencils->finalize();
|
2015-12-11 22:33:31 +00:00
|
|
|
} else {
|
|
|
|
delete localPointStencils;
|
|
|
|
localPointStencils = NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-19 09:02:07 +00:00
|
|
|
if (localPointVaryingStencils && localPointVaryingStencils->GetNumStencils() > 0) {
|
2016-03-15 18:36:34 +00:00
|
|
|
localPointVaryingStencils->finalize();
|
2015-12-11 22:33:31 +00:00
|
|
|
} else {
|
|
|
|
delete localPointVaryingStencils;
|
|
|
|
localPointVaryingStencils = NULL;
|
|
|
|
}
|
2015-10-08 01:53:02 +00:00
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
2015-10-08 01:53:02 +00:00
|
|
|
table->_localPointStencils = localPointStencils;
|
|
|
|
table->_localPointVaryingStencils = localPointVaryingStencils;
|
2015-04-23 23:58:45 +00:00
|
|
|
delete endCapGregoryBasis;
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
2015-10-08 01:53:02 +00:00
|
|
|
table->_localPointStencils = localPointStencils;
|
|
|
|
table->_localPointVaryingStencils = localPointVaryingStencils;
|
2015-04-23 23:58:45 +00:00
|
|
|
delete endCapBSpline;
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_LEGACY_GREGORY:
|
2015-05-21 02:44:43 +00:00
|
|
|
endCapLegacyGregory->Finalize(
|
2015-05-22 18:50:01 +00:00
|
|
|
table->GetMaxValence(),
|
|
|
|
&table->_quadOffsetsTable,
|
|
|
|
&table->_vertexValenceTable);
|
2015-04-23 23:58:45 +00:00
|
|
|
delete endCapLegacyGregory;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-08-19 00:21:59 +00:00
|
|
|
|
|
|
|
if (context.RequiresFVarPatches()) {
|
|
|
|
table->_localPointFaceVaryingStencils.resize(
|
|
|
|
context.fvarChannelIndices.size());
|
|
|
|
|
|
|
|
for (int fvc=0; fvc<(int)context.fvarChannelIndices.size(); ++fvc) {
|
|
|
|
if (localPointFVarStencils[fvc]->GetNumStencils() > 0) {
|
|
|
|
localPointFVarStencils[fvc]->finalize();
|
|
|
|
} else {
|
|
|
|
delete localPointFVarStencils[fvc];
|
|
|
|
localPointFVarStencils[fvc] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
|
|
|
delete fvarEndCapGregoryBasis[fvc];
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
|
|
|
delete fvarEndCapBSpline[fvc];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
table->_localPointFaceVaryingStencils[fvc] =
|
|
|
|
localPointFVarStencils[fvc];
|
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2016-09-03 03:53:24 +00:00
|
|
|
//
|
|
|
|
// Implementation of the PatchFaceTag:
|
|
|
|
//
|
|
|
|
void
|
|
|
|
PatchTableFactory::PatchFaceTag::clear() {
|
|
|
|
std::memset(this, 0, sizeof(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchTableFactory::PatchFaceTag::assignTransitionPropertiesFromEdgeMask(int tMask) {
|
|
|
|
_transitionMask = tMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchTableFactory::PatchFaceTag::assignBoundaryPropertiesFromEdgeMask(int eMask) {
|
|
|
|
|
|
|
|
static int const edgeMaskToCount[16] =
|
|
|
|
{ 0, 1, 1, 2, 1, -1, 2, -1, 1, 2, -1, -1, 2, -1, -1, -1 };
|
|
|
|
static int const edgeMaskToIndex[16] =
|
|
|
|
{ -1, 0, 1, 1, 2, -1, 2, -1, 3, 0, -1, -1, 3, -1, -1,-1 };
|
|
|
|
|
|
|
|
assert(edgeMaskToCount[eMask] != -1);
|
|
|
|
assert(edgeMaskToIndex[eMask] != -1);
|
|
|
|
|
|
|
|
_boundaryMask = eMask;
|
|
|
|
_hasBoundaryEdge = (eMask > 0);
|
|
|
|
|
|
|
|
_boundaryCount = edgeMaskToCount[eMask];
|
|
|
|
_boundaryIndex = edgeMaskToIndex[eMask];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchTableFactory::PatchFaceTag::assignBoundaryPropertiesFromVertexMask(int vMask) {
|
|
|
|
|
|
|
|
// This is only intended to support the case of a single boundary vertex with no
|
|
|
|
// boundary edges, which can only occur with an irregular vertex
|
|
|
|
|
|
|
|
static int const singleBitVertexMaskToCount[16] =
|
|
|
|
{ 0, 1, 1, -1, 1, -1 , -1, -1, 1, -1 , -1, -1, -1, -1 , -1, -1 };
|
|
|
|
static int const singleBitVertexMaskToIndex[16] =
|
|
|
|
{ 0, 0, 1, -1, 2, -1 , -1, -1, 3, -1 , -1, -1, -1, -1 , -1, -1 };
|
|
|
|
|
|
|
|
assert(_hasBoundaryEdge == false);
|
|
|
|
assert(singleBitVertexMaskToCount[vMask] != -1);
|
|
|
|
assert(singleBitVertexMaskToIndex[vMask] != -1);
|
|
|
|
|
|
|
|
_boundaryMask = vMask;
|
|
|
|
|
|
|
|
_boundaryCount = singleBitVertexMaskToCount[vMask];
|
|
|
|
_boundaryIndex = singleBitVertexMaskToIndex[vMask];
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
} // end namespace Far
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|
2015-04-18 00:36:55 +00:00
|
|
|
|