OpenMesh
ModQuadricT.hh
Go to the documentation of this file.
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2023, 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
63namespace OpenMesh {
64namespace Decimater {
65
66
67//== CLASS DEFINITION =========================================================
68
69
74template <class MeshT>
75class ModQuadricT : public ModBaseT<MeshT>
76{
77public:
78
79 // Defines the types Self, Handle, Base, Mesh, and CollapseInfo
80 // and the memberfunction name()
81 DECIMATING_MODULE( ModQuadricT, MeshT, Quadric );
82
83public:
84
88 explicit ModQuadricT( MeshT &_mesh )
89 : Base(_mesh, false)
90 {
92 Base::mesh().add_property( quadrics_ );
93 }
94
95
97 virtual ~ModQuadricT()
98 {
99 Base::mesh().remove_property(quadrics_);
100 }
101
102
103public: // inherited
104
106 virtual void initialize(void) override;
107
113 virtual float collapse_priority(const CollapseInfo& _ci) override
114 {
115 using namespace OpenMesh;
116
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
145public: // 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
171private:
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
Bodies of template member function.
Base class for all decimation modules.
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:149
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
/class QuadricT Geometry/QuadricT.hh
Definition: QuadricT.hh:83
Handle representing a vertex property.
Definition: Property.hh:417
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:74
Mesh::VertexHandle v1
Remaining vertex.
Definition: CollapseInfoT.hh:83
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:85
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:82
Base class for all decimation modules.
Definition: ModBaseT.hh:193
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:76
ModQuadricT(MeshT &_mesh)
Constructor.
Definition: ModQuadricT.hh:88
void set_max_err(double _err, bool _binary=true)
Set maximum quadric error constraint and enable binary mode.
Definition: ModQuadricT.hh:153
void set_error_tolerance_factor(double _factor) override
set the percentage of maximum quadric error
Definition: ModQuadricT_impl.hh:136
virtual ~ModQuadricT()
Destructor.
Definition: ModQuadricT.hh:97
virtual void initialize(void) override
Initalize the module and prepare the mesh for decimation.
Definition: ModQuadricT_impl.hh:73
double max_err() const
Return value of max. allowed error.
Definition: ModQuadricT.hh:168
virtual void postprocess_collapse(const CollapseInfo &_ci) override
Post-process halfedge collapse (accumulate quadrics)
Definition: ModQuadricT.hh:134
virtual float collapse_priority(const CollapseInfo &_ci) override
Compute collapse priority based on error quadrics.
Definition: ModQuadricT.hh:113
void unset_max_err(void)
Unset maximum quadric error constraint and restore non-binary mode.
Definition: ModQuadricT.hh:161

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .