OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ModQuadricT.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
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>
56 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
57 #include <OpenMesh/Core/Utils/Property.hh>
58 #include <OpenMesh/Core/Utils/vector_cast.hh>
59 #include <OpenMesh/Core/Geometry/QuadricT.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
178 VPropHandleT< Geometry::QuadricT<double> > quadrics_;
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