00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef OPENMESH_BASE_KERNEL_HH
00040 #define OPENMESH_BASE_KERNEL_HH
00041
00042
00043
00044
00045
00046 #include <OpenMesh/Core/System/config.h>
00047
00048 #include <vector>
00049 #include <string>
00050 #include <algorithm>
00051
00052 #include <OpenMesh/Core/Utils/Property.hh>
00053
00054
00055
00056
00057
00058 namespace OpenMesh {
00059
00060
00061
00062
00079
00080 class BaseKernel
00081 {
00082 public:
00083
00084 BaseKernel() {}
00085 virtual ~BaseKernel() {}
00086
00087
00088 public:
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:
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:
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:
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:
00318
00320
00321
00325 template <class T>
00326 T& property(VPropHandleT<T> _ph, VertexHandle _vh) {
00327 return vprops_.property(_ph)[_vh.idx()];
00328 }
00329 template <class T>
00330 const T& property(VPropHandleT<T> _ph, VertexHandle _vh) const {
00331 return vprops_.property(_ph)[_vh.idx()];
00332 }
00333
00334
00335 template <class T>
00336 T& property(HPropHandleT<T> _ph, HalfedgeHandle _hh) {
00337 return hprops_.property(_ph)[_hh.idx()];
00338 }
00339 template <class T>
00340 const T& property(HPropHandleT<T> _ph, HalfedgeHandle _hh) const {
00341 return hprops_.property(_ph)[_hh.idx()];
00342 }
00343
00344
00345 template <class T>
00346 T& property(EPropHandleT<T> _ph, EdgeHandle _eh) {
00347 return eprops_.property(_ph)[_eh.idx()];
00348 }
00349 template <class T>
00350 const T& property(EPropHandleT<T> _ph, EdgeHandle _eh) const {
00351 return eprops_.property(_ph)[_eh.idx()];
00352 }
00353
00354
00355 template <class T>
00356 T& property(FPropHandleT<T> _ph, FaceHandle _fh) {
00357 return fprops_.property(_ph)[_fh.idx()];
00358 }
00359 template <class T>
00360 const T& property(FPropHandleT<T> _ph, FaceHandle _fh) const {
00361 return fprops_.property(_ph)[_fh.idx()];
00362 }
00363
00364
00365 template <class T>
00366 T& property(MPropHandleT<T> _ph) {
00367 return mprops_.property(_ph)[0];
00368 }
00369 template <class T>
00370 const T& property(MPropHandleT<T> _ph) const {
00371 return mprops_.property(_ph)[0];
00372 }
00373
00375
00376 protected:
00377
00378 public:
00379
00380 size_t n_vprops(void) const { return vprops_.size(); }
00381
00382 size_t n_eprops(void) const { return eprops_.size(); }
00383
00384 size_t n_hprops(void) const { return hprops_.size(); }
00385
00386 size_t n_fprops(void) const { return fprops_.size(); }
00387
00388 size_t n_mprops(void) const { return mprops_.size(); }
00389
00390 BaseProperty* _get_vprop( const std::string& _name)
00391 { return vprops_.property(_name); }
00392
00393 BaseProperty* _get_eprop( const std::string& _name)
00394 { return eprops_.property(_name); }
00395
00396 BaseProperty* _get_hprop( const std::string& _name)
00397 { return hprops_.property(_name); }
00398
00399 BaseProperty* _get_fprop( const std::string& _name)
00400 { return fprops_.property(_name); }
00401
00402 BaseProperty* _get_mprop( const std::string& _name)
00403 { return mprops_.property(_name); }
00404
00405 const BaseProperty* _get_vprop( const std::string& _name) const
00406 { return vprops_.property(_name); }
00407
00408 const BaseProperty* _get_eprop( const std::string& _name) const
00409 { return eprops_.property(_name); }
00410
00411 const BaseProperty* _get_hprop( const std::string& _name) const
00412 { return hprops_.property(_name); }
00413
00414 const BaseProperty* _get_fprop( const std::string& _name) const
00415 { return fprops_.property(_name); }
00416
00417 const BaseProperty* _get_mprop( const std::string& _name) const
00418 { return mprops_.property(_name); }
00419
00420 BaseProperty& _vprop( size_t _idx ) { return vprops_._property( _idx ); }
00421 BaseProperty& _eprop( size_t _idx ) { return eprops_._property( _idx ); }
00422 BaseProperty& _hprop( size_t _idx ) { return hprops_._property( _idx ); }
00423 BaseProperty& _fprop( size_t _idx ) { return fprops_._property( _idx ); }
00424 BaseProperty& _mprop( size_t _idx ) { return mprops_._property( _idx ); }
00425
00426 const BaseProperty& _vprop( size_t _idx ) const
00427 { return vprops_._property( _idx ); }
00428 const BaseProperty& _eprop( size_t _idx ) const
00429 { return eprops_._property( _idx ); }
00430 const BaseProperty& _hprop( size_t _idx ) const
00431 { return hprops_._property( _idx ); }
00432 const BaseProperty& _fprop( size_t _idx ) const
00433 { return fprops_._property( _idx ); }
00434 const BaseProperty& _mprop( size_t _idx ) const
00435 { return mprops_._property( _idx ); }
00436
00437 size_t _add_vprop( BaseProperty* _bp ) { return vprops_._add( _bp ); }
00438 size_t _add_eprop( BaseProperty* _bp ) { return eprops_._add( _bp ); }
00439 size_t _add_hprop( BaseProperty* _bp ) { return hprops_._add( _bp ); }
00440 size_t _add_fprop( BaseProperty* _bp ) { return fprops_._add( _bp ); }
00441 size_t _add_mprop( BaseProperty* _bp ) { return mprops_._add( _bp ); }
00442
00443 protected:
00444
00445 BaseProperty& _vprop( BaseHandle _h )
00446 { return vprops_._property( _h.idx() ); }
00447 BaseProperty& _eprop( BaseHandle _h )
00448 { return eprops_._property( _h.idx() ); }
00449 BaseProperty& _hprop( BaseHandle _h )
00450 { return hprops_._property( _h.idx() ); }
00451 BaseProperty& _fprop( BaseHandle _h )
00452 { return fprops_._property( _h.idx() ); }
00453 BaseProperty& _mprop( BaseHandle _h )
00454 { return mprops_._property( _h.idx() ); }
00455
00456 const BaseProperty& _vprop( BaseHandle _h ) const
00457 { return vprops_._property( _h.idx() ); }
00458 const BaseProperty& _eprop( BaseHandle _h ) const
00459 { return eprops_._property( _h.idx() ); }
00460 const BaseProperty& _hprop( BaseHandle _h ) const
00461 { return hprops_._property( _h.idx() ); }
00462 const BaseProperty& _fprop( BaseHandle _h ) const
00463 { return fprops_._property( _h.idx() ); }
00464 const BaseProperty& _mprop( BaseHandle _h ) const
00465 { return mprops_._property( _h.idx() ); }
00466
00467
00468 public:
00469
00470
00471 virtual unsigned int n_vertices() const { return 0; }
00472 virtual unsigned int n_halfedges() const { return 0; }
00473 virtual unsigned int n_edges() const { return 0; }
00474 virtual unsigned int n_faces() const { return 0; }
00475
00476
00477 protected:
00478
00479 void vprops_reserve(unsigned int _n) const { vprops_.reserve(_n); }
00480 void vprops_resize(unsigned int _n) const { vprops_.resize(_n); }
00481 void vprops_swap(unsigned int _i0, unsigned int _i1) const {
00482 vprops_.swap(_i0, _i1);
00483 }
00484
00485 void hprops_reserve(unsigned int _n) const { hprops_.reserve(_n); }
00486 void hprops_resize(unsigned int _n) const { hprops_.resize(_n); }
00487 void hprops_swap(unsigned int _i0, unsigned int _i1) const {
00488 hprops_.swap(_i0, _i1);
00489 }
00490
00491 void eprops_reserve(unsigned int _n) const { eprops_.reserve(_n); }
00492 void eprops_resize(unsigned int _n) const { eprops_.resize(_n); }
00493 void eprops_swap(unsigned int _i0, unsigned int _i1) const {
00494 eprops_.swap(_i0, _i1);
00495 }
00496
00497 void fprops_reserve(unsigned int _n) const { fprops_.reserve(_n); }
00498 void fprops_resize(unsigned int _n) const { fprops_.resize(_n); }
00499 void fprops_swap(unsigned int _i0, unsigned int _i1) const {
00500 fprops_.swap(_i0, _i1);
00501 }
00502
00503 void mprops_resize(unsigned int _n) const { mprops_.resize(_n); }
00504
00505
00506 public:
00507
00508 void property_stats( std::ostream& _ostr = std::clog )
00509 {
00510 const PropertyContainer::Properties& vps = vprops_.properties();
00511 const PropertyContainer::Properties& hps = hprops_.properties();
00512 const PropertyContainer::Properties& eps = eprops_.properties();
00513 const PropertyContainer::Properties& fps = fprops_.properties();
00514 const PropertyContainer::Properties& mps = mprops_.properties();
00515
00516 PropertyContainer::Properties::const_iterator it;
00517
00518 _ostr << vprops_.size() << " vprops:\n";
00519 for (it=vps.begin(); it!=vps.end(); ++it)
00520 _ostr << " " << (*it)->name()
00521 << ((*it)->persistent() ? ", persistent " : "") << "\n";
00522
00523 _ostr << hprops_.size() << " hprops:\n";
00524 for (it=hps.begin(); it!=hps.end(); ++it)
00525 _ostr << " " << (*it)->name()
00526 << ((*it)->persistent() ? ", persistent " : "") << "\n";
00527
00528 _ostr << eprops_.size() << " eprops:\n";
00529 for (it=eps.begin(); it!=eps.end(); ++it)
00530 _ostr << " " << (*it)->name()
00531 << ((*it)->persistent() ? ", persistent " : "") << "\n";
00532
00533 _ostr << fprops_.size() << " fprops:\n";
00534 for (it=fps.begin(); it!=fps.end(); ++it)
00535 _ostr << " " << (*it)->name()
00536 << ((*it)->persistent() ? ", persistent " : "") << "\n";
00537
00538 _ostr << mprops_.size() << " mprops:\n";
00539 for (it=mps.begin(); it!=mps.end(); ++it)
00540 _ostr << " " << (*it)->name()
00541 << ((*it)->persistent() ? ", persistent " : "") << "\n";
00542 }
00543
00544 public:
00545
00546 typedef PropertyContainer::iterator prop_iterator;
00547 typedef PropertyContainer::const_iterator const_prop_iterator;
00548
00549 prop_iterator vprops_begin() { return vprops_.begin(); }
00550 prop_iterator vprops_end() { return vprops_.end(); }
00551 const_prop_iterator vprops_begin() const { return vprops_.begin(); }
00552 const_prop_iterator vprops_end() const { return vprops_.end(); }
00553
00554 prop_iterator eprops_begin() { return eprops_.begin(); }
00555 prop_iterator eprops_end() { return eprops_.end(); }
00556 const_prop_iterator eprops_begin() const { return eprops_.begin(); }
00557 const_prop_iterator eprops_end() const { return eprops_.end(); }
00558
00559 prop_iterator hprops_begin() { return hprops_.begin(); }
00560 prop_iterator hprops_end() { return hprops_.end(); }
00561 const_prop_iterator hprops_begin() const { return hprops_.begin(); }
00562 const_prop_iterator hprops_end() const { return hprops_.end(); }
00563
00564 prop_iterator fprops_begin() { return fprops_.begin(); }
00565 prop_iterator fprops_end() { return fprops_.end(); }
00566 const_prop_iterator fprops_begin() const { return fprops_.begin(); }
00567 const_prop_iterator fprops_end() const { return fprops_.end(); }
00568
00569 prop_iterator mprops_begin() { return mprops_.begin(); }
00570 prop_iterator mprops_end() { return mprops_.end(); }
00571 const_prop_iterator mprops_begin() const { return mprops_.begin(); }
00572 const_prop_iterator mprops_end() const { return mprops_.end(); }
00573
00574 private:
00575
00576 PropertyContainer vprops_;
00577 PropertyContainer hprops_;
00578 PropertyContainer eprops_;
00579 PropertyContainer fprops_;
00580 PropertyContainer mprops_;
00581 };
00582
00583
00584
00585 }
00586
00587 #endif // OPENMESH_BASE_KERNEL_HH defined
00588