OpenMesh
ModBaseT.hh
Go to the documentation of this file.
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, 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 
48 //=============================================================================
49 //
50 // CLASS ModBaseT
51 //
52 //=============================================================================
53 
54 #ifndef OPENMESH_DECIMATER_MODBASET_HH
55 #define OPENMESH_DECIMATER_MODBASET_HH
56 
57 
58 //== INCLUDES =================================================================
59 
60 #include <OpenMesh/Core/Utils/Noncopyable.hh>
62 #include <string>
63 
64 
65 //== NAMESPACE ================================================================
66 
67 namespace OpenMesh {
68 namespace Decimater {
69 
70 
71 //== FORWARD DECLARATIONS =====================================================
72 
73 template <typename Mesh> class BaseDecimaterT;
74 
75 
76 //== CLASS DEFINITION =========================================================
77 
82 template <typename Module>
84 {
85 public:
86 
87  typedef ModHandleT<Module> Self;
88  typedef Module module_type;
89 
90 public:
91 
93  ModHandleT() : mod_(NULL) {}
94 
96  ~ModHandleT() { /* don't delete mod_, since handle is not owner! */ }
97 
100  bool is_valid() const { return mod_ != NULL; }
101 
102 private:
103 
104 #if defined(OM_CC_MSVC)
105  friend class BaseDecimaterT;
106 #else
107  template <typename Mesh> friend class BaseDecimaterT;
108 #endif
109 
110  void clear() { mod_ = NULL; }
111  void init(Module* _m) { mod_ = _m; }
112  Module* module() { return mod_; }
113 
114 
115 private:
116 
117  Module* mod_;
118 
119 };
120 
121 
122 
123 
124 //== CLASS DEFINITION =========================================================
125 
126 
127 
130 #define DECIMATER_MODNAME(_mod_name) \
131  virtual const std::string& name() const { \
132  static std::string _s_modname_(#_mod_name); return _s_modname_; \
133 }
134 
135 
149 #define DECIMATING_MODULE(Classname, MeshT, Name) \
150  typedef Classname < MeshT > Self; \
151  typedef OpenMesh::Decimater::ModHandleT< Self > Handle; \
152  typedef OpenMesh::Decimater::ModBaseT< MeshT > Base; \
153  typedef typename Base::Mesh Mesh; \
154  typedef typename Base::CollapseInfo CollapseInfo; \
155  DECIMATER_MODNAME( Name )
156 
157 
158 
159 //== CLASS DEFINITION =========================================================
160 
161 
191 template <typename MeshT>
192 class ModBaseT
193 {
194 public:
195  typedef MeshT Mesh;
197 
198  enum {
199  ILLEGAL_COLLAPSE = -1,
200  LEGAL_COLLAPSE = 0
201  };
202 
203 protected:
204 
207  ModBaseT(MeshT& _mesh, bool _is_binary)
208  : error_tolerance_factor_(1.0), mesh_(_mesh), is_binary_(_is_binary) {}
209 
210 public:
211 
213  virtual ~ModBaseT() { }
214 
217 
218 
220  bool is_binary(void) const { return is_binary_; }
221 
223  void set_binary(bool _b) { is_binary_ = _b; }
224 
225 
226 public: // common interface
227 
229  virtual void initialize() { }
230 
245  virtual float collapse_priority(const CollapseInfoT<MeshT>& /* _ci */)
246  { return LEGAL_COLLAPSE; }
247 
251  virtual void preprocess_collapse(const CollapseInfoT<MeshT>& /* _ci */)
252  {}
253 
257  virtual void postprocess_collapse(const CollapseInfoT<MeshT>& /* _ci */)
258  {}
259 
268  virtual void set_error_tolerance_factor(double _factor) {
269  if (_factor >= 0.0 && _factor <= 1.0)
270  error_tolerance_factor_ = _factor;
271  }
272 
273 
274 protected:
275 
277  MeshT& mesh() { return mesh_; }
278 
279  // current percentage of the original constraint
280  double error_tolerance_factor_;
281 
282 private:
283 
284  // hide copy constructor & assignemnt
285  ModBaseT(const ModBaseT& _cpy);
286  ModBaseT& operator=(const ModBaseT& );
287 
288  MeshT& mesh_;
289 
290  bool is_binary_;
291 };
292 
293 
294 //=============================================================================
295 } // namespace Decimater
296 } // namespace OpenMesh
297 //=============================================================================
298 #endif // OPENMESH_DECIMATER_MODBASE_HH defined
299 //=============================================================================
300 
Base class for all decimation modules.
Definition: ModBaseT.hh:192
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:71
bool is_binary(void) const
Returns true if criteria returns a binary value.
Definition: ModBaseT.hh:220
Provides data class CollapseInfoT for storing all information about a halfedge collapse.
bool is_valid() const
Check handle status.
Definition: ModBaseT.hh:100
virtual ~ModBaseT()
Virtual desctructor.
Definition: ModBaseT.hh:213
virtual float collapse_priority(const CollapseInfoT< MeshT > &)
Return collapse priority.
Definition: ModBaseT.hh:245
#define DECIMATER_MODNAME(_mod_name)
Macro that sets up the name() function.
Definition: ModBaseT.hh:130
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
Definition: BaseDecimaterT.hh:85
~ModHandleT()
Destructor.
Definition: ModBaseT.hh:96
void set_binary(bool _b)
Set whether module is binary or not.
Definition: ModBaseT.hh:223
ModHandleT()
Default constructor.
Definition: ModBaseT.hh:93
virtual void preprocess_collapse(const CollapseInfoT< MeshT > &)
Before _from_vh has been collapsed into _to_vh, this method will be called.
Definition: ModBaseT.hh:251
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
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:268
Handle for mesh decimation modules.
Definition: ModBaseT.hh:83
virtual void initialize()
Initialize module-internal stuff.
Definition: ModBaseT.hh:229
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:74
ModBaseT(MeshT &_mesh, bool _is_binary)
Default constructor.
Definition: ModBaseT.hh:207
MeshT & mesh()
Access the mesh associated with the decimater.
Definition: ModBaseT.hh:277

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .