OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
53 //=============================================================================
54 //
55 // CLASS ModBaseT
56 //
57 //=============================================================================
58 
59 #ifndef OPENMESH_DECIMATER_MODBASET_HH
60 #define OPENMESH_DECIMATER_MODBASET_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 #include <OpenMesh/Core/Utils/Noncopyable.hh>
67 #include <string>
68 
69 
70 //== NAMESPACE ================================================================
71 
72 namespace OpenMesh {
73 namespace Decimater {
74 
75 
76 //== FORWARD DECLARATIONS =====================================================
77 
78 template <typename Mesh> class BaseDecimaterT;
79 
80 
81 //== CLASS DEFINITION =========================================================
82 
87 template <typename Module>
89 {
90 public:
91 
92  typedef ModHandleT<Module> Self;
93  typedef Module module_type;
94 
95 public:
96 
98  ModHandleT() : mod_(NULL) {}
99 
101  ~ModHandleT() { /* don't delete mod_, since handle is not owner! */ }
102 
105  bool is_valid() const { return mod_ != NULL; }
106 
107 private:
108 
109 #if defined(OM_CC_MSVC)
110  friend class BaseDecimaterT;
111 #else
112  template <typename Mesh> friend class BaseDecimaterT;
113 #endif
114 
115  void clear() { mod_ = NULL; }
116  void init(Module* _m) { mod_ = _m; }
117  Module* module() { return mod_; }
118 
119 
120 private:
121 
122  Module* mod_;
123 
124 };
125 
126 
127 
128 
129 //== CLASS DEFINITION =========================================================
130 
131 
132 
135 #define DECIMATER_MODNAME(_mod_name) \
136  virtual const std::string& name() const { \
137  static std::string _s_modname_(#_mod_name); return _s_modname_; \
138 }
139 
140 
154 #define DECIMATING_MODULE(Classname, MeshT, Name) \
155  typedef Classname < MeshT > Self; \
156  typedef OpenMesh::Decimater::ModHandleT< Self > Handle; \
157  typedef OpenMesh::Decimater::ModBaseT< MeshT > Base; \
158  typedef typename Base::Mesh Mesh; \
159  typedef typename Base::CollapseInfo CollapseInfo; \
160  DECIMATER_MODNAME( Name )
161 
162 
163 
164 //== CLASS DEFINITION =========================================================
165 
166 
196 template <typename MeshT>
197 class ModBaseT
198 {
199 public:
200  typedef MeshT Mesh;
202 
203  enum {
206  };
207 
208 protected:
209 
212  ModBaseT(MeshT& _mesh, bool _is_binary)
213  : error_tolerance_factor_(1.0), mesh_(_mesh), is_binary_(_is_binary) {}
214 
215 public:
216 
218  virtual ~ModBaseT() { }
219 
222 
223 
225  bool is_binary(void) const { return is_binary_; }
226 
228  void set_binary(bool _b) { is_binary_ = _b; }
229 
230 
231 public: // common interface
232 
234  virtual void initialize() { }
235 
250  virtual float collapse_priority(const CollapseInfoT<MeshT>& /* _ci */)
251  { return LEGAL_COLLAPSE; }
252 
256  virtual void preprocess_collapse(const CollapseInfoT<MeshT>& /* _ci */)
257  {}
258 
262  virtual void postprocess_collapse(const CollapseInfoT<MeshT>& /* _ci */)
263  {}
264 
273  virtual void set_error_tolerance_factor(double _factor) {
274  if (_factor >= 0.0 && _factor <= 1.0)
275  error_tolerance_factor_ = _factor;
276  }
277 
278 
279 protected:
280 
282  MeshT& mesh() { return mesh_; }
283 
284  // current percentage of the original constraint
285  double error_tolerance_factor_;
286 
287 private:
288 
289  // hide copy constructor & assignemnt
290  ModBaseT(const ModBaseT& _cpy);
291  ModBaseT& operator=(const ModBaseT& );
292 
293  MeshT& mesh_;
294 
295  bool is_binary_;
296 };
297 
298 
299 //=============================================================================
300 } // namespace Decimater
301 } // namespace OpenMesh
302 //=============================================================================
303 #endif // OPENMESH_DECIMATER_MODBASE_HH defined
304 //=============================================================================
305 
indicates an illegal collapse
Definition: ModBaseT.hh:204
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:80
Definition: BaseDecimaterT.hh:90
virtual void preprocess_collapse(const CollapseInfoT< MeshT > &)
Before _from_vh has been collapsed into _to_vh, this method will be called.
Definition: ModBaseT.hh:256
Handle for mesh decimation modules.
Definition: ModBaseT.hh:88
#define DECIMATER_MODNAME(_mod_name)
Macro that sets up the name() function.
Definition: ModBaseT.hh:135
virtual void initialize()
Initialize module-internal stuff.
Definition: ModBaseT.hh:234
void set_binary(bool _b)
Set whether module is binary or not.
Definition: ModBaseT.hh:228
indicates a legal collapse
Definition: ModBaseT.hh:205
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:273
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:76
virtual float collapse_priority(const CollapseInfoT< MeshT > &)
Return collapse priority.
Definition: ModBaseT.hh:250
bool is_binary(void) const
Returns true if criteria returns a binary value.
Definition: ModBaseT.hh:225
MeshT & mesh()
Access the mesh associated with the decimater.
Definition: ModBaseT.hh:282
~ModHandleT()
Destructor.
Definition: ModBaseT.hh:101
ModHandleT()
Default constructor.
Definition: ModBaseT.hh:98
bool is_valid() const
Check handle status.
Definition: ModBaseT.hh:105
Provides data class CollapseInfoT for storing all information about a halfedge collapse.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
virtual void postprocess_collapse(const CollapseInfoT< MeshT > &)
After _from_vh has been collapsed into _to_vh, this method will be called.
Definition: ModBaseT.hh:262
ModBaseT(MeshT &_mesh, bool _is_binary)
Default constructor.
Definition: ModBaseT.hh:212
virtual ~ModBaseT()
Virtual desctructor.
Definition: ModBaseT.hh:218
Base class for all decimation modules.
Definition: ModBaseT.hh:197

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