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
00034
00035
00036
00037
00038
00039
00040 #ifndef OPENMESH_DECIMATER_DECIMATERT_HH
00041 #define OPENMESH_DECIMATER_DECIMATERT_HH
00042
00043
00044
00045
00046 #include <memory>
00047
00048 #include <OpenMesh/Core/Utils/Property.hh>
00049 #include <OpenMesh/Tools/Utils/HeapT.hh>
00050 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
00051
00052
00053
00054
00055
00056 namespace OpenMesh {
00057 namespace Decimater {
00058
00059
00060
00061
00062
00066 template < typename MeshT >
00067 class DecimaterT
00068 {
00069 public:
00070
00071 typedef DecimaterT< MeshT > Self;
00072 typedef MeshT Mesh;
00073 typedef CollapseInfoT<MeshT> CollapseInfo;
00074 typedef ModBaseT<Self> Module;
00075 typedef std::vector< Module* > ModuleList;
00076
00077 public:
00078
00080 DecimaterT( Mesh& _mesh );
00081
00083 ~DecimaterT();
00084
00085
00093 bool initialize();
00094
00095
00097 bool is_initialized() const { return initialized_; }
00098
00099
00101 void info( std::ostream& _os );
00102
00103
00107 size_t decimate( size_t _n_collapses );
00108
00109
00111 size_t decimate_to( size_t _n_vertices )
00112 {
00113 assert( _n_vertices < mesh().n_vertices() );
00114 return decimate( mesh().n_vertices() - _n_vertices );
00115 }
00116
00117
00119 Mesh& mesh() { return mesh_; }
00120
00121
00122
00123
00124
00125 public:
00126
00128 template < typename Module >
00129 bool add( ModHandleT<Module>& _mh )
00130 {
00131 if (_mh.is_valid())
00132 return false;
00133
00134 _mh.init( new Module(*this) );
00135 bmodules_.push_back( _mh.module() );
00136
00137 return !(initialized_=false);
00138 }
00139
00140
00142 template < typename Module >
00143 bool remove( ModHandleT<Module>& _mh )
00144 {
00145 if (!_mh.is_valid())
00146 return false;
00147
00148 typename ModuleList::iterator it = std::find(bmodules_.begin(),
00149 bmodules_.end(),
00150 _mh.module() );
00151
00152 if ( it == bmodules_.end() )
00153 return false;
00154
00155 delete *it;
00156 bmodules_.erase( it );
00157 _mh.clear();
00158
00159 initialized_ = false;
00160 return true;
00161 }
00162
00163
00165 template < typename Module >
00166 Module& module( ModHandleT<Module>& _mh )
00167 {
00168 assert( _mh.is_valid() );
00169 return *_mh.module();
00170 }
00171
00172
00173
00174
00175 private:
00176
00177 typedef typename Mesh::VertexHandle VertexHandle;
00178 typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
00179
00181 class HeapInterface
00182 {
00183 public:
00184
00185 HeapInterface(Mesh& _mesh,
00186 VPropHandleT<float> _prio,
00187 VPropHandleT<int> _pos)
00188 : mesh_(_mesh), prio_(_prio), pos_(_pos)
00189 { }
00190
00191 inline bool
00192 less( VertexHandle _vh0, VertexHandle _vh1 )
00193 { return mesh_.property(prio_, _vh0) < mesh_.property(prio_, _vh1); }
00194
00195 inline bool
00196 greater( VertexHandle _vh0, VertexHandle _vh1 )
00197 { return mesh_.property(prio_, _vh0) > mesh_.property(prio_, _vh1); }
00198
00199 inline int
00200 get_heap_position(VertexHandle _vh)
00201 { return mesh_.property(pos_, _vh); }
00202
00203 inline void
00204 set_heap_position(VertexHandle _vh, int _pos)
00205 { mesh_.property(pos_, _vh) = _pos; }
00206
00207
00208 private:
00209 Mesh& mesh_;
00210 VPropHandleT<float> prio_;
00211 VPropHandleT<int> pos_;
00212 };
00213
00214 typedef Utils::HeapT<VertexHandle, HeapInterface> DeciHeap;
00215
00216
00217 private:
00218
00220 void heap_vertex(VertexHandle _vh);
00221
00226 bool is_collapse_legal(const CollapseInfo& _ci);
00227
00229 float collapse_priority(const CollapseInfo& _ci);
00230
00232 void postprocess_collapse(CollapseInfo& _ci);
00233
00234
00235
00236
00237 private:
00238
00239
00240
00241 Mesh& mesh_;
00242
00243
00244 std::auto_ptr<DeciHeap> heap_;
00245
00246
00247 ModuleList bmodules_;
00248 Module* cmodule_;
00249
00250 bool initialized_;
00251
00252
00253
00254 VPropHandleT<HalfedgeHandle> collapse_target_;
00255 VPropHandleT<float> priority_;
00256 VPropHandleT<int> heap_position_;
00257
00258
00259
00260 private:
00261
00262 DecimaterT(const Self&);
00263 Self& operator = (const Self&);
00264
00265 };
00266
00267
00268 }
00269 }
00270
00271 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_DECIMATERT_CC)
00272 #define OPENMESH_DECIMATER_TEMPLATES
00273 #include "DecimaterT.cc"
00274 #endif
00275
00276 #endif // OPENMESH_DECIMATER_DECIMATERT_HH defined
00277
00278