OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CompositeT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 756 $ *
38 * $Date: 2012-10-31 12:58:22 +0100 (Mi, 31 Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
46 //=============================================================================
47 //
48 // CLASS CompositeT
49 //
50 //=============================================================================
51
52 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
53 #define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
54
55
56 //== INCLUDES =================================================================
57
58 #include <OpenMesh/Core/System/config.hh>
59 #include <OpenMesh/Tools/Subdivider/Adaptive/Composite/CompositeTraits.hh>
60 // --------------------
61 #include <vector>
62 #include <memory>
63 #include <string>
64
65
66 //== NAMESPACE ================================================================
67
68 namespace OpenMesh { // BEGIN_NS_OPENMESH
69 namespace Subdivider { // BEGIN_NS_SUBDIVIDER
70 namespace Adaptive { // BEGIN_NS_ADAPTIVE
71
72
73 //== CLASS DEFINITION =========================================================
74
75
76 template <typename R> struct RuleHandleT;
77 template <typename M> class RuleInterfaceT;
78
79
80 //== CLASS DEFINITION =========================================================
81
131 template <typename M> class CompositeT
132 {
133 public:
134
135 typedef RuleInterfaceT<M> Rule;
136 typedef M Mesh;
137 typedef std::vector<Rule*> RuleSequence;
138
139 typedef typename M::VertexHandle VH;
140 typedef typename M::FaceHandle FH;
141 typedef typename M::EdgeHandle EH;
142 typedef typename M::HalfedgeHandle HH;
143
144 public:
145
147 CompositeT(Mesh& _mesh)
148 : subdiv_type_(0),
149 subdiv_rule_(NULL), /*first_rule_(NULL), last_rule_(NULL),*/ mesh_(_mesh)
150 { }
151
153 virtual ~CompositeT()
154 { cleanup(); }
155
156
159 void cleanup(void)
160 {
161 subdiv_type_ = 0;
162 subdiv_rule_ = NULL;
163
164 std::for_each(rule_sequence_.begin(),
165 rule_sequence_.end(), DeleteRule() );
166 rule_sequence_.clear();
167 }
168
169
171 bool initialize(void);
172
173
175 void refine(typename M::FaceHandle& _fh);
176
177
179 void refine(typename M::VertexHandle& _vh);
180
181
183 int subdiv_type() { return subdiv_type_; }
184
185
186 // Return subdivision rule.
187 const Rule& subdiv_rule() const { return *subdiv_rule_; }
188
189 public:
190
192 //*@
193
198 template < typename R >
199 RuleHandleT<R> add()
200 {
201 size_t idx = rule_sequence_.size();
202 rule_sequence_.push_back( new R( mesh_ ) );
203 return RuleHandleT<R>( (idx < rule_sequence_.size()) ? idx : -1 );
204 }
205
210 template < typename R >
211 RuleHandleT<R>& add( RuleHandleT<R>& _rh )
212 {
213 return _rh = add< R >();
214 }
215
221 template < typename R >
222 typename RuleHandleT<R>::Rule& rule( const RuleHandleT<R>& _rh )
223 {
224 typedef typename RuleHandleT<R>::Rule rule_t;
225 assert( _rh.is_valid() );
226 return *dynamic_cast<rule_t*>(rule_sequence_[ _rh.idx() ]);
227 }
228
229
235 RuleInterfaceT<M>& rule( size_t _idx )
236 {
237 assert( _idx < n_rules() );
238 return *rule_sequence_[ _idx ];
239 }
240
242 size_t n_rules() const { return rule_sequence_.size(); }
243
245 std::string rules_as_string(const std::string& _sep= " * ") const;
246
248
249 protected:
250
252 const RuleSequence& rules() const { return rule_sequence_; }
253
254 protected: // helper
255
256 // get current generation from state
257 state_t generation(state_t _s) { return _s-(_s % n_rules()); }
258 state_t generation( VH _vh ) { return generation(mesh_.data(_vh).state()); }
259 state_t generation( EH _eh ) { return generation(mesh_.data(_eh).state()); }
260 state_t generation( FH _fh ) { return generation(mesh_.data(_fh).state()); }
261
262 private:
263
264 // short cuts
265 Rule* t_rule() { return subdiv_rule_; }
266 Rule* f_rule() { return rule_sequence_.front(); }
267 Rule* l_rule() { return rule_sequence_.back(); }
268
269 private:
270
271 //
272 RuleSequence rule_sequence_;
273
274 // Split type
275 int subdiv_type_;
276
277 Rule *subdiv_rule_;
278 // Rule *first_rule_;
279 // Rule *last_rule_;
280
281 //
282 Mesh &mesh_;
283
284 private: // helper
285
286 #ifndef DOXY_IGNORE_THIS
287 struct DeleteRule { void operator()( Rule* _r ) { delete _r; } };
288 #endif
289
290 private:
291
292 CompositeT( const CompositeT& );
293 CompositeT& operator = ( const CompositeT );
294
295 };
296
297
298 //=============================================================================
299 } // END_NS_ADAPTIVE
300 } // END_NS_SUBDIVIDER
301 } // END_NS_OPENMESH
302 //=============================================================================
303 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_CC)
304 # define OPENMESH_SUBDIVIDER_TEMPLATES
305 # include "CompositeT.cc"
306 #endif
307 //=============================================================================
308 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH defined
309 //=============================================================================