All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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 <vector>
37 
38 namespace OpenSubdiv {
39 namespace OPENSUBDIV_VERSION {
40 
41 namespace Far {
42 
55 class PatchTable {
56 
57 public:
58 
60  class PatchHandle {
61  // XXXX manuelk members will eventually be made private
62  public:
63 
64  friend class PatchTable;
65  friend class PatchMap;
66 
67  Index arrayIndex, // Array index of the patch
68  patchIndex, // Absolute Index of the patch
69  vertIndex; // Relative offset to the first CV of the patch in array
70  };
71 
72 public:
73 
75  PatchTable(PatchTable const & src);
76 
78  ~PatchTable();
79 
81  bool IsFeatureAdaptive() const;
82 
85  return (int)_patchVerts.size();
86  }
87 
89  int GetNumPatchesTotal() const;
90 
92  int GetMaxValence() const { return _maxValence; }
93 
95  int GetNumPtexFaces() const { return _numPtexFaces; }
96 
97 
99 
107  PatchDescriptor GetPatchDescriptor(PatchHandle const & handle) const;
108 
110  ConstIndexArray GetPatchVertices(PatchHandle const & handle) const;
111 
113  PatchParam GetPatchParam(PatchHandle const & handle) const;
114 
116  ConstIndexArray GetPatchVertices(int array, int patch) const;
117 
119  PatchParam GetPatchParam(int array, int patch) const;
121 
122 
124 
132  int GetNumPatchArrays() const;
133 
135  int GetNumPatches(int array) const;
136 
138  int GetNumControlVertices(int array) const;
139 
141  PatchDescriptor GetPatchArrayDescriptor(int array) const;
142 
144  ConstIndexArray GetPatchArrayVertices(int array) const;
145 
147  ConstPatchParamArray const GetPatchParams(int array) const;
149 
150 
152 
161  int GetNumLocalPoints() const;
162 
172  template <class T> void
173  ComputeLocalPointValues(T const *src, T *dst) const;
174 
177  return _localPointStencils;
178  }
179 
181  int GetNumLocalPointsVarying() const;
182 
192  template <class T> void
193  ComputeLocalPointValuesVarying(T const *src, T *dst) const;
194 
197  return _localPointVaryingStencils;
198  }
199 
201  int GetNumLocalPointsFaceVarying(int channel = 0) const;
202 
214  template <class T> void
215  ComputeLocalPointValuesFaceVarying(T const *src, T *dst, int channel = 0) const;
216 
218  StencilTable const *GetLocalPointFaceVaryingStencilTable(int channel = 0) const {
219  if (channel >= 0 && channel < (int)_localPointFaceVaryingStencils.size()) {
220  return _localPointFaceVaryingStencils[channel];
221  }
222  return NULL;
223  }
225 
226 
228 
234 
237 
238  typedef std::vector<Index> VertexValenceTable;
239 
242  return _vertexValenceTable;
243  }
245 
246 
248 
257  float GetSingleCreasePatchSharpnessValue(PatchHandle const & handle) const;
258 
261  float GetSingleCreasePatchSharpnessValue(int array, int patch) const;
263 
264 
266 
275 
277  ConstIndexArray GetPatchVaryingVertices(PatchHandle const & handle) const;
278 
280  ConstIndexArray GetPatchVaryingVertices(int array, int patch) const;
281 
284 
288 
289 
291 
299  int GetNumFVarChannels() const;
300 
302  PatchDescriptor GetFVarPatchDescriptor(int channel = 0) const;
303 
305  ConstIndexArray GetPatchFVarValues(PatchHandle const & handle, int channel = 0) const;
306 
308  ConstIndexArray GetPatchFVarValues(int array, int patch, int channel = 0) const;
309 
311  ConstIndexArray GetPatchArrayFVarValues(int array, int channel = 0) const;
312 
314  ConstIndexArray GetFVarValues(int channel = 0) const;
315 
317  PatchParam GetPatchFVarPatchParam(PatchHandle const & handle, int channel = 0) const;
318 
320  PatchParam GetPatchFVarPatchParam(int array, int patch, int channel = 0) const;
321 
323  ConstPatchParamArray GetPatchArrayFVarPatchParams(int array, int channel = 0) const;
324 
326  ConstPatchParamArray GetFVarPatchParams(int channel = 0) const;
327 
331 
332 
334 
340  typedef std::vector<Index> PatchVertsTable;
341 
343  PatchVertsTable const & GetPatchControlVerticesTable() const { return _patchVerts; }
344 
346  PatchParamTable const & GetPatchParamTable() const { return _paramTable; }
347 
349  std::vector<Index> const &GetSharpnessIndexTable() const { return _sharpnessIndices; }
350 
352  std::vector<float> const &GetSharpnessValues() const { return _sharpnessValues; }
353 
354  typedef std::vector<unsigned int> QuadOffsetsTable;
355 
358  return _quadOffsetsTable;
359  }
361 
363  void print() const;
364 
365 public:
366 
368 
393  void EvaluateBasis(PatchHandle const & handle, float u, float v,
394  float wP[], float wDu[] = 0, float wDv[] = 0,
395  float wDuu[] = 0, float wDuv[] = 0, float wDvv[] = 0) const;
396 
419  void EvaluateBasisVarying(PatchHandle const & handle, float u, float v,
420  float wP[], float wDu[] = 0, float wDv[] = 0,
421  float wDuu[] = 0, float wDuv[] = 0, float wDvv[] = 0) const;
422 
447  void EvaluateBasisFaceVarying(PatchHandle const & handle, float u, float v,
448  float wP[], float wDu[] = 0, float wDv[] = 0,
449  float wDuu[] = 0, float wDuv[] = 0, float wDvv[] = 0,
450  int channel = 0) const;
452 
453 protected:
454 
455  friend class PatchTableBuilder;
456 
457  // Factory constructor
458  PatchTable(int maxvalence);
459 
460  Index getPatchIndex(int array, int patch) const;
461 
462  PatchParamArray getPatchParams(int arrayIndex);
463 
464  Index * getSharpnessIndices(Index arrayIndex);
465  float * getSharpnessValues(Index arrayIndex);
466 
467 private:
468 
469  //
470  // Patch arrays
471  //
472 
473  struct PatchArray;
474  typedef std::vector<PatchArray> PatchArrayVector;
475 
476  PatchArray & getPatchArray(Index arrayIndex);
477  PatchArray const & getPatchArray(Index arrayIndex) const;
478 
479  void reservePatchArrays(int numPatchArrays);
480  void pushPatchArray(PatchDescriptor desc, int npatches,
481  Index * vidx, Index * pidx, Index * qoidx=0);
482 
483  IndexArray getPatchArrayVertices(int arrayIndex);
484 
485  Index findPatchArray(PatchDescriptor desc);
486 
487 
488  //
489  // Varying patch arrays
490  //
491  IndexArray getPatchArrayVaryingVertices(int arrayIndex);
492 
493  void allocateVaryingVertices(
494  PatchDescriptor desc, int numPatches);
495  void populateVaryingVertices();
496 
497  //
498  // Face-varying patch channels
499  //
500 
501  struct FVarPatchChannel;
502  typedef std::vector<FVarPatchChannel> FVarPatchChannelVector;
503 
504  FVarPatchChannel & getFVarPatchChannel(int channel);
505  FVarPatchChannel const & getFVarPatchChannel(int channel) const;
506 
507  void allocateFVarPatchChannels(int numChannels);
508  void allocateFVarPatchChannelValues(
509  PatchDescriptor desc, int numPatches, int channel);
510 
511  // deprecated
512  void setFVarPatchChannelLinearInterpolation(
513  Sdc::Options::FVarLinearInterpolation interpolation, int channel);
514 
515  IndexArray getFVarValues(int channel);
516  ConstIndexArray getPatchFVarValues(int patch, int channel) const;
517 
518  PatchParamArray getFVarPatchParams(int channel);
519  PatchParam getPatchFVarPatchParam(int patch, int channel) const;
520 
521 private:
522 
523  //
524  // Topology
525  //
526 
527  int _maxValence, // highest vertex valence found in the mesh
528  _numPtexFaces; // total number of ptex faces
529 
530  PatchArrayVector _patchArrays; // Vector of descriptors for arrays of patches
531 
532  std::vector<Index> _patchVerts; // Indices of the control vertices of the patches
533 
534  PatchParamTable _paramTable; // PatchParam bitfields (one per patch)
535 
536  //
537  // Extraordinary vertex closed-form evaluation / endcap basis conversion
538  //
539  // XXXtakahito: these data will probably be replaced with mask coefficient or something
540  // SchemeWorker populates.
541  //
542  QuadOffsetsTable _quadOffsetsTable; // Quad offsets (for Gregory patches)
543  VertexValenceTable _vertexValenceTable; // Vertex valence table (for Gregory patches)
544  StencilTable const * _localPointStencils; // endcap basis conversion stencils
545  StencilTable const * _localPointVaryingStencils; // endcap varying stencils (for convenience)
546 
547  //
548  // Varying data
549  //
550 
551  PatchDescriptor _varyingDesc;
552 
553  std::vector<Index> _varyingVerts;
554 
555  //
556  // Face-varying data
557  //
558 
559  FVarPatchChannelVector _fvarChannels;
560 
561  std::vector<StencilTable const *> _localPointFaceVaryingStencils;
562 
563  //
564  // 'single-crease' patch sharpness tables
565  //
566 
567  std::vector<Index> _sharpnessIndices; // Indices of single-crease sharpness (one per patch)
568  std::vector<float> _sharpnessValues; // Sharpness values.
569 };
570 
571 template <class T>
572 inline void
573 PatchTable::ComputeLocalPointValues(T const *src, T *dst) const {
574  if (_localPointStencils) {
575  _localPointStencils->UpdateValues(src, dst);
576  }
577 }
578 
579 template <class T>
580 inline void
581 PatchTable::ComputeLocalPointValuesVarying(T const *src, T *dst) const {
582  if (_localPointVaryingStencils) {
583  _localPointVaryingStencils->UpdateValues(src, dst);
584  }
585 }
586 
587 template <class T>
588 inline void
589 PatchTable::ComputeLocalPointValuesFaceVarying(T const *src, T *dst, int channel) const {
590  if (channel >= 0 && channel < (int)_localPointFaceVaryingStencils.size()) {
591  if (_localPointFaceVaryingStencils[channel]) {
592  _localPointFaceVaryingStencils[channel]->UpdateValues(src, dst);
593  }
594  }
595 }
596 
597 
598 } // end namespace Far
599 
600 } // end namespace OPENSUBDIV_VERSION
601 using namespace OPENSUBDIV_VERSION;
602 
603 } // end namespace OpenSubdiv
604 
605 #endif /* OPENSUBDIV3_FAR_PATCH_TABLE */
ConstIndexArray GetPatchArrayVaryingVertices(int array) const
Returns the varying vertex indices for the patches in array.
int GetNumFVarChannels() const
Returns the number of face-varying channels.
std::vector< PatchArray > PatchArrayVector
Definition: types.h:98
ConstIndexArray GetFVarValues(int channel=0) const
Returns an array of value indices for the patches in channel.
void ComputeLocalPointValuesFaceVarying(T const *src, T *dst, int channel=0) const
Updates local point face-varying values.
Definition: patchTable.h:589
void EvaluateBasisFaceVarying(PatchHandle const &handle, float u, float v, float wP[], float wDu[]=0, float wDv[]=0, float wDuu[]=0, float wDuv[]=0, float wDvv[]=0, int channel=0) const
Evaluate basis functions for a face-varying value and derivatives at a given (u,v) parametric locatio...
void EvaluateBasis(PatchHandle const &handle, float u, float v, float wP[], float wDu[]=0, float wDv[]=0, float wDuu[]=0, float wDuv[]=0, float wDvv[]=0) const
Evaluate basis functions for position and derivatives at a given (u,v) parametric location of a patch...
PatchParamTable const & GetPatchParamTable() const
Returns the PatchParamTable (PatchParams order matches patch array sorting)
Definition: patchTable.h:346
float GetSingleCreasePatchSharpnessValue(PatchHandle const &handle) const
Returns the crease sharpness for the patch identified by handle if it is a single-crease patch...
void EvaluateBasisVarying(PatchHandle const &handle, float u, float v, float wP[], float wDu[]=0, float wDv[]=0, float wDuu[]=0, float wDuv[]=0, float wDvv[]=0) const
Evaluate basis functions for a varying value and derivatives at a given (u,v) parametric location of ...
ConstIndexArray GetPatchVaryingVertices(PatchHandle const &handle) const
Returns the varying vertex indices for a given patch.
PatchVertsTable const & GetPatchControlVerticesTable() const
Get the table of patch control vertices.
Definition: patchTable.h:343
ConstPatchParamArray const GetPatchParams(int array) const
Returns the PatchParams for the patches in array.
Vtr::ConstArray< unsigned int > ConstQuadOffsetsArray
Accessors for the gregory patch evaluation buffers. These methods will be deprecated.
Definition: patchTable.h:233
PatchDescriptor GetFVarPatchDescriptor(int channel=0) const
Returns the patch descriptor for channel.
StencilTable const * GetLocalPointVaryingStencilTable() const
Returns the stencil table to compute local point varying values.
Definition: patchTable.h:196
PatchDescriptor GetVaryingPatchDescriptor() const
Returns the varying patch descriptor.
ConstIndexArray GetVaryingVertices() const
Returns an array of varying vertex indices for the patches.
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:189
int GetNumControlVerticesTotal() const
Returns the total number of control vertex indices in the table.
Definition: patchTable.h:84
ConstQuadOffsetsArray GetPatchQuadOffsets(PatchHandle const &handle) const
Returns the 'QuadOffsets' for the Gregory patch identified by handle.
StencilTable const * GetLocalPointFaceVaryingStencilTable(int channel=0) const
Returns the stencil table to compute local point face-varying values.
Definition: patchTable.h:218
Index getPatchIndex(int array, int patch) const
Container for arrays of parametric patches.
Definition: patchTable.h:55
ConstIndexArray GetPatchArrayFVarValues(int array, int channel=0) const
Returns the value indices for the patches in array in channel.
PatchTable(PatchTable const &src)
Copy constructor.
std::vector< Index > const & GetSharpnessIndexTable() const
Returns a sharpness index table for each patch (if exists)
Definition: patchTable.h:349
void ComputeLocalPointValuesVarying(T const *src, T *dst) const
Updates local point varying values.
Definition: patchTable.h:581
QuadOffsetsTable const & GetQuadOffsetsTable() const
Returns the quad-offsets table.
Definition: patchTable.h:357
int GetNumLocalPoints() const
Returns the number of local vertex points.
ConstPatchParamArray GetPatchArrayFVarPatchParams(int array, int channel=0) const
Returns the face-varying for a given patch in array in channel.
int GetNumPtexFaces() const
Returns the total number of ptex faces in the mesh.
Definition: patchTable.h:95
StencilTable const * GetLocalPointStencilTable() const
Returns the stencil table to compute local point vertex values.
Definition: patchTable.h:176
bool IsFeatureAdaptive() const
True if the patches are of feature adaptive types.
int GetNumPatches(int array) const
Returns the number of patches in array.
std::vector< unsigned int > QuadOffsetsTable
Definition: patchTable.h:354
int GetNumPatchesTotal() const
Returns the total number of patches stored in the table.
ConstIndexArray GetPatchFVarValues(PatchHandle const &handle, int channel=0) const
Returns the value indices for a given patch in channel.
ConstIndexArray GetPatchVertices(PatchHandle const &handle) const
Returns the control vertex indices for the patch identified by handle.
int GetNumLocalPointsFaceVarying(int channel=0) const
Returns the number of local face-varying points for channel.
PatchParam GetPatchFVarPatchParam(PatchHandle const &handle, int channel=0) const
Returns the value indices for a given patch in channel.
int GetNumControlVertices(int array) const
Returns the number of control vertices in array.
An quadtree-based map connecting coarse faces to their sub-patches.
Definition: patchMap.h:49
int GetNumLocalPointsVarying() const
Returns the number of local varying points.
VertexValenceTable const & GetVertexValenceTable() const
Returns the 'VertexValences' table (vertex neighborhoods table)
Definition: patchTable.h:241
void ComputeLocalPointValues(T const *src, T *dst) const
Updates local point vertex values.
Definition: patchTable.h:573
int GetNumPatchArrays() const
Returns the number of patch arrays in the table.
Sdc::Options::FVarLinearInterpolation GetFVarChannelLinearInterpolation(int channel=0) const
Deprecated.
PatchParam GetPatchParam(PatchHandle const &handle) const
Returns a PatchParam for the patch identified by handle.
ConstPatchParamArray GetFVarPatchParams(int channel=0) const
Returns an array of face-varying patch param for channel.
ConstIndexArray GetPatchArrayVertices(int array) const
Returns the control vertex indices for the patches in array.
int GetMaxValence() const
Returns max vertex valence.
Definition: patchTable.h:92
PatchParamArray getPatchParams(int arrayIndex)
std::vector< float > const & GetSharpnessValues() const
Returns sharpness values table.
Definition: patchTable.h:352
PatchDescriptor GetPatchArrayDescriptor(int array) const
Returns the PatchDescriptor for the patches in array.
Handle that can be used as unique patch identifier within PatchTable.
Definition: patchTable.h:60
std::vector< PatchParam > PatchParamTable
Definition: patchParam.h:234
PatchDescriptor GetPatchDescriptor(PatchHandle const &handle) const
Returns the PatchDescriptor for the patch identified by handle.