Developer Documentation
BaseDecimaterT.hh
Go to the documentation of this file.
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2025, 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>
63#include <OpenMesh/Core/Utils/Noncopyable.hh>
65
66
67
68//== NAMESPACE ================================================================
69
70namespace OpenMesh {
71namespace Decimater {
72
73
74//== CLASS DEFINITION =========================================================
75
76
81{
82};
83
84template < typename MeshT >
86{
87public: //-------------------------------------------------------- public types
88
90 typedef MeshT Mesh;
92 typedef ModBaseT<MeshT> Module;
93 typedef std::vector< Module* > ModuleList;
94 typedef typename ModuleList::iterator ModuleListIterator;
95
96public: //------------------------------------------------------ public methods
97 explicit 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
117public: //--------------------------------------------------- module management
118
127 {
128 observer_ = _o;
129 }
130
133 {
134 return observer_;
135 }
136
138 Mesh& mesh() { return mesh_; }
139
141 template < typename _Module >
143 {
144 if (_mh.is_valid())
145 return false;
146
147 _mh.init( new _Module(mesh()) );
148 all_modules_.push_back( _mh.module() );
149
151
152 return true;
153 }
154
155
157 template < typename _Module >
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
175 return true;
176 }
177
178
180 template < typename Module >
182 {
183 assert( _mh.is_valid() );
184 return *_mh.module();
185 }
186
187
188protected:
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
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);
214 }
215
216
217protected: //---------------------------------------------------- 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
251private: //------------------------------------------------------- private data
252
253
256
258 ModuleList bmodules_;
259
262
264 ModuleList all_modules_;
265
268
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//=============================================================================
void info(std::ostream &_os)
Print information about modules to _os.
bool remove(ModHandleT< _Module > &_mh)
remove module
bool notify_observer(size_t _n_collapses)
returns false, if abort requested by observer
bool add(ModHandleT< _Module > &_mh)
add module to decimater
float collapse_priority(const CollapseInfo &_ci)
Calculate priority of an halfedge collapse (using the modules)
Observer * observer()
Get current observer of a decimater.
ModuleList all_modules_
list of all allocated modules (including cmodule_ and all of bmodules_)
void set_observer(Observer *_o)
Add observer.
void preprocess_collapse(CollapseInfo &_ci)
Pre-process a collapse.
Module * cmodule_
the current priority module
void set_uninitialized()
Reset the initialized flag, and clear the bmodules_ and cmodule_.
void postprocess_collapse(CollapseInfo &_ci)
Post-process a collapse.
bool initialized_
Flag if all modules were initialized.
ModuleList bmodules_
list of binary modules
Mesh & mesh()
access mesh. used in modules.
bool is_initialized() const
Returns whether decimater has been successfully initialized.
Module & module(ModHandleT< Module > &_mh)
get module referenced by handle _mh
bool is_collapse_legal(const CollapseInfo &_ci)
virtual void postprocess_collapse(const CollapseInfoT< MeshT > &)
Definition: ModBaseT.hh:257
virtual bool abort() const
Abort callback.
Definition: Observer.cc:82
virtual void notify(size_t _step)=0
callback