OpenSubdiv: opensubdiv/far/stencilTableFactory.h Source File

| OpenSubdiv

stencilTableFactory.h
Go to the documentation of this file.
1//
2// Copyright 2013 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24
25#ifndef OPENSUBDIV3_FAR_STENCILTABLE_FACTORY_H
26#define OPENSUBDIV3_FAR_STENCILTABLE_FACTORY_H
27
28#include "../version.h"
29
30#include "../far/patchTable.h"
31
32#include <vector>
33
34namespace OpenSubdiv {
35namespace OPENSUBDIV_VERSION {
36
37namespace Far {
38
39class TopologyRefiner;
40
41template <typename REAL> class StencilReal;
42template <typename REAL> class StencilTableReal;
43
44template <typename REAL> class LimitStencilReal;
45template <typename REAL> class LimitStencilTableReal;
46
47
50template <typename REAL>
51 class StencilTableFactoryReal {
52
53public:
54
55 enum Mode {
56 INTERPOLATE_VERTEX=0,
57 INTERPOLATE_VARYING,
58 INTERPOLATE_FACE_VARYING
59 };
60
61 struct Options {
62
63 Options() : interpolationMode(INTERPOLATE_VERTEX),
64 generateOffsets(false),
65 generateControlVerts(false),
66 generateIntermediateLevels(true),
67 factorizeIntermediateLevels(true),
68 maxLevel(10),
69 fvarChannel(0) { }
70
71 unsigned int interpolationMode : 2,
72 generateOffsets : 1,
73 generateControlVerts : 1,
74 generateIntermediateLevels : 1,
75 factorizeIntermediateLevels : 1,
78 maxLevel : 4;
79 unsigned int fvarChannel;
81 };
82
94 static StencilTableReal<REAL> const * Create(
95 TopologyRefiner const & refiner, Options options = Options());
96
97
110 static StencilTableReal<REAL> const * Create(
111 int numTables, StencilTableReal<REAL> const ** tables);
112
113
128 static StencilTableReal<REAL> const * AppendLocalPointStencilTable(
129 TopologyRefiner const &refiner,
130 StencilTableReal<REAL> const *baseStencilTable,
131 StencilTableReal<REAL> const *localPointStencilTable,
132 bool factorize = true);
133
148 static StencilTableReal<REAL> const * AppendLocalPointStencilTableVarying(
149 TopologyRefiner const &refiner,
150 StencilTableReal<REAL> const *baseStencilTable,
151 StencilTableReal<REAL> const *localPointStencilTable,
152 bool factorize = true) {
153 return AppendLocalPointStencilTable(
154 refiner, baseStencilTable, localPointStencilTable, factorize);
155 }
156
174 static StencilTableReal<REAL> const * AppendLocalPointStencilTableFaceVarying(
175 TopologyRefiner const &refiner,
176 StencilTableReal<REAL> const *baseStencilTable,
177 StencilTableReal<REAL> const *localPointStencilTable,
178 int channel = 0,
179 bool factorize = true);
180
181private:
182
183 // Generate stencils for the coarse control-vertices (single weight = 1.0f)
184 static void generateControlVertStencils(
185 int numControlVerts,
186 StencilReal<REAL> & dst);
187
188 // Internal method to splice local point stencils
189 static StencilTableReal<REAL> const * appendLocalPointStencilTable(
190 TopologyRefiner const &refiner,
191 StencilTableReal<REAL> const * baseStencilTable,
192 StencilTableReal<REAL> const * localPointStencilTable,
193 int channel,
194 bool factorize);
195};
196
208template <typename REAL>
209 class LimitStencilTableFactoryReal {
210
211public:
212
213 enum Mode {
214 INTERPOLATE_VERTEX=0,
215 INTERPOLATE_VARYING,
216 INTERPOLATE_FACE_VARYING
217 };
218
219 struct Options {
220
221 Options() : interpolationMode(INTERPOLATE_VERTEX),
222 generate1stDerivatives(true),
223 generate2ndDerivatives(false),
224 fvarChannel(0) { }
225
226 unsigned int interpolationMode : 2,
227 generate1stDerivatives : 1,
228 generate2ndDerivatives : 1;
229 unsigned int fvarChannel;
230 };
231
233 struct LocationArray {
234
235 LocationArray() : ptexIdx(-1), numLocations(0), s(0), t(0) { }
236
237 int ptexIdx,
238 numLocations;
239
240 REAL const * s,
241 * t;
242 };
243
244 typedef std::vector<LocationArray> LocationArrayVec;
245
269 static LimitStencilTableReal<REAL> const * Create(
270 TopologyRefiner const & refiner,
271 LocationArrayVec const & locationArrays,
272 StencilTableReal<REAL> const * cvStencils = 0,
273 PatchTable const * patchTable = 0,
274 Options options = Options());
275
276};
277
278
279//
280// Public wrapper classes for the templates
281//
282class Stencil;
283class StencilTable;
284
287 class StencilTableFactory : public StencilTableFactoryReal<float> {
288private:
289 typedef StencilTableFactoryReal<float> BaseFactory;
290 typedef StencilTableReal<float> BaseTable;
291
292public:
293 static StencilTable const * Create(
294 TopologyRefiner const & refiner, Options options = Options()) {
295
296 return static_cast<StencilTable const *>(
297 BaseFactory::Create(refiner, options));
298 }
299
300 static StencilTable const * Create(
301 int numTables, StencilTable const ** tables) {
302
303 return static_cast<StencilTable const *>(
304 BaseFactory::Create(numTables,
305 reinterpret_cast<BaseTable const **>(tables)));
306 }
307
308 static StencilTable const * AppendLocalPointStencilTable(
309 TopologyRefiner const &refiner,
310 StencilTable const *baseStencilTable,
311 StencilTable const *localPointStencilTable,
312 bool factorize = true) {
313
314 return static_cast<StencilTable const *>(
315 BaseFactory::AppendLocalPointStencilTable(refiner,
316 static_cast<BaseTable const *>(baseStencilTable),
317 static_cast<BaseTable const *>(localPointStencilTable),
318 factorize));
319 }
320
321 static StencilTable const * AppendLocalPointStencilTableVarying(
322 TopologyRefiner const &refiner,
323 StencilTable const *baseStencilTable,
324 StencilTable const *localPointStencilTable,
325 bool factorize = true) {
326
327 return static_cast<StencilTable const *>(
328 BaseFactory::AppendLocalPointStencilTableVarying(refiner,
329 static_cast<BaseTable const *>(baseStencilTable),
330 static_cast<BaseTable const *>(localPointStencilTable),
331 factorize));
332 }
333
334 static StencilTable const * AppendLocalPointStencilTableFaceVarying(
335 TopologyRefiner const &refiner,
336 StencilTable const *baseStencilTable,
337 StencilTable const *localPointStencilTable,
338 int channel = 0,
339 bool factorize = true) {
340
341 return static_cast<StencilTable const *>(
342 BaseFactory::AppendLocalPointStencilTableFaceVarying(refiner,
343 static_cast<BaseTable const *>(baseStencilTable),
344 static_cast<BaseTable const *>(localPointStencilTable),
345 channel, factorize));
346 }
347};
348
349class LimitStencil;
350class LimitStencilTable;
351
354 class LimitStencilTableFactory : public LimitStencilTableFactoryReal<float> {
355private:
356 typedef LimitStencilTableFactoryReal<float> BaseFactory;
357 typedef StencilTableReal<float> BaseTable;
358
359public:
360 static LimitStencilTable const * Create(
361 TopologyRefiner const & refiner,
362 LocationArrayVec const & locationArrays,
363 StencilTable const * cvStencils = 0,
364 PatchTable const * patchTable = 0,
365 Options options = Options()) {
366
367 return static_cast<LimitStencilTable const *>(
368 BaseFactory::Create(
369 refiner,
370 locationArrays,
371 static_cast<BaseTable const *>(cvStencils),
372 patchTable,
373 options));
374 }
375};
376
377} // end namespace Far
378
379} // end namespace OPENSUBDIV_VERSION
380using namespace OPENSUBDIV_VERSION;
381
382} // end namespace OpenSubdiv
383
384#endif // OPENSUBDIV3_FAR_STENCILTABLE_FACTORY_H
OpenSubdiv
Definition: limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTable
Container for arrays of parametric patches.
Definition: patchTable.h:55
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal
A specialized factory for StencilTable.
Definition: stencilTableFactory.h:51
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Create
static StencilTableReal< REAL > const * Create(TopologyRefiner const &refiner, Options options=Options())
Instantiates StencilTable from TopologyRefiner that have been refined uniformly or adaptively.
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::AppendLocalPointStencilTableFaceVarying
static StencilTableReal< REAL > const * AppendLocalPointStencilTableFaceVarying(TopologyRefiner const &refiner, StencilTableReal< REAL > const *baseStencilTable, StencilTableReal< REAL > const *localPointStencilTable, int channel=0, bool factorize=true)
Utility function for stencil splicing for local point face-varying stencils.
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Mode
Mode
Definition: stencilTableFactory.h:55
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::INTERPOLATE_FACE_VARYING
@ INTERPOLATE_FACE_VARYING
face-varying primvar stencils
Definition: stencilTableFactory.h:58
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::INTERPOLATE_VARYING
@ INTERPOLATE_VARYING
varying primvar stencils
Definition: stencilTableFactory.h:57
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::INTERPOLATE_VERTEX
@ INTERPOLATE_VERTEX
vertex primvar stencils
Definition: stencilTableFactory.h:56
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::AppendLocalPointStencilTableVarying
static StencilTableReal< REAL > const * AppendLocalPointStencilTableVarying(TopologyRefiner const &refiner, StencilTableReal< REAL > const *baseStencilTable, StencilTableReal< REAL > const *localPointStencilTable, bool factorize=true)
Utility function for stencil splicing for local point varying stencils.
Definition: stencilTableFactory.h:148
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::AppendLocalPointStencilTable
static StencilTableReal< REAL > const * AppendLocalPointStencilTable(TopologyRefiner const &refiner, StencilTableReal< REAL > const *baseStencilTable, StencilTableReal< REAL > const *localPointStencilTable, bool factorize=true)
Utility function for stencil splicing for local point stencils.
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Create
static StencilTableReal< REAL > const * Create(int numTables, StencilTableReal< REAL > const **tables)
Instantiates StencilTable by concatenating an array of existing stencil tables.
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal
A specialized factory for LimitStencilTable.
Definition: stencilTableFactory.h:209
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::Mode
Mode
Definition: stencilTableFactory.h:213
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::INTERPOLATE_FACE_VARYING
@ INTERPOLATE_FACE_VARYING
face-varying primvar stencils
Definition: stencilTableFactory.h:216
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::INTERPOLATE_VARYING
@ INTERPOLATE_VARYING
varying primvar stencils
Definition: stencilTableFactory.h:215
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::INTERPOLATE_VERTEX
@ INTERPOLATE_VERTEX
vertex primvar stencils
Definition: stencilTableFactory.h:214
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::LocationArrayVec
std::vector< LocationArray > LocationArrayVec
Definition: stencilTableFactory.h:244
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::Create
static LimitStencilTableReal< REAL > const * Create(TopologyRefiner const &refiner, LocationArrayVec const &locationArrays, StencilTableReal< REAL > const *cvStencils=0, PatchTable const *patchTable=0, Options options=Options())
Instantiates LimitStencilTable from a TopologyRefiner that has been refined either uniformly or adapt...
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilReal
Vertex stencil descriptor.
Definition: stencilTable.h:53
OpenSubdiv::OPENSUBDIV_VERSION::Far::Stencil
Vertex stencil class wrapping the template for compatibility.
Definition: stencilTable.h:116
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableReal
Table of subdivision stencils.
Definition: stencilTable.h:141
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTable
Stencil table class wrapping the template for compatibility.
Definition: stencilTable.h:273
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableReal
Table of limit subdivision stencils.
Definition: stencilTable.h:409
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTable
Limit stencil table class wrapping the template for compatibility.
Definition: stencilTable.h:583
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options
Definition: stencilTableFactory.h:61
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options::factorizeIntermediateLevels
unsigned int factorizeIntermediateLevels
Definition: stencilTableFactory.h:77
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options::maxLevel
unsigned int maxLevel
generate stencils up to 'maxLevel'
Definition: stencilTableFactory.h:78
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options::Options
Options()
Definition: stencilTableFactory.h:63
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options::generateIntermediateLevels
unsigned int generateIntermediateLevels
vertices at all levels or highest only
Definition: stencilTableFactory.h:74
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options::generateControlVerts
unsigned int generateControlVerts
generate stencils for control-vertices
Definition: stencilTableFactory.h:73
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options::generateOffsets
unsigned int generateOffsets
populate optional "_offsets" field
Definition: stencilTableFactory.h:72
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options::fvarChannel
unsigned int fvarChannel
Definition: stencilTableFactory.h:79
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactoryReal::Options::interpolationMode
unsigned int interpolationMode
interpolation mode
Definition: stencilTableFactory.h:71
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::Options
Definition: stencilTableFactory.h:219
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::Options::Options
Options()
Definition: stencilTableFactory.h:221
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::Options::fvarChannel
unsigned int fvarChannel
face-varying channel to use
Definition: stencilTableFactory.h:229
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::Options::interpolationMode
unsigned int interpolationMode
interpolation mode
Definition: stencilTableFactory.h:226
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::Options::generate2ndDerivatives
unsigned int generate2ndDerivatives
Generate weights for 2nd derivatives.
Definition: stencilTableFactory.h:228
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::Options::generate1stDerivatives
unsigned int generate1stDerivatives
Generate weights for 1st derivatives.
Definition: stencilTableFactory.h:227
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::LocationArray
Descriptor for limit surface locations.
Definition: stencilTableFactory.h:233
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::LocationArray::t
REAL const * t
array of v coordinates
Definition: stencilTableFactory.h:241
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::LocationArray::s
REAL const * s
array of u coordinates
Definition: stencilTableFactory.h:240
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::LocationArray::LocationArray
LocationArray()
Definition: stencilTableFactory.h:235
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::LocationArray::numLocations
int numLocations
number of (u,v) coordinates in the array
Definition: stencilTableFactory.h:238
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactoryReal::LocationArray::ptexIdx
int ptexIdx
ptex face index
Definition: stencilTableFactory.h:237
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactory
Stencil table factory class wrapping the template for compatibility.
Definition: stencilTableFactory.h:287
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactory::AppendLocalPointStencilTableVarying
static StencilTable const * AppendLocalPointStencilTableVarying(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, bool factorize=true)
Definition: stencilTableFactory.h:321
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactory::Create
static StencilTable const * Create(TopologyRefiner const &refiner, Options options=Options())
Definition: stencilTableFactory.h:293
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactory::AppendLocalPointStencilTableFaceVarying
static StencilTable const * AppendLocalPointStencilTableFaceVarying(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, int channel=0, bool factorize=true)
Definition: stencilTableFactory.h:334
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactory::AppendLocalPointStencilTable
static StencilTable const * AppendLocalPointStencilTable(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, bool factorize=true)
Definition: stencilTableFactory.h:308
OpenSubdiv::OPENSUBDIV_VERSION::Far::StencilTableFactory::Create
static StencilTable const * Create(int numTables, StencilTable const **tables)
Definition: stencilTableFactory.h:300
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactory
Stencil table factory class wrapping the template for compatibility.
Definition: stencilTableFactory.h:354
OpenSubdiv::OPENSUBDIV_VERSION::Far::LimitStencilTableFactory::Create
static LimitStencilTable const * Create(TopologyRefiner const &refiner, LocationArrayVec const &locationArrays, StencilTable const *cvStencils=0, PatchTable const *patchTable=0, Options options=Options())
Definition: stencilTableFactory.h:360
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner
Stores topology data for a specified set of refinement options.
Definition: topologyRefiner.h:51