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-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
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
OpenMesh::Decimater::ModBaseT::mesh
MeshT & mesh()
Access the mesh associated with the decimater.
Definition: ModBaseT.hh:275
OpenMesh::Decimater::ModHandleT::ModHandleT
ModHandleT()
Default constructor.
Definition: ModBaseT.hh:91
OpenMesh::Decimater::ModBaseT::LEGAL_COLLAPSE
indicates a legal collapse
Definition: ModBaseT.hh:198
OpenMesh::Decimater::ModBaseT::set_binary
void set_binary(bool _b)
Set whether module is binary or not.
Definition: ModBaseT.hh:221
OpenMesh::Decimater::ModBaseT::ILLEGAL_COLLAPSE
indicates an illegal collapse
Definition: ModBaseT.hh:197
CollapseInfoT.hh
Provides data class CollapseInfoT for storing all information about a halfedge collapse.
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::ModBaseT::is_binary
bool is_binary(void) const
Returns true if criteria returns a binary value.
Definition: ModBaseT.hh:218
OpenMesh::Decimater::ModBaseT::ModBaseT
ModBaseT(MeshT &_mesh, bool _is_binary)
Default constructor.
Definition: ModBaseT.hh:205
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::ModBaseT::collapse_priority
virtual float collapse_priority(const CollapseInfoT< MeshT > &)
Return collapse priority.
Definition: ModBaseT.hh:243
OpenMesh::Decimater::ModHandleT::is_valid
bool is_valid() const
Check handle status.
Definition: ModBaseT.hh:98
OpenMesh::Decimater::ModBaseT::initialize
virtual void initialize()
Initialize module-internal stuff.
Definition: ModBaseT.hh:227
OpenMesh::Utils::Noncopyable
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:69
OpenMesh::Decimater::ModBaseT::preprocess_collapse
virtual void preprocess_collapse(const CollapseInfoT< MeshT > &)
Before _from_vh has been collapsed into _to_vh, this method will be called.
Definition: ModBaseT.hh:249
OpenMesh::Decimater::ModHandleT::~ModHandleT
~ModHandleT()
Destructor.
Definition: ModBaseT.hh:94
DECIMATER_MODNAME
#define DECIMATER_MODNAME(_mod_name)
Macro that sets up the name() function.
Definition: ModBaseT.hh:128
OpenMesh::Decimater::ModBaseT::set_error_tolerance_factor
virtual void set_error_tolerance_factor(double _factor)
This provides a function that allows the setting of a percentage of the original contraint.
Definition: ModBaseT.hh:266
OpenMesh::Decimater::ModBaseT::~ModBaseT
virtual ~ModBaseT()
Virtual desctructor.
Definition: ModBaseT.hh:211