OpenMesh
ModHausdorffT.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
46//=============================================================================
47//
48// CLASS ModHausdorffT
49//
50//=============================================================================
51
52#ifndef OPENMESH_DECIMATER_MODHAUSDORFFT_HH
53#define OPENMESH_DECIMATER_MODHAUSDORFFT_HH
54
55//== INCLUDES =================================================================
56
58#include <OpenMesh/Core/Utils/Property.hh>
59#include <vector>
60#include <cfloat>
61
62//== NAMESPACES ===============================================================
63
64namespace OpenMesh {
65namespace Decimater {
66
67//== CLASS DEFINITION =========================================================
68
78template<class MeshT>
79class ModHausdorffT: public ModBaseT<MeshT> {
80 public:
81
82 DECIMATING_MODULE( ModHausdorffT, MeshT, Hausdorff );
83
84 typedef typename Mesh::Scalar Scalar;
85 typedef typename Mesh::Point Point;
86 typedef typename Mesh::FaceHandle FaceHandle;
87 typedef std::vector<Point> Points;
88
90 explicit ModHausdorffT(MeshT& _mesh, Scalar _error_tolerance = FLT_MAX) :
91 Base(_mesh, true), mesh_(Base::mesh()), tolerance_(_error_tolerance) {
92 mesh_.add_property(points_);
93 }
94
97 mesh_.remove_property(points_);
98 }
99
101 Scalar tolerance() const {
102 return tolerance_;
103 }
104
106 void set_tolerance(Scalar _e) {
107 tolerance_ = _e;
108 }
109
111 virtual void initialize() override;
112
123 virtual float collapse_priority(const CollapseInfo& _ci) override;
124
126 virtual void postprocess_collapse(const CollapseInfo& _ci) override;
127
129 void set_error_tolerance_factor(double _factor) override;
130
131 private:
132
134 Scalar distPointTriangleSquared(const Point& _p, const Point& _v0, const Point& _v1, const Point& _v2);
135
137 Scalar compute_sqr_error(FaceHandle _fh, const Point& _p) const;
138
139 private:
140
142 Points tmp_points_;
143
144 Mesh& mesh_;
145 Scalar tolerance_;
146
148};
149
150//=============================================================================
151}// END_NS_DECIMATER
152} // END_NS_OPENMESH
153//=============================================================================
154#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODHAUSDORFFT_C)
155#define OPENMESH_DECIMATER_MODHAUSDORFFT_TEMPLATES
156#include "ModHausdorffT_impl.hh"
157#endif
158//=============================================================================
159#endif // OPENMESH_DECIMATER_MODHAUSDORFFT_HH defined
160//=============================================================================
161
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
Handle for a face entity.
Definition: Handles.hh:142
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:96
Kernel::Scalar Scalar
Scalar type.
Definition: PolyMeshT.hh:110
Base class for all decimation modules.
Definition: ModBaseT.hh:193
MeshT & mesh()
Access the mesh associated with the decimater.
Definition: ModBaseT.hh:277
Use Hausdorff distance to control decimation.
Definition: ModHausdorffT.hh:79
ModHausdorffT(MeshT &_mesh, Scalar _error_tolerance=FLT_MAX)
Constructor.
Definition: ModHausdorffT.hh:90
virtual float collapse_priority(const CollapseInfo &_ci) override
compute Hausdorff error for one-ring
Definition: ModHausdorffT_impl.hh:205
void set_tolerance(Scalar _e)
set max error tolerance
Definition: ModHausdorffT.hh:106
virtual void postprocess_collapse(const CollapseInfo &_ci) override
re-distribute points
Definition: ModHausdorffT_impl.hh:281
virtual void initialize() override
reset per-face point lists
Definition: ModHausdorffT_impl.hh:190
void set_error_tolerance_factor(double _factor) override
set the percentage of tolerance
Definition: ModHausdorffT_impl.hh:265
Scalar tolerance() const
get max error tolerance
Definition: ModHausdorffT.hh:101
~ModHausdorffT()
Destructor.
Definition: ModHausdorffT.hh:96

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