patchTable.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_PATCH_TABLE_H
26 #define OPENSUBDIV3_FAR_PATCH_TABLE_H
27 
28 #include "../version.h"
29 
30 #include "../far/patchDescriptor.h"
31 #include "../far/patchParam.h"
32 #include "../far/stencilTable.h"
33 
34 #include "../sdc/options.h"
35 
36 #include <cstdlib>
37 #include <vector>
38 
39 namespace OpenSubdiv {
40 namespace OPENSUBDIV_VERSION {
41 
42 namespace Far {
43 
56 class PatchTable {
57 
58 public:
59 
61  class PatchHandle {
62  // XXXX manuelk members will eventually be made private
63  public:
64 
65  friend class PatchTable;
66  friend class PatchMap;
67 
68  Index arrayIndex, // Array index of the patch
69  patchIndex, // Absolute Index of the patch
70  vertIndex; // Relative offset to the first CV of the patch in array
71  };
72 
73 public:
74 
76  PatchTable(PatchTable const & src);
77 
79  ~PatchTable();
80 
82  bool IsFeatureAdaptive() const;
83 
86  return (int)_patchVerts.size();
87  }
88 
90  int GetNumPatchesTotal() const;
91 
93  int GetMaxValence() const { return _maxValence; }
94 
96  int GetNumPtexFaces() const { return _numPtexFaces; }
97 
98 
100 
108  PatchDescriptor GetPatchDescriptor(PatchHandle const & handle) const;
109 
111  ConstIndexArray GetPatchVertices(PatchHandle const & handle) const;
112 
114  PatchParam GetPatchParam(PatchHandle const & handle) const;
115 
117  ConstIndexArray GetPatchVertices(int array, int patch) const;
118 
120  PatchParam GetPatchParam(int array, int patch) const;
122 
123 
125 
133  int GetNumPatchArrays() const;
134 
136  int GetNumPatches(int array) const;
137 
139  int GetNumControlVertices(int array) const;
140 
142  PatchDescriptor GetPatchArrayDescriptor(int array) const;
143 
145  ConstIndexArray GetPatchArrayVertices(int array) const;
146 
148  ConstPatchParamArray const GetPatchParams(int array) const;
150 
151 
153 
162  int GetNumLocalPoints() const;
163 
172  template <class T> void
173  ComputeLocalPointValues(T const *src, T *dst) const;
174 
177  return _localPointStencils;
178  }
179 
183  return _localPointVaryingStencils;
184  }
186 
187 
189 
195 
197  ConstQuadOffsetsArray GetPatchQuadOffsets(PatchHandle const & handle) const;
198 
199  typedef std::vector<Index> VertexValenceTable;
200 
202  VertexValenceTable const & GetVertexValenceTable() const {
203  return _vertexValenceTable;
204  }
206 
207 
209 
218  float GetSingleCreasePatchSharpnessValue(PatchHandle const & handle) const;
219 
222  float GetSingleCreasePatchSharpnessValue(int array, int patch) const;
224 
225 
227 
235  int GetNumFVarChannels() const;
236 
237 
240 
241 
243  ConstIndexArray GetPatchFVarValues(PatchHandle const & handle, int channel = 0) const;
244 
246  ConstIndexArray GetPatchFVarValues(int array, int patch, int channel = 0) const;
247 
248 
250  ConstIndexArray GetFVarValues(int channel = 0) const;
252 
253 
255 
261  typedef std::vector<Index> PatchVertsTable;
262 
264  PatchVertsTable const & GetPatchControlVerticesTable() const { return _patchVerts; }
265 
267  PatchParamTable const & GetPatchParamTable() const { return _paramTable; }
268 
270  std::vector<Index> const &GetSharpnessIndexTable() const { return _sharpnessIndices; }
271 
273  std::vector<float> const &GetSharpnessValues() const { return _sharpnessValues; }
274 
275  typedef std::vector<unsigned int> QuadOffsetsTable;
276 
278  QuadOffsetsTable const & GetQuadOffsetsTable() const {
279  return _quadOffsetsTable;
280  }
282 
284  void print() const;
285 
286 public:
287 
289 
308  void EvaluateBasis(PatchHandle const & handle, float s, float t,
309  float wP[], float wDs[], float wDt[]) const;
310 
312 
313 protected:
314 
315  friend class PatchTableFactory;
316 
317  // Factory constructor
318  PatchTable(int maxvalence);
319 
320  Index getPatchIndex(int array, int patch) const;
321 
322  PatchParamArray getPatchParams(int arrayIndex);
323 
324  Index * getSharpnessIndices(Index arrayIndex);
325  float * getSharpnessValues(Index arrayIndex);
326 
327 private:
328 
329  //
330  // Patch arrays
331  //
332 
333  struct PatchArray;
334  typedef std::vector<PatchArray> PatchArrayVector;
335 
336  PatchArray & getPatchArray(Index arrayIndex);
337  PatchArray const & getPatchArray(Index arrayIndex) const;
338 
339  void reservePatchArrays(int numPatchArrays);
340  void pushPatchArray(PatchDescriptor desc, int npatches,
341  Index * vidx, Index * pidx, Index * qoidx=0);
342 
343  IndexArray getPatchArrayVertices(int arrayIndex);
344 
345  Index findPatchArray(PatchDescriptor desc);
346 
347 
348  //
349  // FVar patch channels
350  //
351 
352  struct FVarPatchChannel;
353  typedef std::vector<FVarPatchChannel> FVarPatchChannelVector;
354 
355  FVarPatchChannel & getFVarPatchChannel(int channel);
356  FVarPatchChannel const & getFVarPatchChannel(int channel) const;
357 
358  void allocateFVarPatchChannels(int numChannels);
359  void allocateFVarPatchChannelValues(
360  int numPatches, int numVerticesTotal, int channel);
361 
362  void setFVarPatchChannelLinearInterpolation(
363  Sdc::Options::FVarLinearInterpolation interpolation, int channel);
364 
365 
366  PatchDescriptor::Type getFVarPatchType(int patch, int channel) const;
367  Vtr::Array<PatchDescriptor::Type> getFVarPatchTypes(int channel);
368 
369  IndexArray getFVarValues(int channel);
370  ConstIndexArray getPatchFVarValues(int patch, int channel) const;
371 
372 
373 private:
374 
375  //
376  // Topology
377  //
378 
379  int _maxValence, // highest vertex valence found in the mesh
380  _numPtexFaces; // total number of ptex faces
381 
382  PatchArrayVector _patchArrays; // Vector of descriptors for arrays of patches
383 
384  std::vector<Index> _patchVerts; // Indices of the control vertices of the patches
385 
386  PatchParamTable _paramTable; // PatchParam bitfields (one per patch)
387 
388  //
389  // Extraordinary vertex closed-form evaluation / endcap basis conversion
390  //
391  // XXXtakahito: these data will probably be replaced with mask coefficient or something
392  // SchemeWorker populates.
393  //
394  QuadOffsetsTable _quadOffsetsTable; // Quad offsets (for Gregory patches)
395  VertexValenceTable _vertexValenceTable; // Vertex valence table (for Gregory patches)
396  StencilTable const * _localPointStencils; // endcap basis conversion stencils
397  StencilTable const * _localPointVaryingStencils; // endcap varying stencils (for convenience)
398 
399  //
400  // Face-varying data
401  //
402 
403  FVarPatchChannelVector _fvarChannels;
404 
405  //
406  // 'single-crease' patch sharpness tables
407  //
408 
409  std::vector<Index> _sharpnessIndices; // Indices of single-crease sharpness (one per patch)
410  std::vector<float> _sharpnessValues; // Sharpness values.
411 };
412 
413 template <class T>
414 inline void
415 PatchTable::ComputeLocalPointValues(T const *src, T *dst) const {
416  if (_localPointStencils) {
417  _localPointStencils->UpdateValues(src, dst);
418  }
419 };
420 
421 
422 } // end namespace Far
423 
424 } // end namespace OPENSUBDIV_VERSION
425 using namespace OPENSUBDIV_VERSION;
426 
427 } // end namespace OpenSubdiv
428 
429 #endif /* OPENSUBDIV3_FAR_PATCH_TABLE */
Local patch parameterization descriptor.
Definition: patchParam.h:64
void ComputeLocalPointValues(T const *src, T *dst) const
Updates local point values based on the refined values.
Definition: patchTable.h:415
PatchParam GetPatchParam(PatchHandle const &handle) const
Returns a PatchParam for the patch identified by 'handle'.
std::vector< Index > const & GetSharpnessIndexTable() const
Returns a sharpness index table for each patch (if exists)
Definition: patchTable.h:270
int GetMaxValence() const
Returns max vertex valence.
Definition: patchTable.h:93
float GetSingleCreasePatchSharpnessValue(PatchHandle const &handle) const
Returns the crease sharpness for the patch identified by 'handle' if it is a single-crease patch...
std::vector< PatchArray > PatchArrayVector
Definition: types.h:98
int GetNumPatchArrays() const
Returns the number of patch arrays in the table.
void UpdateValues(T const *controlValues, T *values, Index start=-1, Index end=-1) const
Updates point values based on the control values.
Definition: stencilTable.h:187
PatchVertsTable const & GetPatchControlVerticesTable() const
Get the table of patch control vertices.
Definition: patchTable.h:264
PatchParamTable const & GetPatchParamTable() const
Returns the PatchParamTable (PatchParams order matches patch array sorting)
Definition: patchTable.h:267
QuadOffsetsTable const & GetQuadOffsetsTable() const
Returns the quad-offsets table.
Definition: patchTable.h:278
StencilTable const * GetLocalPointVaryingStencilTable() const
Returns the varying stencil table for the change of basis patch points.
Definition: patchTable.h:182
std::vector< unsigned int > QuadOffsetsTable
Definition: patchTable.h:275
ConstQuadOffsetsArray GetPatchQuadOffsets(PatchHandle const &handle) const
Returns the 'QuadOffsets' for the Gregory patch identified by 'handle'.
int GetNumFVarChannels() const
Returns the number of face-varying channels.
PatchDescriptor GetPatchArrayDescriptor(int array) const
Returns the PatchDescriptor for the patches in array 'array'.
PatchTable(PatchTable const &src)
Copy constructor.
int GetNumControlVertices(int array) const
Returns the number of control vertices in patch array 'array'.
VertexValenceTable const & GetVertexValenceTable() const
Returns the 'VertexValences' table (vertex neighborhoods table)
Definition: patchTable.h:202
int GetNumPatches(int array) const
Returns the number of patches in patch array 'array'.
int GetNumControlVerticesTotal() const
Returns the total number of control vertex indices in the table.
Definition: patchTable.h:85
ConstIndexArray GetPatchFVarValues(PatchHandle const &handle, int channel=0) const
Returns the value indices for a given patch in a channel.
ConstIndexArray GetPatchVertices(PatchHandle const &handle) const
Returns the control vertex indices for the patch identified by 'handle'.
StencilTable const * GetLocalPointStencilTable() const
Returns the stencil table to get change of basis patch points.
Definition: patchTable.h:176
An quadtree-based map connecting coarse faces to their sub-patches.
Definition: patchMap.h:49
ConstPatchParamArray const GetPatchParams(int array) const
Returns the PatchParams for the patches in array 'array'.
Vtr::ConstArray< unsigned int > ConstQuadOffsetsArray
Accessors for the gregory patch evaluation buffers. These methods will be deprecated.
Definition: patchTable.h:194
Index getPatchIndex(int array, int patch) const
std::vector< PatchParam > PatchParamTable
Definition: patchParam.h:123
ConstIndexArray GetFVarValues(int channel=0) const
Returns an array of value indices for the patches in a channel.
Container for arrays of parametric patches.
Definition: patchTable.h:56
Sdc::Options::FVarLinearInterpolation GetFVarChannelLinearInterpolation(int channel=0) const
Returns the interpolation mode for a given channel.
bool IsFeatureAdaptive() const
True if the patches are of feature adaptive types.
PatchParamArray getPatchParams(int arrayIndex)
int GetNumPatchesTotal() const
Returns the total number of patches stored in the table.
Handle that can be used as unique patch identifier within PatchTable.
Definition: patchTable.h:61
std::vector< float > const & GetSharpnessValues() const
Returns sharpness values table.
Definition: patchTable.h:273
int GetNumLocalPoints() const
Returns the number of points of the change of basis patches.
ConstIndexArray GetPatchArrayVertices(int array) const
Returns the control vertex indices for the patches in array 'array'.
void EvaluateBasis(PatchHandle const &handle, float s, float t, float wP[], float wDs[], float wDt[]) const
Evaluate basis functions for position and first derivatives at a given (s,t) parametric location of a...
int GetNumPtexFaces() const
Returns the total number of ptex faces in the mesh.
Definition: patchTable.h:96
PatchDescriptor GetPatchDescriptor(PatchHandle const &handle) const
Returns the PatchDescriptor for the patches in array 'array'.