| 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
47 //=============================================================================
48 //
49 // CLASS McDecimaterT
50 //
51 //=============================================================================
52
53 #ifndef OPENMESH_BASE_DECIMATER_DECIMATERT_HH
54 #define OPENMESH_BASE_DECIMATER_DECIMATERT_HH
55
56
57 //== INCLUDES =================================================================
58
59 #include <memory>
60
61 #include <OpenMesh/Core/Utils/Property.hh>
62 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
63 #include <OpenMesh/Core/Utils/Noncopyable.hh>
64 #include <OpenMesh/Tools/Decimater/Observer.hh>
65
66
67
68 //== NAMESPACE ================================================================
69
70 namespace OpenMesh {
71 namespace Decimater {
72
73
74 //== CLASS DEFINITION =========================================================
75
76
80 class BaseDecimaterModule
81 {
82 };
83
84 template < typename MeshT >
85 class BaseDecimaterT : private Utils::Noncopyable
86 {
87 public: //-------------------------------------------------------- public types
88
89 typedef BaseDecimaterT< MeshT > Self;
90 typedef MeshT Mesh;
91 typedef CollapseInfoT<MeshT> CollapseInfo;
92 typedef ModBaseT<MeshT> Module;
93 typedef std::vector< Module* > ModuleList;
94 typedef typename ModuleList::iterator ModuleListIterator;
95
96 public: //------------------------------------------------------ public methods
97 BaseDecimaterT(Mesh& _mesh);
98 virtual ~BaseDecimaterT();
99
107 bool initialize();
108
109
111 bool is_initialized() const { return initialized_; }
112
113
115 void info( std::ostream& _os );
116
117 public: //--------------------------------------------------- module management
118
126 void set_observer(Observer* _o)
127 {
128 observer_ = _o;
129 }
130
132 Observer* observer()
133 {
134 return observer_;
135 }
136
138 Mesh& mesh() { return mesh_; }
139
141 template < typename _Module >
142 bool add( ModHandleT<_Module>& _mh )
143 {
144 if (_mh.is_valid())
145 return false;
146
147 _mh.init( new _Module(mesh()) );
148 all_modules_.push_back( _mh.module() );
149
150 set_uninitialized();
151
152 return true;
153 }
154
155
157 template < typename _Module >
158 bool remove( ModHandleT<_Module>& _mh )
159 {
160 if (!_mh.is_valid())
161 return false;
162
163 typename ModuleList::iterator it = std::find(all_modules_.begin(),
164 all_modules_.end(),
165 _mh.module() );
166
167 if ( it == all_modules_.end() ) // module not found
168 return false;
169
170 delete *it;
171 all_modules_.erase( it ); // finally remove from list
172 _mh.clear();
173
174 set_uninitialized();
175 return true;
176 }
177
178
180 template < typename Module >
181 Module& module( ModHandleT<Module>& _mh )
182 {
183 assert( _mh.is_valid() );
184 return *_mh.module();
185 }
186
187
188 protected:
189
191 bool notify_observer(size_t _n_collapses)
192 {
193 if (observer() && _n_collapses % observer()->get_interval() == 0)
194 {
195 observer()->notify(_n_collapses);
196 return !observer()->abort();
197 }
198 return true;
199 }
200
202 void set_uninitialized() {
203 initialized_ = false;
204 cmodule_ = 0;
205 bmodules_.clear();
206 }
207
208 void update_modules(CollapseInfo& _ci)
209 {
210 typename ModuleList::iterator m_it, m_end = bmodules_.end();
211 for (m_it = bmodules_.begin(); m_it != m_end; ++m_it)
212 (*m_it)->postprocess_collapse(_ci);
213 cmodule_->postprocess_collapse(_ci);
214 }
215
216
217 protected: //---------------------------------------------------- private methods
218
223 bool is_collapse_legal(const CollapseInfo& _ci);
224
226 float collapse_priority(const CollapseInfo& _ci);
227
229 void preprocess_collapse(CollapseInfo& _ci);
230
232 void postprocess_collapse(CollapseInfo& _ci);
233
242 void set_error_tolerance_factor(double _factor);
243
248 void reset(){ initialized_ = false; };
249
250
251 private: //------------------------------------------------------- private data
252
253
255 Mesh& mesh_;
256
258 ModuleList bmodules_;
259
261 Module* cmodule_;
262
264 ModuleList all_modules_;
265
267 bool initialized_;
268
270 Observer* observer_;
271
272 };
273
274 //=============================================================================
275 } // END_NS_DECIMATER
276 } // END_NS_OPENMESH
277 //=============================================================================
278 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_BASE_DECIMATER_DECIMATERT_CC)
279 #define OPENMESH_BASE_DECIMATER_TEMPLATES
280 #include "BaseDecimaterT_impl.hh"
281 #endif
282 //=============================================================================
283 #endif // OPENMESH_BASE_DECIMATER_DECIMATERT_HH defined
284 //=============================================================================
OpenMesh::Decimater::ModBaseT
Base class for all decimation modules.
Definition: ModBaseT.hh:192
OpenMesh::Utils::Noncopyable
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:71
OpenMesh::Decimater::BaseDecimaterT::module
Module & module(ModHandleT< Module > &_mh)
get module referenced by handle _mh
Definition: BaseDecimaterT.hh:181
OpenMesh::Decimater::BaseDecimaterT::set_uninitialized
void set_uninitialized()
Reset the initialized flag, and clear the bmodules_ and cmodule_.
Definition: BaseDecimaterT.hh:202
OpenMesh::Decimater::Observer
Observer class.
Definition: Observer.hh:75
OpenMesh::Decimater::ModHandleT::is_valid
bool is_valid() const
Check handle status.
Definition: ModBaseT.hh:100
Observer.hh
This file contains an observer class which is used to monitor the progress of an decimater.
OpenMesh::Decimater::BaseDecimaterT::add
bool add(ModHandleT< _Module > &_mh)
add module to decimater
Definition: BaseDecimaterT.hh:142
OpenMesh::Decimater::BaseDecimaterT::set_observer
void set_observer(Observer *_o)
Add observer.
Definition: BaseDecimaterT.hh:126
OpenMesh::Decimater::BaseDecimaterT
Definition: BaseDecimaterT.hh:85
OpenMesh::Decimater::BaseDecimaterT::mesh
Mesh & mesh()
access mesh. used in modules.
Definition: BaseDecimaterT.hh:138
OpenMesh::Decimater::BaseDecimaterT::observer
Observer * observer()
Get current observer of a decimater.
Definition: BaseDecimaterT.hh:132
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
ModBaseT.hh
Base class for all decimation modules.
OpenMesh::Decimater::BaseDecimaterT::reset
void reset()
Reset the status of this class.
Definition: BaseDecimaterT.hh:248
OpenMesh::Decimater::BaseDecimaterModule
base class decimater framework
Definition: BaseDecimaterT.hh:80
OpenMesh::Decimater::ModHandleT
Handle for mesh decimation modules.
Definition: ModBaseT.hh:83
OpenMesh::Decimater::CollapseInfoT
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:74
OpenMesh::Decimater::BaseDecimaterT::notify_observer
bool notify_observer(size_t _n_collapses)
returns false, if abort requested by observer
Definition: BaseDecimaterT.hh:191
OpenMesh::Decimater::BaseDecimaterT::is_initialized
bool is_initialized() const
Returns whether decimater has been successfully initialized.
Definition: BaseDecimaterT.hh:111