OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
BaseKernel.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2011 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: 543 $ *
38  * $Date: 2012-02-29 14:21:06 +0100 (Mi, 29 Feb 2012) $ *
39  * *
40 \*===========================================================================*/
41 
42 
43 //=============================================================================
44 //
45 // CLASS BaseKernel
46 //
47 //=============================================================================
48 
49 
50 #ifndef OPENMESH_BASE_KERNEL_HH
51 #define OPENMESH_BASE_KERNEL_HH
52 
53 
54 //== INCLUDES =================================================================
55 
56 
57 #include <OpenMesh/Core/System/config.h>
58 // --------------------
59 #include <vector>
60 #include <string>
61 #include <algorithm>
62 // --------------------
63 #include <OpenMesh/Core/Utils/PropertyContainer.hh>
64 
65 
66 //== NAMESPACES ===============================================================
67 
68 
69 namespace OpenMesh {
70 
71 
72 //== CLASS DEFINITION =========================================================
73 
90 
92 {
93 public: //-------------------------------------------- constructor / destructor
94 
95  BaseKernel() {}
96  virtual ~BaseKernel() {
97  vprops_.clear();
98  eprops_.clear();
99  hprops_.clear();
100  fprops_.clear();
101  }
102 
103 
104 public: //-------------------------------------------------- add new properties
105 
107 
109 
130  template <class T>
131  void add_property( VPropHandleT<T>& _ph, const std::string& _name="<vprop>")
132  {
133  _ph = VPropHandleT<T>( vprops_.add(T(), _name) );
134  vprops_.resize(n_vertices());
135  }
136 
137  template <class T>
138  void add_property( HPropHandleT<T>& _ph, const std::string& _name="<hprop>")
139  {
140  _ph = HPropHandleT<T>( hprops_.add(T(), _name) );
141  hprops_.resize(n_halfedges());
142  }
143 
144  template <class T>
145  void add_property( EPropHandleT<T>& _ph, const std::string& _name="<eprop>")
146  {
147  _ph = EPropHandleT<T>( eprops_.add(T(), _name) );
148  eprops_.resize(n_edges());
149  }
150 
151  template <class T>
152  void add_property( FPropHandleT<T>& _ph, const std::string& _name="<fprop>")
153  {
154  _ph = FPropHandleT<T>( fprops_.add(T(), _name) );
155  fprops_.resize(n_faces());
156  }
157 
158  template <class T>
159  void add_property( MPropHandleT<T>& _ph, const std::string& _name="<mprop>")
160  {
161  _ph = MPropHandleT<T>( mprops_.add(T(), _name) );
162  mprops_.resize(1);
163  }
164 
166 
167 
168 public: //--------------------------------------------------- remove properties
169 
171 
172 
180  template <typename T>
182  {
183  if (_ph.is_valid())
184  vprops_.remove(_ph);
185  _ph.reset();
186  }
187 
188  template <typename T>
190  {
191  if (_ph.is_valid())
192  hprops_.remove(_ph);
193  _ph.reset();
194  }
195 
196  template <typename T>
198  {
199  if (_ph.is_valid())
200  eprops_.remove(_ph);
201  _ph.reset();
202  }
203 
204  template <typename T>
206  {
207  if (_ph.is_valid())
208  fprops_.remove(_ph);
209  _ph.reset();
210  }
211 
212  template <typename T>
214  {
215  if (_ph.is_valid())
216  mprops_.remove(_ph);
217  _ph.reset();
218  }
219 
221 
222 public: //------------------------------------------------ get handle from name
223 
225 
226 
235  template <class T>
237  const std::string& _name) const
238  {
239  return (_ph = VPropHandleT<T>(vprops_.handle(T(), _name))).is_valid();
240  }
241 
242  template <class T>
244  const std::string& _name) const
245  {
246  return (_ph = HPropHandleT<T>(hprops_.handle(T(), _name))).is_valid();
247  }
248 
249  template <class T>
251  const std::string& _name) const
252  {
253  return (_ph = EPropHandleT<T>(eprops_.handle(T(), _name))).is_valid();
254  }
255 
256  template <class T>
258  const std::string& _name) const
259  {
260  return (_ph = FPropHandleT<T>(fprops_.handle(T(), _name))).is_valid();
261  }
262 
263  template <class T>
265  const std::string& _name) const
266  {
267  return (_ph = MPropHandleT<T>(mprops_.handle(T(), _name))).is_valid();
268  }
269 
271 
272 public: //--------------------------------------------------- access properties
273 
275 
276 
286  template <class T>
288  return vprops_.property(_ph);
289  }
290  template <class T>
292  return vprops_.property(_ph);
293  }
294 
295  template <class T>
297  return hprops_.property(_ph);
298  }
299  template <class T>
301  return hprops_.property(_ph);
302  }
303 
304  template <class T>
306  return eprops_.property(_ph);
307  }
308  template <class T>
310  return eprops_.property(_ph);
311  }
312 
313  template <class T>
315  return fprops_.property(_ph);
316  }
317  template <class T>
319  return fprops_.property(_ph);
320  }
321 
322  template <class T>
324  return mprops_.property(_ph);
325  }
326  template <class T>
328  return mprops_.property(_ph);
329  }
330 
332 
333 public: //-------------------------------------------- access property elements
334 
336 
337 
341  template <class T>
342  typename VPropHandleT<T>::reference
344  return vprops_.property(_ph)[_vh.idx()];
345  }
346 
347  template <class T>
348  typename VPropHandleT<T>::const_reference
350  return vprops_.property(_ph)[_vh.idx()];
351  }
352 
353 
354  template <class T>
355  typename HPropHandleT<T>::reference
357  return hprops_.property(_ph)[_hh.idx()];
358  }
359 
360  template <class T>
361  typename HPropHandleT<T>::const_reference
363  return hprops_.property(_ph)[_hh.idx()];
364  }
365 
366 
367  template <class T>
368  typename EPropHandleT<T>::reference
370  return eprops_.property(_ph)[_eh.idx()];
371  }
372 
373  template <class T>
374  typename EPropHandleT<T>::const_reference
376  return eprops_.property(_ph)[_eh.idx()];
377  }
378 
379 
380  template <class T>
381  typename FPropHandleT<T>::reference
383  return fprops_.property(_ph)[_fh.idx()];
384  }
385 
386  template <class T>
387  typename FPropHandleT<T>::const_reference
389  return fprops_.property(_ph)[_fh.idx()];
390  }
391 
392 
393  template <class T>
394  typename MPropHandleT<T>::reference
396  return mprops_.property(_ph)[0];
397  }
398 
399  template <class T>
400  typename MPropHandleT<T>::const_reference
402  return mprops_.property(_ph)[0];
403  }
404 
406 
407 protected: //------------------------------------------------- low-level access
408 
409 public: // used by non-native kernel and MeshIO, should be protected
410 
411  size_t n_vprops(void) const { return vprops_.size(); }
412 
413  size_t n_eprops(void) const { return eprops_.size(); }
414 
415  size_t n_hprops(void) const { return hprops_.size(); }
416 
417  size_t n_fprops(void) const { return fprops_.size(); }
418 
419  size_t n_mprops(void) const { return mprops_.size(); }
420 
421  BaseProperty* _get_vprop( const std::string& _name)
422  { return vprops_.property(_name); }
423 
424  BaseProperty* _get_eprop( const std::string& _name)
425  { return eprops_.property(_name); }
426 
427  BaseProperty* _get_hprop( const std::string& _name)
428  { return hprops_.property(_name); }
429 
430  BaseProperty* _get_fprop( const std::string& _name)
431  { return fprops_.property(_name); }
432 
433  BaseProperty* _get_mprop( const std::string& _name)
434  { return mprops_.property(_name); }
435 
436  const BaseProperty* _get_vprop( const std::string& _name) const
437  { return vprops_.property(_name); }
438 
439  const BaseProperty* _get_eprop( const std::string& _name) const
440  { return eprops_.property(_name); }
441 
442  const BaseProperty* _get_hprop( const std::string& _name) const
443  { return hprops_.property(_name); }
444 
445  const BaseProperty* _get_fprop( const std::string& _name) const
446  { return fprops_.property(_name); }
447 
448  const BaseProperty* _get_mprop( const std::string& _name) const
449  { return mprops_.property(_name); }
450 
451  BaseProperty& _vprop( size_t _idx ) { return vprops_._property( _idx ); }
452  BaseProperty& _eprop( size_t _idx ) { return eprops_._property( _idx ); }
453  BaseProperty& _hprop( size_t _idx ) { return hprops_._property( _idx ); }
454  BaseProperty& _fprop( size_t _idx ) { return fprops_._property( _idx ); }
455  BaseProperty& _mprop( size_t _idx ) { return mprops_._property( _idx ); }
456 
457  const BaseProperty& _vprop( size_t _idx ) const
458  { return vprops_._property( _idx ); }
459  const BaseProperty& _eprop( size_t _idx ) const
460  { return eprops_._property( _idx ); }
461  const BaseProperty& _hprop( size_t _idx ) const
462  { return hprops_._property( _idx ); }
463  const BaseProperty& _fprop( size_t _idx ) const
464  { return fprops_._property( _idx ); }
465  const BaseProperty& _mprop( size_t _idx ) const
466  { return mprops_._property( _idx ); }
467 
468  size_t _add_vprop( BaseProperty* _bp ) { return vprops_._add( _bp ); }
469  size_t _add_eprop( BaseProperty* _bp ) { return eprops_._add( _bp ); }
470  size_t _add_hprop( BaseProperty* _bp ) { return hprops_._add( _bp ); }
471  size_t _add_fprop( BaseProperty* _bp ) { return fprops_._add( _bp ); }
472  size_t _add_mprop( BaseProperty* _bp ) { return mprops_._add( _bp ); }
473 
474 protected: // low-level access non-public
475 
476  BaseProperty& _vprop( BaseHandle _h )
477  { return vprops_._property( _h.idx() ); }
478  BaseProperty& _eprop( BaseHandle _h )
479  { return eprops_._property( _h.idx() ); }
480  BaseProperty& _hprop( BaseHandle _h )
481  { return hprops_._property( _h.idx() ); }
482  BaseProperty& _fprop( BaseHandle _h )
483  { return fprops_._property( _h.idx() ); }
484  BaseProperty& _mprop( BaseHandle _h )
485  { return mprops_._property( _h.idx() ); }
486 
487  const BaseProperty& _vprop( BaseHandle _h ) const
488  { return vprops_._property( _h.idx() ); }
489  const BaseProperty& _eprop( BaseHandle _h ) const
490  { return eprops_._property( _h.idx() ); }
491  const BaseProperty& _hprop( BaseHandle _h ) const
492  { return hprops_._property( _h.idx() ); }
493  const BaseProperty& _fprop( BaseHandle _h ) const
494  { return fprops_._property( _h.idx() ); }
495  const BaseProperty& _mprop( BaseHandle _h ) const
496  { return mprops_._property( _h.idx() ); }
497 
498 
499 public: //----------------------------------------------------- element numbers
500 
501 
502  virtual uint n_vertices() const { return 0; }
503  virtual uint n_halfedges() const { return 0; }
504  virtual uint n_edges() const { return 0; }
505  virtual uint n_faces() const { return 0; }
506 
507 
508 protected: //------------------------------------------- synchronize properties
509 
510  void vprops_reserve(unsigned int _n) const { vprops_.reserve(_n); }
511  void vprops_resize(unsigned int _n) const { vprops_.resize(_n); }
512  void vprops_clear() {
513  vprops_.clear();
514  }
515  void vprops_swap(unsigned int _i0, unsigned int _i1) const {
516  vprops_.swap(_i0, _i1);
517  }
518 
519  void hprops_reserve(unsigned int _n) const { hprops_.reserve(_n); }
520  void hprops_resize(unsigned int _n) const { hprops_.resize(_n); }
521  void hprops_clear() {
522  hprops_.clear();
523  }
524  void hprops_swap(unsigned int _i0, unsigned int _i1) const {
525  hprops_.swap(_i0, _i1);
526  }
527 
528  void eprops_reserve(unsigned int _n) const { eprops_.reserve(_n); }
529  void eprops_resize(unsigned int _n) const { eprops_.resize(_n); }
530  void eprops_clear() {
531  eprops_.clear();
532  }
533  void eprops_swap(unsigned int _i0, unsigned int _i1) const {
534  eprops_.swap(_i0, _i1);
535  }
536 
537  void fprops_reserve(unsigned int _n) const { fprops_.reserve(_n); }
538  void fprops_resize(unsigned int _n) const { fprops_.resize(_n); }
539  void fprops_clear() {
540  fprops_.clear();
541  }
542  void fprops_swap(unsigned int _i0, unsigned int _i1) const {
543  fprops_.swap(_i0, _i1);
544  }
545 
546  void mprops_resize(unsigned int _n) const { mprops_.resize(_n); }
547  void mprops_clear() {
548  mprops_.clear();
549  }
550 
551 public:
552 
553  void property_stats(std::ostream& _ostr = std::clog) const;
554 
555  void vprop_stats( std::string& _string ) const;
556  void hprop_stats( std::string& _string ) const;
557  void eprop_stats( std::string& _string ) const;
558  void fprop_stats( std::string& _string ) const;
559  void mprop_stats( std::string& _string ) const;
560 
561  void vprop_stats(std::ostream& _ostr = std::clog) const;
562  void hprop_stats(std::ostream& _ostr = std::clog) const;
563  void eprop_stats(std::ostream& _ostr = std::clog) const;
564  void fprop_stats(std::ostream& _ostr = std::clog) const;
565  void mprop_stats(std::ostream& _ostr = std::clog) const;
566 
567 public:
568 
569  typedef PropertyContainer::iterator prop_iterator;
570  typedef PropertyContainer::const_iterator const_prop_iterator;
571 
572  prop_iterator vprops_begin() { return vprops_.begin(); }
573  prop_iterator vprops_end() { return vprops_.end(); }
574  const_prop_iterator vprops_begin() const { return vprops_.begin(); }
575  const_prop_iterator vprops_end() const { return vprops_.end(); }
576 
577  prop_iterator eprops_begin() { return eprops_.begin(); }
578  prop_iterator eprops_end() { return eprops_.end(); }
579  const_prop_iterator eprops_begin() const { return eprops_.begin(); }
580  const_prop_iterator eprops_end() const { return eprops_.end(); }
581 
582  prop_iterator hprops_begin() { return hprops_.begin(); }
583  prop_iterator hprops_end() { return hprops_.end(); }
584  const_prop_iterator hprops_begin() const { return hprops_.begin(); }
585  const_prop_iterator hprops_end() const { return hprops_.end(); }
586 
587  prop_iterator fprops_begin() { return fprops_.begin(); }
588  prop_iterator fprops_end() { return fprops_.end(); }
589  const_prop_iterator fprops_begin() const { return fprops_.begin(); }
590  const_prop_iterator fprops_end() const { return fprops_.end(); }
591 
592  prop_iterator mprops_begin() { return mprops_.begin(); }
593  prop_iterator mprops_end() { return mprops_.end(); }
594  const_prop_iterator mprops_begin() const { return mprops_.begin(); }
595  const_prop_iterator mprops_end() const { return mprops_.end(); }
596 
597 private:
598 
599  PropertyContainer vprops_;
600  PropertyContainer hprops_;
601  PropertyContainer eprops_;
602  PropertyContainer fprops_;
603  PropertyContainer mprops_;
604 };
605 
606 
607 //=============================================================================
608 } // namespace OpenMesh
609 //=============================================================================
610 #endif // OPENMESH_BASE_KERNEL_HH defined
611 //=============================================================================

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