OpenMesh: OpenMesh/Tools/Decimater/ModQuadricT.hh Source File

| OpenMesh

ModQuadricT.hh
Go to the documentation of this file.
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2022, 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>
55 #include <OpenMesh/Tools/Decimater/ModBaseT.hh>
56 #include <OpenMesh/Core/Utils/Property.hh>
57 #include <OpenMesh/Core/Utils/vector_cast.hh>
58 #include <OpenMesh/Core/Geometry/QuadricT.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
177 VPropHandleT< Geometry::QuadricT<double> > quadrics_;
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
QuadricT.hh
ModBaseT.hh
Base class for all decimation modules.
DECIMATING_MODULE
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:149
ModQuadricT_impl.hh
Bodies of template member function.
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::Geometry::QuadricT
/class QuadricT Geometry/QuadricT.hh
Definition: QuadricT.hh:83
OpenMesh::VPropHandleT
Handle representing a vertex property.
Definition: Property.hh:417
OpenMesh::Decimater::CollapseInfoT
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:74
OpenMesh::Decimater::CollapseInfoT::v1
Mesh::VertexHandle v1
Remaining vertex.
Definition: CollapseInfoT.hh:83
OpenMesh::Decimater::CollapseInfoT::p1
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:85
OpenMesh::Decimater::CollapseInfoT::v0
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:82
OpenMesh::Decimater::ModBaseT
Base class for all decimation modules.
Definition: ModBaseT.hh:193
OpenMesh::Decimater::ModQuadricT
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:76
OpenMesh::Decimater::ModQuadricT::ModQuadricT
ModQuadricT(MeshT &_mesh)
Constructor.
Definition: ModQuadricT.hh:88
OpenMesh::Decimater::ModQuadricT::set_max_err
void set_max_err(double _err, bool _binary=true)
Set maximum quadric error constraint and enable binary mode.
Definition: ModQuadricT.hh:153
OpenMesh::Decimater::ModQuadricT::set_error_tolerance_factor
void set_error_tolerance_factor(double _factor) override
set the percentage of maximum quadric error
Definition: ModQuadricT_impl.hh:136
OpenMesh::Decimater::ModQuadricT::~ModQuadricT
virtual ~ModQuadricT()
Destructor.
Definition: ModQuadricT.hh:97
OpenMesh::Decimater::ModQuadricT::initialize
virtual void initialize(void) override
Initalize the module and prepare the mesh for decimation.
Definition: ModQuadricT_impl.hh:73
OpenMesh::Decimater::ModQuadricT::max_err
double max_err() const
Return value of max. allowed error.
Definition: ModQuadricT.hh:168
OpenMesh::Decimater::ModQuadricT::postprocess_collapse
virtual void postprocess_collapse(const CollapseInfo &_ci) override
Post-process halfedge collapse (accumulate quadrics)
Definition: ModQuadricT.hh:134
OpenMesh::Decimater::ModQuadricT::collapse_priority
virtual float collapse_priority(const CollapseInfo &_ci) override
Compute collapse priority based on error quadrics.
Definition: ModQuadricT.hh:113
OpenMesh::Decimater::ModQuadricT::unset_max_err
void unset_max_err(void)
Unset maximum quadric error constraint and restore non-binary mode.
Definition: ModQuadricT.hh:161