OpenMesh
 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-2011 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: 460 $ *
38  * $Date: 2011-11-16 10:45:08 +0100 (Mi, 16 Nov 2011) $ *
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 DecimaterType>
76 class ModQuadricT : public ModBaseT<DecimaterType>
77 {
78 public:
79 
80  // Defines the types Self, Handle, Base, Mesh, and CollapseInfo
81  // and the memberfunction name()
82  DECIMATING_MODULE( ModQuadricT, DecimaterType, Quadric );
83 
84 public:
85 
89  ModQuadricT( DecimaterType &_dec )
90  : Base(_dec, 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 
141 
142 
143 public: // specific methods
144 
151  void set_max_err(double _err, bool _binary=true)
152  {
153  max_err_ = _err;
154  Base::set_binary(_binary);
155  }
156 
159  void unset_max_err(void)
160  {
161  max_err_ = DBL_MAX;
162  Base::set_binary(false);
163  }
164 
166  double max_err() const { return max_err_; }
167 
168 
169 private:
170 
171  // maximum quadric error
172  double max_err_;
173 
174  // this vertex property stores a quadric for each vertex
176 };
177 
178 //=============================================================================
179 } // END_NS_DECIMATER
180 } // END_NS_OPENMESH
181 //=============================================================================
182 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODQUADRIC_CC)
183 #define OSG_MODQUADRIC_TEMPLATES
184 #include "ModQuadricT.cc"
185 #endif
186 //=============================================================================
187 #endif // OSG_MODQUADRIC_HH defined
188 //=============================================================================
189 

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