OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ModQuadricT.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 
42 
43 //=============================================================================
44 //
45 // CLASS ModQuadricT
46 //
47 //=============================================================================
48 
49 #ifndef OSG_MODQUADRIC_HH
50 #define OSG_MODQUADRIC_HH
51 
52 
53 //== INCLUDES =================================================================
54 
55 #include <float.h>
57 #include <OpenMesh/Core/Utils/Property.hh>
58 #include <OpenMesh/Core/Utils/vector_cast.hh>
60 
61 
62 //== NAMESPACE ================================================================
63 
64 namespace OpenMesh {
65 namespace Decimater {
66 
67 
68 //== CLASS DEFINITION =========================================================
69 
70 
75 template <class MeshT>
76 class ModQuadricT : public ModBaseT<MeshT>
77 {
78 public:
79 
80  // Defines the types Self, Handle, Base, Mesh, and CollapseInfo
81  // and the memberfunction name()
82  DECIMATING_MODULE( ModQuadricT, MeshT, Quadric );
83 
84 public:
85 
89  ModQuadricT( MeshT &_mesh )
90  : Base(_mesh, false)
91  {
92  unset_max_err();
93  Base::mesh().add_property( quadrics_ );
94  }
95 
96 
98  virtual ~ModQuadricT()
99  {
100  Base::mesh().remove_property(quadrics_);
101  }
102 
103 
104 public: // inherited
105 
107  virtual void initialize(void);
108 
114  virtual float collapse_priority(const CollapseInfo& _ci)
115  {
116  using namespace OpenMesh;
117 
118  typedef Geometry::QuadricT<double> Q;
119 
120  Q q = Base::mesh().property(quadrics_, _ci.v0);
121  q += Base::mesh().property(quadrics_, _ci.v1);
122 
123  double err = q(_ci.p1);
124 
125  //min_ = std::min(err, min_);
126  //max_ = std::max(err, max_);
127 
128  //double err = q( p );
129 
130  return float( (err < max_err_) ? err : float( Base::ILLEGAL_COLLAPSE ) );
131  }
132 
133 
135  virtual void postprocess_collapse(const CollapseInfo& _ci)
136  {
137  Base::mesh().property(quadrics_, _ci.v1) +=
138  Base::mesh().property(quadrics_, _ci.v0);
139  }
140 
142  void set_error_tolerance_factor(double _factor);
143 
144 
145 
146 public: // specific methods
147 
154  void set_max_err(double _err, bool _binary=true)
155  {
156  max_err_ = _err;
157  Base::set_binary(_binary);
158  }
159 
162  void unset_max_err(void)
163  {
164  max_err_ = DBL_MAX;
165  Base::set_binary(false);
166  }
167 
169  double max_err() const { return max_err_; }
170 
171 
172 private:
173 
174  // maximum quadric error
175  double max_err_;
176 
177  // this vertex property stores a quadric for each vertex
179 };
180 
181 //=============================================================================
182 } // END_NS_DECIMATER
183 } // END_NS_OPENMESH
184 //=============================================================================
185 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODQUADRIC_CC)
186 #define OSG_MODQUADRIC_TEMPLATES
187 #include "ModQuadricT.cc"
188 #endif
189 //=============================================================================
190 #endif // OSG_MODQUADRIC_HH defined
191 //=============================================================================
192 
virtual float collapse_priority(const CollapseInfo &_ci)
Compute collapse priority based on error quadrics.
Definition: ModQuadricT.hh:114
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:76
/class QuadricT Geometry/QuadricT.hh
Definition: QuadricT.hh:78
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:147
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:73
void set_max_err(double _err, bool _binary=true)
Set maximum quadric error constraint and enable binary mode.
Definition: ModQuadricT.hh:154
Base class for all decimation modules.
Definition: ModBaseT.hh:190
void unset_max_err(void)
Unset maximum quadric error constraint and restore non-binary mode.
Definition: ModQuadricT.hh:162
virtual ~ModQuadricT()
Destructor.
Definition: ModQuadricT.hh:98
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:90
void set_error_tolerance_factor(double _factor)
set the percentage of maximum quadric error
Definition: ModQuadricT.cc:134
Bodies of template member function.
virtual void initialize(void)
Initalize the module and prepare the mesh for decimation.
Definition: ModQuadricT.cc:71
ModQuadricT(MeshT &_mesh)
Constructor.
Definition: ModQuadricT.hh:89
virtual void postprocess_collapse(const CollapseInfo &_ci)
Post-process halfedge collapse (accumulate quadrics)
Definition: ModQuadricT.hh:135
double max_err() const
Return value of max. allowed error.
Definition: ModQuadricT.hh:169
Handle representing a vertex property.
Definition: Property.hh:476
Base class for all decimation modules.
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:93
Mesh::VertexHandle v1
Remaining vertex.
Definition: CollapseInfoT.hh:91

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