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

Renamed to Remesher

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12766 383ad7c9-94d9-4d36-a494-682f7c89f535
parents
This diff is collapsed.
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper 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. *
* *
* OpenFlipper 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 OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#ifndef ADVANCEDREMESHERPLUGIN_HH
#define ADVANCEDREMESHERPLUGIN_HH
#include <QtGui>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/BasePlugin/ProcessInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include "AdvancedRemesherToolbox.hh"
#include "ProgressEmitter.hh"
class AdvancedRemesherPlugin : public QObject, BaseInterface, BackupInterface, ToolboxInterface, LoggingInterface, RPCInterface, ProcessInterface, ScriptInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(BackupInterface)
Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(RPCInterface)
Q_INTERFACES(ProcessInterface)
Q_INTERFACES(ScriptInterface)
signals:
//BaseInterface
void updateView();
void updatedObject(int _id, const UpdateType _type);
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
//LoggingInterface:
void log( Logtype _type, QString _message );
void log( QString _message );
// RPC Interface
void pluginExists( QString _pluginName , bool& _exists ) ;
void functionExists( QString _pluginName , QString _functionName , bool& _exists );
// ToolboxInterface
void addToolbox( QString _name , QWidget* _widget, QIcon* _icon );
// ProcessInterface
void startJob( QString _jobId, QString _description, int _min, int _max, bool _blocking = false);
void setJobState(QString _jobId, int _value);
void setJobName(QString _jobId, QString _name);
void finishJob(QString _jobId);
void setJobDescription(QString _jobId, QString _description);
// BackupInterface
void createBackup(int _id , QString _name, UpdateType _type = UPDATE_ALL);
// ScriptInterface
void scriptInfo(QString _functionName);
private slots:
// BaseInterface
void initializePlugin();
void pluginsInitialized(); // BaseInterface
public :
AdvancedRemesherPlugin();
~AdvancedRemesherPlugin();
QString name() { return (QString("AdvancedRemesher")); };
QString description( ) { return (QString("An advanced remesher plugin.")); };
//GUI
private :
AdvancedRemesherToolBox* tool_;
ProgressEmitter* progress_;
QIcon* toolIcon_;
private slots:
//---- Adaptive Remeshing ------------
void adaptiveRemeshingButtonClicked();
void adaptiveRemeshing();
//---- Adaptive Remeshing ------------
void uniformRemeshingButtonClicked();
void uniformRemeshing();
//------------------------------------
void threadFinished(QString _jobId);
//------------------------------------
/// Compute mean edge length and set values
void computeInitValues();
//scripting functions
public slots:
void adaptiveRemeshing(int _objectId,
double _error,
double _min_edge_length,
double _max_edge_length,
unsigned int _iters,
bool _use_projection = true);
void uniformRemeshing(int _objectId,
double _edge_length,
unsigned int _iters,
unsigned int _area_iters,
bool _use_projection = true);
public slots:
QString version() { return QString("1.0"); };
};
#endif //ADVANCEDREMESHERPLUGIN_HH
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper 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. *
* *
* OpenFlipper 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 OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#include "AdvancedRemesherToolbox.hh"
#include <QtGui>
AdvancedRemesherToolBox::AdvancedRemesherToolBox(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
void AdvancedRemesherToolBox::showEvent ( QShowEvent * _event )
{
QWidget::showEvent ( _event );
emit showing();
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper 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. *
* *
* OpenFlipper 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 OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#include "ui_toolbox.hh"
#include <QtGui>
#include <iostream>
class AdvancedRemesherToolBox : public QWidget, public Ui::AdvancedRemesherTool
{
Q_OBJECT
signals:
// emitted when the widget will get visible
void showing();
public:
AdvancedRemesherToolBox(QWidget *parent = 0);
protected:
void showEvent ( QShowEvent * _event );
};
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper 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. *
* *
* OpenFlipper 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 OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS AdaptiveRemesherT - IMPLEMENTATION
//
//=============================================================================
#define ADAPTIVE_REMESHERT_C
//== INCLUDES =================================================================
#include "AdaptiveRemesherT.hh"
#include <ACG/Geometry/Algorithms.hh>
#include "DiffGeoT.hh"
//== NAMESPACES ===============================================================
namespace Remeshing {
//== IMPLEMENTATION ==========================================================
template <class Mesh>
void
AdaptiveRemesherT<Mesh>::
init_reference()
{
Base::init_reference();
// compute max curvature on both meshes
Base::refmesh_->add_property(refcurv_);
compute_curvature(*Base::refmesh_, refcurv_);
Base::mesh_.add_property(curvature_);
compute_curvature(Base::mesh_, curvature_);
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
AdaptiveRemesherT<Mesh>::
project_to_reference(typename Mesh::VertexHandle _vh) const
{
typename Mesh::Point p = Base::mesh_.point(_vh);
typename Mesh::FaceHandle fh = Base::bsp_->nearest(p).handle;
typename Mesh::CFVIter fv_it = Base::refmesh_->cfv_iter(fh);
const typename Mesh::Point& p0 = Base::refmesh_->point(fv_it);
typename Mesh::Normal n0 = Base::refmesh_->normal(fv_it);
typename Mesh::Scalar c0 = Base::refmesh_->property(refcurv_, fv_it);
const typename Mesh::Point& p1 = Base::refmesh_->point(++fv_it);
typename Mesh::Normal n1 = Base::refmesh_->normal(fv_it);
typename Mesh::Scalar c1 = Base::refmesh_->property(refcurv_, fv_it);
const typename Mesh::Point& p2 = Base::refmesh_->point(++fv_it);
typename Mesh::Normal n2 = Base::refmesh_->normal(fv_it);
typename Mesh::Scalar c2 = Base::refmesh_->property(refcurv_, fv_it);
// project
//Geometry::dist_point_triangle(p, p0, p1, p2, p);
ACG::Geometry::distPointTriangle<typename Mesh::Point>(p, p0, p1, p2, p);
Base::mesh_.set_point(_vh, p);
// get barycentric coordinates
if (!ACG::Geometry::baryCoord(p, p0, p1, p2, p))
p[0] = p[1] = p[2] = 1.0/3.0;
// interpolate normal
typename Mesh::Normal n;
n = (n0 *= p[0]);
n += (n1 *= p[1]);
n += (n2 *= p[2]);
n.normalize();
Base::mesh_.set_normal(_vh, n);
// interpolate curvature
typename Mesh::Scalar c;
c = (c0 *= p[0]);
c += (c1 *= p[1]);
c += (c2 *= p[2]);
Base::mesh_.property(curvature_, _vh) = c;
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
AdaptiveRemesherT<Mesh>::
compute_curvature(Mesh& _mesh, OpenMesh::VPropHandleT<Scalar> _ph)
{
DiffGeoT<Mesh> diffgeo(_mesh);
diffgeo.compute(2);
typename Mesh::VIter v_it, v_end(_mesh.vertices_end());
for (v_it=_mesh.vertices_begin(); v_it!=v_end; ++v_it)
_mesh.property(_ph, v_it) = diffgeo.max_curvature(v_it);
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
AdaptiveRemesherT<Mesh>::
remesh(Scalar _error,
Scalar _emin,
Scalar _emax,
unsigned int _iters,
bool _use_projection)
{
// set thesholds
error_ = _error;
emin_ = _emin;
emax_ = _emax;
// do it
Base::remesh(_iters, 0, _use_projection);
// free curvature property (refmesh has been deleted already)
Base::mesh_.remove_property(curvature_);
}
//-----------------------------------------------------------------------------
template <class Mesh>
bool
AdaptiveRemesherT<Mesh>::
is_too_long(VertexHandle v0, VertexHandle v1) const
{
const Point& p0 = Base::mesh_.point(v0);
const Point& p1 = Base::mesh_.point(v1);
Scalar c = 0.5 * ( Base::mesh_.property(curvature_, v0) +
Base::mesh_.property(curvature_, v1) );
Scalar e = 2.0/c*error_ - error_*error_;
e = (e <= 0.0 ? error_ : 2.0*sqrt(e));
if (e<emin_) e=emin_; else if (e>emax_) e=emax_;
Scalar emax = 4.0/3.0 * e;
return ((p0 - p1).sqrnorm() > emax*emax);
}
//-----------------------------------------------------------------------------
template <class Mesh>
bool
AdaptiveRemesherT<Mesh>::
is_too_short(VertexHandle v0, VertexHandle v1) const
{
const Point& p0 = Base::mesh_.point(v0);
const Point& p1 = Base::mesh_.point(v1);
Scalar c = 0.5 * ( Base::mesh_.property(curvature_, v0) +
Base::mesh_.property(curvature_, v1) );
Scalar e = 2.0/c*error_ - error_*error_;
e = (e <= 0.0 ? error_ : 2.0*sqrt(e));
if (e<emin_) e=emin_; else if (e>emax_) e=emax_;
Scalar emin = 4.0/5.0 * e;
return ((p0 - p1).sqrnorm() < emin*emin);
}
//=============================================================================
} // namespace Remeshing
//=============================================================================
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper 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. *
* *
* OpenFlipper 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 OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS AdaptiveRemesherT
//
//=============================================================================
#ifndef ADAPTIVE_REMESHERT_HH
#define ADAPTIVE_REMESHERT_HH
//== INCLUDES =================================================================
#include "BaseRemesherT.hh"
#include "DiffGeoT.hh"
#include <OpenMesh/Core/Utils/Property.hh>
#include "../ProgressEmitter.hh"
//== NAMESPACES ===============================================================
namespace Remeshing {
//== CLASS DEFINITION =========================================================
template <class Mesh>
class AdaptiveRemesherT : public BaseRemesherT<Mesh>
{
public:
typedef BaseRemesherT<Mesh> Base;
typedef typename Mesh::Scalar Scalar;
typedef typename Mesh::Point Point;
typedef typename Mesh::EdgeHandle EdgeHandle;
typedef typename Mesh::VertexHandle VertexHandle;
AdaptiveRemesherT(Mesh& _mesh, ProgressEmitter* _progress = NULL) : Base(_mesh, _progress) {}
void remesh(Scalar _error,
Scalar _min_edge_length,
Scalar _max_edge_length,
unsigned int _iters,
bool _use_projection = true);
protected:
virtual void init_reference();
virtual void project_to_reference(VertexHandle _vh) const;
void compute_curvature(Mesh& _mesh, OpenMesh::VPropHandleT<Scalar> _ph);
virtual bool is_too_long (VertexHandle _v0, VertexHandle _v1) const;
virtual bool is_too_short (VertexHandle _v0, VertexHandle _v1) const;
protected:
Scalar error_, emax_, emin_;
OpenMesh::VPropHandleT<Scalar> refcurv_, curvature_;
};
//=============================================================================
} // namespace Remeshing
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(ADAPTIVE_REMESHERT_C)
#define ADAPTIVE_REMESHERT_TEMPLATES
#include "AdaptiveRemesherT.cc"
#endif
//=============================================================================
#endif // ADAPTIVE_REMESHERT_HH defined