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
ModBaseT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 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: 737 $ *
38 * $Date: 2012-10-08 09:33:20 +0200 (Mo, 08. Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
46 //=============================================================================
47 //
48 // CLASS ModBaseT
49 //
50 //=============================================================================
51
52 #ifndef OPENMESH_DECIMATER_MODBASET_HH
53 #define OPENMESH_DECIMATER_MODBASET_HH
54
55
56 //== INCLUDES =================================================================
57
58 #include <OpenMesh/Core/Utils/Noncopyable.hh>
59 #include <OpenMesh/Tools/Decimater/CollapseInfoT.hh>
60 #include <string>
61
62
63 //== NAMESPACE ================================================================
64
65 namespace OpenMesh {
66 namespace Decimater {
67
68
69 //== FORWARD DECLARATIONS =====================================================
70
71 template <typename Mesh> class BaseDecimaterT;
72
73
74 //== CLASS DEFINITION =========================================================
75
80 template <typename Module>
81 class ModHandleT : private Utils::Noncopyable
82 {
83 public:
84
85 typedef ModHandleT<Module> Self;
86 typedef Module module_type;
87
88 public:
89
91 ModHandleT() : mod_(NULL) {}
92
94 ~ModHandleT() { /* don't delete mod_, since handle is not owner! */ }
95
98 bool is_valid() const { return mod_ != NULL; }
99
100 private:
101
102 #if defined(OM_CC_MSVC)
103 friend class BaseDecimaterT;
104 #else
105 template <typename Mesh> friend class BaseDecimaterT;
106 #endif
107
108 void clear() { mod_ = NULL; }
109 void init(Module* _m) { mod_ = _m; }
110 Module* module() { return mod_; }
111
112
113 private:
114
115 Module* mod_;
116
117 };
118
119
120
121
122 //== CLASS DEFINITION =========================================================
123
124
125
128 #define DECIMATER_MODNAME(_mod_name) \
129 virtual const std::string& name() const { \
130 static std::string _s_modname_(#_mod_name); return _s_modname_; \
131 }
132
133
147 #define DECIMATING_MODULE(Classname, MeshT, Name) \
148 typedef Classname < MeshT > Self; \
149 typedef OpenMesh::Decimater::ModHandleT< Self > Handle; \
150 typedef OpenMesh::Decimater::ModBaseT< MeshT > Base; \
151 typedef typename Base::Mesh Mesh; \
152 typedef typename Base::CollapseInfo CollapseInfo; \
153 DECIMATER_MODNAME( Name )
154
155
156
157 //== CLASS DEFINITION =========================================================
158
159
189 template <typename MeshT>
190 class ModBaseT
191 {
192 public:
193 typedef MeshT Mesh;
194 typedef CollapseInfoT<MeshT> CollapseInfo;
195
196 enum {
197 ILLEGAL_COLLAPSE = -1,
198 LEGAL_COLLAPSE = 0
199 };
200
201 protected:
202
205 ModBaseT(MeshT& _mesh, bool _is_binary)
206 : error_tolerance_factor_(1.0), mesh_(_mesh), is_binary_(_is_binary) {}
207
208 public:
209
211 virtual ~ModBaseT() { }
212
214 DECIMATER_MODNAME(ModBase);
215
216
218 bool is_binary(void) const { return is_binary_; }
219
221 void set_binary(bool _b) { is_binary_ = _b; }
222
223
224 public: // common interface
225
227 virtual void initialize() { }
228
243 virtual float collapse_priority(const CollapseInfoT<MeshT>& /* _ci */)
244 { return LEGAL_COLLAPSE; }
245
249 virtual void preprocess_collapse(const CollapseInfoT<MeshT>& /* _ci */)
250 {}
251
255 virtual void postprocess_collapse(const CollapseInfoT<MeshT>& /* _ci */)
256 {}
257
266 virtual void set_error_tolerance_factor(double _factor) {
267 if (_factor >= 0.0 && _factor <= 1.0)
268 error_tolerance_factor_ = _factor;
269 }
270
271
272 protected:
273
275 MeshT& mesh() { return mesh_; }
276
277 // current percentage of the original constraint
278 double error_tolerance_factor_;
279
280 private:
281
282 // hide copy constructor & assignemnt
283 ModBaseT(const ModBaseT& _cpy);
284 ModBaseT& operator=(const ModBaseT& );
285
286 MeshT& mesh_;
287
288 bool is_binary_;
289 };
290
291
292 //=============================================================================
293 } // namespace Decimater
294 } // namespace OpenMesh
295 //=============================================================================
296 #endif // OPENMESH_DECIMATER_MODBASE_HH defined
297 //=============================================================================
298