topologyRefiner.h
Go to the documentation of this file.
1 //
2 // Copyright 2014 DreamWorks Animation LLC.
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 #ifndef OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H
25 #define OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H
26 
27 #include "../version.h"
28 
29 #include "../sdc/types.h"
30 #include "../sdc/options.h"
31 #include "../far/types.h"
32 #include "../far/topologyLevel.h"
33 
34 #include <vector>
35 
36 
37 namespace OpenSubdiv {
38 namespace OPENSUBDIV_VERSION {
39 
40 namespace Vtr { namespace internal { class SparseSelector; } }
41 namespace Far { namespace internal { class FeatureMask; } }
42 
43 namespace Far {
44 
45 template <class MESH> class TopologyRefinerFactory;
46 
51 
52 public:
53 
56 
59 
61  Sdc::SchemeType GetSchemeType() const { return _subdivType; }
62 
64  Sdc::Options GetSchemeOptions() const { return _subdivOptions; }
65 
67  bool IsUniform() const { return _isUniform; }
68 
70  int GetNumLevels() const { return (int)_farLevels.size(); }
71 
73  int GetMaxLevel() const { return _maxLevel; }
74 
76  int GetMaxValence() const { return _maxValence; }
77 
79  bool HasHoles() const { return _hasHoles; }
80 
82  int GetNumVerticesTotal() const { return _totalVertices; }
83 
85  int GetNumEdgesTotal() const { return _totalEdges; }
86 
88  int GetNumFacesTotal() const { return _totalFaces; }
89 
91  int GetNumFaceVerticesTotal() const { return _totalFaceVertices; }
92 
94  TopologyLevel const & GetLevel(int level) const { return _farLevels[level]; }
95 
97 
100  //
101  // Uniform refinement
102  //
103 
117  struct UniformOptions {
118 
119  UniformOptions(int level) :
120  refinementLevel(level),
122  fullTopologyInLastLevel(false) { }
123 
124  unsigned int refinementLevel:4,
128  };
131 
142  void RefineUniform(UniformOptions options);
143 
145  UniformOptions GetUniformOptions() const { return _uniformOptions; }
146 
147  //
148  // Adaptive refinement
149  //
150 
153 
154  AdaptiveOptions(int level) :
155  isolationLevel(level),
156  secondaryLevel(15),
157  useSingleCreasePatch(false),
158  useInfSharpPatch(false),
159  considerFVarChannels(false),
160  orderVerticesFromFacesFirst(false) { }
161 
162  unsigned int isolationLevel:4;
163  unsigned int secondaryLevel:4;
165  unsigned int useSingleCreasePatch:1;
167  unsigned int useInfSharpPatch:1;
169  unsigned int considerFVarChannels:1;
171  unsigned int orderVerticesFromFacesFirst:1;
173  };
175 
180  void RefineAdaptive(AdaptiveOptions options);
181 
183  AdaptiveOptions GetAdaptiveOptions() const { return _adaptiveOptions; }
184 
186  void Unrefine();
187 
188 
190 
194  int GetNumFVarChannels() const;
195 
198 
200  int GetNumFVarValuesTotal(int channel = 0) const;
201 
203 
204 protected:
205 
206  //
207  // Lower level protected methods intended strictly for internal use:
208  //
209  template <class MESH>
212  friend class PatchTableBuilder;
213  friend class PatchBuilder;
214  friend class PtexIndices;
215  friend class PrimvarRefiner;
216 
217  Vtr::internal::Level & getLevel(int l) { return *_levels[l]; }
218  Vtr::internal::Level const & getLevel(int l) const { return *_levels[l]; }
219 
220  Vtr::internal::Refinement & getRefinement(int l) { return *_refinements[l]; }
221  Vtr::internal::Refinement const & getRefinement(int l) const { return *_refinements[l]; }
222 
223 private:
224  // Not default constructible or copyable:
225  TopologyRefiner() : _uniformOptions(0), _adaptiveOptions(0) { }
226  TopologyRefiner(TopologyRefiner const &) : _uniformOptions(0), _adaptiveOptions(0) { }
227  TopologyRefiner & operator=(TopologyRefiner const &) { return *this; }
228 
229  void selectFeatureAdaptiveComponents(Vtr::internal::SparseSelector& selector,
230  internal::FeatureMask const & mask);
231 
232  void initializeInventory();
233  void updateInventory(Vtr::internal::Level const & newLevel);
234 
235  void appendLevel(Vtr::internal::Level & newLevel);
236  void appendRefinement(Vtr::internal::Refinement & newRefinement);
237  void assembleFarLevels();
238 
239 private:
240 
241  Sdc::SchemeType _subdivType;
242  Sdc::Options _subdivOptions;
243 
244  unsigned int _isUniform : 1,
245  _hasHoles : 1,
246  _maxLevel : 4;
247 
248  // Options assigned on refinement:
249  UniformOptions _uniformOptions;
250  AdaptiveOptions _adaptiveOptions;
251 
252  // Cumulative properties of all levels:
253  int _totalVertices;
254  int _totalEdges;
255  int _totalFaces;
256  int _totalFaceVertices;
257  int _maxValence;
258 
259  // There is some redundancy here -- to be reduced later
260  std::vector<Vtr::internal::Level *> _levels;
261  std::vector<Vtr::internal::Refinement *> _refinements;
262 
263  std::vector<TopologyLevel> _farLevels;
264 };
265 
266 
267 inline int
269 
270  return _levels[0]->getNumFVarChannels();
271 }
274 
275  return _levels[0]->getFVarOptions(channel).GetFVarLinearInterpolation();
276 }
277 
278 } // end namespace Far
279 
280 } // end namespace OPENSUBDIV_VERSION
281 using namespace OPENSUBDIV_VERSION;
282 } // end namespace OpenSubdiv
283 
284 #endif /* OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H */
int GetNumFacesTotal() const
Returns the total number of edges in all levels.
Factory for constructing TopologyRefiners from specific mesh classes.
void RefineAdaptive(AdaptiveOptions options)
Feature Adaptive topology refinement (restricted to scheme Catmark)
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition: types.h:37
int GetMaxValence() const
Returns the maximum vertex valence in all levels.
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
Applies refinement operations to generic primvar data.
int GetNumFaceVerticesTotal() const
Returns the total number of face vertices in all levels.
unsigned int refinementLevel
Number of refinement iterations.
An interface for accessing data in a specific level of a refined topology hierarchy.
Definition: topologyLevel.h:49
int GetNumFVarValuesTotal(int channel=0) const
Returns the total number of face-varying values in all levels.
UniformOptions GetUniformOptions() const
Returns the options specified on refinement.
int GetNumEdgesTotal() const
Returns the total number of edges in all levels.
Vtr::internal::Level const & getLevel(int l) const
Private base class of Factories for constructing TopologyRefiners.
Stores topology data for a specified set of refinement options.
TopologyLevel const & GetLevel(int level) const
Returns a handle to access data specific to a particular level.
Object used to compute and query ptex face indices.
Definition: ptexIndices.h:46
Sdc::Options::FVarLinearInterpolation GetFVarLinearInterpolation(int channel=0) const
Returns the face-varying interpolation rule set for a given channel.
void RefineUniform(UniformOptions options)
Refine the topology uniformly.
All supported options applying to subdivision scheme.
Definition: options.h:51
AdaptiveOptions GetAdaptiveOptions() const
Returns the options specified on refinement.
int GetNumLevels() const
Returns the number of refinement levels.
int GetNumVerticesTotal() const
Returns the total number of vertices in all levels.
Sdc::SchemeType GetSchemeType() const
Returns the subdivision scheme.
bool HasHoles() const
Returns true if faces have been tagged as holes.
Sdc::Options GetSchemeOptions() const
Returns the subdivision options.
int GetMaxLevel() const
Returns the highest level of refinement.
Vtr::internal::Refinement const & getRefinement(int l) const
void Unrefine()
Unrefine the topology, keeping only the base level.
Vtr::internal::Refinement & getRefinement(int l)
bool IsUniform() const
Returns true if uniform refinement has been applied.