| OpenMesh

CompositeT.hh
Go to the documentation of this file.
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43
48 //=============================================================================
49 //
50 // CLASS CompositeT
51 //
52 //=============================================================================
53
54 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
55 #define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
56
57
58 //== INCLUDES =================================================================
59
60 #include <OpenMesh/Core/System/config.hh>
61 #include <OpenMesh/Tools/Subdivider/Adaptive/Composite/CompositeTraits.hh>
62 // --------------------
63 #include <vector>
64 #include <memory>
65 #include <string>
66
67
68 //== NAMESPACE ================================================================
69
70 namespace OpenMesh { // BEGIN_NS_OPENMESH
71 namespace Subdivider { // BEGIN_NS_SUBDIVIDER
72 namespace Adaptive { // BEGIN_NS_ADAPTIVE
73
74
75 //== CLASS DEFINITION =========================================================
76
77
78 template <typename R> struct RuleHandleT;
79 template <typename M> class RuleInterfaceT;
80
81
82 //== CLASS DEFINITION =========================================================
83
133 template <typename M> class CompositeT
134 {
135 public:
136
137 typedef RuleInterfaceT<M> Rule;
138 typedef M Mesh;
139 typedef std::vector<Rule*> RuleSequence;
140
141 typedef typename M::VertexHandle VH;
142 typedef typename M::FaceHandle FH;
143 typedef typename M::EdgeHandle EH;
144 typedef typename M::HalfedgeHandle HH;
145
146 public:
147
149 explicit CompositeT(Mesh& _mesh)
150 : subdiv_type_(0),
151 subdiv_rule_(nullptr), /*first_rule_(nullptr), last_rule_(nullptr),*/ mesh_(_mesh)
152 { }
153
155 virtual ~CompositeT()
156 { cleanup(); }
157
158
161 void cleanup(void)
162 {
163 subdiv_type_ = 0;
164 subdiv_rule_ = nullptr;
165
166 std::for_each(rule_sequence_.begin(),
167 rule_sequence_.end(), DeleteRule() );
168 rule_sequence_.clear();
169 }
170
171
173 bool initialize(void);
174
175
177 void refine(typename M::FaceHandle& _fh);
178
179
181 void refine(typename M::VertexHandle& _vh);
182
183
185 int subdiv_type() { return subdiv_type_; }
186
187
188 // Return subdivision rule.
189 const Rule& subdiv_rule() const { return *subdiv_rule_; }
190
191 public:
192
194 //*@
195
200 template < typename R >
201 RuleHandleT<R> add()
202 {
203 size_t idx = rule_sequence_.size();
204 rule_sequence_.push_back( new R( mesh_ ) );
205 return RuleHandleT<R>( (idx < rule_sequence_.size()) ? idx : -1 );
206 }
207
212 template < typename R >
213 RuleHandleT<R>& add( RuleHandleT<R>& _rh )
214 {
215 return _rh = add< R >();
216 }
217
223 template < typename R >
224 typename RuleHandleT<R>::Rule& rule( const RuleHandleT<R>& _rh )
225 {
226 typedef typename RuleHandleT<R>::Rule rule_t;
227 assert( _rh.is_valid() );
228 return *dynamic_cast<rule_t*>(rule_sequence_[ _rh.idx() ]);
229 }
230
231
237 RuleInterfaceT<M>& rule( size_t _idx )
238 {
239 assert( _idx < n_rules() );
240 return *rule_sequence_[ _idx ];
241 }
242
244 size_t n_rules() const { return rule_sequence_.size(); }
245
247 std::string rules_as_string(const std::string& _sep= " * ") const;
248
250
251 protected:
252
254 const RuleSequence& rules() const { return rule_sequence_; }
255
256 protected: // helper
257
258 // get current generation from state
259 state_t generation(state_t _s) const { return _s-(_s % n_rules()); }
260 state_t generation( VH _vh ) const { return generation(mesh_.data(_vh).state()); }
261 state_t generation( EH _eh ) const { return generation(mesh_.data(_eh).state()); }
262 state_t generation( FH _fh ) const { return generation(mesh_.data(_fh).state()); }
263
264 private:
265
266 // short cuts
267 Rule* t_rule() const { return subdiv_rule_; }
268 Rule* f_rule() { return rule_sequence_.front(); }
269 Rule* l_rule() { return rule_sequence_.back(); }
270
271 private:
272
273 //
274 RuleSequence rule_sequence_;
275
276 // Split type
277 int subdiv_type_;
278
279 Rule *subdiv_rule_;
280 // Rule *first_rule_;
281 // Rule *last_rule_;
282
283 //
284 Mesh &mesh_;
285
286 private: // helper
287
288 #ifndef DOXY_IGNORE_THIS
289 struct DeleteRule { void operator()( Rule* _r ) { delete _r; } };
290 #endif
291
292 private:
293
294 CompositeT( const CompositeT& );
295 CompositeT& operator = ( const CompositeT );
296
297 };
298
299
300 //=============================================================================
301 } // END_NS_ADAPTIVE
302 } // END_NS_SUBDIVIDER
303 } // END_NS_OPENMESH
304 //=============================================================================
305 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_CC)
306 # define OPENMESH_SUBDIVIDER_TEMPLATES
307 # include "CompositeT_impl.hh"
308 #endif
309 //=============================================================================
310 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH defined
311 //=============================================================================
OpenMesh::Subdivider::Adaptive::CompositeT
Adaptive Composite Subdivision framework.
Definition: CompositeT.hh:133
OpenMesh::Subdivider::Adaptive::CompositeT::CompositeT
CompositeT(Mesh &_mesh)
Constructor.
Definition: CompositeT.hh:149
OpenMesh::Subdivider::Adaptive::CompositeT::rules
const RuleSequence & rules() const
The rule sequence.
Definition: CompositeT.hh:254
OpenMesh::Subdivider::Adaptive::CompositeT::rule
RuleInterfaceT< M > & rule(size_t _idx)
Get rule (interface) by index.
Definition: CompositeT.hh:237
CompositeTraits.hh
Mesh traits for adaptive composite subdivider.
OpenMesh::Subdivider::Adaptive::state_t
CompositeTraits::state_t state_t
Adaptive Composite Subdivision framework.
Definition: CompositeTraits.hh:250
OpenMesh::BaseHandle::is_valid
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72
OpenMesh::Subdivider::Adaptive::CompositeT::add
RuleHandleT< R > add()
Add new rule to rule sequence by passing the type of the wanted rule as template argument to the meth...
Definition: CompositeT.hh:201
OpenMesh::Subdivider::Adaptive::CompositeT::n_rules
size_t n_rules() const
Number of rules in the rule sequence.
Definition: CompositeT.hh:244
OpenMesh::Subdivider::Adaptive::RuleInterfaceT
Base class for adaptive composite subdivision rules.
Definition: CompositeT.hh:79
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:69
OpenMesh::Subdivider::Adaptive::CompositeT::subdiv_type
int subdiv_type()
Return subdivision split type (3 for 1-to-3 split, 4 for 1-to-4 split).
Definition: CompositeT.hh:185
OpenMesh::Subdivider::Adaptive::CompositeT::rules_as_string
std::string rules_as_string(const std::string &_sep=" * ") const
Return the sequence as string.
Definition: CompositeT_impl.hh:289
OpenMesh::Subdivider::Adaptive::CompositeT::initialize
bool initialize(void)
Initialize faces, edges, vertices, and rules.
Definition: CompositeT_impl.hh:77
OpenMesh::Subdivider::Adaptive::CompositeT::add
RuleHandleT< R > & add(RuleHandleT< R > &_rh)
Add new rule to rule sequence by passing an appropriate handle to the method.
Definition: CompositeT.hh:213
OpenMesh::Subdivider::Adaptive::CompositeT::cleanup
void cleanup(void)
Reset self to state after the default constructor except of the mesh.
Definition: CompositeT.hh:161
OpenMesh::Subdivider::Adaptive::RuleHandleT
Handle template for adaptive composite subdividion rules.
Definition: CompositeT.hh:78
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::Subdivider::Adaptive::CompositeT::refine
void refine(typename M::FaceHandle &_fh)
Refine one face.
Definition: CompositeT_impl.hh:174
OpenMesh::Subdivider::Adaptive::CompositeT::rule
RuleHandleT< R >::Rule & rule(const RuleHandleT< R > &_rh)
Get rule in the rule sequence by a handle.
Definition: CompositeT.hh:224