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
50 class TopologyRefiner {
51
52 public:
53
55 TopologyRefiner(Sdc::SchemeType type, Sdc::Options options = Sdc::Options());
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
152 struct AdaptiveOptions {
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>
210 friend class TopologyRefinerFactory;
211 friend class TopologyRefinerFactoryBase;
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 }
273 inline Sdc::Options::FVarLinearInterpolation
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 */
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetNumEdgesTotal
int GetNumEdgesTotal() const
Returns the total number of edges in all levels.
Definition: topologyRefiner.h:85
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::getLevel
Vtr::internal::Level const & getLevel(int l) const
Definition: topologyRefiner.h:219
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetNumFaceVerticesTotal
int GetNumFaceVerticesTotal() const
Returns the total number of face vertices in all levels.
Definition: topologyRefiner.h:91
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetSchemeOptions
Sdc::Options GetSchemeOptions() const
Returns the subdivision options.
Definition: topologyRefiner.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetNumLevels
int GetNumLevels() const
Returns the number of refinement levels.
Definition: topologyRefiner.h:70
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::UniformOptions::UniformOptions
UniformOptions(int level)
Definition: topologyRefiner.h:119
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetMaxLevel
int GetMaxLevel() const
Returns the highest level of refinement.
Definition: topologyRefiner.h:73
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::getRefinement
Vtr::internal::Refinement const & getRefinement(int l) const
Definition: topologyRefiner.h:222
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Level
Definition: level.h:83
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::UniformOptions
Uniform refinement options.
Definition: topologyRefiner.h:117
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options
All supported options applying to subdivision scheme.
Definition: options.h:51
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyLevel
An interface for accessing data in a specific level of a refined topology hierarchy.
Definition: topologyLevel.h:49
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::SchemeType
SchemeType
Enumerated type for all subdivisions schemes supported by OpenSubdiv.
Definition: types.h:37
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetUniformOptions
UniformOptions GetUniformOptions() const
Returns the options specified on refinement.
Definition: topologyRefiner.h:145
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::Refinement
Definition: refinement.h:69
OpenSubdiv::OPENSUBDIV_VERSION::Far::PatchTableFactory
Factory for constructing a PatchTable from a TopologyRefiner.
Definition: patchTableFactory.h:43
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefinerFactoryBase
Private base class of Factories for constructing TopologyRefiners.
Definition: topologyRefinerFactory.h:47
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner
Stores topology data for a specified set of refinement options.
Definition: topologyRefiner.h:50
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetNumFacesTotal
int GetNumFacesTotal() const
Returns the total number of edges in all levels.
Definition: topologyRefiner.h:88
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::internal::SparseSelector
Definition: sparseSelector.h:57
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetAdaptiveOptions
AdaptiveOptions GetAdaptiveOptions() const
Returns the options specified on refinement.
Definition: topologyRefiner.h:183
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetNumVerticesTotal
int GetNumVerticesTotal() const
Returns the total number of vertices in all levels.
Definition: topologyRefiner.h:82
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetMaxValence
int GetMaxValence() const
Returns the maximum vertex valence in all levels.
Definition: topologyRefiner.h:76
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::AdaptiveOptions
Adaptive refinement options.
Definition: topologyRefiner.h:152
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::AdaptiveOptions::AdaptiveOptions
AdaptiveOptions(int level)
Definition: topologyRefiner.h:154
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::getLevel
Vtr::internal::Level & getLevel(int l)
Definition: topologyRefiner.h:218
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::getRefinement
Vtr::internal::Refinement & getRefinement(int l)
Definition: topologyRefiner.h:221
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetSchemeType
Sdc::SchemeType GetSchemeType() const
Returns the subdivision scheme.
Definition: topologyRefiner.h:61
OpenSubdiv::OPENSUBDIV_VERSION::Far::PrimvarRefiner
Applies refinement operations to generic primvar data.
Definition: primvarRefiner.h:56
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::GetLevel
TopologyLevel const & GetLevel(int level) const
Returns a handle to access data specific to a particular level.
Definition: topologyRefiner.h:94
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::IsUniform
bool IsUniform() const
Returns true if uniform refinement has been applied.
Definition: topologyRefiner.h:67
OpenSubdiv
Definition: error.h:30
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options::FVarLinearInterpolation
FVarLinearInterpolation
Definition: options.h:58
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefiner::HasHoles
bool HasHoles() const
Returns true if faces have been tagged as holes.
Definition: topologyRefiner.h:79
OpenSubdiv::OPENSUBDIV_VERSION::Far::PtexIndices
Object used to compute and query ptex face indices.
Definition: ptexIndices.h:46
OpenSubdiv::OPENSUBDIV_VERSION::Far::TopologyRefinerFactory
Factory for constructing TopologyRefiners from specific mesh classes.
Definition: topologyRefiner.h:45