Developer Documentation
ModQuadricT.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 
49 
50 //=============================================================================
51 //
52 // CLASS ModQuadricT
53 //
54 //=============================================================================
55 
56 #ifndef OSG_MODQUADRIC_HH
57 #define OSG_MODQUADRIC_HH
58 
59 
60 //== INCLUDES =================================================================
61 
62 #include <float.h>
64 #include <OpenMesh/Core/Utils/Property.hh>
65 #include <OpenMesh/Core/Utils/vector_cast.hh>
67 
68 
69 //== NAMESPACE ================================================================
70 
71 namespace OpenMesh {
72 namespace Decimater {
73 
74 
75 //== CLASS DEFINITION =========================================================
76 
77 
82 template <class MeshT>
83 class ModQuadricT : public ModBaseT<MeshT>
84 {
85 public:
86 
87  // Defines the types Self, Handle, Base, Mesh, and CollapseInfo
88  // and the memberfunction name()
89  DECIMATING_MODULE( ModQuadricT, MeshT, Quadric );
90 
91 public:
92 
96  ModQuadricT( MeshT &_mesh )
97  : Base(_mesh, false)
98  {
99  unset_max_err();
100  Base::mesh().add_property( quadrics_ );
101  }
102 
103 
105  virtual ~ModQuadricT()
106  {
107  Base::mesh().remove_property(quadrics_);
108  }
109 
110 
111 public: // inherited
112 
114  virtual void initialize(void);
115 
121  virtual float collapse_priority(const CollapseInfo& _ci)
122  {
123  using namespace OpenMesh;
124 
125  typedef Geometry::QuadricT<double> Q;
126 
127  Q q = Base::mesh().property(quadrics_, _ci.v0);
128  q += Base::mesh().property(quadrics_, _ci.v1);
129 
130  double err = q(_ci.p1);
131 
132  //min_ = std::min(err, min_);
133  //max_ = std::max(err, max_);
134 
135  //double err = q( p );
136 
137  return float( (err < max_err_) ? err : float( Base::ILLEGAL_COLLAPSE ) );
138  }
139 
140 
142  virtual void postprocess_collapse(const CollapseInfo& _ci)
143  {
144  Base::mesh().property(quadrics_, _ci.v1) +=
145  Base::mesh().property(quadrics_, _ci.v0);
146  }
147 
149  void set_error_tolerance_factor(double _factor);
150 
151 
152 
153 public: // specific methods
154 
161  void set_max_err(double _err, bool _binary=true)
162  {
163  max_err_ = _err;
164  Base::set_binary(_binary);
165  }
166 
169  void unset_max_err(void)
170  {
171  max_err_ = DBL_MAX;
172  Base::set_binary(false);
173  }
174 
176  double max_err() const { return max_err_; }
177 
178 
179 private:
180 
181  // maximum quadric error
182  double max_err_;
183 
184  // this vertex property stores a quadric for each vertex
186 };
187 
188 //=============================================================================
189 } // END_NS_DECIMATER
190 } // END_NS_OPENMESH
191 //=============================================================================
192 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODQUADRIC_CC)
193 #define OSG_MODQUADRIC_TEMPLATES
194 #include "ModQuadricT.cc"
195 #endif
196 //=============================================================================
197 #endif // OSG_MODQUADRIC_HH defined
198 //=============================================================================
199 
virtual void initialize(void)
Initalize the module and prepare the mesh for decimation.
Definition: ModQuadricT.cc:78
double max_err() const
Return value of max. allowed error.
Definition: ModQuadricT.hh:176
Mesh::VertexHandle v1
Remaining vertex.
Mesh::Point p1
Positions of remaining vertex.
virtual float collapse_priority(const CollapseInfo &_ci)
Definition: ModQuadricT.hh:121
virtual void postprocess_collapse(const CollapseInfo &_ci)
Post-process halfedge collapse (accumulate quadrics)
Definition: ModQuadricT.hh:142
Mesh::VertexHandle v0
Vertex to be removed.
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:83
void set_max_err(double _err, bool _binary=true)
Definition: ModQuadricT.hh:161
virtual ~ModQuadricT()
Destructor.
Definition: ModQuadricT.hh:105
void set_error_tolerance_factor(double _factor)
set the percentage of maximum quadric error
Definition: ModQuadricT.cc:141