patchTableFactory.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_FACTORY_H
26 #define OPENSUBDIV3_FAR_PATCH_TABLE_FACTORY_H
27 
28 #include "../version.h"
29 
30 #include "../far/patchTable.h"
31 
32 namespace OpenSubdiv {
33 namespace OPENSUBDIV_VERSION {
34 
35 namespace Far {
36 
37 // Forward declarations (for internal implementation purposes):
38 class PtexIndices;
39 class TopologyRefiner;
40 
42 public:
43  // PatchFaceTag
44  // A simple struct containing all information gathered about a face that is relevant
45  // to constructing a patch for it (some of these enums should probably be defined more
46  // as part of PatchTable)
47  //
48  // Like the HbrFace<T>::AdaptiveFlags, this struct aggregates all of the face tags
49  // supporting feature adaptive refinement. For now it is not used elsewhere and can
50  // remain local to this implementation, but we may want to move it into a header of
51  // its own if it has greater use later.
52  //
53  // Note that several properties being assigned here attempt to do so given a 4-bit
54  // mask of properties at the edges or vertices of the quad. Still not sure exactly
55  // what will be done this way, but the goal is to create lookup tables (of size 16
56  // for the 4 bits) to quickly determine was is needed, rather than iteration and
57  // branching on the edges or vertices.
58  //
59  struct PatchFaceTag {
60  public:
61  unsigned int _hasPatch : 1;
62  unsigned int _isRegular : 1;
63  unsigned int _transitionMask : 4;
64  unsigned int _boundaryMask : 4;
65  unsigned int _boundaryIndex : 2;
66  unsigned int _boundaryCount : 3;
67  unsigned int _hasBoundaryEdge : 3;
68  unsigned int _isSingleCrease : 1;
69 
70  void clear();
71  void assignBoundaryPropertiesFromEdgeMask(int boundaryEdgeMask);
72  void assignBoundaryPropertiesFromVertexMask(int boundaryVertexMask);
73  void assignTransitionPropertiesFromEdgeMask(int transitionMask) {
74  _transitionMask = transitionMask;
75  }
76  };
77  typedef std::vector<PatchFaceTag> PatchTagVector;
78 
79  struct Options {
80 
81  enum EndCapType {
82  ENDCAP_NONE = 0,
86  ENDCAP_LEGACY_GREGORY
87  };
88 
89  Options(unsigned int maxIsolation=10) :
90  generateAllLevels(false),
91  triangulateQuads(false),
92  useSingleCreasePatch(false),
93  maxIsolationLevel(maxIsolation),
94  endCapType(ENDCAP_GREGORY_BASIS),
95  shareEndCapPatchPoints(true),
96  generateFVarTables(false),
97  numFVarChannels(-1),
98  fvarChannelIndices(0)
99  { }
100 
102  EndCapType GetEndCapType() const { return (EndCapType)endCapType; }
103 
105  void SetEndCapType(EndCapType e) { endCapType = e; }
106 
107  unsigned int generateAllLevels : 1,
108  triangulateQuads : 1,
110  maxIsolationLevel : 4,
111 
112  // end-capping
113  endCapType : 3,
114  shareEndCapPatchPoints : 1,
115 
117  // face-varying
118  generateFVarTables : 1;
120  int const * fvarChannelIndices;
121  };
122 
131  static PatchTable * Create(TopologyRefiner const & refiner,
132  Options options=Options());
133 
134 private:
135  //
136  // Private helper structures
137  //
138  struct AdaptiveContext;
139 
140  //
141  // Methods for allocating and managing the patch table data arrays:
142  //
143  static PatchTable * createUniform(TopologyRefiner const & refiner,
144  Options options);
145 
146  static PatchTable * createAdaptive(TopologyRefiner const & refiner,
147  Options options);
148 
149  //
150  // High-level methods for identifying and populating patches associated with faces:
151  //
152 
153  static void identifyAdaptivePatches(AdaptiveContext & state);
154 
155  static void populateAdaptivePatches(AdaptiveContext & state,
156  PtexIndices const &ptexIndices);
157 
158  static void allocateVertexTables(PatchTable * table, int nlevels, bool hasSharpness);
159 
160  static void allocateFVarChannels(TopologyRefiner const & refiner,
161  Options options, int npatches, PatchTable * table);
162 
163  static PatchParam * computePatchParam(TopologyRefiner const & refiner,
164  PtexIndices const & ptexIndices,
165  int level, int face,
166  int boundaryMask, int transitionMask, PatchParam * coord);
167 
168  static int gatherFVarData(AdaptiveContext & state,
169  int level, Index faceIndex, Index levelFaceOffset, int rotation,
170  Index const * levelOffsets, Index fofss, Index ** fptrs);
171 
172 };
173 
174 } // end namespace Far
175 
176 } // end namespace OPENSUBDIV_VERSION
177 using namespace OPENSUBDIV_VERSION;
178 
179 } // end namespace OpenSubdiv
180 
181 
182 #endif /* OPENSUBDIV3_FAR_PATCH_TABLE_FACTORY_H */
int numFVarChannels
Number of channel indices and interpolation modes passed.
Local patch parameterization descriptor.
Definition: patchParam.h:64
int const * fvarChannelIndices
List containing the indices of the channels selected for the factory.
Object used to compute and query ptex face indices.
Definition: ptexIndices.h:46
static PatchTable * Create(TopologyRefiner const &refiner, Options options=Options())
Factory constructor for PatchTable.
Stores topology data for a specified set of refinement options.
Container for arrays of parametric patches.
Definition: patchTable.h:56