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

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
...@@ -64,6 +64,10 @@ ...@@ -64,6 +64,10 @@
#include <OpenMesh/Tools/Utils/getopt.h> #include <OpenMesh/Tools/Utils/getopt.h>
#include <OpenMesh/Tools/Utils/Timer.hh> #include <OpenMesh/Tools/Utils/Timer.hh>
#include <OpenMesh/Tools/Decimater/DecimaterT.hh> #include <OpenMesh/Tools/Decimater/DecimaterT.hh>
#include <OpenMesh/Tools/Decimater/ModAspectRatioT.hh>
#include <OpenMesh/Tools/Decimater/ModEdgeLengthT.hh>
#include <OpenMesh/Tools/Decimater/ModHausdorffT.hh>
#include <OpenMesh/Tools/Decimater/ModNormalDeviationT.hh>
#include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh> #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
#include <OpenMesh/Tools/Decimater/ModQuadricT.hh> #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
#include <OpenMesh/Tools/Decimater/ModProgMeshT.hh> #include <OpenMesh/Tools/Decimater/ModProgMeshT.hh>
...@@ -116,13 +120,17 @@ struct DecOptions ...@@ -116,13 +120,17 @@ struct DecOptions
CmdOption<bool> decorate_name; CmdOption<bool> decorate_name;
CmdOption<float> n_collapses; CmdOption<float> n_collapses;
CmdOption<float> Q; // Quadrics
CmdOption<float> NF; // Normal Flipping CmdOption<float> AR; // Aspect ratio
CmdOption<float> EL; // Edge length
CmdOption<float> HD; // Hausdorff distance
CmdOption<bool> IS; // Independent Sets CmdOption<bool> IS; // Independent Sets
CmdOption<float> ND; // Normal deviation
CmdOption<float> NF; // Normal flipping
CmdOption<std::string> PM; // Progressive Mesh CmdOption<std::string> PM; // Progressive Mesh
CmdOption<float> Q; // Quadrics
CmdOption<float> R; // Roundness CmdOption<float> R; // Roundness
template <typename T> template <typename T>
bool init( CmdOption<T>& _o, const std::string& _val ) bool init( CmdOption<T>& _o, const std::string& _val )
{ {
...@@ -160,15 +168,18 @@ struct DecOptions ...@@ -160,15 +168,18 @@ struct DecOptions
strip(name); strip(name);
strip(value); strip(value);
if (name == "Q") return init(Q, value); if (name == "AR") return init(AR, value);
if (name == "EL") return init(EL, value);
if (name == "HD") return init(HD, value);
if (name == "IS") return init(IS, value);
if (name == "ND") return init(ND, value);
if (name == "NF") return init(NF, value); if (name == "NF") return init(NF, value);
if (name == "PM") return init(PM, value); if (name == "PM") return init(PM, value);
if (name == "IS") return init(IS, value); if (name == "Q") return init(Q, value);
if (name == "R") return init(R, value); if (name == "R") return init(R, value);
return false; return false;
} }
std::string& strip(std::string & line) std::string& strip(std::string & line)
{ {
std::string::size_type pos = 0; std::string::size_type pos = 0;
...@@ -238,18 +249,52 @@ decimate(const std::string &_ifname, ...@@ -238,18 +249,52 @@ decimate(const std::string &_ifname,
// ---- 1 - create decimater instance // ---- 1 - create decimater instance
Decimater decimater( mesh ); Decimater decimater( mesh );
// ---- 2 - registrate modules // ---- 2 - register modules
if (gverbose) if (gverbose)
clog << " registrate modules" << endl; clog << " register modules" << endl;
typename OpenMesh::Decimater::ModQuadricT<Decimater>::Handle modQ;
if (_opt.Q.is_enabled()) typename OpenMesh::Decimater::ModAspectRatioT<Decimater>::Handle modAR;
if (_opt.AR.is_enabled())
{ {
decimater.add(modQ); decimater.add(modAR);
if (_opt.Q.has_value()) if (_opt.AR.has_value())
decimater.module( modQ ).set_max_err( _opt.Q ); decimater.module( modAR ).set_aspect_ratio( _opt.AR ) ;
}
typename OpenMesh::Decimater::ModEdgeLengthT<Decimater>::Handle modEL;
if (_opt.EL.is_enabled())
{
decimater.add(modEL);
if (_opt.EL.has_value())
decimater.module( modEL ).set_edge_length( _opt.EL ) ;
}
typename OpenMesh::Decimater::ModHausdorffT <Decimater>::Handle modHD;
if (_opt.HD.is_enabled())
{
decimater.add(modHD);
if (_opt.HD.has_value())
decimater.module( modHD ).set_tolerance( _opt.HD ) ;
}
typename OpenMesh::Decimater::ModIndependentSetsT<Decimater>::Handle modIS;
if ( _opt.IS.is_enabled() )
decimater.add(modIS);
typename OpenMesh::Decimater::ModNormalDeviationT<Decimater>::Handle modND;
if (_opt.ND.is_enabled())
{
decimater.add(modND);
if (_opt.ND.has_value())
decimater.module( modND ).set_normal_deviation( _opt.ND );
} }
typename OpenMesh::Decimater::ModNormalFlippingT<Decimater>::Handle modNF; typename OpenMesh::Decimater::ModNormalFlippingT<Decimater>::Handle modNF;
...@@ -258,20 +303,23 @@ decimate(const std::string &_ifname, ...@@ -258,20 +303,23 @@ decimate(const std::string &_ifname,
{ {
decimater.add(modNF); decimater.add(modNF);
if (_opt.NF.has_value()) if (_opt.NF.has_value())
decimater.module( modNF ).set_normal_deviation( _opt.NF ); decimater.module( modNF ).set_max_normal_deviation( _opt.NF );
} }
typename OpenMesh::Decimater::ModProgMeshT<Decimater>::Handle modPM; typename OpenMesh::Decimater::ModProgMeshT<Decimater>::Handle modPM;
if ( _opt.PM.is_enabled() ) if ( _opt.PM.is_enabled() )
decimater.add(modPM); decimater.add(modPM);
typename OpenMesh::Decimater::ModQuadricT<Decimater>::Handle modQ;
typename OpenMesh::Decimater::ModIndependentSetsT<Decimater>::Handle modIS; if (_opt.Q.is_enabled())
{
if ( _opt.IS.is_enabled() ) decimater.add(modQ);
decimater.add(modIS); if (_opt.Q.has_value())
decimater.module( modQ ).set_max_err( _opt.Q );
}
typename OpenMesh::Decimater::ModRoundnessT<Decimater>::Handle modR; typename OpenMesh::Decimater::ModRoundnessT<Decimater>::Handle modR;
...@@ -475,26 +523,25 @@ void usage_and_exit(int xcode) ...@@ -475,26 +523,25 @@ void usage_and_exit(int xcode)
} }
std::cerr << std::endl; std::cerr << std::endl;
if (xcode) if (xcode) {
{
std::cerr << "Error " << xcode << ": " << errmsg << std::endl << std::endl; std::cerr << "Error " << xcode << ": " << errmsg << std::endl << std::endl;
} }
std::cerr << "Usage: decimator [Options] -i input-file -o output-file\n" std::cerr << "Usage: decimator [Options] -i input-file -o output-file\n"
<< " Decimating a mesh using quadrics and normal flipping.\n" << " Decimating a mesh using quadrics and normal flipping.\n" << std::endl;
<< std::endl; std::cerr << "Options\n" << std::endl;
std::cerr << "Options\n"
<< std::endl;
std::cerr << " -M \"{Module-Name}[:Value]}\"\n" std::cerr << " -M \"{Module-Name}[:Value]}\"\n"
<< " Use named module with eventually given parameterization\n" << " Use named module with eventually given parameterization\n" << std::endl;
<< std::endl;
std::cerr << " -n <N>\n" std::cerr << " -n <N>\n"
<< " N >= 1: do N halfedge collapses.\n" << " N >= 1: do N halfedge collapses.\n"
<< " N <=-1: decimate down to |N| vertices.\n" << " N <=-1: decimate down to |N| vertices.\n"
<< " 0 < N < 1: decimate down to N%.\n" << " 0 < N < 1: decimate down to N%.\n" << std::endl;
<< std::endl;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "Modules:\n\n"; std::cerr << "Modules:\n\n";
std::cerr << " AR[:ratio] - ModAspectRatio\n";
std::cerr << " EL[:legth] - ModEdgeLength\n";
std::cerr << " HD[:distance] - ModHausdorff\n";
std::cerr << " IS - ModIndependentSets\n"; std::cerr << " IS - ModIndependentSets\n";
std::cerr << " ND[:angle] - ModNormalDeviation\n";
std::cerr << " NF[:angle] - ModNormalFlipping\n"; std::cerr << " NF[:angle] - ModNormalFlipping\n";
std::cerr << " PM[:file name] - ModProgMesh\n"; std::cerr << " PM[:file name] - ModProgMesh\n";
std::cerr << " Q[:error] - ModQuadric\n"; std::cerr << " Q[:error] - ModQuadric\n";
......
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Date$ * * $Date$ *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/** \file CollapseInfoT.hh /** \file CollapseInfoT.hh
Provides data class CollapseInfoT for storing all information Provides data class CollapseInfoT for storing all information
...@@ -49,20 +49,16 @@ ...@@ -49,20 +49,16 @@
// STRUCT CollpaseInfoT // STRUCT CollpaseInfoT
// //
//============================================================================= //=============================================================================
#ifndef OPENMESH_DECIMATER_COLLAPSEINFOT_HH #ifndef OPENMESH_DECIMATER_COLLAPSEINFOT_HH
#define OPENMESH_DECIMATER_COLLAPSEINFOT_HH #define OPENMESH_DECIMATER_COLLAPSEINFOT_HH
//== INCLUDES ================================================================= //== INCLUDES =================================================================
//== NAMESPACE ================================================================ //== NAMESPACE ================================================================
namespace OpenMesh { namespace OpenMesh {
namespace Decimater { namespace Decimater {
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
/** Stores information about a halfedge collapse. /** Stores information about a halfedge collapse.
...@@ -73,10 +69,9 @@ namespace Decimater { ...@@ -73,10 +69,9 @@ namespace Decimater {
\image html collapse_info.png \image html collapse_info.png
\see ModProgMeshT::Info \see ModProgMeshT::Info
*/ */
template <class Mesh> template<class Mesh>
struct CollapseInfoT struct CollapseInfoT {
{ public:
public:
/** Initializing constructor. /** Initializing constructor.
* *
* Given a mesh and a halfedge handle of the halfedge to be collapsed * Given a mesh and a halfedge handle of the halfedge to be collapsed
...@@ -108,49 +103,38 @@ public: ...@@ -108,49 +103,38 @@ public:
//@} //@}
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/**
// CollapseInfoT::CollapseInfoT( _mesh, _heh ) * Local configuration of halfedge collapse to be stored in CollapseInfoT:
// *
// Local configuration of halfedge collapse to be stored in CollapseInfoT: * vl
/* * *
vl * / \
* * / \
/ \ * / fl \
/ \ * v0 *------>* v1
/ fl \ * \ fr /
v0 *------>* v1 * \ /
\ fr / * \ /
\ / * *
\ / * vr
* *
vr *
* @param _mesh Reference to mesh
* @param _heh The halfedge (v0 -> v1) defining the collapse
*/ */
// Parameters: template<class Mesh>
// _mesh Reference to mesh inline CollapseInfoT<Mesh>::CollapseInfoT(Mesh& _mesh,
// _heh The halfedge (v0 -> v1) defining the collapse typename Mesh::HalfedgeHandle _heh) :
// mesh(_mesh), v0v1(_heh), v1v0(_mesh.opposite_halfedge_handle(v0v1)), v0(
template <class Mesh> _mesh.to_vertex_handle(v1v0)), v1(_mesh.to_vertex_handle(v0v1)), p0(
inline _mesh.point(v0)), p1(_mesh.point(v1)), fl(_mesh.face_handle(v0v1)), fr(
CollapseInfoT<Mesh>:: _mesh.face_handle(v1v0))
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 // get vl
if (fl.is_valid()) if (fl.is_valid()) {
{
vlv1 = mesh.next_halfedge_handle(v0v1); vlv1 = mesh.next_halfedge_handle(v0v1);
v0vl = mesh.next_halfedge_handle(vlv1); v0vl = mesh.next_halfedge_handle(vlv1);
vl = mesh.to_vertex_handle(vlv1); vl = mesh.to_vertex_handle(vlv1);
...@@ -158,10 +142,8 @@ CollapseInfoT(Mesh& _mesh, typename Mesh::HalfedgeHandle _heh) : ...@@ -158,10 +142,8 @@ CollapseInfoT(Mesh& _mesh, typename Mesh::HalfedgeHandle _heh) :
v0vl = mesh.opposite_halfedge_handle(v0vl); v0vl = mesh.opposite_halfedge_handle(v0vl);
} }
// get vr // get vr
if (fr.is_valid()) if (fr.is_valid()) {
{
vrv0 = mesh.next_halfedge_handle(v1v0); vrv0 = mesh.next_halfedge_handle(v1v0);
v1vr = mesh.next_halfedge_handle(vrv0); v1vr = mesh.next_halfedge_handle(vrv0);
vr = mesh.to_vertex_handle(vrv0); vr = mesh.to_vertex_handle(vrv0);
...@@ -171,7 +153,7 @@ CollapseInfoT(Mesh& _mesh, typename Mesh::HalfedgeHandle _heh) : ...@@ -171,7 +153,7 @@ CollapseInfoT(Mesh& _mesh, typename Mesh::HalfedgeHandle _heh) :
} }
//============================================================================= //=============================================================================
} // END_NS_DECIMATER }// END_NS_DECIMATER
} // END_NS_OPENMESH } // END_NS_OPENMESH
//============================================================================= //=============================================================================
#endif // OPENMESH_DECIMATER_COLLAPSEINFOT_HH defined #endif // OPENMESH_DECIMATER_COLLAPSEINFOT_HH defined
......
...@@ -30,28 +30,25 @@ ...@@ -30,28 +30,25 @@
* License along with OpenMesh. If not, * * License along with OpenMesh. If not, *
* see <http://www.gnu.org/licenses/>. * * see <http://www.gnu.org/licenses/>. *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/*===========================================================================*\ /*===========================================================================*\
* * * *
* $Revision$ * * $Revision$ *
* $Date$ * * $Date$ *
* * * *
\*===========================================================================*/ \*===========================================================================*/
/** \file DecimaterT.cc /** \file DecimaterT.cc
*/ */
//============================================================================= //=============================================================================
// //
// CLASS DecimaterT - IMPLEMENTATION // CLASS DecimaterT - IMPLEMENTATION
// //
//============================================================================= //=============================================================================
#define OPENMESH_DECIMATER_DECIMATERT_CC #define OPENMESH_DECIMATER_DECIMATERT_CC
//== INCLUDES ================================================================= //== INCLUDES =================================================================
#include <OpenMesh/Tools/Decimater/DecimaterT.hh> #include <OpenMesh/Tools/Decimater/DecimaterT.hh>
...@@ -63,26 +60,16 @@ ...@@ -63,26 +60,16 @@
# include <cfloat> # include <cfloat>
#endif #endif
//== NAMESPACE =============================================================== //== NAMESPACE ===============================================================
namespace OpenMesh { namespace OpenMesh {
namespace Decimater { namespace Decimater {
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
template<class Mesh>
DecimaterT<Mesh>::DecimaterT(Mesh& _mesh) :
template <class Mesh> mesh_(_mesh), heap_(NULL), cmodule_(NULL), initialized_(false) {
DecimaterT<Mesh>::
DecimaterT( Mesh& _mesh )
: mesh_(_mesh),
heap_(NULL),
cmodule_(NULL),
initialized_(false)
{
// default properties // default properties
mesh_.request_vertex_status(); mesh_.request_vertex_status();
mesh_.request_edge_status(); mesh_.request_edge_status();
...@@ -90,19 +77,15 @@ DecimaterT( Mesh& _mesh ) ...@@ -90,19 +77,15 @@ DecimaterT( Mesh& _mesh )
mesh_.request_face_normals(); mesh_.request_face_normals();
// private vertex properties // private vertex properties
mesh_.add_property( collapse_target_ ); mesh_.add_property(collapse_target_);
mesh_.add_property( priority_ ); mesh_.add_property(priority_);
mesh_.add_property( heap_position_ ); mesh_.add_property(heap_position_);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template<class Mesh>
template <class Mesh> DecimaterT<Mesh>::~DecimaterT() {
DecimaterT<Mesh>::
~DecimaterT()
{
// default properties // default properties
mesh_.release_vertex_status(); mesh_.release_vertex_status();
mesh_.release_edge_status(); mesh_.release_edge_status();
...@@ -118,40 +101,33 @@ DecimaterT<Mesh>:: ...@@ -118,40 +101,33 @@ DecimaterT<Mesh>::
{ {
set_uninitialized(); set_uninitialized();
typename ModuleList::iterator m_it, m_end = all_modules_.end(); typename ModuleList::iterator m_it, m_end = all_modules_.end();
for( m_it=all_modules_.begin(); m_it!=m_end; ++m_it) for (m_it = all_modules_.begin(); m_it != m_end; ++m_it)
delete *m_it; delete *m_it;
all_modules_.clear(); all_modules_.clear();
} }
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template<class Mesh>
template <class Mesh> void DecimaterT<Mesh>::info(std::ostream& _os) {
void if (initialized_) {
DecimaterT<Mesh>::
info( std::ostream& _os )
{
if(initialized_)
{
_os << "initialized : yes" << std::endl; _os << "initialized : yes" << std::endl;
_os << "binary modules: " << bmodules_.size() << std::endl; _os << "binary modules: " << bmodules_.size() << std::endl;
for( ModuleListIterator m_it=bmodules_.begin(); m_it!=bmodules_.end(); ++m_it) for (ModuleListIterator m_it = bmodules_.begin(); m_it != bmodules_.end();
{ ++m_it) {
_os << " " << (*m_it)->name() << std::endl; _os << " " << (*m_it)->name() << std::endl;
} }
_os << "priority module: " << cmodule_->name().c_str() << std::endl; _os << "priority module: " << cmodule_->name().c_str() << std::endl;
} } else {
else {
_os << "initialized : no" << std::endl; _os << "initialized : no" << std::endl;
_os << "available modules: " << all_modules_.size() << std::endl; _os << "available modules: " << all_modules_.size() << std::endl;
for( ModuleListIterator m_it=all_modules_.begin(); m_it!=all_modules_.end(); ++m_it) for (ModuleListIterator m_it = all_modules_.begin();
{ m_it != all_modules_.end(); ++m_it) {
_os << " " << (*m_it)->name() << " : "; _os << " " << (*m_it)->name() << " : ";
if((*m_it)->is_binary()) { if ((*m_it)->is_binary()) {
_os << "binary"; _os << "binary";
if((*m_it)->name() == "Quadric") { if ((*m_it)->name() == "Quadric") {
_os << " and priority (special treatment)";