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"
|
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 {
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
namespace {
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// A convenience container for the different types of feature adaptive patches
|
|
|
|
//
|
2015-02-26 21:57:47 +00:00
|
|
|
template <class TYPE>
|
2014-09-05 22:07:46 +00:00
|
|
|
struct PatchTypes {
|
|
|
|
|
|
|
|
|
2015-04-17 14:42:53 +00:00
|
|
|
TYPE R, // regular patch
|
|
|
|
G, // gregory patch
|
|
|
|
GB, // gregory boundary patch
|
|
|
|
GP; // gregory basis patch
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
PatchTypes() { std::memset(this, 0, sizeof(PatchTypes<TYPE>)); }
|
|
|
|
|
|
|
|
// Returns the number of patches based on the patch type in the descriptor
|
2015-02-26 21:57:47 +00:00
|
|
|
TYPE & getValue( Far::PatchDescriptor desc ) {
|
2014-09-05 22:07:46 +00:00
|
|
|
switch (desc.GetType()) {
|
2015-04-17 14:42:53 +00:00
|
|
|
case Far::PatchDescriptor::REGULAR : return R;
|
2015-02-26 21:57:47 +00:00
|
|
|
case Far::PatchDescriptor::GREGORY : return G;
|
|
|
|
case Far::PatchDescriptor::GREGORY_BOUNDARY : return GB;
|
|
|
|
case Far::PatchDescriptor::GREGORY_BASIS : return GP;
|
2014-09-05 22:07:46 +00:00
|
|
|
default : assert(0);
|
|
|
|
}
|
|
|
|
// can't be reached (suppress compiler warning)
|
2015-04-17 14:42:53 +00:00
|
|
|
return R;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Counts the number of arrays required to store each type of patch used
|
|
|
|
// in the primitive
|
|
|
|
int getNumPatchArrays() const {
|
|
|
|
int result=0;
|
2015-04-17 14:42:53 +00:00
|
|
|
if (R) ++result;
|
2014-09-05 22:07:46 +00:00
|
|
|
if (G) ++result;
|
|
|
|
if (GB) ++result;
|
2014-11-11 19:27:25 +00:00
|
|
|
if (GP) ++result;
|
2014-09-05 22:07:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
typedef PatchTypes<Far::Index *> PatchCVPointers;
|
|
|
|
typedef PatchTypes<Far::PatchParam *> PatchParamPointers;
|
|
|
|
typedef PatchTypes<Far::Index *> SharpnessIndexPointers;
|
|
|
|
typedef PatchTypes<Far::Index> PatchFVarOffsets;
|
|
|
|
typedef PatchTypes<Far::Index **> PatchFVarPointers;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
} // namespace anon
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
namespace Far {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::PatchFaceTag::clear() {
|
2015-04-18 00:36:55 +00:00
|
|
|
std::memset(this, 0, sizeof(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::PatchFaceTag::assignBoundaryPropertiesFromEdgeMask(int boundaryEdgeMask) {
|
2015-04-18 00:36:55 +00:00
|
|
|
//
|
|
|
|
// The number of rotations to apply for boundary or corner patches varies on both
|
|
|
|
// where the boundary/corner occurs and whether boundary or corner -- so using a
|
|
|
|
// 4-bit mask should be sufficient to quickly determine all cases:
|
|
|
|
//
|
|
|
|
// Note that we currently expect patches with multiple boundaries to have already
|
|
|
|
// been isolated, so asserts are applied for such unexpected cases.
|
|
|
|
//
|
|
|
|
// Is the compiler going to build the 16-entry lookup table here, or should we do
|
|
|
|
// it ourselves?
|
|
|
|
//
|
|
|
|
_hasBoundaryEdge = true;
|
|
|
|
_boundaryMask = boundaryEdgeMask;
|
|
|
|
|
|
|
|
switch (boundaryEdgeMask) {
|
|
|
|
case 0x0: _boundaryCount = 0, _boundaryIndex = 0, _hasBoundaryEdge = false; break; // no boundaries
|
|
|
|
|
|
|
|
case 0x1: _boundaryCount = 1, _boundaryIndex = 0; break; // boundary edge 0
|
|
|
|
case 0x2: _boundaryCount = 1, _boundaryIndex = 1; break; // boundary edge 1
|
|
|
|
case 0x3: _boundaryCount = 2, _boundaryIndex = 1; break; // corner/crease vertex 1
|
|
|
|
case 0x4: _boundaryCount = 1, _boundaryIndex = 2; break; // boundary edge 2
|
|
|
|
case 0x5: assert(false); break; // N/A - opposite boundary edges
|
|
|
|
case 0x6: _boundaryCount = 2, _boundaryIndex = 2; break; // corner/crease vertex 2
|
|
|
|
case 0x7: assert(false); break; // N/A - three boundary edges
|
|
|
|
case 0x8: _boundaryCount = 1, _boundaryIndex = 3; break; // boundary edge 3
|
|
|
|
case 0x9: _boundaryCount = 2, _boundaryIndex = 0; break; // corner/crease vertex 0
|
|
|
|
case 0xa: assert(false); break; // N/A - opposite boundary edges
|
|
|
|
case 0xb: assert(false); break; // N/A - three boundary edges
|
|
|
|
case 0xc: _boundaryCount = 2, _boundaryIndex = 3; break; // corner/crease vertex 3
|
|
|
|
case 0xd: assert(false); break; // N/A - three boundary edges
|
|
|
|
case 0xe: assert(false); break; // N/A - three boundary edges
|
|
|
|
case 0xf: assert(false); break; // N/A - all boundaries
|
|
|
|
default: assert(false); break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-04-18 00:36:55 +00:00
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::PatchFaceTag::assignBoundaryPropertiesFromVertexMask(int boundaryVertexMask) {
|
2015-04-18 00:36:55 +00:00
|
|
|
//
|
|
|
|
// This is strictly needed for the irregular case when a vertex is a boundary in
|
|
|
|
// the presence of no boundary edges -- an extra-ordinary face with only one corner
|
|
|
|
// on the boundary.
|
|
|
|
//
|
|
|
|
// Its unclear at this point if patches with more than one such vertex are supported
|
|
|
|
// (if so, how do we deal with rotations) so for now we only allow one such vertex
|
|
|
|
// and assert for all other cases.
|
|
|
|
//
|
|
|
|
assert(_hasBoundaryEdge == false);
|
|
|
|
_boundaryMask = boundaryVertexMask;
|
|
|
|
|
|
|
|
switch (boundaryVertexMask) {
|
|
|
|
case 0x0: _boundaryCount = 0; break; // no boundaries
|
|
|
|
case 0x1: _boundaryCount = 1, _boundaryIndex = 0; break; // boundary vertex 0
|
|
|
|
case 0x2: _boundaryCount = 1, _boundaryIndex = 1; break; // boundary vertex 1
|
|
|
|
case 0x3: assert(false); break;
|
|
|
|
case 0x4: _boundaryCount = 1, _boundaryIndex = 2; break; // boundary vertex 2
|
|
|
|
case 0x5: assert(false); break;
|
|
|
|
case 0x6: assert(false); break;
|
|
|
|
case 0x7: assert(false); break;
|
|
|
|
case 0x8: _boundaryCount = 1, _boundaryIndex = 3; break; // boundary vertex 3
|
|
|
|
case 0x9: assert(false); break;
|
|
|
|
case 0xa: assert(false); break;
|
|
|
|
case 0xb: assert(false); break;
|
|
|
|
case 0xc: assert(false); break;
|
|
|
|
case 0xd: assert(false); break;
|
|
|
|
case 0xe: assert(false); break;
|
|
|
|
case 0xf: assert(false); break;
|
|
|
|
default: assert(false); break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Trivial anonymous helper functions:
|
|
|
|
//
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Face-varying channel cursor
|
|
|
|
//
|
|
|
|
// This cursors allows to iterate over a set of selected face-varying channels.
|
|
|
|
// If client-code specifies an optional sub-set of the list of channels carried
|
|
|
|
// by the TopologyRefiner, the cursor can traverse this list and return both its
|
|
|
|
// current position in the sub-set and the original index of the corresponding
|
|
|
|
// channel in the TopologyRefiner.
|
|
|
|
//
|
|
|
|
class FVarChannelCursor {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
FVarChannelCursor(TopologyRefiner const & refiner,
|
2015-06-03 20:17:40 +00:00
|
|
|
PatchTableFactory::Options options)
|
|
|
|
: _channelIndices(0)
|
|
|
|
{
|
2015-02-26 21:57:47 +00:00
|
|
|
if (options.generateFVarTables) {
|
|
|
|
// If client-code does not select specific channels, default to all
|
|
|
|
// the channels in the refiner.
|
|
|
|
if (options.numFVarChannels==-1) {
|
|
|
|
_numChannels = refiner.GetNumFVarChannels();
|
|
|
|
_channelIndices = 0;
|
|
|
|
} else {
|
|
|
|
assert(options.numFVarChannels<=refiner.GetNumFVarChannels());
|
|
|
|
_numChannels = options.numFVarChannels;
|
|
|
|
_channelIndices = options.fvarChannelIndices;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-02-26 21:57:47 +00:00
|
|
|
_numChannels = 0;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
_currentChannel = this->begin();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
// Increment cursor
|
|
|
|
FVarChannelCursor & operator++() {
|
|
|
|
++_currentChannel;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign a position to a cursor
|
|
|
|
FVarChannelCursor & operator = (int currentChannel) {
|
|
|
|
_currentChannel = currentChannel;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare cursor positions
|
|
|
|
bool operator != (int pos) {
|
|
|
|
return _currentChannel < pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return FVar channel index in the TopologyRefiner list
|
|
|
|
// XXXX use something better than dereferencing operator maybe ?
|
|
|
|
int operator*() {
|
|
|
|
assert(_currentChannel<_numChannels);
|
|
|
|
// If the cursor is iterating over a sub-set of channels, return the
|
|
|
|
// channel index from the sub-set, otherwise use the current cursor
|
|
|
|
// position as channel index.
|
|
|
|
return _channelIndices ?
|
|
|
|
_channelIndices[_currentChannel] : _currentChannel;
|
|
|
|
}
|
|
|
|
|
2015-06-02 21:58:35 +00:00
|
|
|
int pos() const { return _currentChannel; }
|
|
|
|
int begin() const { return 0; }
|
|
|
|
int end() const { return _numChannels; }
|
|
|
|
int size() const { return _numChannels; }
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int _numChannels, // total number of channels
|
|
|
|
_currentChannel; // current cursor position
|
|
|
|
int const * _channelIndices; // list of selected channel indices
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Adaptive Context
|
|
|
|
//
|
|
|
|
// Helper class aggregating transient contextual data structures during the
|
2015-05-22 18:50:01 +00:00
|
|
|
// creation of feature adaptive patch table. The structure simplifies
|
2015-02-26 21:57:47 +00:00
|
|
|
// the function prototypes of high-level private methods in the factory.
|
|
|
|
// This helps keeping the factory class stateless.
|
|
|
|
//
|
|
|
|
// Note : struct members are not re-entrant nor are they intended to be !
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
struct PatchTableFactory::AdaptiveContext {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
AdaptiveContext(TopologyRefiner const & refiner, Options options);
|
|
|
|
|
|
|
|
TopologyRefiner const & refiner;
|
|
|
|
|
|
|
|
Options const options;
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
// The patch table being created
|
|
|
|
PatchTable * table;
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
//
|
|
|
|
// Vertex
|
|
|
|
//
|
|
|
|
|
|
|
|
// Counters accumulating each type of patches during topology traversal
|
|
|
|
PatchTypes<int> patchInventory;
|
|
|
|
|
|
|
|
// Bit tags accumulating patch attributes during topology traversal
|
|
|
|
PatchTagVector patchTags;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
//
|
|
|
|
// Face-varying
|
|
|
|
//
|
|
|
|
|
|
|
|
// True if face-varying patches need to be generated for this topology
|
|
|
|
bool RequiresFVarPatches() const;
|
|
|
|
|
|
|
|
// A cursor to iterate through the face-varying channels requested
|
|
|
|
// by client-code
|
|
|
|
FVarChannelCursor fvarChannelCursor;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Constructor
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::AdaptiveContext::AdaptiveContext(
|
2015-02-26 21:57:47 +00:00
|
|
|
TopologyRefiner const & ref, Options opts) :
|
2015-05-22 18:50:01 +00:00
|
|
|
refiner(ref), options(opts), table(0),
|
2015-04-18 00:36:55 +00:00
|
|
|
fvarChannelCursor(ref, opts) {
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::AdaptiveContext::RequiresFVarPatches() const {
|
2015-06-02 21:58:35 +00:00
|
|
|
return (fvarChannelCursor.size() > 0);
|
2015-02-26 21:57:47 +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
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::allocateVertexTables(PatchTable * table, int /* nlevels */, bool hasSharpness) {
|
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
|
|
|
}
|
|
|
|
|
2014-11-18 18:48:37 +00:00
|
|
|
if (ncvs==0 or 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
|
|
|
|
|
|
|
if (hasSharpness) {
|
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
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::allocateFVarChannels(TopologyRefiner const & refiner,
|
|
|
|
Options options, int npatches, PatchTable * table) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
assert(options.generateFVarTables and
|
2015-05-22 18:50:01 +00:00
|
|
|
refiner.GetNumFVarChannels()>0 and npatches>0 and table);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
// Create a channel cursor to iterate over client-selected channels or
|
|
|
|
// default to the channels found in the TopologyRefiner
|
|
|
|
FVarChannelCursor fvc(refiner, options);
|
|
|
|
if (fvc.size()==0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
table->allocateFVarPatchChannels(fvc.size());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
// Iterate with the cursor to initialize each channel
|
|
|
|
for (fvc=fvc.begin(); fvc!=fvc.end(); ++fvc) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
Sdc::Options::FVarLinearInterpolation interpolation =
|
|
|
|
refiner.GetFVarLinearInterpolation(*fvc);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 20:51:32 +00:00
|
|
|
table->setFVarPatchChannelLinearInterpolation(interpolation, fvc.pos());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
int nverts = 0;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 21:58:35 +00:00
|
|
|
PatchDescriptor::Type type = options.triangulateQuads ?
|
|
|
|
PatchDescriptor::TRIANGLES : PatchDescriptor::QUADS;
|
|
|
|
|
|
|
|
nverts =
|
|
|
|
npatches * PatchDescriptor::GetNumFVarControlVertices(type);
|
2015-06-03 19:49:01 +00:00
|
|
|
|
2015-06-02 20:51:32 +00:00
|
|
|
table->allocateFVarPatchChannelValues(npatches, nverts, fvc.pos());
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// gather face-varying patch points
|
2015-04-18 00:36:55 +00:00
|
|
|
int
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::gatherFVarData(AdaptiveContext & context, int level,
|
2015-02-26 21:57:47 +00:00
|
|
|
Index faceIndex, Index levelFaceOffset, int rotation,
|
|
|
|
Index const * levelFVarVertOffsets, Index fofss, Index ** fptrs) {
|
2015-06-03 19:49:01 +00:00
|
|
|
|
2015-06-02 21:58:35 +00:00
|
|
|
(void)levelFaceOffset; // not used
|
|
|
|
(void)fofss; // not used
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
if (not context.RequiresFVarPatches()) {
|
|
|
|
return 0;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
TopologyRefiner const & refiner = context.refiner;
|
|
|
|
|
|
|
|
// Iterate over valid FVar channels (if any)
|
|
|
|
FVarChannelCursor & fvc = context.fvarChannelCursor;
|
|
|
|
for (fvc=fvc.begin(); fvc!=fvc.end(); ++fvc) {
|
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level const & vtxLevel = refiner.getLevel(level);
|
|
|
|
Vtr::internal::FVarLevel const & fvarLevel = vtxLevel.getFVarLevel(*fvc);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2015-06-03 19:49:01 +00:00
|
|
|
//
|
|
|
|
// Bi-linear patches
|
|
|
|
//
|
2015-02-26 21:57:47 +00:00
|
|
|
|
2015-06-03 19:49:01 +00:00
|
|
|
ConstIndexArray fvarValues = fvarLevel.getFaceValues(faceIndex);
|
2015-06-02 21:58:35 +00:00
|
|
|
|
2015-06-03 19:49:01 +00:00
|
|
|
// Store verts values directly in non-sparse context channel arrays
|
|
|
|
for (int vert=0; vert<fvarValues.size(); ++vert) {
|
|
|
|
fptrs[fvc.pos()][vert] =
|
|
|
|
levelFVarVertOffsets[fvc.pos()] + fvarValues[(vert+rotation)%4];
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2015-06-03 19:49:01 +00:00
|
|
|
fptrs[fvc.pos()]+=fvarValues.size();
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
|
|
|
return 1;
|
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
|
|
|
//
|
|
|
|
PatchParam *
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::computePatchParam(
|
2015-04-20 06:25:43 +00:00
|
|
|
TopologyRefiner const & refiner, PtexIndices const &ptexIndices,
|
2015-04-24 20:18:03 +00:00
|
|
|
int depth, Vtr::Index faceIndex, int boundaryMask,
|
2015-06-11 20:18:25 +00:00
|
|
|
int transitionMask, PatchParam *param) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-11 20:18:25 +00:00
|
|
|
if (param == NULL) return NULL;
|
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) {
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Refinement const& refinement = refiner.getRefinement(i-1);
|
|
|
|
Vtr::internal::Level const& parentLevel = refiner.getLevel(i-1);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vtr::Index parentFaceIndex = refinement.getChildFaceParentFace(faceIndex);
|
|
|
|
childIndexInParent = refinement.getChildFaceInParentFace(faceIndex);
|
|
|
|
|
|
|
|
if (parentLevel.getFaceVertices(parentFaceIndex).size() == 4) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-22 05:23:22 +00:00
|
|
|
Vtr::Index ptexIndex = ptexIndices.GetFaceId(faceIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(ptexIndex!=-1);
|
|
|
|
|
|
|
|
if (nonquad) {
|
|
|
|
ptexIndex+=childIndexInParent;
|
|
|
|
--depth;
|
|
|
|
}
|
|
|
|
|
2015-06-11 20:18:25 +00:00
|
|
|
param->Set(ptexIndex, (short)u, (short)v, (unsigned short) depth, nonquad,
|
2015-04-17 14:42:53 +00:00
|
|
|
(unsigned short) boundaryMask, (unsigned short) transitionMask);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-11 20:18:25 +00:00
|
|
|
return ++param;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
//
|
|
|
|
// Indexing sharpnesses
|
|
|
|
//
|
|
|
|
inline int
|
|
|
|
assignSharpnessIndex(float sharpness, std::vector<float> & sharpnessValues) {
|
|
|
|
|
|
|
|
// linear search
|
|
|
|
for (int i=0; i<(int)sharpnessValues.size(); ++i) {
|
|
|
|
if (sharpnessValues[i] == sharpness) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sharpnessValues.push_back(sharpness);
|
|
|
|
return (int)sharpnessValues.size()-1;
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
2014-09-17 18:17:25 +00:00
|
|
|
// ensure that triangulateQuads is only set for quadrilateral schemes
|
2015-01-07 01:40:11 +00:00
|
|
|
options.triangulateQuads &= (refiner.GetSchemeType()==Sdc::SCHEME_BILINEAR or
|
|
|
|
refiner.GetSchemeType()==Sdc::SCHEME_CATMARK);
|
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
|
|
|
maxlevel = refiner.GetMaxLevel(),
|
|
|
|
firstlevel = options.generateAllLevels ? 0 : maxlevel,
|
2014-11-25 20:41:19 +00:00
|
|
|
nlevels = maxlevel-firstlevel+1;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-04-20 06:25:43 +00:00
|
|
|
PtexIndices ptexIndices(refiner);
|
|
|
|
|
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.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable * table = new PatchTable(maxvalence);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
table->_numPtexFaces = 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
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (level>=firstlevel) {
|
2015-05-22 18:50:01 +00:00
|
|
|
table->pushPatchArray(desc, npatches, &voffset, &poffset, 0);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate various tables
|
2015-05-22 18:50:01 +00:00
|
|
|
allocateVertexTables( table, 0, /*hasSharpness=*/false );
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
FVarChannelCursor fvc(refiner, options);
|
2015-05-28 20:09:44 +00:00
|
|
|
bool generateFVarPatches = (options.generateFVarTables and fvc.size()>0);
|
|
|
|
if (generateFVarPatches) {
|
2015-05-22 18:50:01 +00:00
|
|
|
int npatches = table->GetNumPatchesTotal();
|
|
|
|
allocateFVarChannels(refiner, options, npatches, table);
|
|
|
|
assert(fvc.size() == table->GetNumFVarChannels());
|
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-02-26 21:57:47 +00:00
|
|
|
Index levelVertOffset = options.generateAllLevels ?
|
2015-05-22 04:26:41 +00:00
|
|
|
0 : refiner.GetLevel(0).GetNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-09 21:48:50 +00:00
|
|
|
Index * levelFVarVertOffsets = 0;
|
2015-02-26 21:57:47 +00:00
|
|
|
if (generateFVarPatches) {
|
|
|
|
|
|
|
|
levelFVarVertOffsets = (Index *)alloca(fvc.size()*sizeof(Index));
|
|
|
|
memset(levelFVarVertOffsets, 0, fvc.size()*sizeof(Index));
|
|
|
|
|
|
|
|
fptr = (Index **)alloca(fvc.size()*sizeof(Index *));
|
|
|
|
for (fvc=fvc.begin(); fvc!=fvc.end(); ++fvc) {
|
2015-06-02 16:13:17 +00:00
|
|
|
fptr[fvc.pos()] = table->getFVarValues(fvc.pos()).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
|
|
|
|
2015-05-22 04:26:41 +00:00
|
|
|
if (refiner.HasHoles() and 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];
|
|
|
|
}
|
|
|
|
|
2015-04-24 20:18:03 +00:00
|
|
|
pptr = computePatchParam(refiner, ptexIndices, level, face, /*boundary*/0, /*transition*/0, pptr);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
if (generateFVarPatches) {
|
|
|
|
for (fvc=fvc.begin(); fvc!=fvc.end(); ++fvc) {
|
2015-06-01 23:25:44 +00:00
|
|
|
ConstIndexArray fvalues = refLevel.GetFaceFVarValues(face, *fvc);
|
2015-03-05 21:09:27 +00:00
|
|
|
for (int vert=0; vert<fvalues.size(); ++vert) {
|
2015-06-02 16:13:17 +00:00
|
|
|
assert((levelVertOffset + fvalues[vert]) < (int)table->getFVarValues(fvc.pos()).size());
|
2015-03-05 21:09:27 +00:00
|
|
|
fptr[fvc.pos()][vert] = levelFVarVertOffsets[fvc.pos()] + fvalues[vert];
|
2015-02-26 21:57:47 +00:00
|
|
|
}
|
2015-03-05 21:09:27 +00:00
|
|
|
fptr[fvc.pos()]+=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;
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
if (generateFVarPatches) {
|
|
|
|
for (fvc=fvc.begin(); fvc!=fvc.end(); ++fvc) {
|
|
|
|
*fptr[fvc.pos()] = *(fptr[fvc.pos()]-4); // copy fv0 index
|
|
|
|
++fptr[fvc.pos()];
|
|
|
|
*fptr[fvc.pos()] = *(fptr[fvc.pos()]-3); // copy fv2 index
|
|
|
|
++fptr[fvc.pos()];
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.generateAllLevels) {
|
2015-05-22 04:26:41 +00:00
|
|
|
levelVertOffset += refiner.GetLevel(level).GetNumVertices();
|
2015-02-26 21:57:47 +00:00
|
|
|
for (fvc=fvc.begin(); fvc!=fvc.end(); ++fvc) {
|
2015-05-22 04:26:41 +00:00
|
|
|
levelFVarVertOffsets[fvc.pos()] += refiner.GetLevel(level).GetNumFVarValues(fvc.pos());
|
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
|
|
|
|
|
|
|
assert(not refiner.IsUniform());
|
|
|
|
|
2015-04-20 06:25:43 +00:00
|
|
|
PtexIndices ptexIndices(refiner);
|
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
AdaptiveContext context(refiner, options);
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// First identify the patches -- accumulating the inventory patches for all of the
|
|
|
|
// different types and information about the patch for each face:
|
|
|
|
//
|
2015-04-23 23:58:45 +00:00
|
|
|
identifyAdaptivePatches(context);
|
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 based on
|
2014-09-05 22:07:46 +00:00
|
|
|
// the inventory of patches determined above:
|
|
|
|
//
|
2015-04-02 03:44:33 +00:00
|
|
|
int maxValence = refiner.GetMaxValence();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
context.table = new PatchTable(maxValence);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// Populate the patch array descriptors
|
2015-05-22 18:50:01 +00:00
|
|
|
context.table->reservePatchArrays(context.patchInventory.getNumPatchArrays());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
// Sort through the inventory and push back non-empty patch arrays
|
2015-02-11 22:25:44 +00:00
|
|
|
ConstPatchDescriptorArray const & descs =
|
|
|
|
PatchDescriptor::GetAdaptivePatchDescriptors(Sdc::SCHEME_CATMARK);
|
2014-10-09 21:48:50 +00:00
|
|
|
|
|
|
|
int voffset=0, poffset=0, qoffset=0;
|
2015-02-11 22:25:44 +00:00
|
|
|
for (int i=0; i<descs.size(); ++i) {
|
|
|
|
PatchDescriptor desc = descs[i];
|
2015-05-22 18:50:01 +00:00
|
|
|
context.table->pushPatchArray(desc,
|
2015-02-26 21:57:47 +00:00
|
|
|
context.patchInventory.getValue(desc), &voffset, &poffset, &qoffset );
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
context.table->_numPtexFaces = ptexIndices.GetNumFaces();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// Allocate various tables
|
2015-04-17 23:26:57 +00:00
|
|
|
bool hasSharpness = context.options.useSingleCreasePatch;
|
2015-05-22 18:50:01 +00:00
|
|
|
allocateVertexTables(context.table, 0, hasSharpness);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
if (context.RequiresFVarPatches()) {
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
int npatches = context.table->GetNumPatchesTotal();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
allocateFVarChannels(refiner, options, npatches, context.table);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now populate the patches:
|
|
|
|
//
|
2015-04-23 23:58:45 +00:00
|
|
|
populateAdaptivePatches(context, ptexIndices);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
return context.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
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::identifyAdaptivePatches(AdaptiveContext & 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.
|
|
|
|
//
|
2015-02-26 21:57:47 +00:00
|
|
|
context.patchTags.resize(refiner.GetNumFacesTotal());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
PatchFaceTag * levelPatchTags = &context.patchTags[0];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-03-26 17:42:32 +00:00
|
|
|
for (int levelIndex = 0; levelIndex < refiner.GetNumLevels(); ++levelIndex) {
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level const * level = &refiner.getLevel(levelIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Given components at Level[i], we need to be looking at Refinement[i] -- and not
|
|
|
|
// [i-1] -- because the Refinement has transitional information for its parent edges
|
2015-03-26 17:42:32 +00:00
|
|
|
// and faces.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// For components in this level, we want to determine:
|
|
|
|
// - what Edges are "transitional" (already done in Refinement for parent)
|
|
|
|
// - what Faces are "transitional" (already done in Refinement for parent)
|
2015-03-26 17:42:32 +00:00
|
|
|
// - what Faces are "complete" (applied to this Level in previous refinement)
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Refinement const * refinement = 0;
|
|
|
|
Vtr::internal::Refinement::SparseTag const * refinedFaceTags = 0;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-03-26 17:42:32 +00:00
|
|
|
if (levelIndex < refiner.GetMaxLevel()) {
|
|
|
|
refinement = &refiner.getRefinement(levelIndex);
|
2015-06-01 01:26:13 +00:00
|
|
|
refinedFaceTags = &refinement->getParentFaceSparseTag(0);
|
2015-03-26 17:42:32 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int faceIndex = 0; faceIndex < level->getNumFaces(); ++faceIndex) {
|
2014-11-11 19:27:25 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
PatchFaceTag & patchTag = levelPatchTags[faceIndex];
|
2014-09-05 22:07:46 +00:00
|
|
|
patchTag.clear();
|
|
|
|
patchTag._hasPatch = false;
|
|
|
|
|
2015-04-02 03:44:33 +00:00
|
|
|
if (level->isFaceHole(faceIndex)) {
|
2015-03-26 17:42:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// This face does not warrant a patch under the following conditions:
|
|
|
|
//
|
|
|
|
// - the face was fully refined into child faces
|
|
|
|
// - the face is not a quad (should have been refined, so assert)
|
|
|
|
// - the face is not "complete"
|
|
|
|
//
|
|
|
|
// The first is trivially determined, and the second is really redundant. The
|
|
|
|
// last -- "incompleteness" -- indicates a face that exists to support the limit
|
|
|
|
// of some neighboring component, and which does not have its own neighborhood
|
|
|
|
// fully defined for its limit. If any child vertex of a vertex of this face is
|
2015-03-26 17:42:32 +00:00
|
|
|
// "incomplete" (and all are tagged) the face must be "incomplete", so get the
|
|
|
|
// "composite" tag which combines bits for all vertices:
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Refinement::SparseTag refinedFaceTag = refinedFaceTags ?
|
|
|
|
refinedFaceTags[faceIndex] : Vtr::internal::Refinement::SparseTag();
|
2015-03-26 17:42:32 +00:00
|
|
|
|
|
|
|
if (refinedFaceTag._selected) {
|
2014-09-05 22:07:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
Vtr::ConstIndexArray fVerts = level->getFaceVertices(faceIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(fVerts.size() == 4);
|
|
|
|
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level::VTag compFaceVertTag = level->getFaceCompositeVTag(fVerts);
|
2015-03-26 17:42:32 +00:00
|
|
|
if (compFaceVertTag._incomplete) {
|
2014-09-05 22:07:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-05-21 00:43:13 +00:00
|
|
|
// We have a quad that will be represented as a B-spline or end cap patch. Use
|
2015-03-26 17:42:32 +00:00
|
|
|
// the "composite" tag again to quickly determine if any vertex is irregular, on
|
|
|
|
// a boundary, non-manifold, etc.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Inspect the edges for boundaries and transitional edges and pack results into
|
|
|
|
// 4-bit masks. We detect boundary edges rather than vertices as we hope to
|
|
|
|
// replace the mask in future with one for infinitely sharp edges -- allowing
|
|
|
|
// us to detect regular patches and avoid isolation. We still need to account
|
|
|
|
// for the irregular/xordinary case when a corner vertex is a boundary but there
|
|
|
|
// are no boundary edges.
|
|
|
|
//
|
2015-05-21 00:43:13 +00:00
|
|
|
// As for transition detection, assign the transition properties (even if 0).
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-03-26 17:42:32 +00:00
|
|
|
// NOTE on patches around non-manifold vertices:
|
2015-05-21 00:43:13 +00:00
|
|
|
// In most cases the use of regular boundary or corner patches is what we want,
|
2015-03-26 17:42:32 +00:00
|
|
|
// but in some, i.e. when a non-manifold vertex is infinitely sharp, using
|
|
|
|
// such patches will create some discontinuities. At this point non-manifold
|
|
|
|
// support is still evolving and is not strictly defined, so this is left to
|
|
|
|
// a later date to resolve.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// NOTE on infinitely sharp (hard) edges:
|
|
|
|
// We should be able to adapt this later to detect hard (inf-sharp) edges
|
|
|
|
// rather than just boundary edges -- there is a similar tag per edge. That
|
|
|
|
// should allow us to generate regular patches for interior hard features.
|
|
|
|
//
|
2015-03-26 17:42:32 +00:00
|
|
|
bool hasBoundaryVertex = compFaceVertTag._boundary;
|
|
|
|
bool hasNonManifoldVertex = compFaceVertTag._nonManifold;
|
|
|
|
bool hasXOrdinaryVertex = compFaceVertTag._xordinary;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
patchTag._hasPatch = true;
|
2015-03-26 17:42:32 +00:00
|
|
|
patchTag._isRegular = not hasXOrdinaryVertex or hasNonManifoldVertex;
|
2014-10-13 15:52:09 +00:00
|
|
|
|
|
|
|
// single crease patch optimization
|
2015-02-26 21:57:47 +00:00
|
|
|
if (context.options.useSingleCreasePatch and
|
2015-03-26 17:42:32 +00:00
|
|
|
not hasXOrdinaryVertex and not hasBoundaryVertex and not hasNonManifoldVertex) {
|
2014-10-13 15:52:09 +00:00
|
|
|
|
2014-12-20 02:18:13 +00:00
|
|
|
Vtr::ConstIndexArray fEdges = level->getFaceEdges(faceIndex);
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level::ETag compFaceETag = level->getFaceCompositeETag(fEdges);
|
2014-12-20 02:18:13 +00:00
|
|
|
|
|
|
|
if (compFaceETag._semiSharp or compFaceETag._infSharp) {
|
|
|
|
float sharpness = 0;
|
|
|
|
int rotation = 0;
|
|
|
|
if (level->isSingleCreasePatch(faceIndex, &sharpness, &rotation)) {
|
|
|
|
|
|
|
|
// cap sharpness to the max isolation level
|
2015-03-26 17:42:32 +00:00
|
|
|
float cappedSharpness =
|
|
|
|
std::min(sharpness, (float)(context.options.maxIsolationLevel - levelIndex));
|
2014-12-20 02:18:13 +00:00
|
|
|
if (cappedSharpness > 0) {
|
|
|
|
patchTag._isSingleCrease = true;
|
2015-06-02 04:18:35 +00:00
|
|
|
patchTag._boundaryIndex = rotation;
|
2014-12-20 02:18:13 +00:00
|
|
|
}
|
2014-10-13 15:52:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 17:42:32 +00:00
|
|
|
// Identify boundaries for both regular and xordinary patches -- non-manifold
|
|
|
|
// edges and vertices are interpreted as boundaries for regular patches
|
|
|
|
if (hasBoundaryVertex or hasNonManifoldVertex) {
|
2014-12-15 18:23:13 +00:00
|
|
|
Vtr::ConstIndexArray fEdges = level->getFaceEdges(faceIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-01 01:26:13 +00:00
|
|
|
int boundaryEdgeMask = ((level->getEdgeTag(fEdges[0])._boundary) << 0) |
|
|
|
|
((level->getEdgeTag(fEdges[1])._boundary) << 1) |
|
|
|
|
((level->getEdgeTag(fEdges[2])._boundary) << 2) |
|
|
|
|
((level->getEdgeTag(fEdges[3])._boundary) << 3);
|
2015-03-26 17:42:32 +00:00
|
|
|
if (hasNonManifoldVertex) {
|
2015-06-01 01:26:13 +00:00
|
|
|
int nonManEdgeMask = ((level->getEdgeTag(fEdges[0])._nonManifold) << 0) |
|
|
|
|
((level->getEdgeTag(fEdges[1])._nonManifold) << 1) |
|
|
|
|
((level->getEdgeTag(fEdges[2])._nonManifold) << 2) |
|
|
|
|
((level->getEdgeTag(fEdges[3])._nonManifold) << 3);
|
2015-03-26 17:42:32 +00:00
|
|
|
boundaryEdgeMask |= nonManEdgeMask;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
if (boundaryEdgeMask) {
|
|
|
|
patchTag.assignBoundaryPropertiesFromEdgeMask(boundaryEdgeMask);
|
|
|
|
} else {
|
2015-06-01 01:26:13 +00:00
|
|
|
int boundaryVertMask = ((level->getVertexTag(fVerts[0])._boundary) << 0) |
|
|
|
|
((level->getVertexTag(fVerts[1])._boundary) << 1) |
|
|
|
|
((level->getVertexTag(fVerts[2])._boundary) << 2) |
|
|
|
|
((level->getVertexTag(fVerts[3])._boundary) << 3);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-03-26 17:42:32 +00:00
|
|
|
if (hasNonManifoldVertex) {
|
2015-06-01 01:26:13 +00:00
|
|
|
int nonManVertMask = ((level->getVertexTag(fVerts[0])._nonManifold) << 0) |
|
|
|
|
((level->getVertexTag(fVerts[1])._nonManifold) << 1) |
|
|
|
|
((level->getVertexTag(fVerts[2])._nonManifold) << 2) |
|
|
|
|
((level->getVertexTag(fVerts[3])._nonManifold) << 3);
|
2015-03-26 17:42:32 +00:00
|
|
|
boundaryVertMask |= nonManVertMask;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
patchTag.assignBoundaryPropertiesFromVertexMask(boundaryVertMask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 17:42:32 +00:00
|
|
|
// XXXX (barfowl) -- why are we approximating a smooth x-ordinary corner with
|
|
|
|
// a sharp corner patch? The boundary/corner points of the regular patch are
|
|
|
|
// not even made colinear to make it smoother. Something historical here...
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-03-26 17:42:32 +00:00
|
|
|
// So this treatment may become optional in future and is bracketed with a
|
|
|
|
// condition now for that reason. We approximate x-ordinary smooth corners
|
|
|
|
// with regular B-spline patches instead of using a Gregory patch. The smooth
|
|
|
|
// corner must be properly isolated from any other irregular vertices (as it
|
|
|
|
// will be at any level > 1) otherwise the Gregory patch is necessary.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-03-26 17:42:32 +00:00
|
|
|
// This flag to be initialized with a future option... ?
|
2014-09-05 22:07:46 +00:00
|
|
|
bool approxSmoothCornerWithRegularPatch = true;
|
2015-03-26 17:42:32 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (approxSmoothCornerWithRegularPatch) {
|
2015-02-26 21:57:47 +00:00
|
|
|
if (!patchTag._isRegular and (patchTag._boundaryCount == 2)) {
|
2014-09-05 22:07:46 +00:00
|
|
|
// We may have a sharp corner opposite/adjacent an xordinary vertex --
|
|
|
|
// need to make sure there is only one xordinary vertex and that it
|
|
|
|
// is the corner vertex.
|
2015-03-26 17:42:32 +00:00
|
|
|
if (levelIndex > 1) {
|
|
|
|
patchTag._isRegular = true;
|
|
|
|
} else {
|
|
|
|
int xordVertex = 0;
|
|
|
|
int xordCount = 0;
|
2015-06-01 01:26:13 +00:00
|
|
|
if (level->getVertexTag(fVerts[0])._xordinary) { xordCount++; xordVertex = 0; }
|
|
|
|
if (level->getVertexTag(fVerts[1])._xordinary) { xordCount++; xordVertex = 1; }
|
|
|
|
if (level->getVertexTag(fVerts[2])._xordinary) { xordCount++; xordVertex = 2; }
|
|
|
|
if (level->getVertexTag(fVerts[3])._xordinary) { xordCount++; xordVertex = 3; }
|
2015-03-26 17:42:32 +00:00
|
|
|
|
|
|
|
if (xordCount == 1) {
|
|
|
|
// We require the vertex opposite the xordinary vertex be interior:
|
2015-06-01 01:26:13 +00:00
|
|
|
if (not level->getVertexTag(fVerts[(xordVertex + 2) % 4])._boundary) {
|
2015-03-26 17:42:32 +00:00
|
|
|
patchTag._isRegular = true;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 17:42:32 +00:00
|
|
|
//
|
|
|
|
// Now that all boundary features have have been identified and tagged, assign
|
|
|
|
// the transition type for the patch before taking inventory.
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Identify and increment counts for regular patches (both non-transitional and
|
|
|
|
// transitional) and extra-ordinary patches (always non-transitional):
|
|
|
|
//
|
2015-03-26 17:42:32 +00:00
|
|
|
patchTag.assignTransitionPropertiesFromEdgeMask(refinedFaceTag._transitional);
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (patchTag._isRegular) {
|
|
|
|
|
2015-04-17 23:26:57 +00:00
|
|
|
if (patchTag._boundaryCount == 0) {
|
2015-04-17 14:42:53 +00:00
|
|
|
context.patchInventory.R++;
|
2014-09-05 22:07:46 +00:00
|
|
|
} else if (patchTag._boundaryCount == 1) {
|
2015-04-17 14:42:53 +00:00
|
|
|
context.patchInventory.R++;
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
2015-04-17 14:42:53 +00:00
|
|
|
context.patchInventory.R++;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-23 23:58:45 +00:00
|
|
|
// select endcap patchtype
|
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
|
|
|
context.patchInventory.GP++;
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
|
|
|
context.patchInventory.R++;
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_LEGACY_GREGORY:
|
|
|
|
if (patchTag._boundaryCount == 0) {
|
|
|
|
context.patchInventory.G++;
|
|
|
|
} else {
|
|
|
|
context.patchInventory.GB++;
|
2014-11-11 19:27:25 +00:00
|
|
|
}
|
2015-04-23 23:58:45 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
levelPatchTags += level->getNumFaces();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Populate all adaptive patches now that the tables to hold data for them have been allocated.
|
|
|
|
// We need the inventory (counts per patch type) and the patch tags per face that were previously
|
|
|
|
// idenified.
|
|
|
|
//
|
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::populateAdaptivePatches(
|
2015-04-23 23:58:45 +00:00
|
|
|
AdaptiveContext & context, PtexIndices const & ptexIndices) {
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
TopologyRefiner const & refiner = context.refiner;
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable * table = context.table;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Setup convenience pointers at the beginning of each patch array for each
|
|
|
|
// table (patches, ptex)
|
|
|
|
//
|
|
|
|
PatchCVPointers iptrs;
|
|
|
|
PatchParamPointers pptrs;
|
2015-02-26 21:57:47 +00:00
|
|
|
PatchFVarOffsets fofss;
|
2014-09-05 22:07:46 +00:00
|
|
|
PatchFVarPointers fptrs;
|
2014-10-13 15:52:09 +00:00
|
|
|
SharpnessIndexPointers sptrs;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-11 22:25:44 +00:00
|
|
|
ConstPatchDescriptorArray const & descs =
|
|
|
|
PatchDescriptor::GetAdaptivePatchDescriptors(Sdc::SCHEME_CATMARK);
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-02-11 22:25:44 +00:00
|
|
|
for (int i=0; i<descs.size(); ++i) {
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-02-11 22:25:44 +00:00
|
|
|
PatchDescriptor desc = descs[i];
|
2014-10-09 21:48:50 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
Index arrayIndex = table->findPatchArray(desc);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-25 20:41:19 +00:00
|
|
|
if (arrayIndex==Vtr::INDEX_INVALID) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
iptrs.getValue(desc) = table->getPatchArrayVertices(arrayIndex).begin();
|
|
|
|
pptrs.getValue(desc) = table->getPatchParams(arrayIndex).begin();
|
2015-04-17 23:26:57 +00:00
|
|
|
if (context.options.useSingleCreasePatch) {
|
2015-05-22 18:50:01 +00:00
|
|
|
sptrs.getValue(desc) = 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()) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
Index & offsets = fofss.getValue(desc);
|
2015-05-22 18:50:01 +00:00
|
|
|
offsets = table->getPatchIndex(arrayIndex, 0);
|
2015-02-26 21:57:47 +00:00
|
|
|
|
|
|
|
// XXXX manuelk this stuff will go away as we use offsets from FVarPatchChannel
|
|
|
|
FVarChannelCursor & fvc = context.fvarChannelCursor;
|
2015-05-22 18:50:01 +00:00
|
|
|
assert(fvc.size() == table->GetNumFVarChannels());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
Index ** fptr = (Index **)alloca(fvc.size()*sizeof(Index *));
|
|
|
|
for (fvc=fvc.begin(); fvc!=fvc.end(); ++fvc) {
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
Index pidx = table->getPatchIndex(arrayIndex, 0);
|
2015-02-26 21:57:47 +00:00
|
|
|
int ofs = pidx * 4;
|
2015-06-02 16:13:17 +00:00
|
|
|
fptr[fvc.pos()] = &table->getFVarValues(fvc.pos())[ofs];
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-02-11 22:25:44 +00:00
|
|
|
fptrs.getValue(desc) = fptr;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now iterate through the faces for all levels and populate the patches:
|
|
|
|
//
|
2015-02-26 21:57:47 +00:00
|
|
|
int levelFaceOffset = 0,
|
|
|
|
levelVertOffset = 0;
|
2014-09-05 22:07:46 +00:00
|
|
|
int * levelFVarVertOffsets = 0;
|
2015-02-26 21:57:47 +00:00
|
|
|
if (context.RequiresFVarPatches()) {
|
|
|
|
int nchannels = refiner.GetNumFVarChannels();
|
2015-05-14 20:25:33 +00:00
|
|
|
levelFVarVertOffsets = (int *)alloca(nchannels*sizeof(int));
|
2015-02-26 21:57:47 +00:00
|
|
|
memset(levelFVarVertOffsets, 0, nchannels*sizeof(int));
|
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;
|
|
|
|
|
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
|
|
|
endCapGregoryBasis = new EndCapGregoryBasisPatchFactory(
|
|
|
|
refiner, context.options.shareEndCapPatchPoints);
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
|
|
|
endCapBSpline = new EndCapBSplineBasisPatchFactory(refiner);
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_LEGACY_GREGORY:
|
|
|
|
endCapLegacyGregory = new EndCapLegacyGregoryPatchFactory(refiner);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
for (int i = 0; i < refiner.GetNumLevels(); ++i) {
|
2015-05-26 03:34:50 +00:00
|
|
|
Vtr::internal::Level const * level = &refiner.getLevel(i);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-02-26 21:57:47 +00:00
|
|
|
const PatchFaceTag * levelPatchTags = &context.patchTags[levelFaceOffset];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int faceIndex = 0; faceIndex < level->getNumFaces(); ++faceIndex) {
|
|
|
|
|
2015-04-02 03:44:33 +00:00
|
|
|
if (level->isFaceHole(faceIndex)) {
|
2014-10-24 20:52:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PatchFaceTag& patchTag = levelPatchTags[faceIndex];
|
2014-11-11 19:27:25 +00:00
|
|
|
if (not patchTag._hasPatch) {
|
2014-10-24 20:52:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
if (patchTag._isRegular) {
|
2014-10-09 21:48:50 +00:00
|
|
|
Index patchVerts[16];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
int bIndex = patchTag._boundaryIndex;
|
2015-04-17 14:42:53 +00:00
|
|
|
int boundaryMask = patchTag._boundaryMask;
|
|
|
|
int transitionMask = patchTag._transitionMask;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 04:18:35 +00:00
|
|
|
int const * permutation = 0;
|
|
|
|
// only single-crease patch has a sharpness.
|
|
|
|
float sharpness = 0;
|
2015-04-27 19:40:18 +00:00
|
|
|
|
2015-06-02 04:18:35 +00:00
|
|
|
if (patchTag._boundaryCount == 0) {
|
|
|
|
static int const permuteRegular[16] = { 5, 6, 7, 8, 4, 0, 1, 9, 15, 3, 2, 10, 14, 13, 12, 11 };
|
|
|
|
permutation = permuteRegular;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 04:18:35 +00:00
|
|
|
if (patchTag._isSingleCrease) {
|
|
|
|
boundaryMask = (1<<bIndex);
|
|
|
|
sharpness = level->getEdgeSharpness((level->getFaceEdges(faceIndex)[bIndex]));
|
|
|
|
sharpness = std::min(sharpness, (float)(context.options.maxIsolationLevel-i));
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 04:18:35 +00:00
|
|
|
level->gatherQuadRegularInteriorPatchPoints(faceIndex, patchVerts, 0 /* no rotation*/);
|
|
|
|
} else if (patchTag._boundaryCount == 1) {
|
|
|
|
// 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];
|
|
|
|
level->gatherQuadRegularBoundaryPatchPoints(faceIndex, patchVerts, bIndex);
|
|
|
|
} else if (patchTag._boundaryCount == 2) {
|
|
|
|
// 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];
|
|
|
|
level->gatherQuadRegularCornerPatchPoints(faceIndex, patchVerts, bIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
2015-06-02 04:18:35 +00:00
|
|
|
assert(patchTag._boundaryCount >=0 && patchTag._boundaryCount <= 2);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 04:18:35 +00:00
|
|
|
offsetAndPermuteIndices(patchVerts, 16, levelVertOffset, permutation, iptrs.R);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-06-02 04:18:35 +00:00
|
|
|
iptrs.R += 16;
|
|
|
|
pptrs.R = computePatchParam(refiner, ptexIndices, i, faceIndex, boundaryMask, transitionMask, pptrs.R);
|
|
|
|
// XXX: sharpness will be integrated into patch param soon.
|
|
|
|
if (sptrs.R) *sptrs.R++ = assignSharpnessIndex(sharpness, table->_sharpnessValues);
|
2015-04-17 23:26:57 +00:00
|
|
|
|
2015-06-02 04:18:35 +00:00
|
|
|
fofss.R += gatherFVarData(context,
|
|
|
|
i, faceIndex, levelFaceOffset, /*rotation*/0, levelFVarVertOffsets, fofss.R, fptrs.R);
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
2015-04-18 00:36:55 +00:00
|
|
|
// emit end patch. end patch should be in the max level (until we implement DFAS)
|
|
|
|
assert(i==refiner.GetMaxLevel());
|
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
// switch endcap patchtype by option
|
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
|
|
|
{
|
|
|
|
// note: this call will be moved into vtr::level.
|
|
|
|
ConstIndexArray cvs = endCapGregoryBasis->GetPatchPoints(
|
2015-05-29 19:41:11 +00:00
|
|
|
level, faceIndex, levelPatchTags, levelVertOffset);
|
2015-04-23 23:58:45 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < cvs.size(); ++j) iptrs.GP[j] = cvs[j];
|
|
|
|
iptrs.GP += cvs.size();
|
|
|
|
pptrs.GP = computePatchParam(
|
2015-04-24 20:18:03 +00:00
|
|
|
refiner, ptexIndices, i, faceIndex, /*boundary*/0, /*transition*/0, pptrs.GP);
|
2015-05-22 18:50:01 +00:00
|
|
|
if (sptrs.R) *sptrs.R++ = assignSharpnessIndex(0, table->_sharpnessValues);
|
2015-04-23 23:58:45 +00:00
|
|
|
fofss.GP += gatherFVarData(context,
|
|
|
|
i, faceIndex, levelFaceOffset,
|
|
|
|
0, levelFVarVertOffsets, fofss.GP, fptrs.GP);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
|
|
|
{
|
|
|
|
ConstIndexArray cvs = endCapBSpline->GetPatchPoints(
|
2015-05-29 19:41:11 +00:00
|
|
|
level, faceIndex, levelPatchTags, levelVertOffset);
|
2015-04-23 23:58:45 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < cvs.size(); ++j) iptrs.R[j] = cvs[j];
|
|
|
|
iptrs.R += cvs.size();
|
|
|
|
pptrs.R = computePatchParam(
|
2015-04-24 20:18:03 +00:00
|
|
|
refiner, ptexIndices, i, faceIndex, /*boundary*/0, /*transition*/0, pptrs.R);
|
2015-05-22 18:50:01 +00:00
|
|
|
if (sptrs.R) *sptrs.R++ = assignSharpnessIndex(0, table->_sharpnessValues);
|
2015-04-23 23:58:45 +00:00
|
|
|
fofss.R += gatherFVarData(context,
|
|
|
|
i, faceIndex, levelFaceOffset,
|
|
|
|
0, levelFVarVertOffsets, fofss.R, fptrs.R);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Options::ENDCAP_LEGACY_GREGORY:
|
|
|
|
{
|
|
|
|
ConstIndexArray cvs = endCapLegacyGregory->GetPatchPoints(
|
|
|
|
level, faceIndex, levelPatchTags, levelVertOffset);
|
|
|
|
|
|
|
|
if (patchTag._boundaryCount == 0) {
|
2015-04-18 00:36:55 +00:00
|
|
|
for (int j = 0; j < cvs.size(); ++j) iptrs.G[j] = cvs[j];
|
|
|
|
iptrs.G += cvs.size();
|
|
|
|
pptrs.G = computePatchParam(
|
2015-04-24 20:18:03 +00:00
|
|
|
refiner, ptexIndices, i, faceIndex, /*boundary*/0, /*transition*/0, pptrs.G);
|
2015-05-22 18:50:01 +00:00
|
|
|
if (sptrs.R) *sptrs.R++ = assignSharpnessIndex(0, table->_sharpnessValues);
|
2015-02-26 21:57:47 +00:00
|
|
|
fofss.G += gatherFVarData(context,
|
2015-04-18 00:36:55 +00:00
|
|
|
i, faceIndex, levelFaceOffset,
|
|
|
|
0, levelFVarVertOffsets, fofss.G, fptrs.G);
|
2015-04-23 23:58:45 +00:00
|
|
|
} else {
|
2015-04-18 00:36:55 +00:00
|
|
|
for (int j = 0; j < cvs.size(); ++j) iptrs.GB[j] = cvs[j];
|
|
|
|
iptrs.GB += cvs.size();
|
|
|
|
pptrs.GB = computePatchParam(
|
2015-04-24 20:18:03 +00:00
|
|
|
refiner, ptexIndices, i, faceIndex, /*boundary*/0, /*transition*/0, pptrs.GB);
|
2015-05-22 18:50:01 +00:00
|
|
|
if (sptrs.R) *sptrs.R++ = assignSharpnessIndex(0, table->_sharpnessValues);
|
2015-02-26 21:57:47 +00:00
|
|
|
fofss.GB += gatherFVarData(context,
|
2015-04-18 00:36:55 +00:00
|
|
|
i, faceIndex, levelFaceOffset,
|
|
|
|
0, levelFVarVertOffsets, fofss.GB, fptrs.GB);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
2015-04-23 23:58:45 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
levelFaceOffset += level->getNumFaces();
|
|
|
|
levelVertOffset += level->getNumVertices();
|
2015-02-26 21:57:47 +00:00
|
|
|
if (context.RequiresFVarPatches()) {
|
2014-09-05 22:07:46 +00:00
|
|
|
int nchannels = refiner.GetNumFVarChannels();
|
|
|
|
for (int channel=0; channel<nchannels; ++channel) {
|
2015-02-26 21:57:47 +00:00
|
|
|
levelFVarVertOffsets[channel] += level->getNumFVarValues(channel);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-23 23:58:45 +00:00
|
|
|
// finalize end patches
|
|
|
|
switch(context.options.GetEndCapType()) {
|
|
|
|
case Options::ENDCAP_GREGORY_BASIS:
|
2015-05-29 19:41:11 +00:00
|
|
|
table->_localPointStencils =
|
2015-05-22 18:50:01 +00:00
|
|
|
endCapGregoryBasis->CreateVertexStencilTable();
|
2015-05-29 19:41:11 +00:00
|
|
|
table->_localPointVaryingStencils =
|
2015-05-22 18:50:01 +00:00
|
|
|
endCapGregoryBasis->CreateVaryingStencilTable();
|
2015-04-23 23:58:45 +00:00
|
|
|
delete endCapGregoryBasis;
|
|
|
|
break;
|
|
|
|
case Options::ENDCAP_BSPLINE_BASIS:
|
2015-05-29 19:41:11 +00:00
|
|
|
table->_localPointStencils =
|
2015-05-22 18:50:01 +00:00
|
|
|
endCapBSpline->CreateVertexStencilTable();
|
2015-05-29 19:41:11 +00:00
|
|
|
table->_localPointVaryingStencils =
|
2015-05-22 18:50:01 +00:00
|
|
|
endCapBSpline->CreateVaryingStencilTable();
|
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;
|
|
|
|
}
|
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
|
|
|
|