OpenSubdiv
Loading...
Searching...
No Matches
topologyRefiner.h
Go to the documentation of this file.
1//
2// Copyright 2014 DreamWorks Animation LLC.
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7#ifndef OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H
8#define OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H
9
10#include "../version.h"
11
12#include "../sdc/types.h"
13#include "../sdc/options.h"
14#include "../far/types.h"
16
17#include <vector>
18
19
20namespace OpenSubdiv {
21namespace OPENSUBDIV_VERSION {
22
23namespace Vtr { namespace internal { class SparseSelector; } }
24namespace Far { namespace internal { class FeatureMask; } }
25
26namespace Far {
27
28template <typename REAL> class PrimvarRefinerReal;
29template <class MESH> class TopologyRefinerFactory;
30
35
36public:
37
40
43
45 Sdc::SchemeType GetSchemeType() const { return _subdivType; }
46
48 Sdc::Options GetSchemeOptions() const { return _subdivOptions; }
49
51 bool IsUniform() const { return _isUniform; }
52
54 int GetNumLevels() const { return (int)_farLevels.size(); }
55
57 int GetMaxLevel() const { return _maxLevel; }
58
60 int GetMaxValence() const { return _maxValence; }
61
63 bool HasHoles() const { return _hasHoles; }
64
66 int GetNumVerticesTotal() const { return _totalVertices; }
67
69 int GetNumEdgesTotal() const { return _totalEdges; }
70
72 int GetNumFacesTotal() const { return _totalFaces; }
73
75 int GetNumFaceVerticesTotal() const { return _totalFaceVertices; }
76
78 TopologyLevel const & GetLevel(int level) const { return _farLevels[level]; }
79
81
83
84 //
85 // Uniform refinement
86 //
87
102
103 UniformOptions(int level) :
104 refinementLevel(level & 0xf),
106 fullTopologyInLastLevel(false) { }
107
109 void SetRefinementLevel(int level) { refinementLevel = level & 0xf; }
110
111 unsigned int refinementLevel:4,
117 };
118
130
132 UniformOptions GetUniformOptions() const { return _uniformOptions; }
133
134 //
135 // Adaptive refinement
136 //
137
140
141 AdaptiveOptions(int level) :
142 isolationLevel(level & 0xf),
143 secondaryLevel(0xf),
145 useInfSharpPatch(false),
148
150 void SetIsolationLevel(int level) { isolationLevel = level & 0xf; }
151
153 void SetSecondaryLevel(int level) { secondaryLevel = level & 0xf; }
154
155 unsigned int isolationLevel:4;
157 unsigned int secondaryLevel:4;
159 unsigned int useSingleCreasePatch:1;
161 unsigned int useInfSharpPatch:1;
163 unsigned int considerFVarChannels:1;
167 };
168
176 ConstIndexArray selectedFaces = ConstIndexArray());
177
179 AdaptiveOptions GetAdaptiveOptions() const { return _adaptiveOptions; }
180
182 void Unrefine();
183
184
186
188
190 int GetNumFVarChannels() const;
191
194
196 int GetNumFVarValuesTotal(int channel = 0) const;
197
199
200protected:
201
202 //
203 // Lower level protected methods intended strictly for internal use:
204 //
205 template <class MESH>
208 friend class PatchTableBuilder;
209 friend class PatchBuilder;
210 friend class PtexIndices;
211 template <typename REAL>
212 friend class PrimvarRefinerReal;
213
214 // Copy constructor exposed via the factory class:
216
217public:
218 // Levels and Refinements available internally (avoids need for more friends)
219 Vtr::internal::Level & getLevel(int l) { return *_levels[l]; }
220 Vtr::internal::Level const & getLevel(int l) const { return *_levels[l]; }
221
222 Vtr::internal::Refinement & getRefinement(int l) { return *_refinements[l]; }
223 Vtr::internal::Refinement const & getRefinement(int l) const { return *_refinements[l]; }
224
225private:
226 // Not default constructible or copyable:
227 TopologyRefiner() : _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 ConstIndexArray selectedFaces);
233 void selectLinearIrregularFaces(Vtr::internal::SparseSelector& selector,
234 ConstIndexArray selectedFaces);
235
236 void initializeInventory();
237 void updateInventory(Vtr::internal::Level const & newLevel);
238
239 void appendLevel(Vtr::internal::Level & newLevel);
240 void appendRefinement(Vtr::internal::Refinement & newRefinement);
241 void assembleFarLevels();
242
243private:
244
245 Sdc::SchemeType _subdivType;
246 Sdc::Options _subdivOptions;
247
248 unsigned int _isUniform : 1;
249 unsigned int _hasHoles : 1;
250 unsigned int _hasIrregFaces : 1;
251 unsigned int _regFaceSize : 3;
252 unsigned int _maxLevel : 4;
253
254 // Options assigned on refinement:
255 UniformOptions _uniformOptions;
256 AdaptiveOptions _adaptiveOptions;
257
258 // Cumulative properties of all levels:
259 int _totalVertices;
260 int _totalEdges;
261 int _totalFaces;
262 int _totalFaceVertices;
263 int _maxValence;
264
265 // Note the base level may be shared with another instance
266 bool _baseLevelOwned;
267
268 std::vector<Vtr::internal::Level *> _levels;
269 std::vector<Vtr::internal::Refinement *> _refinements;
270
271 std::vector<TopologyLevel> _farLevels;
272};
273
274
275inline int
277
278 return _levels[0]->getNumFVarChannels();
279}
282
283 return _levels[0]->getFVarOptions(channel).GetFVarLinearInterpolation();
284}
285
286} // end namespace Far
287
288} // end namespace OPENSUBDIV_VERSION
289using namespace OPENSUBDIV_VERSION;
290} // end namespace OpenSubdiv
291
292#endif /* OPENSUBDIV3_FAR_TOPOLOGY_REFINER_H */
Vtr::ConstIndexArray ConstIndexArray
Definition types.h:30
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition types.h:20
Applies refinement operations to generic primvar data.
Object used to compute and query ptex face indices.
Definition ptexIndices.h:29
An interface for accessing data in a specific level of a refined topology hierarchy.
Factory for constructing TopologyRefiners from specific mesh classes.
Stores topology data for a specified set of refinement options.
TopologyRefiner(TopologyRefiner const &source)
int GetMaxValence() const
Returns the maximum vertex valence in all levels.
Vtr::internal::Level const & getLevel(int l) const
bool HasHoles() const
Returns true if faces have been tagged as holes.
int GetNumLevels() const
Returns the number of refinement levels.
int GetNumFVarValuesTotal(int channel=0) const
Returns the total number of face-varying values in all levels.
Vtr::internal::Refinement const & getRefinement(int l) const
Sdc::Options GetSchemeOptions() const
Returns the subdivision options.
bool IsUniform() const
Returns true if uniform refinement has been applied.
Sdc::SchemeType GetSchemeType() const
Returns the subdivision scheme.
int GetMaxLevel() const
Returns the highest level of refinement.
TopologyRefiner(Sdc::SchemeType type, Sdc::Options options=Sdc::Options())
Constructor.
int GetNumEdgesTotal() const
Returns the total number of edges in all levels.
int GetNumFVarChannels() const
Returns the number of face-varying channels in the tables.
UniformOptions GetUniformOptions() const
Returns the options specified on refinement.
int GetNumFacesTotal() const
Returns the total number of edges in all levels.
int GetNumFaceVerticesTotal() const
Returns the total number of face vertices in all levels.
Vtr::internal::Refinement & getRefinement(int l)
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.
int GetNumVerticesTotal() const
Returns the total number of vertices in all levels.
void Unrefine()
Unrefine the topology, keeping only the base level.
AdaptiveOptions GetAdaptiveOptions() const
Returns the options specified on refinement.
Sdc::Options::FVarLinearInterpolation GetFVarLinearInterpolation(int channel=0) const
Returns the face-varying interpolation rule set for a given channel.
void RefineAdaptive(AdaptiveOptions options, ConstIndexArray selectedFaces=ConstIndexArray())
Feature Adaptive topology refinement.
unsigned int refinementLevel
Number of refinement iterations.
void SetRefinementLevel(int level)
Set uniform refinement level.
void SetSecondaryLevel(int level)
Set secondary isolation level.
Private base class of Factories for constructing TopologyRefiners.
All supported options applying to subdivision scheme.
Definition options.h:34