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/PropertyContainer.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>
00115 void add_property( VPropHandleT<T>& _ph, 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>
00122 void add_property( HPropHandleT<T>& _ph, 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>
00129 void add_property( EPropHandleT<T>& _ph, 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>
00136 void add_property( FPropHandleT<T>& _ph, 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>
00143 void add_property( MPropHandleT<T>& _ph, 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 {
00167 if (_ph.is_valid())
00168 vprops_.remove(_ph);
00169 _ph.reset();
00170 }
00171
00172 template <typename T>
00173 void remove_property(HPropHandleT<T>& _ph)
00174 {
00175 if (_ph.is_valid())
00176 hprops_.remove(_ph);
00177 _ph.reset();
00178 }
00179
00180 template <typename T>
00181 void remove_property(EPropHandleT<T>& _ph)
00182 {
00183 if (_ph.is_valid())
00184 eprops_.remove(_ph);
00185 _ph.reset();
00186 }
00187
00188 template <typename T>
00189 void remove_property(FPropHandleT<T>& _ph)
00190 {
00191 if (_ph.is_valid())
00192 fprops_.remove(_ph);
00193 _ph.reset();
00194 }
00195
00196 template <typename T>
00197 void remove_property(MPropHandleT<T>& _ph)
00198 {
00199 if (_ph.is_valid())
00200 mprops_.remove(_ph);
00201 _ph.reset();
00202 }
00203
00205
00206 public:
00207
00209
00210
00219 template <class T>
00220 bool get_property_handle(VPropHandleT<T>& _ph,
00221 const std::string& _name) const
00222 {
00223 return (_ph = VPropHandleT<T>(vprops_.handle(T(), _name))).is_valid();
00224 }
00225
00226 template <class T>
00227 bool get_property_handle(HPropHandleT<T>& _ph,
00228 const std::string& _name) const
00229 {
00230 return (_ph = HPropHandleT<T>(hprops_.handle(T(), _name))).is_valid();
00231 }
00232
00233 template <class T>
00234 bool get_property_handle(EPropHandleT<T>& _ph,
00235 const std::string& _name) const
00236 {
00237 return (_ph = EPropHandleT<T>(eprops_.handle(T(), _name))).is_valid();
00238 }
00239
00240 template <class T>
00241 bool get_property_handle(FPropHandleT<T>& _ph,
00242 const std::string& _name) const
00243 {
00244 return (_ph = FPropHandleT<T>(fprops_.handle(T(), _name))).is_valid();
00245 }
00246
00247 template <class T>
00248 bool get_property_handle(MPropHandleT<T>& _ph,
00249 const std::string& _name) const
00250 {
00251 return (_ph = MPropHandleT<T>(mprops_.handle(T(), _name))).is_valid();
00252 }
00253
00255
00256 public:
00257
00259
00260
00270 template <class T>
00271 PropertyT<T>& property(VPropHandleT<T> _ph) {
00272 return vprops_.property(_ph);
00273 }
00274 template <class T>
00275 const PropertyT<T>& property(VPropHandleT<T> _ph) const {
00276 return vprops_.property(_ph);
00277 }
00278
00279 template <class T>
00280 PropertyT<T>& property(HPropHandleT<T> _ph) {
00281 return hprops_.property(_ph);
00282 }
00283 template <class T>
00284 const PropertyT<T>& property(HPropHandleT<T> _ph) const {
00285 return hprops_.property(_ph);
00286 }
00287
00288 template <class T>
00289 PropertyT<T>& property(EPropHandleT<T> _ph) {
00290 return eprops_.property(_ph);
00291 }
00292 template <class T>
00293 const PropertyT<T>& property(EPropHandleT<T> _ph) const {
00294 return eprops_.property(_ph);
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 typename VPropHandleT<T>::reference
00327 property(VPropHandleT<T> _ph, VertexHandle _vh) {
00328 return vprops_.property(_ph)[_vh.idx()];
00329 }
00330
00331 template <class T>
00332 typename VPropHandleT<T>::const_reference
00333 property(VPropHandleT<T> _ph, VertexHandle _vh) const {
00334 return vprops_.property(_ph)[_vh.idx()];
00335 }
00336
00337
00338 template <class T>
00339 typename HPropHandleT<T>::reference
00340 property(HPropHandleT<T> _ph, HalfedgeHandle _hh) {
00341 return hprops_.property(_ph)[_hh.idx()];
00342 }
00343
00344 template <class T>
00345 typename HPropHandleT<T>::const_reference
00346 property(HPropHandleT<T> _ph, HalfedgeHandle _hh) const {
00347 return hprops_.property(_ph)[_hh.idx()];
00348 }
00349
00350
00351 template <class T>
00352 typename EPropHandleT<T>::reference
00353 property(EPropHandleT<T> _ph, EdgeHandle _eh) {
00354 return eprops_.property(_ph)[_eh.idx()];
00355 }
00356
00357 template <class T>
00358 typename EPropHandleT<T>::const_reference
00359 property(EPropHandleT<T> _ph, EdgeHandle _eh) const {
00360 return eprops_.property(_ph)[_eh.idx()];
00361 }
00362
00363
00364 template <class T>
00365 typename FPropHandleT<T>::reference
00366 property(FPropHandleT<T> _ph, FaceHandle _fh) {
00367 return fprops_.property(_ph)[_fh.idx()];
00368 }
00369
00370 template <class T>
00371 typename FPropHandleT<T>::const_reference
00372 property(FPropHandleT<T> _ph, FaceHandle _fh) const {
00373 return fprops_.property(_ph)[_fh.idx()];
00374 }
00375
00376
00377 template <class T>
00378 typename MPropHandleT<T>::reference
00379 property(MPropHandleT<T> _ph) {
00380 return mprops_.property(_ph)[0];
00381 }
00382
00383 template <class T>
00384 typename MPropHandleT<T>::const_reference
00385 property(MPropHandleT<T> _ph) const {
00386 return mprops_.property(_ph)[0];
00387 }
00388
00390
00391 protected:
00392
00393 public:
00394
00395 size_t n_vprops(void) const { return vprops_.size(); }
00396
00397 size_t n_eprops(void) const { return eprops_.size(); }
00398
00399 size_t n_hprops(void) const { return hprops_.size(); }
00400
00401 size_t n_fprops(void) const { return fprops_.size(); }
00402
00403 size_t n_mprops(void) const { return mprops_.size(); }
00404
00405 BaseProperty* _get_vprop( const std::string& _name)
00406 { return vprops_.property(_name); }
00407
00408 BaseProperty* _get_eprop( const std::string& _name)
00409 { return eprops_.property(_name); }
00410
00411 BaseProperty* _get_hprop( const std::string& _name)
00412 { return hprops_.property(_name); }
00413
00414 BaseProperty* _get_fprop( const std::string& _name)
00415 { return fprops_.property(_name); }
00416
00417 BaseProperty* _get_mprop( const std::string& _name)
00418 { return mprops_.property(_name); }
00419
00420 const BaseProperty* _get_vprop( const std::string& _name) const
00421 { return vprops_.property(_name); }
00422
00423 const BaseProperty* _get_eprop( const std::string& _name) const
00424 { return eprops_.property(_name); }
00425
00426 const BaseProperty* _get_hprop( const std::string& _name) const
00427 { return hprops_.property(_name); }
00428
00429 const BaseProperty* _get_fprop( const std::string& _name) const
00430 { return fprops_.property(_name); }
00431
00432 const BaseProperty* _get_mprop( const std::string& _name) const
00433 { return mprops_.property(_name); }
00434
00435 BaseProperty& _vprop( size_t _idx ) { return vprops_._property( _idx ); }
00436 BaseProperty& _eprop( size_t _idx ) { return eprops_._property( _idx ); }
00437 BaseProperty& _hprop( size_t _idx ) { return hprops_._property( _idx ); }
00438 BaseProperty& _fprop( size_t _idx ) { return fprops_._property( _idx ); }
00439 BaseProperty& _mprop( size_t _idx ) { return mprops_._property( _idx ); }
00440
00441 const BaseProperty& _vprop( size_t _idx ) const
00442 { return vprops_._property( _idx ); }
00443 const BaseProperty& _eprop( size_t _idx ) const
00444 { return eprops_._property( _idx ); }
00445 const BaseProperty& _hprop( size_t _idx ) const
00446 { return hprops_._property( _idx ); }
00447 const BaseProperty& _fprop( size_t _idx ) const
00448 { return fprops_._property( _idx ); }
00449 const BaseProperty& _mprop( size_t _idx ) const
00450 { return mprops_._property( _idx ); }
00451
00452 size_t _add_vprop( BaseProperty* _bp ) { return vprops_._add( _bp ); }
00453 size_t _add_eprop( BaseProperty* _bp ) { return eprops_._add( _bp ); }
00454 size_t _add_hprop( BaseProperty* _bp ) { return hprops_._add( _bp ); }
00455 size_t _add_fprop( BaseProperty* _bp ) { return fprops_._add( _bp ); }
00456 size_t _add_mprop( BaseProperty* _bp ) { return mprops_._add( _bp ); }
00457
00458 protected:
00459
00460 BaseProperty& _vprop( BaseHandle _h )
00461 { return vprops_._property( _h.idx() ); }
00462 BaseProperty& _eprop( BaseHandle _h )
00463 { return eprops_._property( _h.idx() ); }
00464 BaseProperty& _hprop( BaseHandle _h )
00465 { return hprops_._property( _h.idx() ); }
00466 BaseProperty& _fprop( BaseHandle _h )
00467 { return fprops_._property( _h.idx() ); }
00468 BaseProperty& _mprop( BaseHandle _h )
00469 { return mprops_._property( _h.idx() ); }
00470
00471 const BaseProperty& _vprop( BaseHandle _h ) const
00472 { return vprops_._property( _h.idx() ); }
00473 const BaseProperty& _eprop( BaseHandle _h ) const
00474 { return eprops_._property( _h.idx() ); }
00475 const BaseProperty& _hprop( BaseHandle _h ) const
00476 { return hprops_._property( _h.idx() ); }
00477 const BaseProperty& _fprop( BaseHandle _h ) const
00478 { return fprops_._property( _h.idx() ); }
00479 const BaseProperty& _mprop( BaseHandle _h ) const
00480 { return mprops_._property( _h.idx() ); }
00481
00482
00483 public:
00484
00485
00486 virtual unsigned int n_vertices() const { return 0; }
00487 virtual unsigned int n_halfedges() const { return 0; }
00488 virtual unsigned int n_edges() const { return 0; }
00489 virtual unsigned int n_faces() const { return 0; }
00490
00491
00492 protected:
00493
00494 void vprops_reserve(unsigned int _n) const { vprops_.reserve(_n); }
00495 void vprops_resize(unsigned int _n) const { vprops_.resize(_n); }
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_swap(unsigned int _i0, unsigned int _i1) const {
00503 hprops_.swap(_i0, _i1);
00504 }
00505
00506 void eprops_reserve(unsigned int _n) const { eprops_.reserve(_n); }
00507 void eprops_resize(unsigned int _n) const { eprops_.resize(_n); }
00508 void eprops_swap(unsigned int _i0, unsigned int _i1) const {
00509 eprops_.swap(_i0, _i1);
00510 }
00511
00512 void fprops_reserve(unsigned int _n) const { fprops_.reserve(_n); }
00513 void fprops_resize(unsigned int _n) const { fprops_.resize(_n); }
00514 void fprops_swap(unsigned int _i0, unsigned int _i1) const {
00515 fprops_.swap(_i0, _i1);
00516 }
00517
00518 void mprops_resize(unsigned int _n) const { mprops_.resize(_n); }
00519
00520 public:
00521
00522 void property_stats(std::ostream& _ostr = std::clog) const;
00523
00524 public:
00525
00526 typedef PropertyContainer::iterator prop_iterator;
00527 typedef PropertyContainer::const_iterator const_prop_iterator;
00528
00529 prop_iterator vprops_begin() { return vprops_.begin(); }
00530 prop_iterator vprops_end() { return vprops_.end(); }
00531 const_prop_iterator vprops_begin() const { return vprops_.begin(); }
00532 const_prop_iterator vprops_end() const { return vprops_.end(); }
00533
00534 prop_iterator eprops_begin() { return eprops_.begin(); }
00535 prop_iterator eprops_end() { return eprops_.end(); }
00536 const_prop_iterator eprops_begin() const { return eprops_.begin(); }
00537 const_prop_iterator eprops_end() const { return eprops_.end(); }
00538
00539 prop_iterator hprops_begin() { return hprops_.begin(); }
00540 prop_iterator hprops_end() { return hprops_.end(); }
00541 const_prop_iterator hprops_begin() const { return hprops_.begin(); }
00542 const_prop_iterator hprops_end() const { return hprops_.end(); }
00543
00544 prop_iterator fprops_begin() { return fprops_.begin(); }
00545 prop_iterator fprops_end() { return fprops_.end(); }
00546 const_prop_iterator fprops_begin() const { return fprops_.begin(); }
00547 const_prop_iterator fprops_end() const { return fprops_.end(); }
00548
00549 prop_iterator mprops_begin() { return mprops_.begin(); }
00550 prop_iterator mprops_end() { return mprops_.end(); }
00551 const_prop_iterator mprops_begin() const { return mprops_.begin(); }
00552 const_prop_iterator mprops_end() const { return mprops_.end(); }
00553
00554 private:
00555
00556 PropertyContainer vprops_;
00557 PropertyContainer hprops_;
00558 PropertyContainer eprops_;
00559 PropertyContainer fprops_;
00560 PropertyContainer mprops_;
00561 };
00562
00563
00564
00565 }
00566
00567 #endif // OPENMESH_BASE_KERNEL_HH defined
00568