OpenMesh
BaseDecimaterT.hh
Go to the documentation of this file.
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 /*===========================================================================*\
43  * *
44  * $Revision: 1258 $ *
45  * $Date: 2015-04-28 15:07:46 +0200 (Di, 28 Apr 2015) $ *
46  * *
47 \*===========================================================================*/
48 
52 //=============================================================================
53 //
54 // CLASS McDecimaterT
55 //
56 //=============================================================================
57 
58 #ifndef OPENMESH_BASE_DECIMATER_DECIMATERT_HH
59 #define OPENMESH_BASE_DECIMATER_DECIMATERT_HH
60 
61 
62 //== INCLUDES =================================================================
63 
64 #include <memory>
65 
66 #include <OpenMesh/Core/Utils/Property.hh>
68 #include <OpenMesh/Core/Utils/Noncopyable.hh>
70 
71 
72 
73 //== NAMESPACE ================================================================
74 
75 namespace OpenMesh {
76 namespace Decimater {
77 
78 
79 //== CLASS DEFINITION =========================================================
80 
81 
86 {
87 };
88 
89 template < typename MeshT >
91 {
92 public: //-------------------------------------------------------- public types
93 
95  typedef MeshT Mesh;
97  typedef ModBaseT<MeshT> Module;
98  typedef std::vector< Module* > ModuleList;
99  typedef typename ModuleList::iterator ModuleListIterator;
100 
101 public: //------------------------------------------------------ public methods
102  BaseDecimaterT(Mesh& _mesh);
103  virtual ~BaseDecimaterT();
104 
112  bool initialize();
113 
114 
116  bool is_initialized() const { return initialized_; }
117 
118 
120  void info( std::ostream& _os );
121 
122 public: //--------------------------------------------------- module management
123 
132  {
133  observer_ = _o;
134  }
135 
138  {
139  return observer_;
140  }
141 
143  Mesh& mesh() { return mesh_; }
144 
146  template < typename _Module >
148  {
149  if (_mh.is_valid())
150  return false;
151 
152  _mh.init( new _Module(mesh()) );
153  all_modules_.push_back( _mh.module() );
154 
155  set_uninitialized();
156 
157  return true;
158  }
159 
160 
162  template < typename _Module >
163  bool remove( ModHandleT<_Module>& _mh )
164  {
165  if (!_mh.is_valid())
166  return false;
167 
168  typename ModuleList::iterator it = std::find(all_modules_.begin(),
169  all_modules_.end(),
170  _mh.module() );
171 
172  if ( it == all_modules_.end() ) // module not found
173  return false;
174 
175  delete *it;
176  all_modules_.erase( it ); // finally remove from list
177  _mh.clear();
178 
179  set_uninitialized();
180  return true;
181  }
182 
183 
185  template < typename Module >
186  Module& module( ModHandleT<Module>& _mh )
187  {
188  assert( _mh.is_valid() );
189  return *_mh.module();
190  }
191 
192 
193 protected:
194 
196  bool notify_observer(size_t _n_collapses)
197  {
198  if (observer() && _n_collapses % observer()->get_interval() == 0)
199  {
200  observer()->notify(_n_collapses);
201  return !observer()->abort();
202  }
203  return true;
204  }
205 
208  initialized_ = false;
209  cmodule_ = 0;
210  bmodules_.clear();
211  }
212 
213  void update_modules(CollapseInfo& _ci)
214  {
215  typename ModuleList::iterator m_it, m_end = bmodules_.end();
216  for (m_it = bmodules_.begin(); m_it != m_end; ++m_it)
217  (*m_it)->postprocess_collapse(_ci);
218  cmodule_->postprocess_collapse(_ci);
219  }
220 
221 
222 protected: //---------------------------------------------------- private methods
223 
228  bool is_collapse_legal(const CollapseInfo& _ci);
229 
231  float collapse_priority(const CollapseInfo& _ci);
232 
234  void preprocess_collapse(CollapseInfo& _ci);
235 
237  void postprocess_collapse(CollapseInfo& _ci);
238 
247  void set_error_tolerance_factor(double _factor);
248 
253  void reset(){ initialized_ = false; };
254 
255 
256 private: //------------------------------------------------------- private data
257 
258 
260  Mesh& mesh_;
261 
263  ModuleList bmodules_;
264 
266  Module* cmodule_;
267 
269  ModuleList all_modules_;
270 
272  bool initialized_;
273 
275  Observer* observer_;
276 
277 };
278 
279 //=============================================================================
280 } // END_NS_DECIMATER
281 } // END_NS_OPENMESH
282 //=============================================================================
283 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_BASE_DECIMATER_DECIMATERT_CC)
284 #define OPENMESH_BASE_DECIMATER_TEMPLATES
285 #include "BaseDecimaterT.cc"
286 #endif
287 //=============================================================================
288 #endif // OPENMESH_BASE_DECIMATER_DECIMATERT_HH defined
289 //=============================================================================
Observer * observer()
Get current observer of a decimater.
Definition: BaseDecimaterT.hh:137
Definition: BaseDecimaterT.hh:90
void reset()
Reset the status of this class.
Definition: BaseDecimaterT.hh:253
void set_uninitialized()
Reset the initialized flag, and clear the bmodules_ and cmodule_.
Definition: BaseDecimaterT.hh:207
void set_observer(Observer *_o)
Add observer.
Definition: BaseDecimaterT.hh:131
Handle for mesh decimation modules.
Definition: ModBaseT.hh:88
Mesh & mesh()
access mesh. used in modules.
Definition: BaseDecimaterT.hh:143
This file contains an observer class which is used to monitor the progress of an decimater.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
bool is_initialized() const
Returns whether decimater has been successfully initialized.
Definition: BaseDecimaterT.hh:116
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:80
bool notify_observer(size_t _n_collapses)
returns false, if abort requested by observer
Definition: BaseDecimaterT.hh:196
Module & module(ModHandleT< Module > &_mh)
get module referenced by handle _mh
Definition: BaseDecimaterT.hh:186
bool add(ModHandleT< _Module > &_mh)
add module to decimater
Definition: BaseDecimaterT.hh:147
Base class for all decimation modules.
Definition: ModBaseT.hh:197
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:76
Base class for all decimation modules.
base class decimater framework
Definition: BaseDecimaterT.hh:85
Observer class.
Definition: Observer.hh:82
bool is_valid() const
Check handle status.
Definition: ModBaseT.hh:105

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