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

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7197 383ad7c9-94d9-4d36-a494-682f7c89f535
parents
include (plugin)
openflipper_plugin ()
#include <QtGui>
#include "IsotropicRemesherPlugin.hh"
#include "IsotropicRemesherT.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
/// init the Toolbox
bool IsotropicRemesherPlugin::initializeToolbox(QWidget*& _widget) {
tool_ = new IsotropicRemesherToolBox();
_widget = tool_;
QSize size(300, 300);
tool_->resize(size);
connect(tool_->remeshButton, SIGNAL(clicked()), this, SLOT(slotRemesh()) );
connect(tool_->minEdgeLength, SIGNAL(clicked()), this, SLOT(slotSetMinLength()) );
connect(tool_->maxEdgeLength, SIGNAL(clicked()), this, SLOT(slotSetMaxLength()) );
connect(tool_->meanEdgeLength, SIGNAL(clicked()), this, SLOT(slotSetMeanLength()) );
return true;
}
void IsotropicRemesherPlugin::slotRemesh(){
//read one target objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH)) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
//check dataType
if ( o_it->dataType(DATA_TRIANGLE_MESH) ) {
double edgeLength = tool_->targetEdgeLength->value();
TriMesh* mesh = PluginFunctions::triMesh(o_it);
IsotropicRemesher< TriMesh > remesher;
remesher.remesh(*mesh, edgeLength);
mesh->update_normals();
emit updatedObject( o_it->id() );
emit updateView();
}else{
emit log("Remeshing currently only implemented for triangle Meshes");
}
}
}
void IsotropicRemesherPlugin::slotSetMinLength()
{
double current = 0.0;
bool first = true;
bool ok;
emit functionExists( "info" , "minEdgeLength(int)", ok ) ;
if (!ok)
return;
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType(DATA_TRIANGLE_MESH)) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (first)
{
current = RPC::callFunctionValue<double>("info" , "minEdgeLength",o_it->id() );
first = false;
}
else
current = qMin (current, RPC::callFunctionValue<double>("info" , "minEdgeLength",o_it->id() ));
}
if (!first)
tool_->targetEdgeLength->setValue (current);
}
void IsotropicRemesherPlugin::slotSetMaxLength()
{
double current = 0.0;
bool first = true;
bool ok;
emit functionExists( "info" , "maxEdgeLength(int)", ok ) ;
if (!ok)
return;
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType(DATA_TRIANGLE_MESH)) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (first)
{
current = RPC::callFunctionValue<double>("info" , "maxEdgeLength",o_it->id() );
first = false;
}
else
current = qMax (current, RPC::callFunctionValue<double>("info" , "maxEdgeLength",o_it->id() ));
}
if (!first)
tool_->targetEdgeLength->setValue (current);
}
void IsotropicRemesherPlugin::slotSetMeanLength()
{
double current = 0.0;
int div = 0;
bool ok;
emit functionExists( "info" , "edgeCount(int)", ok ) ;
if (!ok)
return;
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType(DATA_TRIANGLE_MESH)) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
current += RPC::callFunctionValue<int> ("info" , "edgeCount",o_it->id()) *
RPC::callFunctionValue<double>("info" , "meanEdgeLength",o_it->id() );
div += RPC::callFunctionValue<int> ("info" , "edgeCount",o_it->id() );
}
if (div > 0)
tool_->targetEdgeLength->setValue (current / div);
}
/// Initialize the plugin
void IsotropicRemesherPlugin::pluginsInitialized(){
emit setSlotDescription("isotropicRemesh(int,double)", "Isotropic Remeshing",
QString("object_id,targetEdgeLength").split(","),
QString("id of an object, target edge length").split(","));
}
void IsotropicRemesherPlugin::isotropicRemesh(int _objectID, double _targetEdgeLength ){
BaseObjectData* object = 0;
if ( PluginFunctions::getObject(_objectID, object) ){
//check dataType
if ( object->dataType(DATA_TRIANGLE_MESH)) {
TriMesh* mesh = PluginFunctions::triMesh(object);
IsotropicRemesher< TriMesh > remesher;
remesher.remesh(*mesh, _targetEdgeLength);
mesh->update_normals();
emit updatedObject( object->id() );
emit updateView();
return;
}else{
emit log("Remeshing currently only implemented for triangle Meshes");
return;
}
}else{
emit log("Unable to get object");
}
}
Q_EXPORT_PLUGIN2( isotropicRemesherPlugin , IsotropicRemesherPlugin );
#ifndef ISOTROPICREMESHERPLUGIN_HH
#define ISOTROPICREMESHERPLUGIN_HH
#include <QtGui>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include "IsotropicRemesherToolbox.hh"
class IsotropicRemesherPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface, RPCInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(RPCInterface)
//BaseInterface
signals:
void updateView();
void updatedObject(int);
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 );
private slots:
void pluginsInitialized(); // BaseInterface
public :
~IsotropicRemesherPlugin() {};
bool initializeToolbox(QWidget*& _widget); // ToolboxInterface
QString name() { return (QString("IsotropicRemesher")); };
QString description( ) { return (QString("an isotropic remesher")); };
//GUI
private :
IsotropicRemesherToolBox* tool_;
private slots:
void slotRemesh();
void slotSetMinLength();
void slotSetMaxLength();
void slotSetMeanLength();
//scripting functions
public slots:
void isotropicRemesh(int _objectID, double _targetEdgeLength );
public slots:
QString version() { return QString("1.0"); };
};
#endif //ISOTROPICREMESHERPLUGIN_HH
This diff is collapsed.
#ifndef ISOTROPICREMESHER_HH
#define ISOTROPICREMESHER_HH
template< class MeshT >
class IsotropicRemesher{
public:
IsotropicRemesher() {};
~IsotropicRemesher() {};
void remesh( MeshT& _mesh, const double _targetEdgeLength );
private:
void splitLongEdges( MeshT& _mesh, const double _maxEdgeLength );
void collapseShortEdges( MeshT& _mesh, const double _minEdgeLength, const double _maxEdgeLength );
void equalizeValences( MeshT& _mesh );
inline
int targetValence( MeshT& _mesh, const typename MeshT::VertexHandle& _vh );
void tangentialRelaxation( MeshT& _mesh );
template <class SpatialSearchT>
typename MeshT::Point
findNearestPoint(const MeshT& _mesh,
const typename MeshT::Point& _point,
typename MeshT::FaceHandle& _fh,
SpatialSearchT* _ssearch,
double* _dbest);
OpenMeshTriangleBSPT< MeshT >* getTriangleBSP(MeshT& _mesh);
template< class SpatialSearchT >
void projectToSurface( MeshT& _mesh, MeshT& _original, SpatialSearchT* _ssearch );
inline
bool isBoundary( MeshT& _mesh, const typename MeshT::VertexHandle& _vh);
};
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(ISOTROPICREMESHER_C)
#define ISOTROPICREMESHER_TEMPLATES
#include "IsotropicRemesherT.cc"
#endif
//=============================================================================
#endif // ISOTROPICREMESHER_HH defined
//=============================================================================
#include "IsotropicRemesherToolbox.hh"
#include <QtGui>
IsotropicRemesherToolBox::IsotropicRemesherToolBox(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
void IsotropicRemesherToolBox::showEvent ( QShowEvent * _event )
{
QWidget::showEvent ( _event );
emit showing();
}
#include "ui_toolbox.hh"
#include <QtGui>
#include <iostream>
class IsotropicRemesherToolBox : public QWidget, public Ui::IsotropicRemesherTool
{
Q_OBJECT
signals:
// emitted when the widget will get visible
void showing();
public:
IsotropicRemesherToolBox(QWidget *parent = 0);
protected:
void showEvent ( QShowEvent * _event );
};
################################################################################
#
################################################################################
include( $$TOPDIR/qmake/all.include )
Plugin()
DIRECTORIES = .
# Input
HEADERS += $$getFilesFromDir($$DIRECTORIES,*.hh)
SOURCES += $$getFilesFromDir($$DIRECTORIES,*.cc)
FORMS += $$getFilesFromDir($$DIRECTORIES,*.ui)
################################################################################
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IsotropicRemesherTool</class>
<widget class="QWidget" name="IsotropicRemesherTool">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>286</width>
<height>286</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string> Isotropic Remeshing </string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Set target Object edge length:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="minEdgeLength">
<property name="text">
<string>Min</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="meanEdgeLength">
<property name="text">
<string>Mean</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="maxEdgeLength">
<property name="text">
<string>Max</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Target Edge Length:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="targetEdgeLength">
<property name="decimals">
<number>6</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="remeshButton">
<property name="text">
<string>Remesh</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>275</width>
<height>119</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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