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 
42 namespace Far {
43 
44 template <class MESH> class TopologyRefinerFactory;
45 
50 
51 public:
52 
55 
58 
60  Sdc::SchemeType GetSchemeType() const { return _subdivType; }
61 
63  Sdc::Options GetSchemeOptions() const { return _subdivOptions; }
64 
66  bool IsUniform() const { return _isUniform; }
67 
69  int GetNumLevels() const { return (int)_levels.size(); }
70 
72  int GetMaxLevel() const { return _maxLevel; }
73 
75  int GetMaxValence() const { return _maxValence; }
76 
78  bool HasHoles() const { return _hasHoles; }
79 
81  int GetNumVerticesTotal() const { return _totalVertices; }
82 
84  int GetNumEdgesTotal() const { return _totalEdges; }
85 
87  int GetNumFacesTotal() const { return _totalFaces; }
88 
90  int GetNumFaceVerticesTotal() const { return _totalFaceVertices; }
91 
93  TopologyLevel const & GetLevel(int level) const { return _farLevels[level]; }
94 
96 
99  //
100  // Uniform refinement
101  //
102 
104  struct UniformOptions {
105 
106  UniformOptions(int level) :
107  refinementLevel(level),
109  fullTopologyInLastLevel(false) { }
110 
111  unsigned int refinementLevel:4,
115  };
118 
123  void RefineUniform(UniformOptions options);
124 
126  UniformOptions GetUniformOptions() const { return _uniformOptions; }
127 
128  //
129  // Adaptive refinement
130  //
131 
134 
135  AdaptiveOptions(int level) :
136  isolationLevel(level),
137  useSingleCreasePatch(false),
138  orderVerticesFromFacesFirst(false) { }
139 
140  unsigned int isolationLevel:4,
145  };
147 
152  void RefineAdaptive(AdaptiveOptions options);
153 
155  AdaptiveOptions GetAdaptiveOptions() const { return _adaptiveOptions; }
156 
158  void Unrefine();
159 
160 
162 
166  int GetNumFVarChannels() const;
167 
170 
172  int GetNumFVarValuesTotal(int channel = 0) const;
173 
175 
176 protected:
177 
178  //
179  // Lower level protected methods intended strictly for internal use:
180  //
181  template <class MESH>
184  friend class PatchTableFactory;
187  friend class PtexIndices;
188  friend class PrimvarRefiner;
189 
190  Vtr::internal::Level & getLevel(int l) { return *_levels[l]; }
191  Vtr::internal::Level const & getLevel(int l) const { return *_levels[l]; }
192 
193  Vtr::internal::Refinement & getRefinement(int l) { return *_refinements[l]; }
194  Vtr::internal::Refinement const & getRefinement(int l) const { return *_refinements[l]; }
195 
196 private:
197  // Not default constructible or copyable:
198  TopologyRefiner() : _uniformOptions(0), _adaptiveOptions(0) { }
199  TopologyRefiner(TopologyRefiner const &) : _uniformOptions(0), _adaptiveOptions(0) { }
200  TopologyRefiner & operator=(TopologyRefiner const &) { return *this; }
201 
202  void selectFeatureAdaptiveComponents(Vtr::internal::SparseSelector& selector);
203 
204  void initializeInventory();
205  void updateInventory(Vtr::internal::Level const & newLevel);
206 
207  void appendLevel(Vtr::internal::Level & newLevel);
208  void appendRefinement(Vtr::internal::Refinement & newRefinement);
209  void assembleFarLevels();
210 
211 private:
212 
213  Sdc::SchemeType _subdivType;
214  Sdc::Options _subdivOptions;
215 
216  unsigned int _isUniform : 1,
217  _hasHoles : 1,
218  _maxLevel : 4;
219 
220  // Options assigned on refinement:
221  UniformOptions _uniformOptions;
222  AdaptiveOptions _adaptiveOptions;
223 
224  // Cumulative properties of all levels:
225  int _totalVertices;
226  int _totalEdges;
227  int _totalFaces;
228  int _totalFaceVertices;
229  int _maxValence;
230 
231  // There is some redundancy here -- to be reduced later
232  std::vector<Vtr::internal::Level *> _levels;
233  std::vector<Vtr::internal::Refinement *> _refinements;
234 
235  std::vector<TopologyLevel> _farLevels;;
236 };
237 
238 
239 inline int
241 
242  return _levels[0]->getNumFVarChannels();
243 }
246 
247  return _levels[0]->getFVarOptions(channel).GetFVarLinearInterpolation();
248 }
249 
250 } // end namespace Far
251 
252 } // end namespace OPENSUBDIV_VERSION
253 using namespace OPENSUBDIV_VERSION;
254 } // end namespace OpenSubdiv
255 
256 #endif /* OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H */
SchemeType
Enumerated type for all subdivisions schemes supported by OpenSubdiv.
Definition: types.h:37
int GetMaxLevel() const
Returns the highest level of refinement.
void Unrefine()
Unrefine the topology (keep control cage)
Private base class of Factories for constructing TopologyRefiners.
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
int GetNumFaceVerticesTotal() const
Returns the total number of face vertices in all levels.
bool IsUniform() const
Returns true if uniform subdivision has been applied.
unsigned int refinementLevel
Number of refinement iterations.
int GetNumFVarValuesTotal(int channel=0) const
Returns the total number of face-varying values in all levels.
int GetNumFacesTotal() const
Returns the total number of edges in all levels.
Factory for constructing TopologyRefiners from specific mesh classes.
Vtr::internal::Refinement & getRefinement(int l)
int GetMaxValence() const
Returns the maximum vertex valence in all levels.
bool HasHoles() const
\ brief Returns true if faces have been tagged as holes
void RefineUniform(UniformOptions options)
Refine the topology uniformly.
TopologyLevel const & GetLevel(int level) const
Returns a handle to access data specific to a particular level.
UniformOptions GetUniformOptions() const
Returns the options specified on refinement.
Sdc::Options GetSchemeOptions() const
Returns the subdivision options.
All supported options applying to subdivision scheme.
Definition: options.h:51
AdaptiveOptions GetAdaptiveOptions() const
Returns the options specified on refinement.
Vtr::internal::Level const & getLevel(int l) const
Sdc::Options::FVarLinearInterpolation GetFVarLinearInterpolation(int channel=0) const
Returns the face-varying interpolation rule-set for a given channel.
void RefineAdaptive(AdaptiveOptions options)
Feature Adaptive topology refinement (restricted to scheme Catmark)
int GetNumLevels() const
Returns the number of refinement levels.
int GetNumEdgesTotal() const
Returns the total number of edges in all levels.
Stores topology data for a specified set of refinement options.
Object used to compute and query ptex face indices.
Definition: ptexIndices.h:46
Sdc::SchemeType GetSchemeType() const
Returns the subdivision scheme.
Vtr::internal::Refinement const & getRefinement(int l) const
TopologyLevel is an interface for accessing data in a specific level of a refined topology hierarchy...
Definition: topologyLevel.h:47
int GetNumVerticesTotal() const
Returns the total number of vertices in all levels.
Applies refinement operations to generic primvar data.