2014-09-05 22:07:46 +00:00
|
|
|
//
|
2014-10-21 23:36:26 +00:00
|
|
|
// Copyright 2013 Pixar
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// 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/stencilTableFactory.h"
|
2015-05-22 20:07:54 +00:00
|
|
|
#include "../far/stencilBuilder.h"
|
2015-04-18 00:36:55 +00:00
|
|
|
#include "../far/endCapGregoryBasisPatchFactory.h"
|
2015-05-22 18:50:01 +00:00
|
|
|
#include "../far/patchTable.h"
|
|
|
|
#include "../far/patchTableFactory.h"
|
2014-09-12 23:59:16 +00:00
|
|
|
#include "../far/patchMap.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#include "../far/topologyRefiner.h"
|
2015-05-24 01:56:36 +00:00
|
|
|
#include "../far/primvarRefiner.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <algorithm>
|
2015-05-22 20:07:54 +00:00
|
|
|
#include <iostream>
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
namespace Far {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-07-21 00:56:00 +00:00
|
|
|
namespace {
|
|
|
|
#ifdef __INTEL_COMPILER
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning disable 1572
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline bool isWeightZero(float w) { return (w == 0.0f); }
|
|
|
|
|
|
|
|
#ifdef __INTEL_COMPILER
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2014-09-18 00:53:38 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
void
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTableFactory::generateControlVertStencils(
|
2014-10-21 23:36:26 +00:00
|
|
|
int numControlVerts, Stencil & dst) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
// Control vertices contribute a single index with a weight of 1.0
|
|
|
|
for (int i=0; i<numControlVerts; ++i) {
|
|
|
|
*dst._size = 1;
|
|
|
|
*dst._indices = i;
|
|
|
|
*dst._weights = 1.0f;
|
|
|
|
dst.Next();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
// StencilTable factory
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable const *
|
|
|
|
StencilTableFactory::Create(TopologyRefiner const & refiner,
|
2014-09-05 22:07:46 +00:00
|
|
|
Options options) {
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
int maxlevel = std::min(int(options.maxLevel), refiner.GetMaxLevel());
|
2014-11-25 19:48:49 +00:00
|
|
|
if (maxlevel==0 and (not options.generateControlVerts)) {
|
2015-05-22 20:07:54 +00:00
|
|
|
StencilTable * result = new StencilTable;
|
|
|
|
result->_numControlVertices = refiner.GetLevel(0).GetNumVertices();
|
2014-09-12 23:59:16 +00:00
|
|
|
return result;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
bool interpolateVarying = options.interpolationMode==INTERPOLATE_VARYING;
|
2015-05-27 01:19:45 +00:00
|
|
|
internal::StencilBuilder builder(refiner.GetLevel(0).GetNumVertices(),
|
2015-05-22 20:07:54 +00:00
|
|
|
/*genControlVerts*/ true,
|
|
|
|
/*compactWeights*/ true);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-25 19:48:49 +00:00
|
|
|
//
|
2014-09-05 22:07:46 +00:00
|
|
|
// Interpolate stencils for each refinement level using
|
2015-05-29 17:48:19 +00:00
|
|
|
// PrimvarRefiner::InterpolateLevel<>() for vertex or varying
|
2014-10-21 23:36:26 +00:00
|
|
|
//
|
2015-05-24 01:56:36 +00:00
|
|
|
PrimvarRefiner primvarRefiner(refiner);
|
|
|
|
|
2015-05-27 01:19:45 +00:00
|
|
|
internal::StencilBuilder::Index srcIndex(&builder, 0);
|
2015-07-23 06:36:46 +00:00
|
|
|
internal::StencilBuilder::Index dstIndex(&builder,
|
|
|
|
refiner.GetLevel(0).GetNumVertices());
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
for (int level=1; level<=maxlevel; ++level) {
|
|
|
|
if (not interpolateVarying) {
|
2015-05-24 01:56:36 +00:00
|
|
|
primvarRefiner.Interpolate(level, srcIndex, dstIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
2015-05-24 01:56:36 +00:00
|
|
|
primvarRefiner.InterpolateVarying(level, srcIndex, dstIndex);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:36:46 +00:00
|
|
|
if (options.factorizeIntermediateLevels) {
|
|
|
|
srcIndex = dstIndex;
|
|
|
|
}
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
dstIndex = dstIndex[refiner.GetLevel(level).GetNumVertices()];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-07-23 06:36:46 +00:00
|
|
|
if (not options.factorizeIntermediateLevels) {
|
|
|
|
// All previous verts are considered as coarse verts, as a
|
|
|
|
// result, we don't update the srcIndex and update the coarse
|
|
|
|
// vertex count.
|
|
|
|
builder.SetCoarseVertCount(dstIndex.GetOffset());
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 23:36:26 +00:00
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
size_t firstOffset = refiner.GetLevel(0).GetNumVertices();
|
|
|
|
if (not options.generateIntermediateLevels)
|
|
|
|
firstOffset = srcIndex.GetOffset();
|
|
|
|
|
2015-07-23 06:36:46 +00:00
|
|
|
// Copy stencils from the StencilBuilder into the StencilTable.
|
|
|
|
// Always initialize numControlVertices (useful for torus case)
|
2015-05-22 20:07:54 +00:00
|
|
|
StencilTable * result =
|
|
|
|
new StencilTable(refiner.GetLevel(0).GetNumVertices(),
|
|
|
|
builder.GetStencilOffsets(),
|
|
|
|
builder.GetStencilSizes(),
|
|
|
|
builder.GetStencilSources(),
|
|
|
|
builder.GetStencilWeights(),
|
|
|
|
options.generateControlVerts,
|
|
|
|
firstOffset);
|
2014-09-12 23:59:16 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable const *
|
|
|
|
StencilTableFactory::Create(int numTables, StencilTable const ** tables) {
|
2014-11-13 22:03:21 +00:00
|
|
|
|
2015-04-08 01:34:05 +00:00
|
|
|
// XXXtakahito:
|
|
|
|
// This function returns NULL for empty inputs or erroneous condition.
|
|
|
|
// It's convenient for skipping varying stencils etc, however,
|
|
|
|
// other Create() API returns an empty stencil instead of NULL.
|
|
|
|
// They need to be consistent.
|
2014-11-13 22:03:21 +00:00
|
|
|
|
|
|
|
if ( (numTables<=0) or (not tables)) {
|
2015-04-08 01:34:05 +00:00
|
|
|
return NULL;
|
2014-11-13 22:03:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 01:34:05 +00:00
|
|
|
int ncvs = -1,
|
2014-11-13 22:03:21 +00:00
|
|
|
nstencils = 0,
|
|
|
|
nelems = 0;
|
|
|
|
|
|
|
|
for (int i=0; i<numTables; ++i) {
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable const * st = tables[i];
|
2015-04-08 01:34:05 +00:00
|
|
|
// allow the tables could have a null entry.
|
|
|
|
if (!st) continue;
|
2014-11-13 22:03:21 +00:00
|
|
|
|
2015-04-08 01:34:05 +00:00
|
|
|
if (ncvs >= 0 and st->GetNumControlVertices() != ncvs) {
|
|
|
|
return NULL;
|
2014-11-13 22:03:21 +00:00
|
|
|
}
|
2015-04-08 01:34:05 +00:00
|
|
|
ncvs = st->GetNumControlVertices();
|
|
|
|
nstencils += st->GetNumStencils();
|
|
|
|
nelems += (int)st->GetControlIndices().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ncvs == -1) {
|
|
|
|
return NULL;
|
2014-11-13 22:03:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable * result = new StencilTable;
|
2014-11-13 22:03:21 +00:00
|
|
|
result->resize(nstencils, nelems);
|
|
|
|
|
2015-05-19 17:16:56 +00:00
|
|
|
int * sizes = &result->_sizes[0];
|
2014-11-13 22:03:21 +00:00
|
|
|
Index * indices = &result->_indices[0];
|
|
|
|
float * weights = &result->_weights[0];
|
|
|
|
for (int i=0; i<numTables; ++i) {
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable const * st = tables[i];
|
2015-04-08 01:34:05 +00:00
|
|
|
if (!st) continue;
|
|
|
|
|
|
|
|
int st_nstencils = st->GetNumStencils(),
|
|
|
|
st_nelems = (int)st->_indices.size();
|
2015-05-19 17:16:56 +00:00
|
|
|
memcpy(sizes, &st->_sizes[0], st_nstencils*sizeof(int));
|
2015-04-08 01:34:05 +00:00
|
|
|
memcpy(indices, &st->_indices[0], st_nelems*sizeof(Index));
|
|
|
|
memcpy(weights, &st->_weights[0], st_nelems*sizeof(float));
|
2015-01-06 02:56:24 +00:00
|
|
|
|
|
|
|
sizes += st_nstencils;
|
|
|
|
indices += st_nelems;
|
|
|
|
weights += st_nelems;
|
2014-11-13 22:03:21 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 20:41:53 +00:00
|
|
|
result->_numControlVertices = ncvs;
|
|
|
|
|
2014-11-13 22:03:21 +00:00
|
|
|
// have to re-generate offsets from scratch
|
|
|
|
result->generateOffsets();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable const *
|
2015-05-29 19:41:11 +00:00
|
|
|
StencilTableFactory::AppendLocalPointStencilTable(
|
2015-04-23 23:58:45 +00:00
|
|
|
TopologyRefiner const &refiner,
|
2015-05-22 20:07:54 +00:00
|
|
|
StencilTable const * baseStencilTable,
|
2015-05-29 19:41:11 +00:00
|
|
|
StencilTable const * localPointStencilTable,
|
2015-04-23 23:58:45 +00:00
|
|
|
bool factorize) {
|
|
|
|
|
|
|
|
// factorize and append.
|
2015-05-22 18:50:01 +00:00
|
|
|
if (baseStencilTable == NULL or
|
2015-05-29 19:41:11 +00:00
|
|
|
localPointStencilTable == NULL) return NULL;
|
2015-04-23 23:58:45 +00:00
|
|
|
|
2015-05-29 19:41:11 +00:00
|
|
|
// baseStencilTable can be built with or without singular stencils
|
|
|
|
// (single weight of 1.0f) as place-holders for coarse mesh vertices.
|
2015-04-23 23:58:45 +00:00
|
|
|
|
|
|
|
int controlVertsIndexOffset = 0;
|
2015-05-22 18:50:01 +00:00
|
|
|
int nBaseStencils = baseStencilTable->GetNumStencils();
|
|
|
|
int nBaseStencilsElements = (int)baseStencilTable->_indices.size();
|
2015-04-23 23:58:45 +00:00
|
|
|
{
|
|
|
|
int nverts = refiner.GetNumVerticesTotal();
|
|
|
|
if (nBaseStencils == nverts) {
|
|
|
|
|
|
|
|
// the table contain stencils for the control vertices
|
|
|
|
//
|
|
|
|
// <----------------- nverts ------------------>
|
|
|
|
//
|
|
|
|
// +---------------+----------------------------+-----------------+
|
2015-05-29 19:41:11 +00:00
|
|
|
// | control verts | refined verts : (max lv) | local points |
|
2015-04-23 23:58:45 +00:00
|
|
|
// +---------------+----------------------------+-----------------+
|
2015-05-29 19:41:11 +00:00
|
|
|
// | base stencil table | LP stencils |
|
2015-04-23 23:58:45 +00:00
|
|
|
// +--------------------------------------------+-----------------+
|
2015-05-29 19:41:11 +00:00
|
|
|
// ^ /
|
|
|
|
// \_________________________/
|
2015-04-23 23:58:45 +00:00
|
|
|
//
|
|
|
|
//
|
2015-05-29 19:41:11 +00:00
|
|
|
controlVertsIndexOffset = 0;
|
2015-04-23 23:58:45 +00:00
|
|
|
|
2015-05-22 04:26:41 +00:00
|
|
|
} else if (nBaseStencils == (nverts -refiner.GetLevel(0).GetNumVertices())) {
|
2015-04-23 23:58:45 +00:00
|
|
|
|
|
|
|
// the table does not contain stencils for the control vertices
|
|
|
|
//
|
|
|
|
// <----------------- nverts ------------------>
|
|
|
|
// <------ nBaseStencils ------->
|
|
|
|
// +---------------+----------------------------+-----------------+
|
2015-05-29 19:41:11 +00:00
|
|
|
// | control verts | refined verts : (max lv) | local points |
|
2015-04-23 23:58:45 +00:00
|
|
|
// +---------------+----------------------------+-----------------+
|
2015-05-29 19:41:11 +00:00
|
|
|
// | base stencil table | LP stencils |
|
2015-04-23 23:58:45 +00:00
|
|
|
// +----------------------------+-----------------+
|
2015-05-29 19:41:11 +00:00
|
|
|
// ^ /
|
|
|
|
// \_________________/
|
|
|
|
// <-------------->
|
|
|
|
// controlVertsIndexOffset
|
2015-04-23 23:58:45 +00:00
|
|
|
//
|
2015-05-29 19:41:11 +00:00
|
|
|
controlVertsIndexOffset = refiner.GetLevel(0).GetNumVertices();
|
2015-04-23 23:58:45 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// these are not the stencils you are looking for.
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-05-29 19:41:11 +00:00
|
|
|
|
2015-07-23 06:36:46 +00:00
|
|
|
// copy all local points stencils to proto stencils, and factorize if needed.
|
2015-05-29 19:41:11 +00:00
|
|
|
int nLocalPointStencils = localPointStencilTable->GetNumStencils();
|
|
|
|
int nLocalPointStencilsElements = 0;
|
2015-04-23 23:58:45 +00:00
|
|
|
|
2015-05-27 01:19:45 +00:00
|
|
|
internal::StencilBuilder builder(refiner.GetLevel(0).GetNumVertices(),
|
2015-05-22 20:07:54 +00:00
|
|
|
/*genControlVerts*/ false,
|
|
|
|
/*compactWeights*/ factorize);
|
2015-05-27 01:19:45 +00:00
|
|
|
internal::StencilBuilder::Index origin(&builder, 0);
|
|
|
|
internal::StencilBuilder::Index dst = origin;
|
|
|
|
internal::StencilBuilder::Index srcIdx = origin;
|
2015-05-22 20:07:54 +00:00
|
|
|
|
2015-05-29 19:41:11 +00:00
|
|
|
for (int i = 0 ; i < nLocalPointStencils; ++i) {
|
|
|
|
Stencil src = localPointStencilTable->GetStencil(i);
|
2015-05-22 20:07:54 +00:00
|
|
|
dst = origin[i];
|
2015-04-23 23:58:45 +00:00
|
|
|
for (int j = 0; j < src.GetSize(); ++j) {
|
|
|
|
Index index = src.GetVertexIndices()[j];
|
|
|
|
float weight = src.GetWeights()[j];
|
2015-07-21 00:56:00 +00:00
|
|
|
if (isWeightZero(weight)) continue;
|
2015-04-23 23:58:45 +00:00
|
|
|
|
|
|
|
if (factorize) {
|
2015-05-22 20:07:54 +00:00
|
|
|
dst.AddWithWeight(
|
2015-05-29 19:41:11 +00:00
|
|
|
// subtracting controlVertsIndex if the baseStencil doesn't
|
|
|
|
// include control vertices (see above diagram)
|
|
|
|
// since currently local point stencils are created with
|
|
|
|
// absolute indices including control (level=0) vertices.
|
|
|
|
baseStencilTable->GetStencil(index - controlVertsIndexOffset),
|
2015-05-22 20:07:54 +00:00
|
|
|
weight);
|
2015-04-23 23:58:45 +00:00
|
|
|
} else {
|
2015-05-22 20:07:54 +00:00
|
|
|
srcIdx = origin[index + controlVertsIndexOffset];
|
|
|
|
dst.AddWithWeight(srcIdx, weight);
|
2015-04-23 23:58:45 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-29 19:41:11 +00:00
|
|
|
nLocalPointStencilsElements += builder.GetNumVertsInStencil(i);
|
2015-04-23 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
// create new stencil table
|
|
|
|
StencilTable * result = new StencilTable;
|
2015-05-22 04:26:41 +00:00
|
|
|
result->_numControlVertices = refiner.GetLevel(0).GetNumVertices();
|
2015-05-29 19:41:11 +00:00
|
|
|
result->resize(nBaseStencils + nLocalPointStencils,
|
|
|
|
nBaseStencilsElements + nLocalPointStencilsElements);
|
2015-04-23 23:58:45 +00:00
|
|
|
|
2015-05-19 17:16:56 +00:00
|
|
|
int* sizes = &result->_sizes[0];
|
2015-04-23 23:58:45 +00:00
|
|
|
Index * indices = &result->_indices[0];
|
|
|
|
float * weights = &result->_weights[0];
|
|
|
|
|
|
|
|
// put base stencils first
|
2015-05-22 18:50:01 +00:00
|
|
|
memcpy(sizes, &baseStencilTable->_sizes[0],
|
2015-05-19 17:16:56 +00:00
|
|
|
nBaseStencils*sizeof(int));
|
2015-05-22 18:50:01 +00:00
|
|
|
memcpy(indices, &baseStencilTable->_indices[0],
|
2015-04-23 23:58:45 +00:00
|
|
|
nBaseStencilsElements*sizeof(Index));
|
2015-05-22 18:50:01 +00:00
|
|
|
memcpy(weights, &baseStencilTable->_weights[0],
|
2015-04-23 23:58:45 +00:00
|
|
|
nBaseStencilsElements*sizeof(float));
|
|
|
|
|
|
|
|
sizes += nBaseStencils;
|
|
|
|
indices += nBaseStencilsElements;
|
|
|
|
weights += nBaseStencilsElements;
|
|
|
|
|
|
|
|
// endcap stencils second
|
2015-05-29 19:41:11 +00:00
|
|
|
for (int i = 0 ; i < nLocalPointStencils; ++i) {
|
2015-05-22 20:07:54 +00:00
|
|
|
int size = builder.GetNumVertsInStencil(i);
|
|
|
|
int idx = builder.GetStencilOffsets()[i];
|
2015-04-23 23:58:45 +00:00
|
|
|
for (int j = 0; j < size; ++j) {
|
2015-05-22 20:07:54 +00:00
|
|
|
*indices++ = builder.GetStencilSources()[idx+j];
|
|
|
|
*weights++ = builder.GetStencilWeights()[idx+j];
|
2015-04-23 23:58:45 +00:00
|
|
|
}
|
|
|
|
*sizes++ = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// have to re-generate offsets from scratch
|
|
|
|
result->generateOffsets();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2015-05-22 18:50:01 +00:00
|
|
|
LimitStencilTable const *
|
|
|
|
LimitStencilTableFactory::Create(TopologyRefiner const & refiner,
|
|
|
|
LocationArrayVec const & locationArrays, StencilTable const * cvStencilsIn,
|
|
|
|
PatchTable const * patchTableIn) {
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2014-09-19 00:48:34 +00:00
|
|
|
// Compute the total number of stencils to generate
|
|
|
|
int numStencils=0, numLimitStencils=0;
|
|
|
|
for (int i=0; i<(int)locationArrays.size(); ++i) {
|
2014-10-02 23:09:17 +00:00
|
|
|
assert(locationArrays[i].numLocations>=0);
|
2014-09-19 00:48:34 +00:00
|
|
|
numStencils += locationArrays[i].numLocations;
|
|
|
|
}
|
|
|
|
if (numStencils<=0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
bool uniform = refiner.IsUniform();
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
int maxlevel = refiner.GetMaxLevel();
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable const * cvstencils = cvStencilsIn;
|
2014-10-21 23:36:26 +00:00
|
|
|
if (not cvstencils) {
|
2014-11-11 19:27:25 +00:00
|
|
|
// Generate stencils for the control vertices - this is necessary to
|
|
|
|
// properly factorize patches with control vertices at level 0 (natural
|
|
|
|
// regular patches, such as in a torus)
|
2014-10-02 23:09:17 +00:00
|
|
|
// note: the control vertices of the mesh are added as single-index
|
|
|
|
// stencils of weight 1.0f
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTableFactory::Options options;
|
2014-10-21 23:36:26 +00:00
|
|
|
options.generateIntermediateLevels = uniform ? false :true;
|
2014-10-02 23:09:17 +00:00
|
|
|
options.generateControlVerts = true;
|
|
|
|
options.generateOffsets = true;
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
// PERFORMANCE: We could potentially save some mem-copies by not
|
|
|
|
// instanciating the stencil tables and work directly off the source
|
|
|
|
// data.
|
2015-05-22 18:50:01 +00:00
|
|
|
cvstencils = StencilTableFactory::Create(refiner, options);
|
2014-10-02 23:09:17 +00:00
|
|
|
} else {
|
2014-10-21 23:36:26 +00:00
|
|
|
// Sanity checks
|
2015-06-11 20:41:20 +00:00
|
|
|
//
|
|
|
|
// Note that the input cvStencils could be larger than the number of
|
|
|
|
// refiner's vertices, due to the existence of the end cap stencils.
|
|
|
|
if (cvstencils->GetNumStencils() < (uniform ?
|
2015-05-22 04:26:41 +00:00
|
|
|
refiner.GetLevel(maxlevel).GetNumVertices() :
|
2014-10-04 00:54:30 +00:00
|
|
|
refiner.GetNumVerticesTotal())) {
|
2014-10-02 23:09:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 23:36:26 +00:00
|
|
|
|
|
|
|
// If a stencil table was given, use it, otherwise, create a new one
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTable const * patchtable = patchTableIn;
|
2015-04-23 23:58:45 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
if (not patchtable) {
|
|
|
|
// XXXX (manuelk) If no patch-table was passed, we should be able to
|
2014-10-21 23:36:26 +00:00
|
|
|
// infer the patches fairly easily from the refiner. Once more tags
|
|
|
|
// have been added to the refiner, maybe we can remove the need for the
|
2015-05-22 18:50:01 +00:00
|
|
|
// patch table.
|
2014-11-11 19:27:25 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchTableFactory::Options options;
|
2015-04-23 23:58:45 +00:00
|
|
|
options.SetEndCapType(
|
2015-05-22 18:50:01 +00:00
|
|
|
Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS);
|
2015-04-18 00:36:55 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
patchtable = PatchTableFactory::Create(refiner, options);
|
2014-11-11 19:27:25 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
if (not cvStencilsIn) {
|
2015-04-23 23:58:45 +00:00
|
|
|
// if cvstencils is just created above, append endcap stencils
|
2015-05-29 19:41:11 +00:00
|
|
|
if (StencilTable const *localPointStencilTable =
|
|
|
|
patchtable->GetLocalPointStencilTable()) {
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable const *table =
|
2015-05-29 19:41:11 +00:00
|
|
|
StencilTableFactory::AppendLocalPointStencilTable(
|
|
|
|
refiner, cvstencils, localPointStencilTable);
|
2015-04-18 00:36:55 +00:00
|
|
|
delete cvstencils;
|
2015-05-22 18:50:01 +00:00
|
|
|
cvstencils = table;
|
2015-04-18 00:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-02 23:09:17 +00:00
|
|
|
} else {
|
2014-10-21 23:36:26 +00:00
|
|
|
// Sanity checks
|
2015-05-22 18:50:01 +00:00
|
|
|
if (patchtable->IsFeatureAdaptive()==uniform) {
|
|
|
|
if (not cvStencilsIn) {
|
|
|
|
assert(cvstencils and cvstencils!=cvStencilsIn);
|
2014-10-21 23:36:26 +00:00
|
|
|
delete cvstencils;
|
2014-10-02 23:09:17 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 23:36:26 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
assert(patchtable and cvstencils);
|
2014-09-12 23:59:16 +00:00
|
|
|
|
|
|
|
// Create a patch-map to locate sub-patches faster
|
2015-05-22 18:50:01 +00:00
|
|
|
PatchMap patchmap( *patchtable );
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//
|
|
|
|
// Generate limit stencils for locations
|
|
|
|
//
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2015-05-27 01:19:45 +00:00
|
|
|
internal::StencilBuilder builder(refiner.GetLevel(0).GetNumVertices(),
|
2015-05-22 20:07:54 +00:00
|
|
|
/*genControlVerts*/ false,
|
|
|
|
/*compactWeights*/ true);
|
2015-05-27 01:19:45 +00:00
|
|
|
internal::StencilBuilder::Index origin(&builder, 0);
|
|
|
|
internal::StencilBuilder::Index dst = origin;
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2015-05-20 22:44:29 +00:00
|
|
|
float wP[20], wDs[20], wDt[20];
|
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
for (size_t i=0; i<locationArrays.size(); ++i) {
|
2014-09-12 23:59:16 +00:00
|
|
|
LocationArray const & array = locationArrays[i];
|
2014-09-19 00:48:34 +00:00
|
|
|
assert(array.ptexIdx>=0);
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2015-05-21 16:05:33 +00:00
|
|
|
for (int j=0; j<array.numLocations; ++j) {
|
2014-09-19 00:48:34 +00:00
|
|
|
float s = array.s[j],
|
|
|
|
t = array.t[j];
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2015-05-22 20:07:54 +00:00
|
|
|
PatchMap::Handle const * handle =
|
|
|
|
patchmap.FindPatch(array.ptexIdx, s, t);
|
2014-09-12 23:59:16 +00:00
|
|
|
if (handle) {
|
2015-05-22 18:50:01 +00:00
|
|
|
ConstIndexArray cvs = patchtable->GetPatchVertices(*handle);
|
2015-05-20 22:44:29 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
patchtable->EvaluateBasis(*handle, s, t, wP, wDs, wDt);
|
2015-05-20 22:44:29 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
StencilTable const & src = *cvstencils;
|
2015-05-22 20:07:54 +00:00
|
|
|
dst = origin[numLimitStencils];
|
2015-05-20 22:44:29 +00:00
|
|
|
|
|
|
|
dst.Clear();
|
|
|
|
for (int k = 0; k < cvs.size(); ++k) {
|
|
|
|
dst.AddWithWeight(src[cvs[k]], wP[k], wDs[k], wDt[k]);
|
2014-10-02 23:09:17 +00:00
|
|
|
}
|
2015-05-20 22:44:29 +00:00
|
|
|
|
2014-09-12 23:59:16 +00:00
|
|
|
++numLimitStencils;
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-29 17:53:17 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
if (not cvStencilsIn) {
|
2014-10-21 23:36:26 +00:00
|
|
|
delete cvstencils;
|
|
|
|
}
|
2014-09-12 23:59:16 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
if (not patchTableIn) {
|
|
|
|
delete patchtable;
|
2015-04-23 23:58:45 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//
|
2015-05-22 18:50:01 +00:00
|
|
|
// Copy the proto-stencils into the limit stencil table
|
2014-10-21 23:36:26 +00:00
|
|
|
//
|
2015-05-22 20:07:54 +00:00
|
|
|
LimitStencilTable * result = new LimitStencilTable(
|
|
|
|
refiner.GetLevel(0).GetNumVertices(),
|
|
|
|
builder.GetStencilOffsets(),
|
|
|
|
builder.GetStencilSizes(),
|
|
|
|
builder.GetStencilSources(),
|
|
|
|
builder.GetStencilWeights(),
|
|
|
|
builder.GetStencilDuWeights(),
|
|
|
|
builder.GetStencilDvWeights(),
|
|
|
|
/*ctrlVerts*/false,
|
2015-06-10 00:07:18 +00:00
|
|
|
/*fristOffset*/0);
|
2014-09-05 22:07:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace Far
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|