OpenMesh
Loading...
Searching...
No Matches
BaseDecimaterT.hh
Go to the documentation of this file.
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2023, 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);
213 cmodule_->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
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//=============================================================================
Base class for all decimation modules.
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:59
Polygonal mesh based on the ArrayKernel.
Definition PolyMesh_ArrayKernelT.hh:96
This class demonstrates the non copyable idiom.
Definition Noncopyable.hh:72
base class decimater framework
Definition BaseDecimaterT.hh:81
Definition BaseDecimaterT.hh:86
bool remove(ModHandleT< _Module > &_mh)
remove module
Definition BaseDecimaterT.hh:158
bool notify_observer(size_t _n_collapses)
returns false, if abort requested by observer
Definition BaseDecimaterT.hh:191
bool add(ModHandleT< _Module > &_mh)
add module to decimater
Definition BaseDecimaterT.hh:142
Observer * observer()
Get current observer of a decimater.
Definition BaseDecimaterT.hh:132
void set_observer(Observer *_o)
Add observer.
Definition BaseDecimaterT.hh:126
bool initialize()
Initialize decimater and decimating modules.
Definition BaseDecimaterT_impl.hh:236
void set_uninitialized()
Reset the initialized flag, and clear the bmodules_ and cmodule_.
Definition BaseDecimaterT.hh:202
Mesh & mesh()
access mesh. used in modules.
Definition BaseDecimaterT.hh:138
bool is_initialized() const
Returns whether decimater has been successfully initialized.
Definition BaseDecimaterT.hh:111
Module & module(ModHandleT< Module > &_mh)
get module referenced by handle _mh
Definition BaseDecimaterT.hh:181
void reset()
Reset the status of this class.
Definition BaseDecimaterT.hh:248
Stores information about a halfedge collapse.
Definition CollapseInfoT.hh:74
Handle for mesh decimation modules.
Definition ModBaseT.hh:84
bool is_valid() const
Check handle status.
Definition ModBaseT.hh:100
Base class for all decimation modules.
Definition ModBaseT.hh:193
virtual void postprocess_collapse(const CollapseInfoT< MeshT > &)
After _from_vh has been collapsed into _to_vh, this method will be called.
Definition ModBaseT.hh:257
Observer class.
Definition Observer.hh:76
virtual bool abort() const
Abort callback.
Definition Observer.cc:82
virtual void notify(size_t _step)=0
callback

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .