Developer Documentation
ModHausdorffT.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 
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 
64 namespace OpenMesh {
65 namespace Decimater {
66 
67 //== CLASS DEFINITION =========================================================
68 
78 template<class MeshT>
79 class 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  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 
Points tmp_points_
Temporary point storage.
virtual float collapse_priority(const CollapseInfo &_ci) override
compute Hausdorff error for one-ring
Scalar tolerance() const
get max error tolerance
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
void set_error_tolerance_factor(double _factor) override
set the percentage of tolerance
void set_tolerance(Scalar _e)
set max error tolerance
Scalar compute_sqr_error(FaceHandle _fh, const Point &_p) const
compute max error for face _fh w.r.t. its point list and _p
virtual void initialize() override
reset per-face point lists
virtual void postprocess_collapse(const CollapseInfo &_ci) override
re-distribute points
Scalar distPointTriangleSquared(const Point &_p, const Point &_v0, const Point &_v1, const Point &_v2)
squared distance from point _p to triangle (_v0, _v1, _v2)
ModHausdorffT(MeshT &_mesh, Scalar _error_tolerance=FLT_MAX)
Constructor.
Kernel::Scalar Scalar
Scalar type.
Definition: PolyMeshT.hh:110
MeshT & mesh()
Access the mesh associated with the decimater.
Definition: ModBaseT.hh:277
Use Hausdorff distance to control decimation.