OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BaseDecimaterT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2014 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: 990 $ *
38 * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05. Feb 2014) $ *
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>
60 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
61 #include <OpenMesh/Core/Utils/Noncopyable.hh>
62
63
64
65 //== NAMESPACE ================================================================
66
67 namespace OpenMesh {
68 namespace Decimater {
69
70
71 //== CLASS DEFINITION =========================================================
72
73
77 class BaseDecimaterModule
78 {
79 };
80
81 template < typename MeshT >
82 class BaseDecimaterT : private Utils::Noncopyable
83 {
84 public: //-------------------------------------------------------- public types
85
86 typedef BaseDecimaterT< MeshT > Self;
87 typedef MeshT Mesh;
88 typedef CollapseInfoT<MeshT> CollapseInfo;
89 typedef ModBaseT<MeshT> Module;
90 typedef std::vector< Module* > ModuleList;
91 typedef typename ModuleList::iterator ModuleListIterator;
92
93 public: //------------------------------------------------------ public methods
94 BaseDecimaterT(Mesh& _mesh);
95 virtual ~BaseDecimaterT();
96
104 bool initialize();
105
106
108 bool is_initialized() const { return initialized_; }
109
110
112 void info( std::ostream& _os );
113
114 public: //--------------------------------------------------- module management
115
117 Mesh& mesh() { return mesh_; }
118
120 template < typename _Module >
121 bool add( ModHandleT<_Module>& _mh )
122 {
123 if (_mh.is_valid())
124 return false;
125
126 _mh.init( new _Module(mesh()) );
127 all_modules_.push_back( _mh.module() );
128
129 set_uninitialized();
130
131 return true;
132 }
133
134
136 template < typename _Module >
137 bool remove( ModHandleT<_Module>& _mh )
138 {
139 if (!_mh.is_valid())
140 return false;
141
142 typename ModuleList::iterator it = std::find(all_modules_.begin(),
143 all_modules_.end(),
144 _mh.module() );
145
146 if ( it == all_modules_.end() ) // module not found
147 return false;
148
149 delete *it;
150 all_modules_.erase( it ); // finally remove from list
151 _mh.clear();
152
153 set_uninitialized();
154 return true;
155 }
156
157
159 template < typename Module >
160 Module& module( ModHandleT<Module>& _mh )
161 {
162 assert( _mh.is_valid() );
163 return *_mh.module();
164 }
165
166
167 protected:
168
169 // Reset the initialized flag, and clear the bmodules_ and cmodule_
170 void set_uninitialized() {
171 initialized_ = false;
172 cmodule_ = 0;
173 bmodules_.clear();
174 }
175
176 void update_modules(CollapseInfo& _ci)
177 {
178 typename ModuleList::iterator m_it, m_end = bmodules_.end();
179 for (m_it = bmodules_.begin(); m_it != m_end; ++m_it)
180 (*m_it)->postprocess_collapse(_ci);
181 cmodule_->postprocess_collapse(_ci);
182 }
183
184
185 protected: //---------------------------------------------------- private methods
186
191 bool is_collapse_legal(const CollapseInfo& _ci);
192
194 float collapse_priority(const CollapseInfo& _ci);
195
197 void preprocess_collapse(CollapseInfo& _ci);
198
200 void postprocess_collapse(CollapseInfo& _ci);
201
210 void set_error_tolerance_factor(double _factor);
211
216 void reset(){ initialized_ = false; };
217
218
219 private: //------------------------------------------------------- private data
220
221
222 // reference to mesh
223 Mesh& mesh_;
224
225 // list of binary modules
226 ModuleList bmodules_;
227
228 // the current priority module
229 Module* cmodule_;
230
231 // list of all allocated modules (including cmodule_ and all of bmodules_)
232 ModuleList all_modules_;
233
234 // Flag if all modules were initialized
235 bool initialized_;
236
237
238 };
239
240 //=============================================================================
241 } // END_NS_DECIMATER
242 } // END_NS_OPENMESH
243 //=============================================================================
244 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_BASE_DECIMATER_DECIMATERT_CC)
245 #define OPENMESH_BASE_DECIMATER_TEMPLATES
246 #include "BaseDecimaterT.cc"
247 #endif
248 //=============================================================================
249 #endif // OPENMESH_BASE_DECIMATER_DECIMATERT_HH defined
250 //=============================================================================
ModBaseT.hh
Base class for all decimation modules.
OpenMesh::Decimater::ModHandleT
Handle for mesh decimation modules.
Definition: ModBaseT.hh:81
OpenMesh::Decimater::CollapseInfoT
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:73
OpenMesh::Decimater::BaseDecimaterT::add
bool add(ModHandleT< _Module > &_mh)
add module to decimater
Definition: BaseDecimaterT.hh:121
OpenMesh::Decimater::BaseDecimaterT::reset
void reset()
Reset the status of this class.
Definition: BaseDecimaterT.hh:216
OpenMesh::Decimater::BaseDecimaterT
Definition: BaseDecimaterT.hh:82
OpenMesh::Decimater::ModBaseT::postprocess_collapse
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
OpenMesh::Decimater::ModBaseT
Base class for all decimation modules.
Definition: ModBaseT.hh:190
OpenMesh::Decimater::BaseDecimaterT::postprocess_collapse
void postprocess_collapse(CollapseInfo &_ci)
Post-process a collapse.
Definition: BaseDecimaterT.cc:168
OpenMesh::Decimater::BaseDecimaterT::preprocess_collapse
void preprocess_collapse(CollapseInfo &_ci)
Pre-process a collapse.
Definition: BaseDecimaterT.cc:180
OpenMesh::Decimater::BaseDecimaterT::mesh
Mesh & mesh()
access mesh. used in modules.
Definition: BaseDecimaterT.hh:117
OpenMesh::Decimater::ModHandleT::is_valid
bool is_valid() const
Check handle status.
Definition: ModBaseT.hh:98
OpenMesh::Utils::Noncopyable
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:69
OpenMesh::Decimater::BaseDecimaterT::module
Module & module(ModHandleT< Module > &_mh)
get module referenced by handle _mh
Definition: BaseDecimaterT.hh:160
OpenMesh::Decimater::BaseDecimaterModule
base class decimater framework
Definition: BaseDecimaterT.hh:77
OpenMesh::Decimater::BaseDecimaterT::set_error_tolerance_factor
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:192
OpenMesh::Decimater::BaseDecimaterT::initialize
bool initialize()
Initialize decimater and decimating modules.
Definition: BaseDecimaterT.cc:237
OpenMesh::Decimater::BaseDecimaterT::info
void info(std::ostream &_os)
Print information about modules to _os.
Definition: BaseDecimaterT.cc:206
OpenMesh::Decimater::BaseDecimaterT::is_initialized
bool is_initialized() const
Returns whether decimater has been successfully initialized.
Definition: BaseDecimaterT.hh:108
OpenMesh::Decimater::BaseDecimaterT::collapse_priority
float collapse_priority(const CollapseInfo &_ci)
Calculate priority of an halfedge collapse (using the modules)
Definition: BaseDecimaterT.cc:155
OpenMesh::Decimater::BaseDecimaterT::is_collapse_legal
bool is_collapse_legal(const CollapseInfo &_ci)
Is an edge collapse legal? Performs topological test only.
Definition: BaseDecimaterT.cc:101