Commit d4487aaa authored by Jan Möbius's avatar Jan Möbius

Documentation for decimater modules, updated decimater, more modules

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@460 fdac6126-5c0c-442c-9429-916003d36597
parent bbf5e47a
......@@ -138,16 +138,16 @@ public: // inherited
// to be compatible with gcc 2.95.3
{
decimater_o tmp( new decimater_t ( mesh() ) );
decimater_ = tmp;
decimater_o tmp( new decimater_t ( mesh() ) );
decimater_ = tmp;
}
{
mod_quadric_o tmp( new mod_quadric_t( *decimater_ ) );
mod_quadric_ = tmp;
mod_quadric_o tmp( new mod_quadric_t( *decimater_ ) );
mod_quadric_ = tmp;
}
{
mod_nf_o tmp( new mod_nf_t ( *decimater_ ) );
mod_nf_ = tmp;
mod_nf_o tmp( new mod_nf_t ( *decimater_ ) );
mod_nf_ = tmp;
}
decimater_->initialize();
......
This diff is collapsed.
......@@ -30,18 +30,18 @@
* License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* *
\*===========================================================================*/
\*===========================================================================*/
/** \file CollapseInfoT.hh
Provides data class CollapseInfoT for storing all information
about a halfedge collapse.
Provides data class CollapseInfoT for storing all information
about a halfedge collapse.
*/
//=============================================================================
......@@ -49,129 +49,111 @@
// STRUCT CollpaseInfoT
//
//=============================================================================
#ifndef OPENMESH_DECIMATER_COLLAPSEINFOT_HH
#define OPENMESH_DECIMATER_COLLAPSEINFOT_HH
//== INCLUDES =================================================================
//== NAMESPACE ================================================================
namespace OpenMesh {
namespace OpenMesh {
namespace Decimater {
//== CLASS DEFINITION =========================================================
/** Stores information about a halfedge collapse.
The class stores information about a halfedge collapse. The most
important information is \c v0v1, \c v1v0, \c v0, \c v1, \c vl,
\c vr, which you can lookup in the following image:
\image html collapse_info.png
\see ModProgMeshT::Info
The class stores information about a halfedge collapse. The most
important information is \c v0v1, \c v1v0, \c v0, \c v1, \c vl,
\c vr, which you can lookup in the following image:
\image html collapse_info.png
\see ModProgMeshT::Info
*/
template <class Mesh>
struct CollapseInfoT
{
public:
/** Initializing constructor.
*
* Given a mesh and a halfedge handle of the halfedge to be collapsed
* all important information of a halfedge collapse will be stored.
* \param _mesh Mesh source
* \param _heh Halfedge to collapse. The direction of the halfedge
* defines the direction of the collapse, i.e. the from-vertex
* will be removed and the to-vertex remains.
*/
CollapseInfoT(Mesh& _mesh, typename Mesh::HalfedgeHandle _heh);
Mesh& mesh;
typename Mesh::HalfedgeHandle v0v1; ///< Halfedge to be collapsed
typename Mesh::HalfedgeHandle v1v0; ///< Reverse halfedge
typename Mesh::VertexHandle v0; ///< Vertex to be removed
typename Mesh::VertexHandle v1; ///< Remaining vertex
typename Mesh::Point p0; ///< Position of removed vertex
typename Mesh::Point p1; ///< Positions of remaining vertex
typename Mesh::FaceHandle fl; ///< Left face
typename Mesh::FaceHandle fr; ///< Right face
typename Mesh::VertexHandle vl; ///< Left vertex
typename Mesh::VertexHandle vr; ///< Right vertex
//@{
/** Outer remaining halfedge of diamond spanned by \c v0, \c v1,
* \c vl, and \c vr
*/
typename Mesh::HalfedgeHandle vlv1, v0vl, vrv0, v1vr;
//@}
template<class Mesh>
struct CollapseInfoT {
public:
/** Initializing constructor.
*
* Given a mesh and a halfedge handle of the halfedge to be collapsed
* all important information of a halfedge collapse will be stored.
* \param _mesh Mesh source
* \param _heh Halfedge to collapse. The direction of the halfedge
* defines the direction of the collapse, i.e. the from-vertex
* will be removed and the to-vertex remains.
*/
CollapseInfoT(Mesh& _mesh, typename Mesh::HalfedgeHandle _heh);
Mesh& mesh;
typename Mesh::HalfedgeHandle v0v1; ///< Halfedge to be collapsed
typename Mesh::HalfedgeHandle v1v0; ///< Reverse halfedge
typename Mesh::VertexHandle v0; ///< Vertex to be removed
typename Mesh::VertexHandle v1; ///< Remaining vertex
typename Mesh::Point p0; ///< Position of removed vertex
typename Mesh::Point p1; ///< Positions of remaining vertex
typename Mesh::FaceHandle fl; ///< Left face
typename Mesh::FaceHandle fr; ///< Right face
typename Mesh::VertexHandle vl; ///< Left vertex
typename Mesh::VertexHandle vr; ///< Right vertex
//@{
/** Outer remaining halfedge of diamond spanned by \c v0, \c v1,
* \c vl, and \c vr
*/
typename Mesh::HalfedgeHandle vlv1, v0vl, vrv0, v1vr;
//@}
};
//-----------------------------------------------------------------------------
// CollapseInfoT::CollapseInfoT( _mesh, _heh )
//
// Local configuration of halfedge collapse to be stored in CollapseInfoT:
/*
vl
*
/ \
/ \
/ fl \
v0 *------>* v1
\ fr /
\ /
\ /
*
vr
/**
* Local configuration of halfedge collapse to be stored in CollapseInfoT:
*
* vl
* *
* / \
* / \
* / fl \
* v0 *------>* v1
* \ fr /
* \ /
* \ /
* *
* vr
*
*
* @param _mesh Reference to mesh
* @param _heh The halfedge (v0 -> v1) defining the collapse
*/
// Parameters:
// _mesh Reference to mesh
// _heh The halfedge (v0 -> v1) defining the collapse
//
template <class Mesh>
inline
CollapseInfoT<Mesh>::
CollapseInfoT(Mesh& _mesh, typename Mesh::HalfedgeHandle _heh) :
mesh(_mesh),
v0v1(_heh),
v1v0(_mesh.opposite_halfedge_handle(v0v1)),
v0(_mesh.to_vertex_handle(v1v0)),
v1(_mesh.to_vertex_handle(v0v1)),
p0(_mesh.point(v0)),
p1(_mesh.point(v1)),
fl(_mesh.face_handle(v0v1)),
fr(_mesh.face_handle(v1v0))
template<class Mesh>
inline CollapseInfoT<Mesh>::CollapseInfoT(Mesh& _mesh,
typename Mesh::HalfedgeHandle _heh) :
mesh(_mesh), v0v1(_heh), v1v0(_mesh.opposite_halfedge_handle(v0v1)), v0(
_mesh.to_vertex_handle(v1v0)), v1(_mesh.to_vertex_handle(v0v1)), p0(
_mesh.point(v0)), p1(_mesh.point(v1)), fl(_mesh.face_handle(v0v1)), fr(
_mesh.face_handle(v1v0))
{
// get vl
if (fl.is_valid())
{
if (fl.is_valid()) {
vlv1 = mesh.next_halfedge_handle(v0v1);
v0vl = mesh.next_halfedge_handle(vlv1);
vl = mesh.to_vertex_handle(vlv1);
vl = mesh.to_vertex_handle(vlv1);
vlv1 = mesh.opposite_halfedge_handle(vlv1);
v0vl = mesh.opposite_halfedge_handle(v0vl);
}
// get vr
if (fr.is_valid())
{
if (fr.is_valid()) {
vrv0 = mesh.next_halfedge_handle(v1v0);
v1vr = mesh.next_halfedge_handle(vrv0);
vr = mesh.to_vertex_handle(vrv0);
vr = mesh.to_vertex_handle(vrv0);
vrv0 = mesh.opposite_halfedge_handle(vrv0);
v1vr = mesh.opposite_halfedge_handle(v1vr);
}
}
}
//=============================================================================
} // END_NS_DECIMATER
}// END_NS_DECIMATER
} // END_NS_OPENMESH
//=============================================================================
#endif // OPENMESH_DECIMATER_COLLAPSEINFOT_HH defined
......
This diff is collapsed.
......@@ -30,59 +30,49 @@
* License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 448 $ *
* $Date: 2011-11-04 13:59:37 +0100 (Fri, 04 Nov 2011) $ *
* *
\*===========================================================================*/
\*===========================================================================*/
/** \file ModAspectRatioT.cc
*/
//=============================================================================
//
// CLASS ModAspectRatioT - IMPLEMENTATION
//
//=============================================================================
#define MB_MODASPECTRATIOT_C
#define OPENMESH_DECIMATER_MODASPECTRATIOT_C
//== INCLUDES =================================================================
#include "ModAspectRatioT.hh"
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace OpenMesh {
namespace Decimater {
//== IMPLEMENTATION ==========================================================
template <class DecimaterT>
typename ModAspectRatioT<DecimaterT>::Scalar
ModAspectRatioT<DecimaterT>::
aspectRatio( const Point& _v0,
const Point& _v1,
const Point& _v2 )
{
template<class DecimaterT>
typename ModAspectRatioT<DecimaterT>::Scalar ModAspectRatioT<DecimaterT>::aspectRatio(
const Point& _v0, const Point& _v1, const Point& _v2) {
Point d0 = _v0 - _v1;
Point d1 = _v1 - _v2;
// finds the max squared edge length
Scalar l2, maxl2 = d0.sqrnorm();
if ((l2=d1.sqrnorm()) > maxl2)
if ((l2 = d1.sqrnorm()) > maxl2)
maxl2 = l2;
// keep searching for the max squared edge length
d1 = _v2 - _v0;
if ((l2=d1.sqrnorm()) > maxl2)
if ((l2 = d1.sqrnorm()) > maxl2)
maxl2 = l2;
// squared area of the parallelogram spanned by d0 and d1
......@@ -96,116 +86,93 @@ aspectRatio( const Point& _v0,
// returns the length of the longest edge
// divided by its corresponding height
return sqrt( (maxl2 * maxl2) / a2 );
return sqrt((maxl2 * maxl2) / a2);
}
//-----------------------------------------------------------------------------
template<class DecimaterT>
void ModAspectRatioT<DecimaterT>::initialize() {
typename Mesh::FaceIter f_it, f_end(mesh_.faces_end());
typename Mesh::FVIter fv_it;
template <class DecimaterT>
void
ModAspectRatioT<DecimaterT>::
initialize()
{
typename Mesh::FaceIter f_it, f_end(mesh_.faces_end());
typename Mesh::FVIter fv_it;
for (f_it=mesh_.faces_begin(); f_it!=f_end; ++f_it)
{
typename Mesh::Point& p0 = mesh_.point(fv_it=mesh_.fv_iter(f_it));
for (f_it = mesh_.faces_begin(); f_it != f_end; ++f_it) {
typename Mesh::Point& p0 = mesh_.point(fv_it = mesh_.fv_iter(f_it));
typename Mesh::Point& p1 = mesh_.point(++fv_it);
typename Mesh::Point& p2 = mesh_.point(++fv_it);
mesh_.property(roundness_, f_it) =
1.0/aspectRatio(p0, p1, p2);
mesh_.property(aspect_, f_it) = 1.0 / aspectRatio(p0, p1, p2);
}
}
//-----------------------------------------------------------------------------
template<class DecimaterT>
void ModAspectRatioT<DecimaterT>::preprocess_collapse(const CollapseInfo& _ci) {
typename Mesh::FaceHandle fh;
typename Mesh::FVIter fv_it;
template <class DecimaterT>
void
ModAspectRatioT<DecimaterT>::
preprocess_collapse(const CollapseInfo& _ci)
{
typename Mesh::FaceHandle fh;
typename Mesh::FVIter fv_it;
for (typename Mesh::VFIter vf_it=mesh_.vf_iter(_ci.v0); vf_it; ++vf_it)
{
for (typename Mesh::VFIter vf_it = mesh_.vf_iter(_ci.v0); vf_it; ++vf_it) {
fh = vf_it.handle();
if (fh != _ci.fl && fh != _ci.fr)
{
typename Mesh::Point& p0 = mesh_.point(fv_it=mesh_.fv_iter(fh));
if (fh != _ci.fl && fh != _ci.fr) {
typename Mesh::Point& p0 = mesh_.point(fv_it = mesh_.fv_iter(fh));
typename Mesh::Point& p1 = mesh_.point(++fv_it);
typename Mesh::Point& p2 = mesh_.point(++fv_it);
mesh_.property(roundness_, fh) =
1.0/aspectRatio(p0, p1, p2);
mesh_.property(aspect_, fh) = 1.0 / aspectRatio(p0, p1, p2);
}
}
}
//-----------------------------------------------------------------------------
template <class DecimaterT>
float
ModAspectRatioT<DecimaterT>::
collapse_priority(const CollapseInfo& _ci)
{
typename Mesh::VertexHandle v2, v3;
typename Mesh::FaceHandle fh;
const typename Mesh::Point *p1(&_ci.p1), *p2, *p3;
typename Mesh::Scalar r0, r1, r0_min(1.0), r1_min(1.0);
typename Mesh::CVVIter vv_it(mesh_, _ci.v0);
template<class DecimaterT>
float ModAspectRatioT<DecimaterT>::collapse_priority(const CollapseInfo& _ci) {
typename Mesh::VertexHandle v2, v3;
typename Mesh::FaceHandle fh;
const typename Mesh::Point *p1(&_ci.p1), *p2, *p3;
typename Mesh::Scalar r0, r1, r0_min(1.0), r1_min(1.0);
typename Mesh::CVVIter vv_it(mesh_, _ci.v0);
v3 = vv_it.handle();
p3 = &mesh_.point(v3);
p3 = &mesh_.point(v3);
while (vv_it)
{
while (vv_it) {
v2 = v3;
p2 = p3;
v3 = (++vv_it).handle();
v3 = (++vv_it).handle();
p3 = &mesh_.point(v3);
fh = mesh_.face_handle(vv_it.current_halfedge_handle());
// if not boundary
if (fh.is_valid())
{
// roundness before
if ((r0 = mesh_.property(roundness_,fh)) < r0_min)
r0_min = r0;
if (fh.is_valid()) {
// aspect before
if ((r0 = mesh_.property(aspect_, fh)) < r0_min)
r0_min = r0;
// roundness after
// aspect after
if (!(v2 == _ci.v1 || v3 == _ci.v1))
if ((r1 = 1.0/aspectRatio(*p1, *p2, *p3)) < r1_min)
r1_min = r1;
if ((r1 = 1.0 / aspectRatio(*p1, *p2, *p3)) < r1_min)
r1_min = r1;
}
}
if (Base::is_binary()) {
return
((r1_min > r0_min) || (r1_min > min_aspect_)) ? Base::LEGAL_COLLAPSE :
Base::ILLEGAL_COLLAPSE;
if (Base::is_binary())
{
return ((r1_min > r0_min) || (r1_min > min_roundness_)) ? 0.0 : -1.0;
}
else
{
} else {
if (r1_min > r0_min)
return 1.0 - r1_min;
else
return (r1_min > min_roundness_) ? 2.0 - r1_min : -1.0;
else
return
(r1_min > min_aspect_) ? 2.0 - r1_min : float(Base::ILLEGAL_COLLAPSE);
}
}
//=============================================================================
}
}
......
......@@ -30,114 +30,117 @@
* License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 448 $ *
* $Date: 2011-11-04 13:59:37 +0100 (Fri, 04 Nov 2011) $ *
* *
\*===========================================================================*/
\*===========================================================================*/
/** \file ModAspectRatioT.hh
*/
//=============================================================================
//
// CLASS ModAspectRatioT
//
//=============================================================================
#ifndef MODASPECTRATIOT_HH
#define MODASPECTRATIOT_HH
#ifndef OPENMESH_DECIMATER_MODASPECTRATIOT_HH
#define OPENMESH_DECIMATER_MODASPECTRATIOT_HH
//== INCLUDES =================================================================
#include <OpenMesh/Tools/Decimater/ModBaseT.hh>
#include <OpenMesh/Core/Utils/Property.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace OpenMesh {
namespace Decimater {
//== CLASS DEFINITION =========================================================
/** \brief Use aspect ratio to control decimation
*
* This module computes the aspect ratio.
*
* In binary mode, the collapse is legal if:
* - The aspect ratio after the collapse is greater
* - The aspect ratio after the collapse is greater than the given minimum
*
* In continuous mode the collapse is illegal if:
* - The aspect ratio after the collapse is smaller than the given minimum
*
*
*/
template<class DecimaterT>
class ModAspectRatioT: public ModBaseT<DecimaterT> {
public:
template <class DecimaterT>
class ModAspectRatioT : public ModBaseT<DecimaterT>
{
public:
DECIMATING_MODULE( ModAspectRatioT, DecimaterT, Roundness );
typedef typename Mesh::Scalar Scalar;
typedef typename Mesh::Point Point;
// constructor
ModAspectRatioT(DecimaterT& _dec,
float _min_roundness = 5.0,
bool _is_binary = true)
: Base(_dec, _is_binary),
mesh_(Base::mesh()),
min_roundness_(1.0/_min_roundness)
{
mesh_.add_property( roundness_ );
}
// destructor
~ModAspectRatioT()
{
mesh_.remove_property( roundness_ );
}
/// get roundness
float roundness() const { return 1.0/min_roundness_; }
/// set roundness
void set_roundness(float _f) { min_roundness_ = 1.0/_f; }
// precompute face roundness
void initialize();
// blabla
float collapse_priority(const CollapseInfo& _ci);
// update roundness of one-ring
void preprocess_collapse(const CollapseInfo& _ci);
private:
/** \brief return aspect ratio (length/height) of triangle
*
*/
Scalar aspectRatio( const Point& _v0,
const Point& _v1,
const Point& _v2 );
private:
Mesh& mesh_;
float min_roundness_;
FPropHandleT<float> roundness_;
};
DECIMATING_MODULE( ModAspectRatioT, DecimaterT, Roundness )
;
typedef typename Mesh::Scalar Scalar;
typedef typename Mesh::Point Point;
/// constructor
ModAspectRatioT(DecimaterT& _dec, float _min_aspect = 5.0, bool _is_binary =
true) :
Base(_dec, _is_binary), mesh_(Base::mesh()), min_aspect_(
1.0 / _min_aspect) {
mesh_.add_property(aspect_);
}
/// destructor
~ModAspectRatioT() {
mesh_.remove_property(aspect_);
}
/// get aspect ratio
float aspect_ratio() const {
return 1.0 / min_aspect_;
}
/// set aspect ratio
void set_aspect_ratio(float _f) {
min_aspect_ = 1.0 / _f;
}
/// precompute face aspect ratio
void initialize();
/// Returns the collapse priority
float collapse_priority(const CollapseInfo& _ci);
/// update aspect ratio of one-ring
void preprocess_collapse(const CollapseInfo& _ci);
private:
/** \brief return aspect ratio (length/height) of triangle
*
*/
Scalar aspectRatio(const Point& _v0, const Point& _v1, const Point& _v2);
private:
Mesh& mesh_;
float min_aspect_;
FPropHandleT<float> aspect_;
};
//=============================================================================
} // END_NS_DECIMATER
}// END_NS_DECIMATER
} // END_NS_OPENMESH
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(MB_MODASPECTRATIOT_C)
#define MODASPECTRATIOT_TEMPLATES
#if defined(INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODASPECTRATIOT_C)
#define OPENMESH_DECIMATER_MODASPECTRATIOT_TEMPLATES
#include "ModAspectRatioT.cc"
#endif
//=============================================================================
#endif // MB_MODASPECTRATIOT_HH defined
#endif // OPENMESH_DECIMATER_MODASPECTRATIOT_HH defined
//=============================================================================
......@@ -30,68 +30,52 @@
* License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 448 $ *
* $Date: 2011-11-04 13:59:37 +0100 (Fri, 04 Nov 2011) $ *
* *
\*===========================================================================*/
\*===========================================================================*/
/** \file ModEdgeLengthT.cc
*/
//=============================================================================
//
// CLASS ModEdgeLengthT - IMPLEMENTATION
//
//=============================================================================
#define MODEDGELENGTHT_C
#define OPENMESH_DECIMATER_MODEDGELENGTHT_C
//== INCLUDES =================================================================
#include "ModEdgeLengthT.hh"
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace OpenMesh {
namespace Decimater {
//== IMPLEMENTATION ==========================================================
template <class DecimaterT>
ModEdgeLengthT<DecimaterT>::
ModEdgeLengthT(DecimaterT &_dec, float _edge_length, bool _is_binary)
: Base(_dec, _is_binary),
mesh_(Base::mesh())
{