ModHausdorffT.hh 6.35 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
/*===========================================================================*\
 *                                                                           *
 *                               OpenMesh                                    *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
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
 *                           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

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37 38
 *   $Revision$                                                        *
 *   $Date$                   *
Jan Möbius's avatar
Jan Möbius committed
39
 *                                                                           *
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

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

#include <OpenMesh/Tools/Decimater/ModBaseT.hh>
#include <OpenMesh/Core/Utils/Property.hh>
#include <vector>
59
#include <cfloat>
Jan Möbius's avatar
Jan Möbius committed
60 61 62

//== 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 142 143
    /// Temporary point storage
    Points tmp_points_;

    Mesh&  mesh_;
144
    Scalar tolerance_;
Jan Möbius's avatar
Jan Möbius committed
145

146
    OpenMesh::FPropHandleT<Points> points_;
Jan Möbius's avatar
Jan Möbius committed
147 148 149
};

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