My Project
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 
34 namespace OpenSubdiv {
35 namespace OPENSUBDIV_VERSION {
36 
37 namespace Far {
38 
39 class TopologyRefiner;
40 
41 template <typename REAL> class StencilReal;
42 template <typename REAL> class StencilTableReal;
43 
44 template <typename REAL> class LimitStencilReal;
45 template <typename REAL> class LimitStencilTableReal;
46 
47 
50 template <typename REAL>
51 class StencilTableFactoryReal {
52 
53 public:
54 
55  enum Mode {
59  };
60 
61  struct Options {
62 
64  generateOffsets(false),
65  generateControlVerts(false),
68  maxLevel(10),
69  fvarChannel(0) { }
70 
71  unsigned int interpolationMode : 2,
72  generateOffsets : 1,
76  maxLevel : 4;
79  unsigned int fvarChannel;
80  };
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 
129  TopologyRefiner const &refiner,
130  StencilTableReal<REAL> const *baseStencilTable,
131  StencilTableReal<REAL> const *localPointStencilTable,
132  bool factorize = true);
133 
149  TopologyRefiner const &refiner,
150  StencilTableReal<REAL> const *baseStencilTable,
151  StencilTableReal<REAL> const *localPointStencilTable,
152  bool factorize = true) {
154  refiner, baseStencilTable, localPointStencilTable, factorize);
155  }
156 
175  TopologyRefiner const &refiner,
176  StencilTableReal<REAL> const *baseStencilTable,
177  StencilTableReal<REAL> const *localPointStencilTable,
178  int channel = 0,
179  bool factorize = true);
180 
181 private:
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 
208 template <typename REAL>
209 class LimitStencilTableFactoryReal {
210 
211 public:
212 
213  enum Mode {
217  };
218 
219  struct Options {
220 
223  generate2ndDerivatives(false),
224  fvarChannel(0) { }
225 
226  unsigned int interpolationMode : 2,
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 //
282 class Stencil;
283 class StencilTable;
284 
288 private:
291 
292 public:
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 
309  TopologyRefiner const &refiner,
310  StencilTable const *baseStencilTable,
311  StencilTable const *localPointStencilTable,
312  bool factorize = true) {
313 
314  return static_cast<StencilTable const *>(
316  static_cast<BaseTable const *>(baseStencilTable),
317  static_cast<BaseTable const *>(localPointStencilTable),
318  factorize));
319  }
320 
322  TopologyRefiner const &refiner,
323  StencilTable const *baseStencilTable,
324  StencilTable const *localPointStencilTable,
325  bool factorize = true) {
326 
327  return static_cast<StencilTable const *>(
329  static_cast<BaseTable const *>(baseStencilTable),
330  static_cast<BaseTable const *>(localPointStencilTable),
331  factorize));
332  }
333 
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 *>(
343  static_cast<BaseTable const *>(baseStencilTable),
344  static_cast<BaseTable const *>(localPointStencilTable),
345  channel, factorize));
346  }
347 };
348 
349 class LimitStencil;
350 class LimitStencilTable;
351 
355 private:
358 
359 public:
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 *>(
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
380 using namespace OPENSUBDIV_VERSION;
381 
382 } // end namespace OpenSubdiv
383 
384 #endif // OPENSUBDIV3_FAR_STENCILTABLE_FACTORY_H
static LimitStencilTable const * Create(TopologyRefiner const &refiner, LocationArrayVec const &locationArrays, StencilTable const *cvStencils=0, PatchTable const *patchTable=0, Options options=Options())
static StencilTable const * AppendLocalPointStencilTableFaceVarying(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, int channel=0, bool factorize=true)
static StencilTable const * AppendLocalPointStencilTableVarying(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, bool factorize=true)
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...
static StencilTable const * Create(TopologyRefiner const &refiner, Options options=Options())
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.
static StencilTableReal< REAL > const * Create(TopologyRefiner const &refiner, Options options=Options())
Instantiates StencilTable from TopologyRefiner that have been refined uniformly or adaptively.
static StencilTable const * AppendLocalPointStencilTable(TopologyRefiner const &refiner, StencilTable const *baseStencilTable, StencilTable const *localPointStencilTable, bool factorize=true)
unsigned int generateIntermediateLevels
vertices at all levels or highest only
unsigned int generateControlVerts
generate stencils for control-vertices
Stores topology data for a specified set of refinement options.
unsigned int generate2ndDerivatives
Generate weights for 2nd derivatives.
unsigned int generate1stDerivatives
Generate weights for 1st derivatives.
static StencilTable const * Create(int numTables, StencilTable const **tables)
A specialized factory for LimitStencilTable.
Definition: stencilTable.h:46
Limit stencil table class wrapping the template for compatibility.
Definition: stencilTable.h:583
Vertex stencil class wrapping the template for compatibility.
Definition: stencilTable.h:116
Stencil table factory class wrapping the template for compatibility.
Container for arrays of parametric patches.
Definition: patchTable.h:55
unsigned int generateOffsets
populate optional "_offsets" field
Stencil table class wrapping the template for compatibility.
Definition: stencilTable.h:273
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.
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.
Stencil table factory class wrapping the template for compatibility.