OpenMesh
|
00001 /*===========================================================================*\ 00002 * * 00003 * OpenMesh * 00004 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * 00005 * www.openmesh.org * 00006 * * 00007 *---------------------------------------------------------------------------* 00008 * This file is part of OpenMesh. * 00009 * * 00010 * OpenMesh is free software: you can redistribute it and/or modify * 00011 * it under the terms of the GNU Lesser General Public License as * 00012 * published by the Free Software Foundation, either version 3 of * 00013 * the License, or (at your option) any later version with the * 00014 * following exceptions: * 00015 * * 00016 * If other files instantiate templates or use macros * 00017 * or inline functions from this file, or you compile this file and * 00018 * link it with other files to produce an executable, this file does * 00019 * not by itself cause the resulting executable to be covered by the * 00020 * GNU Lesser General Public License. This exception does not however * 00021 * invalidate any other reasons why the executable file might be * 00022 * covered by the GNU Lesser General Public License. * 00023 * * 00024 * OpenMesh is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU Lesser General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU LesserGeneral Public * 00030 * License along with OpenMesh. If not, * 00031 * see <http://www.gnu.org/licenses/>. * 00032 * * 00033 \*===========================================================================*/ 00034 00035 /*===========================================================================*\ 00036 * * 00037 * $Revision: 543 $ * 00038 * $Date: 2012-02-29 14:21:06 +0100 (Mi, 29 Feb 2012) $ * 00039 * * 00040 \*===========================================================================*/ 00041 00042 00043 //============================================================================= 00044 // 00045 // CLASS BaseKernel 00046 // 00047 //============================================================================= 00048 00049 00050 #ifndef OPENMESH_BASE_KERNEL_HH 00051 #define OPENMESH_BASE_KERNEL_HH 00052 00053 00054 //== INCLUDES ================================================================= 00055 00056 00057 #include <OpenMesh/Core/System/config.h> 00058 // -------------------- 00059 #include <vector> 00060 #include <string> 00061 #include <algorithm> 00062 // -------------------- 00063 #include <OpenMesh/Core/Utils/PropertyContainer.hh> 00064 00065 00066 //== NAMESPACES =============================================================== 00067 00068 00069 namespace OpenMesh { 00070 00071 00072 //== CLASS DEFINITION ========================================================= 00073 00090 00091 class BaseKernel 00092 { 00093 public: //-------------------------------------------- constructor / destructor 00094 00095 BaseKernel() {} 00096 virtual ~BaseKernel() { 00097 vprops_.clear(); 00098 eprops_.clear(); 00099 hprops_.clear(); 00100 fprops_.clear(); 00101 } 00102 00103 00104 public: //-------------------------------------------------- add new properties 00105 00107 00109 00130 template <class T> 00131 void add_property( VPropHandleT<T>& _ph, const std::string& _name="<vprop>") 00132 { 00133 _ph = VPropHandleT<T>( vprops_.add(T(), _name) ); 00134 vprops_.resize(n_vertices()); 00135 } 00136 00137 template <class T> 00138 void add_property( HPropHandleT<T>& _ph, const std::string& _name="<hprop>") 00139 { 00140 _ph = HPropHandleT<T>( hprops_.add(T(), _name) ); 00141 hprops_.resize(n_halfedges()); 00142 } 00143 00144 template <class T> 00145 void add_property( EPropHandleT<T>& _ph, const std::string& _name="<eprop>") 00146 { 00147 _ph = EPropHandleT<T>( eprops_.add(T(), _name) ); 00148 eprops_.resize(n_edges()); 00149 } 00150 00151 template <class T> 00152 void add_property( FPropHandleT<T>& _ph, const std::string& _name="<fprop>") 00153 { 00154 _ph = FPropHandleT<T>( fprops_.add(T(), _name) ); 00155 fprops_.resize(n_faces()); 00156 } 00157 00158 template <class T> 00159 void add_property( MPropHandleT<T>& _ph, const std::string& _name="<mprop>") 00160 { 00161 _ph = MPropHandleT<T>( mprops_.add(T(), _name) ); 00162 mprops_.resize(1); 00163 } 00164 00166 00167 00168 public: //--------------------------------------------------- remove properties 00169 00171 00172 00180 template <typename T> 00181 void remove_property(VPropHandleT<T>& _ph) 00182 { 00183 if (_ph.is_valid()) 00184 vprops_.remove(_ph); 00185 _ph.reset(); 00186 } 00187 00188 template <typename T> 00189 void remove_property(HPropHandleT<T>& _ph) 00190 { 00191 if (_ph.is_valid()) 00192 hprops_.remove(_ph); 00193 _ph.reset(); 00194 } 00195 00196 template <typename T> 00197 void remove_property(EPropHandleT<T>& _ph) 00198 { 00199 if (_ph.is_valid()) 00200 eprops_.remove(_ph); 00201 _ph.reset(); 00202 } 00203 00204 template <typename T> 00205 void remove_property(FPropHandleT<T>& _ph) 00206 { 00207 if (_ph.is_valid()) 00208 fprops_.remove(_ph); 00209 _ph.reset(); 00210 } 00211 00212 template <typename T> 00213 void remove_property(MPropHandleT<T>& _ph) 00214 { 00215 if (_ph.is_valid()) 00216 mprops_.remove(_ph); 00217 _ph.reset(); 00218 } 00219 00221 00222 public: //------------------------------------------------ get handle from name 00223 00225 00226 00235 template <class T> 00236 bool get_property_handle(VPropHandleT<T>& _ph, 00237 const std::string& _name) const 00238 { 00239 return (_ph = VPropHandleT<T>(vprops_.handle(T(), _name))).is_valid(); 00240 } 00241 00242 template <class T> 00243 bool get_property_handle(HPropHandleT<T>& _ph, 00244 const std::string& _name) const 00245 { 00246 return (_ph = HPropHandleT<T>(hprops_.handle(T(), _name))).is_valid(); 00247 } 00248 00249 template <class T> 00250 bool get_property_handle(EPropHandleT<T>& _ph, 00251 const std::string& _name) const 00252 { 00253 return (_ph = EPropHandleT<T>(eprops_.handle(T(), _name))).is_valid(); 00254 } 00255 00256 template <class T> 00257 bool get_property_handle(FPropHandleT<T>& _ph, 00258 const std::string& _name) const 00259 { 00260 return (_ph = FPropHandleT<T>(fprops_.handle(T(), _name))).is_valid(); 00261 } 00262 00263 template <class T> 00264 bool get_property_handle(MPropHandleT<T>& _ph, 00265 const std::string& _name) const 00266 { 00267 return (_ph = MPropHandleT<T>(mprops_.handle(T(), _name))).is_valid(); 00268 } 00269 00271 00272 public: //--------------------------------------------------- access properties 00273 00275 00276 00286 template <class T> 00287 PropertyT<T>& property(VPropHandleT<T> _ph) { 00288 return vprops_.property(_ph); 00289 } 00290 template <class T> 00291 const PropertyT<T>& property(VPropHandleT<T> _ph) const { 00292 return vprops_.property(_ph); 00293 } 00294 00295 template <class T> 00296 PropertyT<T>& property(HPropHandleT<T> _ph) { 00297 return hprops_.property(_ph); 00298 } 00299 template <class T> 00300 const PropertyT<T>& property(HPropHandleT<T> _ph) const { 00301 return hprops_.property(_ph); 00302 } 00303 00304 template <class T> 00305 PropertyT<T>& property(EPropHandleT<T> _ph) { 00306 return eprops_.property(_ph); 00307 } 00308 template <class T> 00309 const PropertyT<T>& property(EPropHandleT<T> _ph) const { 00310 return eprops_.property(_ph); 00311 } 00312 00313 template <class T> 00314 PropertyT<T>& property(FPropHandleT<T> _ph) { 00315 return fprops_.property(_ph); 00316 } 00317 template <class T> 00318 const PropertyT<T>& property(FPropHandleT<T> _ph) const { 00319 return fprops_.property(_ph); 00320 } 00321 00322 template <class T> 00323 PropertyT<T>& mproperty(MPropHandleT<T> _ph) { 00324 return mprops_.property(_ph); 00325 } 00326 template <class T> 00327 const PropertyT<T>& mproperty(MPropHandleT<T> _ph) const { 00328 return mprops_.property(_ph); 00329 } 00330 00332 00333 public: //-------------------------------------------- access property elements 00334 00336 00337 00341 template <class T> 00342 typename VPropHandleT<T>::reference 00343 property(VPropHandleT<T> _ph, VertexHandle _vh) { 00344 return vprops_.property(_ph)[_vh.idx()]; 00345 } 00346 00347 template <class T> 00348 typename VPropHandleT<T>::const_reference 00349 property(VPropHandleT<T> _ph, VertexHandle _vh) const { 00350 return vprops_.property(_ph)[_vh.idx()]; 00351 } 00352 00353 00354 template <class T> 00355 typename HPropHandleT<T>::reference 00356 property(HPropHandleT<T> _ph, HalfedgeHandle _hh) { 00357 return hprops_.property(_ph)[_hh.idx()]; 00358 } 00359 00360 template <class T> 00361 typename HPropHandleT<T>::const_reference 00362 property(HPropHandleT<T> _ph, HalfedgeHandle _hh) const { 00363 return hprops_.property(_ph)[_hh.idx()]; 00364 } 00365 00366 00367 template <class T> 00368 typename EPropHandleT<T>::reference 00369 property(EPropHandleT<T> _ph, EdgeHandle _eh) { 00370 return eprops_.property(_ph)[_eh.idx()]; 00371 } 00372 00373 template <class T> 00374 typename EPropHandleT<T>::const_reference 00375 property(EPropHandleT<T> _ph, EdgeHandle _eh) const { 00376 return eprops_.property(_ph)[_eh.idx()]; 00377 } 00378 00379 00380 template <class T> 00381 typename FPropHandleT<T>::reference 00382 property(FPropHandleT<T> _ph, FaceHandle _fh) { 00383 return fprops_.property(_ph)[_fh.idx()]; 00384 } 00385 00386 template <class T> 00387 typename FPropHandleT<T>::const_reference 00388 property(FPropHandleT<T> _ph, FaceHandle _fh) const { 00389 return fprops_.property(_ph)[_fh.idx()]; 00390 } 00391 00392 00393 template <class T> 00394 typename MPropHandleT<T>::reference 00395 property(MPropHandleT<T> _ph) { 00396 return mprops_.property(_ph)[0]; 00397 } 00398 00399 template <class T> 00400 typename MPropHandleT<T>::const_reference 00401 property(MPropHandleT<T> _ph) const { 00402 return mprops_.property(_ph)[0]; 00403 } 00404 00406 00407 protected: //------------------------------------------------- low-level access 00408 00409 public: // used by non-native kernel and MeshIO, should be protected 00410 00411 size_t n_vprops(void) const { return vprops_.size(); } 00412 00413 size_t n_eprops(void) const { return eprops_.size(); } 00414 00415 size_t n_hprops(void) const { return hprops_.size(); } 00416 00417 size_t n_fprops(void) const { return fprops_.size(); } 00418 00419 size_t n_mprops(void) const { return mprops_.size(); } 00420 00421 BaseProperty* _get_vprop( const std::string& _name) 00422 { return vprops_.property(_name); } 00423 00424 BaseProperty* _get_eprop( const std::string& _name) 00425 { return eprops_.property(_name); } 00426 00427 BaseProperty* _get_hprop( const std::string& _name) 00428 { return hprops_.property(_name); } 00429 00430 BaseProperty* _get_fprop( const std::string& _name) 00431 { return fprops_.property(_name); } 00432 00433 BaseProperty* _get_mprop( const std::string& _name) 00434 { return mprops_.property(_name); } 00435 00436 const BaseProperty* _get_vprop( const std::string& _name) const 00437 { return vprops_.property(_name); } 00438 00439 const BaseProperty* _get_eprop( const std::string& _name) const 00440 { return eprops_.property(_name); } 00441 00442 const BaseProperty* _get_hprop( const std::string& _name) const 00443 { return hprops_.property(_name); } 00444 00445 const BaseProperty* _get_fprop( const std::string& _name) const 00446 { return fprops_.property(_name); } 00447 00448 const BaseProperty* _get_mprop( const std::string& _name) const 00449 { return mprops_.property(_name); } 00450 00451 BaseProperty& _vprop( size_t _idx ) { return vprops_._property( _idx ); } 00452 BaseProperty& _eprop( size_t _idx ) { return eprops_._property( _idx ); } 00453 BaseProperty& _hprop( size_t _idx ) { return hprops_._property( _idx ); } 00454 BaseProperty& _fprop( size_t _idx ) { return fprops_._property( _idx ); } 00455 BaseProperty& _mprop( size_t _idx ) { return mprops_._property( _idx ); } 00456 00457 const BaseProperty& _vprop( size_t _idx ) const 00458 { return vprops_._property( _idx ); } 00459 const BaseProperty& _eprop( size_t _idx ) const 00460 { return eprops_._property( _idx ); } 00461 const BaseProperty& _hprop( size_t _idx ) const 00462 { return hprops_._property( _idx ); } 00463 const BaseProperty& _fprop( size_t _idx ) const 00464 { return fprops_._property( _idx ); } 00465 const BaseProperty& _mprop( size_t _idx ) const 00466 { return mprops_._property( _idx ); } 00467 00468 size_t _add_vprop( BaseProperty* _bp ) { return vprops_._add( _bp ); } 00469 size_t _add_eprop( BaseProperty* _bp ) { return eprops_._add( _bp ); } 00470 size_t _add_hprop( BaseProperty* _bp ) { return hprops_._add( _bp ); } 00471 size_t _add_fprop( BaseProperty* _bp ) { return fprops_._add( _bp ); } 00472 size_t _add_mprop( BaseProperty* _bp ) { return mprops_._add( _bp ); } 00473 00474 protected: // low-level access non-public 00475 00476 BaseProperty& _vprop( BaseHandle _h ) 00477 { return vprops_._property( _h.idx() ); } 00478 BaseProperty& _eprop( BaseHandle _h ) 00479 { return eprops_._property( _h.idx() ); } 00480 BaseProperty& _hprop( BaseHandle _h ) 00481 { return hprops_._property( _h.idx() ); } 00482 BaseProperty& _fprop( BaseHandle _h ) 00483 { return fprops_._property( _h.idx() ); } 00484 BaseProperty& _mprop( BaseHandle _h ) 00485 { return mprops_._property( _h.idx() ); } 00486 00487 const BaseProperty& _vprop( BaseHandle _h ) const 00488 { return vprops_._property( _h.idx() ); } 00489 const BaseProperty& _eprop( BaseHandle _h ) const 00490 { return eprops_._property( _h.idx() ); } 00491 const BaseProperty& _hprop( BaseHandle _h ) const 00492 { return hprops_._property( _h.idx() ); } 00493 const BaseProperty& _fprop( BaseHandle _h ) const 00494 { return fprops_._property( _h.idx() ); } 00495 const BaseProperty& _mprop( BaseHandle _h ) const 00496 { return mprops_._property( _h.idx() ); } 00497 00498 00499 public: //----------------------------------------------------- element numbers 00500 00501 00502 virtual uint n_vertices() const { return 0; } 00503 virtual uint n_halfedges() const { return 0; } 00504 virtual uint n_edges() const { return 0; } 00505 virtual uint n_faces() const { return 0; } 00506 00507 00508 protected: //------------------------------------------- synchronize properties 00509 00510 void vprops_reserve(unsigned int _n) const { vprops_.reserve(_n); } 00511 void vprops_resize(unsigned int _n) const { vprops_.resize(_n); } 00512 void vprops_clear() { 00513 vprops_.clear(); 00514 } 00515 void vprops_swap(unsigned int _i0, unsigned int _i1) const { 00516 vprops_.swap(_i0, _i1); 00517 } 00518 00519 void hprops_reserve(unsigned int _n) const { hprops_.reserve(_n); } 00520 void hprops_resize(unsigned int _n) const { hprops_.resize(_n); } 00521 void hprops_clear() { 00522 hprops_.clear(); 00523 } 00524 void hprops_swap(unsigned int _i0, unsigned int _i1) const { 00525 hprops_.swap(_i0, _i1); 00526 } 00527 00528 void eprops_reserve(unsigned int _n) const { eprops_.reserve(_n); } 00529 void eprops_resize(unsigned int _n) const { eprops_.resize(_n); } 00530 void eprops_clear() { 00531 eprops_.clear(); 00532 } 00533 void eprops_swap(unsigned int _i0, unsigned int _i1) const { 00534 eprops_.swap(_i0, _i1); 00535 } 00536 00537 void fprops_reserve(unsigned int _n) const { fprops_.reserve(_n); } 00538 void fprops_resize(unsigned int _n) const { fprops_.resize(_n); } 00539 void fprops_clear() { 00540 fprops_.clear(); 00541 } 00542 void fprops_swap(unsigned int _i0, unsigned int _i1) const { 00543 fprops_.swap(_i0, _i1); 00544 } 00545 00546 void mprops_resize(unsigned int _n) const { mprops_.resize(_n); } 00547 void mprops_clear() { 00548 mprops_.clear(); 00549 } 00550 00551 public: 00552 00553 void property_stats(std::ostream& _ostr = std::clog) const; 00554 00555 void vprop_stats( std::string& _string ) const; 00556 void hprop_stats( std::string& _string ) const; 00557 void eprop_stats( std::string& _string ) const; 00558 void fprop_stats( std::string& _string ) const; 00559 void mprop_stats( std::string& _string ) const; 00560 00561 void vprop_stats(std::ostream& _ostr = std::clog) const; 00562 void hprop_stats(std::ostream& _ostr = std::clog) const; 00563 void eprop_stats(std::ostream& _ostr = std::clog) const; 00564 void fprop_stats(std::ostream& _ostr = std::clog) const; 00565 void mprop_stats(std::ostream& _ostr = std::clog) const; 00566 00567 public: 00568 00569 typedef PropertyContainer::iterator prop_iterator; 00570 typedef PropertyContainer::const_iterator const_prop_iterator; 00571 00572 prop_iterator vprops_begin() { return vprops_.begin(); } 00573 prop_iterator vprops_end() { return vprops_.end(); } 00574 const_prop_iterator vprops_begin() const { return vprops_.begin(); } 00575 const_prop_iterator vprops_end() const { return vprops_.end(); } 00576 00577 prop_iterator eprops_begin() { return eprops_.begin(); } 00578 prop_iterator eprops_end() { return eprops_.end(); } 00579 const_prop_iterator eprops_begin() const { return eprops_.begin(); } 00580 const_prop_iterator eprops_end() const { return eprops_.end(); } 00581 00582 prop_iterator hprops_begin() { return hprops_.begin(); } 00583 prop_iterator hprops_end() { return hprops_.end(); } 00584 const_prop_iterator hprops_begin() const { return hprops_.begin(); } 00585 const_prop_iterator hprops_end() const { return hprops_.end(); } 00586 00587 prop_iterator fprops_begin() { return fprops_.begin(); } 00588 prop_iterator fprops_end() { return fprops_.end(); } 00589 const_prop_iterator fprops_begin() const { return fprops_.begin(); } 00590 const_prop_iterator fprops_end() const { return fprops_.end(); } 00591 00592 prop_iterator mprops_begin() { return mprops_.begin(); } 00593 prop_iterator mprops_end() { return mprops_.end(); } 00594 const_prop_iterator mprops_begin() const { return mprops_.begin(); } 00595 const_prop_iterator mprops_end() const { return mprops_.end(); } 00596 00597 private: 00598 00599 PropertyContainer vprops_; 00600 PropertyContainer hprops_; 00601 PropertyContainer eprops_; 00602 PropertyContainer fprops_; 00603 PropertyContainer mprops_; 00604 }; 00605 00606 00607 //============================================================================= 00608 } // namespace OpenMesh 00609 //============================================================================= 00610 #endif // OPENMESH_BASE_KERNEL_HH defined 00611 //=============================================================================