OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BaseDecimaterT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2015 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 1200 $ *
38  * $Date: 2015-01-16 08:57:02 +0100 (Fr, 16 Jan 2015) $ *
39  * *
40 \*===========================================================================*/
41 
45 //=============================================================================
46 //
47 // CLASS McDecimaterT
48 //
49 //=============================================================================
50 
51 #ifndef OPENMESH_BASE_DECIMATER_DECIMATERT_HH
52 #define OPENMESH_BASE_DECIMATER_DECIMATERT_HH
53 
54 
55 //== INCLUDES =================================================================
56 
57 #include <memory>
58 
59 #include <OpenMesh/Core/Utils/Property.hh>
61 #include <OpenMesh/Core/Utils/Noncopyable.hh>
63 
64 
65 
66 //== NAMESPACE ================================================================
67 
68 namespace OpenMesh {
69 namespace Decimater {
70 
71 
72 //== CLASS DEFINITION =========================================================
73 
74 
79 {
80 };
81 
82 template < typename MeshT >
84 {
85 public: //-------------------------------------------------------- public types
86 
88  typedef MeshT Mesh;
90  typedef ModBaseT<MeshT> Module;
91  typedef std::vector< Module* > ModuleList;
92  typedef typename ModuleList::iterator ModuleListIterator;
93 
94 public: //------------------------------------------------------ public methods
95  BaseDecimaterT(Mesh& _mesh);
96  virtual ~BaseDecimaterT();
97 
105  bool initialize();
106 
107 
109  bool is_initialized() const { return initialized_; }
110 
111 
113  void info( std::ostream& _os );
114 
115 public: //--------------------------------------------------- module management
116 
125  {
126  observer_ = _o;
127  }
128 
131  {
132  return observer_;
133  }
134 
136  Mesh& mesh() { return mesh_; }
137 
139  template < typename _Module >
141  {
142  if (_mh.is_valid())
143  return false;
144 
145  _mh.init( new _Module(mesh()) );
146  all_modules_.push_back( _mh.module() );
147 
149 
150  return true;
151  }
152 
153 
155  template < typename _Module >
156  bool remove( ModHandleT<_Module>& _mh )
157  {
158  if (!_mh.is_valid())
159  return false;
160 
161  typename ModuleList::iterator it = std::find(all_modules_.begin(),
162  all_modules_.end(),
163  _mh.module() );
164 
165  if ( it == all_modules_.end() ) // module not found
166  return false;
167 
168  delete *it;
169  all_modules_.erase( it ); // finally remove from list
170  _mh.clear();
171 
173  return true;
174  }
175 
176 
178  template < typename Module >
179  Module& module( ModHandleT<Module>& _mh )
180  {
181  assert( _mh.is_valid() );
182  return *_mh.module();
183  }
184 
185 
186 protected:
187 
189  bool notify_observer(size_t _n_collapses)
190  {
191  if (observer() && _n_collapses % observer()->get_interval() == 0)
192  {
193  observer()->notify(_n_collapses);
194  return !observer()->abort();
195  }
196  return true;
197  }
198 
201  initialized_ = false;
202  cmodule_ = 0;
203  bmodules_.clear();
204  }
205 
206  void update_modules(CollapseInfo& _ci)
207  {
208  typename ModuleList::iterator m_it, m_end = bmodules_.end();
209  for (m_it = bmodules_.begin(); m_it != m_end; ++m_it)
210  (*m_it)->postprocess_collapse(_ci);
211  cmodule_->postprocess_collapse(_ci);
212  }
213 
214 
215 protected: //---------------------------------------------------- private methods
216 
221  bool is_collapse_legal(const CollapseInfo& _ci);
222 
224  float collapse_priority(const CollapseInfo& _ci);
225 
227  void preprocess_collapse(CollapseInfo& _ci);
228 
230  void postprocess_collapse(CollapseInfo& _ci);
231 
240  void set_error_tolerance_factor(double _factor);
241 
246  void reset(){ initialized_ = false; };
247 
248 
249 private: //------------------------------------------------------- private data
250 
251 
253  Mesh& mesh_;
254 
256  ModuleList bmodules_;
257 
259  Module* cmodule_;
260 
262  ModuleList all_modules_;
263 
265  bool initialized_;
266 
268  Observer* observer_;
269 
270 };
271 
272 //=============================================================================
273 } // END_NS_DECIMATER
274 } // END_NS_OPENMESH
275 //=============================================================================
276 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_BASE_DECIMATER_DECIMATERT_CC)
277 #define OPENMESH_BASE_DECIMATER_TEMPLATES
278 #include "BaseDecimaterT.cc"
279 #endif
280 //=============================================================================
281 #endif // OPENMESH_BASE_DECIMATER_DECIMATERT_HH defined
282 //=============================================================================
Handle for mesh decimation modules.
Definition: ModBaseT.hh:81
bool add(ModHandleT< _Module > &_mh)
add module to decimater
Definition: BaseDecimaterT.hh:140
Mesh & mesh()
access mesh. used in modules.
Definition: BaseDecimaterT.hh:136
bool is_initialized() const
Returns whether decimater has been successfully initialized.
Definition: BaseDecimaterT.hh:109
Observer * observer()
Get current observer of a decimater.
Definition: BaseDecimaterT.hh:130
base class decimater framework
Definition: BaseDecimaterT.hh:78
float collapse_priority(const CollapseInfo &_ci)
Calculate priority of an halfedge collapse (using the modules)
Definition: BaseDecimaterT.cc:154
bool notify_observer(size_t _n_collapses)
returns false, if abort requested by observer
Definition: BaseDecimaterT.hh:189
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:69
void set_observer(Observer *_o)
Add observer.
Definition: BaseDecimaterT.hh:124
void info(std::ostream &_os)
Print information about modules to _os.
Definition: BaseDecimaterT.cc:205
void preprocess_collapse(CollapseInfo &_ci)
Pre-process a collapse.
Definition: BaseDecimaterT.cc:179
virtual void notify(size_t _step)=0
callback
virtual void postprocess_collapse(const CollapseInfoT< MeshT > &)
After _from_vh has been collapsed into _to_vh, this method will be called.
Definition: ModBaseT.hh:255
bool is_valid() const
Check handle status.
Definition: ModBaseT.hh:98
void reset()
Reset the status of this class.
Definition: BaseDecimaterT.hh:246
Observer class.
Definition: Observer.hh:75
void set_error_tolerance_factor(double _factor)
This provides a function that allows the setting of a percentage of the original constraint of the mo...
Definition: BaseDecimaterT.cc:191
bool initialize()
Initialize decimater and decimating modules.
Definition: BaseDecimaterT.cc:236
This file contains an observer class which is used to monitor the progress of an decimater.
Base class for all decimation modules.
bool is_collapse_legal(const CollapseInfo &_ci)
Is an edge collapse legal? Performs topological test only.
Definition: BaseDecimaterT.cc:100
Base class for all decimation modules.
Definition: ModBaseT.hh:190
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:73
virtual bool abort() const
Abort callback.
Definition: Observer.cc:81
Definition: BaseDecimaterT.hh:83
void set_uninitialized()
Reset the initialized flag, and clear the bmodules_ and cmodule_.
Definition: BaseDecimaterT.hh:200
Module & module(ModHandleT< Module > &_mh)
get module referenced by handle _mh
Definition: BaseDecimaterT.hh:179
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
void postprocess_collapse(CollapseInfo &_ci)
Post-process a collapse.
Definition: BaseDecimaterT.cc:167

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