Commit ad4ee279 authored by Isaak Lim's avatar Isaak Lim

Switched to using the Decimater Mod AspectRatio from OpenMesh.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12853 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0a735b6d
//=============================================================================
//
// CLASS ModRoundnessT - IMPLEMENTATION
//
//=============================================================================
#define MB_MODROUNDNESST_C
//== INCLUDES =================================================================
#include "ModRoundnessT.hh"
#include <ACG/Geometry/Algorithms.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Decimater {
//== IMPLEMENTATION ==========================================================
template <class DecimaterT>
void
ModRoundnessT<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));
typename Mesh::Point& p1 = mesh_.point(++fv_it);
typename Mesh::Point& p2 = mesh_.point(++fv_it);
mesh_.property(roundness_, f_it) =
1.0/ACG::Geometry::aspectRatio(p0, p1, p2);
}
}
//-----------------------------------------------------------------------------
template <class DecimaterT>
void
ModRoundnessT<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)
{
fh = vf_it.handle();
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/ACG::Geometry::aspectRatio(p0, p1, p2);
}
}
}
//-----------------------------------------------------------------------------
template <class DecimaterT>
float
ModRoundnessT<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);
while (vv_it)
{
v2 = v3;
p2 = p3;
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;
// roundness after
if (!(v2 == _ci.v1 || v3 == _ci.v1))
if ((r1 = 1.0/ACG::Geometry::aspectRatio(*p1, *p2, *p3)) < r1_min)
r1_min = r1;
}
}
if (Base::is_binary())
{
return ((r1_min > r0_min) || (r1_min > min_roundness_)) ? 0.0 : -1.0;
}
else
{
if (r1_min > r0_min)
return 1.0 - r1_min;
else
return (r1_min > min_roundness_) ? 2.0 - r1_min : -1.0;
}
}
//=============================================================================
}
}
//=============================================================================
//=============================================================================
//
// CLASS ModRoundnessT
//
//=============================================================================
#ifndef MB_MODROUNDNESST_HH
#define MB_MODROUNDNESST_HH
//== INCLUDES =================================================================
#include <OpenMesh/Tools/Decimater/ModBaseT.hh>
#include <OpenMesh/Core/Utils/Property.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Decimater {
//== CLASS DEFINITION =========================================================
template <class DecimaterT>
class ModRoundnessT : public ModBaseT<DecimaterT>
{
public:
DECIMATING_MODULE( ModRoundnessT, DecimaterT, Roundness );
// constructor
ModRoundnessT(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
~ModRoundnessT()
{
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:
Mesh& mesh_;
float min_roundness_;
FPropHandleT<float> roundness_;
};
//=============================================================================
}
}
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(MB_MODROUNDNESST_C)
#define MB_MODROUNDNESST_TEMPLATES
#include "ModRoundnessT.cc"
#endif
//=============================================================================
#endif // MB_MODROUNDNESST_HH defined
//=============================================================================
......@@ -257,7 +257,7 @@ void DecimaterPlugin::slot_decimate() {
ModNormalFlippingH hModNormalFlipping;
ModHausdorffH hModHausdorff;
ModNormalDeviationH hModNormalDeviation;
ModRoundnessH hModRoundness;
ModAspectRatioH hModAspectRatio;
ModEdgeLengthH hModEdgeLength;
// remove old constraints first
......@@ -265,7 +265,7 @@ void DecimaterPlugin::slot_decimate() {
decimater_object.remove(hModHausdorff);
decimater_object.remove(hModNormalDeviation);
decimater_object.remove(hModNormalFlipping);
decimater_object.remove(hModRoundness);
decimater_object.remove(hModAspectRatio);
decimater_object.remove(hModEdgeLength);
// priority module: quadrics, normal dev or edge length
......@@ -283,7 +283,7 @@ void DecimaterPlugin::slot_decimate() {
// binary modules (order wrt. computation cost)
if (tool_->cbEdgeLength->isChecked()) decimater_object.add(hModEdgeLength);
if (tool_->cbAspectRatio->isChecked()) decimater_object.add(hModRoundness);
if (tool_->cbAspectRatio->isChecked()) decimater_object.add(hModAspectRatio);
if (tool_->cbNormalDev->isChecked()) decimater_object.add(hModNormalDeviation);
else decimater_object.add(hModNormalFlipping);
if (tool_->cbDistance->isChecked()) decimater_object.add(hModHausdorff);
......@@ -311,8 +311,8 @@ void DecimaterPlugin::slot_decimate() {
decimater_object.module(hModNormalDeviation).set_normal_deviation(tool_->normalDev->value());
// roundness
if (tool_->aspectRatio->value() >= 0.0 && hModRoundness.is_valid())
decimater_object.module(hModRoundness).set_roundness(tool_->aspectRatio->value());
if (tool_->aspectRatio->value() >= 0.0 && hModAspectRatio.is_valid())
decimater_object.module(hModAspectRatio).set_roundness(tool_->aspectRatio->value());
// edge length
if (tool_->edgeLength->value() >= 0.0 && hModEdgeLength.is_valid())
......
......@@ -60,8 +60,7 @@
#include <OpenMesh/Tools/Decimater/ModHausdorffT.hh>
#include <OpenMesh/Tools/Decimater/ModNormalDeviationT.hh>
#include <OpenMesh/Tools/Decimater/ModEdgeLengthT.hh>
#include "Decimater/DecimaterMods/ModRoundnessT.hh"
#include <OpenMesh/Tools/Decimater/ModAspectRatioT.hh>
//== CLASS DEFINITION =========================================================
......@@ -109,7 +108,7 @@ private:
typedef OpenMesh::Decimater::ModNormalFlippingT< DecimaterType >::Handle ModNormalFlippingH;
typedef OpenMesh::Decimater::ModHausdorffT< DecimaterType >::Handle ModHausdorffH;
typedef OpenMesh::Decimater::ModNormalDeviationT< DecimaterType >::Handle ModNormalDeviationH;
typedef OpenMesh::Decimater::ModRoundnessT< DecimaterType >::Handle ModRoundnessH;
typedef OpenMesh::Decimater::ModAspectRatioT< DecimaterType >::Handle ModAspectRatioH;
typedef OpenMesh::Decimater::ModEdgeLengthT< DecimaterType >::Handle ModEdgeLengthH;
private slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment