OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47  \*===========================================================================*/
48 
52 //=============================================================================
53 //
54 // CLASS ModHausdorffT
55 //
56 //=============================================================================
57 
58 #ifndef OPENMESH_DECIMATER_MODHAUSDORFFT_HH
59 #define OPENMESH_DECIMATER_MODHAUSDORFFT_HH
60 
61 //== INCLUDES =================================================================
62 
64 #include <OpenMesh/Core/Utils/Property.hh>
65 #include <vector>
66 #include <cfloat>
67 
68 //== NAMESPACES ===============================================================
69 
70 namespace OpenMesh {
71 namespace Decimater {
72 
73 //== CLASS DEFINITION =========================================================
74 
84 template<class MeshT>
85 class ModHausdorffT: public ModBaseT<MeshT> {
86  public:
87 
88  DECIMATING_MODULE( ModHausdorffT, MeshT, Hausdorff );
89 
90  typedef typename Mesh::Scalar Scalar;
91  typedef typename Mesh::Point Point;
92  typedef typename Mesh::FaceHandle FaceHandle;
93  typedef std::vector<Point> Points;
94 
96  ModHausdorffT(MeshT& _mesh, Scalar _error_tolerance = FLT_MAX) :
97  Base(_mesh, true), mesh_(Base::mesh()), tolerance_(_error_tolerance) {
98  mesh_.add_property(points_);
99  }
100 
103  mesh_.remove_property(points_);
104  }
105 
107  Scalar tolerance() const {
108  return tolerance_;
109  }
110 
112  void set_tolerance(Scalar _e) {
113  tolerance_ = _e;
114  }
115 
117  virtual void initialize();
118 
129  virtual float collapse_priority(const CollapseInfo& _ci);
130 
132  virtual void postprocess_collapse(const CollapseInfo& _ci);
133 
135  void set_error_tolerance_factor(double _factor);
136 
137  private:
138 
140  Scalar distPointTriangleSquared(const Point& _p, const Point& _v0, const Point& _v1, const Point& _v2);
141 
143  Scalar compute_sqr_error(FaceHandle _fh, const Point& _p) const;
144 
145  private:
146 
148  Points tmp_points_;
149 
150  Mesh& mesh_;
151  Scalar tolerance_;
152 
154 };
155 
156 //=============================================================================
157 }// END_NS_DECIMATER
158 } // END_NS_OPENMESH
159 //=============================================================================
160 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODHAUSDORFFT_C)
161 #define OPENMESH_DECIMATER_MODHAUSDORFFT_TEMPLATES
162 #include "ModHausdorffT.cc"
163 #endif
164 //=============================================================================
165 #endif // OPENMESH_DECIMATER_MODHAUSDORFFT_HH defined
166 //=============================================================================
167 
virtual void postprocess_collapse(const CollapseInfo &_ci)
re-distribute points
Definition: ModHausdorffT.cc:287
Use Hausdorff distance to control decimation.
Definition: ModHausdorffT.hh:85
ModHausdorffT(MeshT &_mesh, Scalar _error_tolerance=FLT_MAX)
Constructor.
Definition: ModHausdorffT.hh:96
Base class for all decimation modules.
void set_tolerance(Scalar _e)
set max error tolerance
Definition: ModHausdorffT.hh:112
void set_error_tolerance_factor(double _factor)
set the percentage of tolerance
Definition: ModHausdorffT.cc:271
~ModHausdorffT()
Destructor.
Definition: ModHausdorffT.hh:102
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
virtual float collapse_priority(const CollapseInfo &_ci)
compute Hausdorff error for one-ring
Definition: ModHausdorffT.cc:211
Scalar tolerance() const
get max error tolerance
Definition: ModHausdorffT.hh:107
MeshT & mesh()
Access the mesh associated with the decimater.
Definition: ModBaseT.hh:282
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:154
virtual void initialize()
reset per-face point lists
Definition: ModHausdorffT.cc:196
Base class for all decimation modules.
Definition: ModBaseT.hh:197

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .