OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
53 //=============================================================================
54 //
55 // CLASS CompositeT
56 //
57 //=============================================================================
58 
59 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
60 #define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 #include <OpenMesh/Core/System/config.hh>
67 // --------------------
68 #include <vector>
69 #include <memory>
70 #include <string>
71 
72 
73 //== NAMESPACE ================================================================
74 
75 namespace OpenMesh { // BEGIN_NS_OPENMESH
76 namespace Subdivider { // BEGIN_NS_SUBDIVIDER
77 namespace Adaptive { // BEGIN_NS_ADAPTIVE
78 
79 
80 //== CLASS DEFINITION =========================================================
81 
82 
83 template <typename R> struct RuleHandleT;
84 template <typename M> class RuleInterfaceT;
85 
86 
87 //== CLASS DEFINITION =========================================================
88 
138 template <typename M> class CompositeT
139 {
140 public:
141 
142  typedef RuleInterfaceT<M> Rule;
143  typedef M Mesh;
144  typedef std::vector<Rule*> RuleSequence;
145 
146  typedef typename M::VertexHandle VH;
147  typedef typename M::FaceHandle FH;
148  typedef typename M::EdgeHandle EH;
149  typedef typename M::HalfedgeHandle HH;
150 
151 public:
152 
154  CompositeT(Mesh& _mesh)
155  : subdiv_type_(0),
156  subdiv_rule_(NULL), /*first_rule_(NULL), last_rule_(NULL),*/ mesh_(_mesh)
157  { }
158 
160  virtual ~CompositeT()
161  { cleanup(); }
162 
163 
166  void cleanup(void)
167  {
168  subdiv_type_ = 0;
169  subdiv_rule_ = NULL;
170 
171  std::for_each(rule_sequence_.begin(),
172  rule_sequence_.end(), DeleteRule() );
173  rule_sequence_.clear();
174  }
175 
176 
178  bool initialize(void);
179 
180 
182  void refine(typename M::FaceHandle& _fh);
183 
184 
186  void refine(typename M::VertexHandle& _vh);
187 
188 
190  int subdiv_type() { return subdiv_type_; }
191 
192 
193  // Return subdivision rule.
194  const Rule& subdiv_rule() const { return *subdiv_rule_; }
195 
196 public:
197 
199  //*@
200 
205  template < typename R >
207  {
208  size_t idx = rule_sequence_.size();
209  rule_sequence_.push_back( new R( mesh_ ) );
210  return RuleHandleT<R>( (idx < rule_sequence_.size()) ? idx : -1 );
211  }
212 
217  template < typename R >
219  {
220  return _rh = add< R >();
221  }
222 
228  template < typename R >
229  typename RuleHandleT<R>::Rule& rule( const RuleHandleT<R>& _rh )
230  {
231  typedef typename RuleHandleT<R>::Rule rule_t;
232  assert( _rh.is_valid() );
233  return *dynamic_cast<rule_t*>(rule_sequence_[ _rh.idx() ]);
234  }
235 
236 
242  RuleInterfaceT<M>& rule( size_t _idx )
243  {
244  assert( _idx < n_rules() );
245  return *rule_sequence_[ _idx ];
246  }
247 
249  size_t n_rules() const { return rule_sequence_.size(); }
250 
252  std::string rules_as_string(const std::string& _sep= " * ") const;
253 
255 
256 protected:
257 
259  const RuleSequence& rules() const { return rule_sequence_; }
260 
261 protected: // helper
262 
263  // get current generation from state
264  state_t generation(state_t _s) { return _s-(_s % n_rules()); }
265  state_t generation( VH _vh ) { return generation(mesh_.data(_vh).state()); }
266  state_t generation( EH _eh ) { return generation(mesh_.data(_eh).state()); }
267  state_t generation( FH _fh ) { return generation(mesh_.data(_fh).state()); }
268 
269 private:
270 
271  // short cuts
272  Rule* t_rule() { return subdiv_rule_; }
273  Rule* f_rule() { return rule_sequence_.front(); }
274  Rule* l_rule() { return rule_sequence_.back(); }
275 
276 private:
277 
278  //
279  RuleSequence rule_sequence_;
280 
281  // Split type
282  int subdiv_type_;
283 
284  Rule *subdiv_rule_;
285 // Rule *first_rule_;
286 // Rule *last_rule_;
287 
288  //
289  Mesh &mesh_;
290 
291 private: // helper
292 
293 #ifndef DOXY_IGNORE_THIS
294  struct DeleteRule { void operator()( Rule* _r ) { delete _r; } };
295 #endif
296 
297 private:
298 
299  CompositeT( const CompositeT& );
300  CompositeT& operator = ( const CompositeT );
301 
302 };
303 
304 
305 //=============================================================================
306 } // END_NS_ADAPTIVE
307 } // END_NS_SUBDIVIDER
308 } // END_NS_OPENMESH
309 //=============================================================================
310 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_CC)
311 # define OPENMESH_SUBDIVIDER_TEMPLATES
312 # include "CompositeT.cc"
313 #endif
314 //=============================================================================
315 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH defined
316 //=============================================================================
CompositeTraits::state_t state_t
Adaptive Composite Subdivision framework.
Definition: CompositeTraits.hh:255
RuleInterfaceT< M > & rule(size_t _idx)
Get rule (interface) by index.
Definition: CompositeT.hh:242
void refine(typename M::FaceHandle &_fh)
Refine one face.
Definition: CompositeT.cc:181
RuleHandleT< R > & add(RuleHandleT< R > &_rh)
Add new rule to rule sequence by passing an appropriate handle to the method.
Definition: CompositeT.hh:218
int subdiv_type()
Return subdivision split type (3 for 1-to-3 split, 4 for 1-to-4 split).
Definition: CompositeT.hh:190
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
std::string rules_as_string(const std::string &_sep=" * ") const
Return the sequence as string.
Definition: CompositeT.cc:296
Handle template for adaptive composite subdividion rules.
Definition: CompositeT.hh:83
void cleanup(void)
Reset self to state after the default constructor except of the mesh.
Definition: CompositeT.hh:166
Mesh traits for adaptive composite subdivider.
const RuleSequence & rules() const
The rule sequence.
Definition: CompositeT.hh:259
Base class for adaptive composite subdivision rules.
Definition: CompositeT.hh:84
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
RuleHandleT< R >::Rule & rule(const RuleHandleT< R > &_rh)
Get rule in the rule sequence by a handle.
Definition: CompositeT.hh:229
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:206
size_t n_rules() const
Number of rules in the rule sequence.
Definition: CompositeT.hh:249
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
CompositeT(Mesh &_mesh)
Constructor.
Definition: CompositeT.hh:154
bool initialize(void)
Initialize faces, edges, vertices, and rules.
Definition: CompositeT.cc:84
Adaptive Composite Subdivision framework.
Definition: CompositeT.hh:138

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .