ModHausdorffT.hh 6.35 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*===========================================================================*\
 *                                                                           *
 *                               OpenMesh                                    *
 *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openmesh.org                                *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenMesh.                                           *
 *                                                                           *
 *  OpenMesh is free software: you can redistribute it and/or modify         *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenMesh is distributed in the hope that it will be useful,              *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenMesh.  If not,                                    *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
33
 \*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
34
35
36
37
38
39

/*===========================================================================*\
 *                                                                           *
 *   $Revision: 448 $                                                        *
 *   $Date: 2011-11-04 13:59:37 +0100 (Fri, 04 Nov 2011) $                   *
 *                                                                           *
40
 \*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
41
42
43
44
45
46
47
48
49
50

/** \file ModHausdorffT.hh
 */

//=============================================================================
//
//  CLASS ModHausdorffT
//
//=============================================================================

51
52
#ifndef OPENMESH_DECIMATER_MODHAUSDORFFT_HH
#define OPENMESH_DECIMATER_MODHAUSDORFFT_HH
Jan Möbius's avatar
Jan Möbius committed
53
54
55
56
57
58
59
60
61
62

//== INCLUDES =================================================================

#include <OpenMesh/Tools/Decimater/ModBaseT.hh>
#include <OpenMesh/Core/Utils/Property.hh>
#include <vector>
#include <float.h>

//== NAMESPACES ===============================================================

63
namespace OpenMesh {
Jan Möbius's avatar
Jan Möbius committed
64
65
66
67
namespace Decimater {

//== CLASS DEFINITION =========================================================

68
69
70
71
72
73
74
75
76
/** \brief Use Hausdorff distance to control decimation
 *
 * This module computes the aspect ratio.
 *
 * In binary mode, the collapse is legal if:
 *  - The distance after the collapse is lower than the given tolerance
 *
 * No continuous mode
 */
77
78
template<class MeshT>
class ModHausdorffT: public ModBaseT<MeshT> {
79
  public:
Jan Möbius's avatar
Jan Möbius committed
80

81
    DECIMATING_MODULE( ModHausdorffT, MeshT, Roundness );
Jan Möbius's avatar
Jan Möbius committed
82

83
84
85
86
    typedef typename Mesh::Scalar Scalar;
    typedef typename Mesh::Point Point;
    typedef typename Mesh::FaceHandle FaceHandle;
    typedef std::vector<Point> Points;
Jan Möbius's avatar
Jan Möbius committed
87

88
    /// Constructor
89
90
    ModHausdorffT(MeshT& _mesh, Scalar _error_tolerance = FLT_MAX) :
        Base(_mesh, true), mesh_(Base::mesh()), tolerance_(_error_tolerance) {
91
92
      mesh_.add_property(points_);
    }
Jan Möbius's avatar
Jan Möbius committed
93

94
95
96
97
    /// Destructor
    ~ModHausdorffT() {
      mesh_.remove_property(points_);
    }
Jan Möbius's avatar
Jan Möbius committed
98

99
100
101
102
    /// get max error tolerance
    Scalar tolerance() const {
      return tolerance_;
    }
Jan Möbius's avatar
Jan Möbius committed
103

104
105
106
107
    /// set max error tolerance
    void set_tolerance(Scalar _e) {
      tolerance_ = _e;
    }
Jan Möbius's avatar
Jan Möbius committed
108

109
110
    /// reset per-face point lists
    virtual void initialize();
Jan Möbius's avatar
Jan Möbius committed
111

112
113
114
115
116
117
118
119
120
    /** \brief compute Hausdorff error for one-ring
     *
     * This mod only allows collapses if the Hausdorff distance
     * after a collapse is lower than the given tolerance.
     *
     *
     * @param _ci Collapse info data
     * @return Binary return, if collapse is legal or illegal
     */
Jan Möbius's avatar
Jan Möbius committed
121

122
    virtual float collapse_priority(const CollapseInfo& _ci);
Jan Möbius's avatar
Jan Möbius committed
123

124
125
    /// re-distribute points
    virtual void postprocess_collapse(const CollapseInfo& _ci);
Jan Möbius's avatar
Jan Möbius committed
126

127
128
129
    /// set the percentage of tolerance
    void set_error_tolerance_factor(double _factor);

130
  private:
Jan Möbius's avatar
Jan Möbius committed
131

132
    /// squared distance from point _p to triangle (_v0, _v1, _v2)
Jan Möbius's avatar
Jan Möbius committed
133
    Scalar distPointTriangleSquared(const Point& _p, const Point& _v0, const Point& _v1, const Point& _v2);
Jan Möbius's avatar
Jan Möbius committed
134

135
136
    /// compute max error for face _fh w.r.t. its point list and _p
    Scalar compute_sqr_error(FaceHandle _fh, const Point& _p) const;
Jan Möbius's avatar
Jan Möbius committed
137

138
  private:
Jan Möbius's avatar
Jan Möbius committed
139

140
141
    Mesh& mesh_;
    Scalar tolerance_;
Jan Möbius's avatar
Jan Möbius committed
142

143
    OpenMesh::FPropHandleT<Points> points_;
Jan Möbius's avatar
Jan Möbius committed
144
145
146
};

//=============================================================================
147
}// END_NS_DECIMATER
Jan Möbius's avatar
Jan Möbius committed
148
149
} // END_NS_OPENMESH
//=============================================================================
150
#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODHAUSDORFFT_C)
151
#define OPENMESH_DECIMATER_MODHAUSDORFFT_TEMPLATES
Jan Möbius's avatar
Jan Möbius committed
152
153
154
#include "ModHausdorffT.cc"
#endif
//=============================================================================
155
#endif // OPENMESH_DECIMATER_MODHAUSDORFFT_HH defined
Jan Möbius's avatar
Jan Möbius committed
156
157
//=============================================================================