Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

BaseKernel.hh

00001 //=============================================================================
00002 //
00003 //                               OpenMesh
00004 //      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen
00005 //                           www.openmesh.org
00006 //
00007 //-----------------------------------------------------------------------------
00008 //
00009 //                                License
00010 //
00011 //   This library is free software; you can redistribute it and/or modify it
00012 //   under the terms of the GNU Library General Public License as published
00013 //   by the Free Software Foundation, version 2.
00014 //
00015 //   This library is distributed in the hope that it will be useful, but
00016 //   WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //   Library General Public License for more details.
00019 //
00020 //   You should have received a copy of the GNU Library General Public
00021 //   License along with this library; if not, write to the Free Software
00022 //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023 //
00024 //-----------------------------------------------------------------------------
00025 //
00026 //   $Revision: 1.2 $
00027 //   $Date: 2005/04/19 07:59:45 $
00028 //
00029 //=============================================================================
00030 
00031 
00032 //=============================================================================
00033 //
00034 //  CLASS BaseKernel
00035 //
00036 //=============================================================================
00037 
00038 
00039 #ifndef OPENMESH_BASE_KERNEL_HH
00040 #define OPENMESH_BASE_KERNEL_HH
00041 
00042 
00043 //== INCLUDES =================================================================
00044 
00045 
00046 #include <OpenMesh/Core/System/config.hh>
00047 // --------------------
00048 #include <vector>
00049 #include <string>
00050 #include <algorithm>
00051 // --------------------
00052 #include <OpenMesh/Core/Utils/Property.hh>
00053 
00054 
00055 //== NAMESPACES ===============================================================
00056 
00057 
00058 namespace OpenMesh {
00059 
00060 
00061 //== CLASS DEFINITION =========================================================
00062 
00079 
00080 class BaseKernel
00081 {
00082 public: //-------------------------------------------- constructor / destructor
00083 
00084   BaseKernel() {}
00085   virtual ~BaseKernel() {}
00086 
00087 
00088 public: //-------------------------------------------------- add new properties
00089 
00091 
00093 
00114   template <class T> void add_property( VPropHandleT<T>& _ph,
00115           const std::string& _name="<vprop>" )
00116   {
00117     _ph = VPropHandleT<T>( vprops_.add(T(), _name) );
00118     vprops_.resize(n_vertices());
00119   }
00120 
00121   template <class T> void add_property( HPropHandleT<T>& _ph,
00122           const std::string& _name="<hprop>" )
00123   {
00124     _ph = HPropHandleT<T>( hprops_.add(T(), _name) );
00125     hprops_.resize(n_halfedges());
00126   }
00127 
00128   template <class T> void add_property( EPropHandleT<T>& _ph,
00129           const std::string& _name="<eprop>" )
00130   {
00131     _ph = EPropHandleT<T>( eprops_.add(T(), _name) );
00132     eprops_.resize(n_edges());
00133   }
00134 
00135   template <class T> void add_property( FPropHandleT<T>& _ph,
00136           const std::string& _name="<fprop>" )
00137   {
00138     _ph = FPropHandleT<T>( fprops_.add(T(), _name) );
00139     fprops_.resize(n_faces());
00140   }
00141 
00142   template <class T> void add_property( MPropHandleT<T>& _ph,
00143           const std::string& _name="<mprop>" )
00144   {
00145     _ph = MPropHandleT<T>( mprops_.add(T(), _name) );
00146     mprops_.resize(1);
00147   }
00148 
00150 
00151 
00152 public: //--------------------------------------------------- remove properties
00153 
00155 
00156 
00164   template <typename T>
00165   void remove_property(VPropHandleT<T>& _ph) {
00166     if (_ph.is_valid())
00167       vprops_.remove(_ph);
00168     _ph.reset();
00169   }
00170 
00171   template <typename T>
00172   void remove_property(HPropHandleT<T>& _ph) {
00173     if (_ph.is_valid())
00174       hprops_.remove(_ph);
00175     _ph.reset();
00176   }
00177 
00178   template <typename T>
00179   void remove_property(EPropHandleT<T>& _ph) {
00180     if (_ph.is_valid())
00181       eprops_.remove(_ph);
00182     _ph.reset();
00183   }
00184 
00185   template <typename T>
00186   void remove_property(FPropHandleT<T>& _ph) {
00187     if (_ph.is_valid())
00188       fprops_.remove(_ph);
00189     _ph.reset();
00190   }
00191 
00192   template <typename T>
00193   void remove_property(MPropHandleT<T>& _ph) {
00194     if (_ph.is_valid())
00195       mprops_.remove(_ph);
00196     _ph.reset();
00197   }
00198 
00200 
00201 
00202 public: //------------------------------------------------ get handle from name
00203 
00205 
00206 
00215   template <class T>
00216   bool get_property_handle(VPropHandleT<T>& _ph,
00217          const std::string& _name) const
00218   {
00219     return (_ph = VPropHandleT<T>(vprops_.handle(T(), _name))).is_valid();
00220   }
00221 
00222   template <class T>
00223   bool get_property_handle(HPropHandleT<T>& _ph,
00224          const std::string& _name) const
00225   {
00226     return (_ph = HPropHandleT<T>(hprops_.handle(T(), _name))).is_valid();
00227   }
00228 
00229   template <class T>
00230   bool get_property_handle(EPropHandleT<T>& _ph,
00231          const std::string& _name) const
00232   {
00233     return (_ph = EPropHandleT<T>(eprops_.handle(T(), _name))).is_valid();
00234   }
00235 
00236   template <class T>
00237   bool get_property_handle(FPropHandleT<T>& _ph,
00238          const std::string& _name) const
00239   {
00240     return (_ph = FPropHandleT<T>(fprops_.handle(T(), _name))).is_valid();
00241   }
00242 
00243   template <class T>
00244   bool get_property_handle(MPropHandleT<T>& _ph,
00245          const std::string& _name) const
00246   {
00247     return (_ph = MPropHandleT<T>(mprops_.handle(T(), _name))).is_valid();
00248   }
00249 
00251 
00252 
00253 public: //--------------------------------------------------- access properties
00254 
00256 
00257 
00267   template <class T>
00268   PropertyT<T>& property(VPropHandleT<T> _ph) {
00269     return vprops_.property(_ph);
00270   }
00271   template <class T>
00272   const PropertyT<T>& property(VPropHandleT<T> _ph) const {
00273     return vprops_.property(_ph);
00274   }
00275 
00276 
00277   template <class T>
00278   PropertyT<T>& property(HPropHandleT<T> _ph) {
00279     return hprops_.property(_ph);
00280   }
00281   template <class T>
00282   const PropertyT<T>& property(HPropHandleT<T> _ph) const {
00283     return hprops_.property(_ph);
00284   }
00285 
00286 
00287   template <class T>
00288   PropertyT<T>& property(EPropHandleT<T> _ph) {
00289     return eprops_.property(_ph);
00290   }
00291   template <class T>
00292   const PropertyT<T>& property(EPropHandleT<T> _ph) const {
00293     return eprops_.property(_ph);
00294   }
00295 
00296 
00297   template <class T>
00298   PropertyT<T>& property(FPropHandleT<T> _ph) {
00299     return fprops_.property(_ph);
00300   }
00301   template <class T>
00302   const PropertyT<T>& property(FPropHandleT<T> _ph) const {
00303     return fprops_.property(_ph);
00304   }
00305 
00306   template <class T>
00307   PropertyT<T>& mproperty(MPropHandleT<T> _ph) {
00308     return mprops_.property(_ph);
00309   }
00310   template <class T>
00311   const PropertyT<T>& mproperty(MPropHandleT<T> _ph) const {
00312     return mprops_.property(_ph);
00313   }
00314 
00316 
00317 public: //-------------------------------------------- access property elements
00318 
00320 
00321 
00325   template <class T>
00326   typename VPropHandleT<T>::reference
00327   property(VPropHandleT<T> _ph, VertexHandle _vh) {
00328     return vprops_.property(_ph)[_vh.idx()];
00329   }
00330   template <class T>
00331   typename VPropHandleT<T>::const_reference
00332   property(VPropHandleT<T> _ph, VertexHandle _vh) const {
00333     return vprops_.property(_ph)[_vh.idx()];
00334   }
00335 
00336 
00337   template <class T>
00338   typename HPropHandleT<T>::reference
00339   property(HPropHandleT<T> _ph, HalfedgeHandle _hh) {
00340     return hprops_.property(_ph)[_hh.idx()];
00341   }
00342 
00343   template <class T>
00344   typename HPropHandleT<T>::const_reference
00345   property(HPropHandleT<T> _ph, HalfedgeHandle _hh) const {
00346     return hprops_.property(_ph)[_hh.idx()];
00347   }
00348 
00349 
00350   template <class T>
00351   typename EPropHandleT<T>::reference
00352   property(EPropHandleT<T> _ph, EdgeHandle _eh) {
00353     return eprops_.property(_ph)[_eh.idx()];
00354   }
00355 
00356   template <class T>
00357   typename EPropHandleT<T>::const_reference
00358   property(EPropHandleT<T> _ph, EdgeHandle _eh) const {
00359     return eprops_.property(_ph)[_eh.idx()];
00360   }
00361 
00362 
00363   template <class T>
00364   typename FPropHandleT<T>::reference
00365   property(FPropHandleT<T> _ph, FaceHandle _fh) {
00366     return fprops_.property(_ph)[_fh.idx()];
00367   }
00368 
00369   template <class T>
00370   typename FPropHandleT<T>::const_reference
00371   property(FPropHandleT<T> _ph, FaceHandle _fh) const {
00372     return fprops_.property(_ph)[_fh.idx()];
00373   }
00374 
00375 
00376   template <class T>
00377   typename MPropHandleT<T>::reference
00378   property(MPropHandleT<T> _ph) {
00379     return mprops_.property(_ph)[0];
00380   }
00381 
00382   template <class T>
00383   typename MPropHandleT<T>::const_reference
00384   property(MPropHandleT<T> _ph) const {
00385     return mprops_.property(_ph)[0];
00386   }
00387 
00389 
00390 protected: //------------------------------------------------- low-level access
00391 
00392 public: // used by non-native kernel and MeshIO, should be protected
00393 
00394   size_t n_vprops(void) const { return vprops_.size(); }
00395 
00396   size_t n_eprops(void) const { return eprops_.size(); }
00397 
00398   size_t n_hprops(void) const { return hprops_.size(); }
00399 
00400   size_t n_fprops(void) const { return fprops_.size(); }
00401 
00402   size_t n_mprops(void) const { return mprops_.size(); }
00403 
00404   BaseProperty* _get_vprop( const std::string& _name)
00405   { return vprops_.property(_name); }
00406 
00407   BaseProperty* _get_eprop( const std::string& _name)
00408   { return eprops_.property(_name); }
00409 
00410   BaseProperty* _get_hprop( const std::string& _name)
00411   { return hprops_.property(_name); }
00412 
00413   BaseProperty* _get_fprop( const std::string& _name)
00414   { return fprops_.property(_name); }
00415 
00416   BaseProperty* _get_mprop( const std::string& _name)
00417   { return mprops_.property(_name); }
00418 
00419   const BaseProperty* _get_vprop( const std::string& _name) const
00420   { return vprops_.property(_name); }
00421 
00422   const BaseProperty* _get_eprop( const std::string& _name) const
00423   { return eprops_.property(_name); }
00424 
00425   const BaseProperty* _get_hprop( const std::string& _name) const
00426   { return hprops_.property(_name); }
00427 
00428   const BaseProperty* _get_fprop( const std::string& _name) const
00429   { return fprops_.property(_name); }
00430 
00431   const BaseProperty* _get_mprop( const std::string& _name) const
00432   { return mprops_.property(_name); }
00433 
00434   BaseProperty& _vprop( size_t _idx ) { return vprops_._property( _idx ); }
00435   BaseProperty& _eprop( size_t _idx ) { return eprops_._property( _idx ); }
00436   BaseProperty& _hprop( size_t _idx ) { return hprops_._property( _idx ); }
00437   BaseProperty& _fprop( size_t _idx ) { return fprops_._property( _idx ); }
00438   BaseProperty& _mprop( size_t _idx ) { return mprops_._property( _idx ); }
00439 
00440   const BaseProperty& _vprop( size_t _idx ) const
00441   { return vprops_._property( _idx ); }
00442   const BaseProperty& _eprop( size_t _idx ) const
00443   { return eprops_._property( _idx ); }
00444   const BaseProperty& _hprop( size_t _idx ) const
00445   { return hprops_._property( _idx ); }
00446   const BaseProperty& _fprop( size_t _idx ) const
00447   { return fprops_._property( _idx ); }
00448   const BaseProperty& _mprop( size_t _idx ) const
00449   { return mprops_._property( _idx ); }
00450 
00451   size_t _add_vprop( BaseProperty* _bp ) { return vprops_._add( _bp ); }
00452   size_t _add_eprop( BaseProperty* _bp ) { return eprops_._add( _bp ); }
00453   size_t _add_hprop( BaseProperty* _bp ) { return hprops_._add( _bp ); }
00454   size_t _add_fprop( BaseProperty* _bp ) { return fprops_._add( _bp ); }
00455   size_t _add_mprop( BaseProperty* _bp ) { return mprops_._add( _bp ); }
00456 
00457 protected: // low-level access non-public
00458 
00459   BaseProperty& _vprop( BaseHandle _h )
00460   { return vprops_._property( _h.idx() ); }
00461   BaseProperty& _eprop( BaseHandle _h )
00462   { return eprops_._property( _h.idx() ); }
00463   BaseProperty& _hprop( BaseHandle _h )
00464   { return hprops_._property( _h.idx() ); }
00465   BaseProperty& _fprop( BaseHandle _h )
00466   { return fprops_._property( _h.idx() ); }
00467   BaseProperty& _mprop( BaseHandle _h )
00468   { return mprops_._property( _h.idx() ); }
00469 
00470   const BaseProperty& _vprop( BaseHandle _h ) const
00471   { return vprops_._property( _h.idx() ); }
00472   const BaseProperty& _eprop( BaseHandle _h ) const
00473   { return eprops_._property( _h.idx() ); }
00474   const BaseProperty& _hprop( BaseHandle _h ) const
00475   { return hprops_._property( _h.idx() ); }
00476   const BaseProperty& _fprop( BaseHandle _h ) const
00477   { return fprops_._property( _h.idx() ); }
00478   const BaseProperty& _mprop( BaseHandle _h ) const
00479   { return mprops_._property( _h.idx() ); }
00480 
00481 
00482 public: //----------------------------------------------------- element numbers
00483 
00484 
00485   virtual unsigned int n_vertices()  const { return 0; }
00486   virtual unsigned int n_halfedges() const { return 0; }
00487   virtual unsigned int n_edges()     const { return 0; }
00488   virtual unsigned int n_faces()     const { return 0; }
00489 
00490 
00491 protected: //------------------------------------------- synchronize properties
00492 
00493   void vprops_reserve(unsigned int _n) const { vprops_.reserve(_n); }
00494   void vprops_resize(unsigned int _n) const { vprops_.resize(_n); }
00495   void vprops_free_mem() const { vprops_.free_mem(); }
00496   void vprops_swap(unsigned int _i0, unsigned int _i1) const {
00497     vprops_.swap(_i0, _i1);
00498   }
00499 
00500   void hprops_reserve(unsigned int _n) const { hprops_.reserve(_n); }
00501   void hprops_resize(unsigned int _n) const { hprops_.resize(_n); }
00502   void hprops_free_mem() const { hprops_.free_mem(); }
00503   void hprops_swap(unsigned int _i0, unsigned int _i1) const {
00504     hprops_.swap(_i0, _i1);
00505   }
00506 
00507   void eprops_reserve(unsigned int _n) const { eprops_.reserve(_n); }
00508   void eprops_resize(unsigned int _n) const { eprops_.resize(_n); }
00509   void eprops_free_mem() const { eprops_.free_mem(); }
00510   void eprops_swap(unsigned int _i0, unsigned int _i1) const {
00511     eprops_.swap(_i0, _i1);
00512   }
00513 
00514   void fprops_reserve(unsigned int _n) const { fprops_.reserve(_n); }
00515   void fprops_resize(unsigned int _n) const { fprops_.resize(_n); }
00516   void fprops_free_mem() const { fprops_.free_mem(); }
00517   void fprops_swap(unsigned int _i0, unsigned int _i1) const {
00518     fprops_.swap(_i0, _i1);
00519   }
00520 
00521   void mprops_resize(unsigned int _n) const { mprops_.resize(_n); }
00522 
00523 public:
00524 
00525   void property_stats(std::ostream& _ostr = std::clog) const;
00526 
00527 public:
00528 
00529   typedef PropertyContainer::iterator prop_iterator;
00530   typedef PropertyContainer::const_iterator const_prop_iterator;
00531 
00532   prop_iterator vprops_begin() { return vprops_.begin(); }
00533   prop_iterator vprops_end()   { return vprops_.end(); }
00534   const_prop_iterator vprops_begin() const { return vprops_.begin(); }
00535   const_prop_iterator vprops_end()   const { return vprops_.end(); }
00536 
00537   prop_iterator eprops_begin() { return eprops_.begin(); }
00538   prop_iterator eprops_end()   { return eprops_.end(); }
00539   const_prop_iterator eprops_begin() const { return eprops_.begin(); }
00540   const_prop_iterator eprops_end()   const { return eprops_.end(); }
00541 
00542   prop_iterator hprops_begin() { return hprops_.begin(); }
00543   prop_iterator hprops_end()   { return hprops_.end(); }
00544   const_prop_iterator hprops_begin() const { return hprops_.begin(); }
00545   const_prop_iterator hprops_end()   const { return hprops_.end(); }
00546 
00547   prop_iterator fprops_begin() { return fprops_.begin(); }
00548   prop_iterator fprops_end()   { return fprops_.end(); }
00549   const_prop_iterator fprops_begin() const { return fprops_.begin(); }
00550   const_prop_iterator fprops_end()   const { return fprops_.end(); }
00551 
00552   prop_iterator mprops_begin() { return mprops_.begin(); }
00553   prop_iterator mprops_end()   { return mprops_.end(); }
00554   const_prop_iterator mprops_begin() const { return mprops_.begin(); }
00555   const_prop_iterator mprops_end()   const { return mprops_.end(); }
00556 
00557 private:
00558 
00559   PropertyContainer  vprops_;
00560   PropertyContainer  hprops_;
00561   PropertyContainer  eprops_;
00562   PropertyContainer  fprops_;
00563   PropertyContainer  mprops_;
00564 };
00565 
00566 
00567 //=============================================================================
00568 } // namespace OpenMesh
00569 //=============================================================================
00570 #endif // OPENMESH_BASE_KERNEL_HH defined
00571 //=============================================================================

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