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 // CLASS ModQuadricT
45 //
46 //=============================================================================
47 
48 #ifndef OSG_MODQUADRIC_HH
49 #define OSG_MODQUADRIC_HH
50 
51 
52 //== INCLUDES =================================================================
53 
54 #include <float.h>
56 #include <OpenMesh/Core/Utils/Property.hh>
57 #include <OpenMesh/Core/Utils/vector_cast.hh>
59 
60 
61 //== NAMESPACE ================================================================
62 
63 namespace OpenMesh {
64 namespace Decimater {
65 
66 
67 //== CLASS DEFINITION =========================================================
68 
69 
74 template <class MeshT>
75 class ModQuadricT : public ModBaseT<MeshT>
76 {
77 public:
78 
79  // Defines the types Self, Handle, Base, Mesh, and CollapseInfo
80  // and the memberfunction name()
81  DECIMATING_MODULE( ModQuadricT, MeshT, Quadric );
82 
83 public:
84 
88  explicit ModQuadricT( MeshT &_mesh )
89  : Base(_mesh, false)
90  {
91  unset_max_err();
92  Base::mesh().add_property( quadrics_ );
93  }
94 
95 
97  virtual ~ModQuadricT()
98  {
99  Base::mesh().remove_property(quadrics_);
100  }
101 
102 
103 public: // inherited
104 
106  virtual void initialize(void) override;
107 
113  virtual float collapse_priority(const CollapseInfo& _ci) override
114  {
115  using namespace OpenMesh;
116 
117  typedef Geometry::QuadricT<double> Q;
118 
119  Q q = Base::mesh().property(quadrics_, _ci.v0);
120  q += Base::mesh().property(quadrics_, _ci.v1);
121 
122  double err = q(_ci.p1);
123 
124  //min_ = std::min(err, min_);
125  //max_ = std::max(err, max_);
126 
127  //double err = q( p );
128 
129  return float( (err < max_err_) ? err : float( Base::ILLEGAL_COLLAPSE ) );
130  }
131 
132 
134  virtual void postprocess_collapse(const CollapseInfo& _ci) override
135  {
136  Base::mesh().property(quadrics_, _ci.v1) +=
137  Base::mesh().property(quadrics_, _ci.v0);
138  }
139 
141  void set_error_tolerance_factor(double _factor) override;
142 
143 
144 
145 public: // specific methods
146 
153  void set_max_err(double _err, bool _binary=true)
154  {
155  max_err_ = _err;
156  Base::set_binary(_binary);
157  }
158 
161  void unset_max_err(void)
162  {
163  max_err_ = DBL_MAX;
164  Base::set_binary(false);
165  }
166 
168  double max_err() const { return max_err_; }
169 
170 
171 private:
172 
173  // maximum quadric error
174  double max_err_;
175 
176  // this vertex property stores a quadric for each vertex
178 };
179 
180 //=============================================================================
181 } // END_NS_DECIMATER
182 } // END_NS_OPENMESH
183 //=============================================================================
184 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODQUADRIC_CC)
185 #define OSG_MODQUADRIC_TEMPLATES
186 #include "ModQuadricT_impl.hh"
187 #endif
188 //=============================================================================
189 #endif // OSG_MODQUADRIC_HH defined
190 //=============================================================================
191 
Mesh::Point p1
Positions of remaining vertex.
double max_err() const
Return value of max. allowed error.
Definition: ModQuadricT.hh:168
virtual void initialize(void) override
Initalize the module and prepare the mesh for decimation.
virtual ~ModQuadricT()
Destructor.
Definition: ModQuadricT.hh:97
virtual void postprocess_collapse(const CollapseInfo &_ci) override
Post-process halfedge collapse (accumulate quadrics)
Definition: ModQuadricT.hh:134
void set_max_err(double _err, bool _binary=true)
Definition: ModQuadricT.hh:153
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:75
Mesh::VertexHandle v0
Vertex to be removed.
Mesh::VertexHandle v1
Remaining vertex.
void set_error_tolerance_factor(double _factor) override
set the percentage of maximum quadric error
virtual float collapse_priority(const CollapseInfo &_ci) override
Definition: ModQuadricT.hh:113