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 
58  ~TopologyRefiner();
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),
121  orderVerticesFromFacesFirst(false),
122  fullTopologyInLastLevel(false) { }
123 
124  unsigned int refinementLevel:4,
125  orderVerticesFromFacesFirst:1,
126  fullTopologyInLastLevel:1;
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 
197  Sdc::Options::FVarLinearInterpolation GetFVarLinearInterpolation(int channel = 0) const;
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 PatchTableFactory;
213  friend class EndCapGregoryBasisPatchFactory;
214  friend class EndCapLegacyGregoryPatchFactory;
215  friend class PtexIndices;
216  friend class PrimvarRefiner;
217 
218  Vtr::internal::Level & getLevel(int l) { return *_levels[l]; }
219  Vtr::internal::Level const & getLevel(int l) const { return *_levels[l]; }
220 
221  Vtr::internal::Refinement & getRefinement(int l) { return *_refinements[l]; }
222  Vtr::internal::Refinement const & getRefinement(int l) const { return *_refinements[l]; }
223 
224 private:
225  // Not default constructible or copyable:
226  TopologyRefiner() : _uniformOptions(0), _adaptiveOptions(0) { }
227  TopologyRefiner(TopologyRefiner const &) : _uniformOptions(0), _adaptiveOptions(0) { }
228  TopologyRefiner & operator=(TopologyRefiner const &) { return *this; }
229 
230  void selectFeatureAdaptiveComponents(Vtr::internal::SparseSelector& selector,
231  internal::FeatureMask const & mask);
232 
233  void initializeInventory();
234  void updateInventory(Vtr::internal::Level const & newLevel);
235 
236  void appendLevel(Vtr::internal::Level & newLevel);
237  void appendRefinement(Vtr::internal::Refinement & newRefinement);
238  void assembleFarLevels();
239 
240 private:
241 
242  Sdc::SchemeType _subdivType;
243  Sdc::Options _subdivOptions;
244 
245  unsigned int _isUniform : 1,
246  _hasHoles : 1,
247  _maxLevel : 4;
248 
249  // Options assigned on refinement:
250  UniformOptions _uniformOptions;
251  AdaptiveOptions _adaptiveOptions;
252 
253  // Cumulative properties of all levels:
254  int _totalVertices;
255  int _totalEdges;
256  int _totalFaces;
257  int _totalFaceVertices;
258  int _maxValence;
259 
260  // There is some redundancy here -- to be reduced later
261  std::vector<Vtr::internal::Level *> _levels;
262  std::vector<Vtr::internal::Refinement *> _refinements;
263 
264  std::vector<TopologyLevel> _farLevels;
265 };
266 
267 
268 inline int
269 TopologyRefiner::GetNumFVarChannels() const {
270 
271  return _levels[0]->getNumFVarChannels();
272 }
274 TopologyRefiner::GetFVarLinearInterpolation(int channel) const {
275 
276  return _levels[0]->getFVarOptions(channel).GetFVarLinearInterpolation();
277 }
278 
279 } // end namespace Far
280 
281 } // end namespace OPENSUBDIV_VERSION
282 using namespace OPENSUBDIV_VERSION;
283 } // end namespace OpenSubdiv
284 
285 #endif /* OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H */
int GetNumEdgesTotal() const
Returns the total number of edges in all levels.
Vtr::internal::Level const & getLevel(int l) const
int GetNumFaceVerticesTotal() const
Returns the total number of face vertices in all levels.
Sdc::Options GetSchemeOptions() const
Returns the subdivision options.
int GetNumLevels() const
Returns the number of refinement levels.
int GetMaxLevel() const
Returns the highest level of refinement.
Vtr::internal::Refinement const & getRefinement(int l) const
All supported options applying to subdivision scheme.
Definition: options.h:51
An interface for accessing data in a specific level of a refined topology hierarchy.
Definition: topologyLevel.h:49
SchemeType
Enumerated type for all subdivisions schemes supported by OpenSubdiv.
Definition: types.h:37
UniformOptions GetUniformOptions() const
Returns the options specified on refinement.
Factory for constructing a PatchTable from a TopologyRefiner.
Private base class of Factories for constructing TopologyRefiners.
Stores topology data for a specified set of refinement options.
int GetNumFacesTotal() const
Returns the total number of edges in all levels.
AdaptiveOptions GetAdaptiveOptions() const
Returns the options specified on refinement.
int GetNumVerticesTotal() const
Returns the total number of vertices in all levels.
int GetMaxValence() const
Returns the maximum vertex valence in all levels.
Vtr::internal::Refinement & getRefinement(int l)
Sdc::SchemeType GetSchemeType() const
Returns the subdivision scheme.
Applies refinement operations to generic primvar data.
TopologyLevel const & GetLevel(int level) const
Returns a handle to access data specific to a particular level.
bool IsUniform() const
Returns true if uniform refinement has been applied.
bool HasHoles() const
Returns true if faces have been tagged as holes.
Object used to compute and query ptex face indices.
Definition: ptexIndices.h:46
Factory for constructing TopologyRefiners from specific mesh classes.