Commit b167e436 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5074 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 06cd8966
......@@ -115,9 +115,6 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
/// Description of the Plugin
QString description() { return (QString("Manages Data Objects")); };
/// User selected plugins Toolbox
void toolboxActivated( bool /* _activated */ ) { };
/// Update the visualization of the active objects
void update_active( );
......
......@@ -86,6 +86,59 @@ slot_decimate()
emit updateView();
}
//-----------------------------------------------------------------------------
void DecimaterPlugin::decimate(int _objID, QString _constraints, QString _values){
BaseObjectData* baseObjectData;
if ( ! PluginFunctions::getObject(_objID,baseObjectData) ) {
emit log(LOGERR,"Unable to get Object");
return;
}
if ( baseObjectData->dataType() == DATA_TRIANGLE_MESH ) {
TriMeshObject* object = PluginFunctions::triMeshObject(baseObjectData);
if ( object == 0 ) {
emit log(LOGWARN , "Unable to get object ( Only Triangle Meshes supported)");
return;
}
DecimaterInfo* decimater = dynamic_cast< DecimaterInfo* > ( object->objectData(DECIMATER) );
if (decimater == 0){
TriMesh* mesh = PluginFunctions::triMesh(*object);
decimater = new DecimaterInfo( tool_, mesh );
object->setObjectData(DECIMATER, decimater);
}
decimater->update();
if( ! decimater->decimater()->is_initialized() ){
emit log(LOGWARN, "Decimater could not be initialized");
continue;
}
//decimate
if ( tool_->cbTriangles->isChecked() )
decimater->decimater()->decimate_to( tool_->triangleCount->value() ); // do decimation
else
decimater->decimater()->decimate(); // do decimation
object->mesh()->garbage_collection();
object->mesh()->update_normals();
object->update();
} else {
emit log(LOGERR,"Unsupported object type for decimater");
return;
}
}
//-----------------------------------------------------------------------------
Q_EXPORT_PLUGIN2( DecimaterPlugin , DecimaterPlugin );
......
......@@ -46,29 +46,26 @@ class DecimaterPlugin : public QObject, BaseInterface, ToolboxInterface, Logging
signals:
/// Force Examiner widget to update their views
// BaseInterface
void updateView();
void updatedObject(int);
void activeObjectChanged();
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
// LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
/// Emit this Signal, if object list has changed (e.g. Source or Target changed)
void updatedObject(int);
void activeObjectChanged();
public :
// default constructor
DecimaterPlugin()
: tool_(0)
{};
/// Default constructor
DecimaterPlugin() : tool_(0) {};
// default destructor
/// Default destructor
~DecimaterPlugin() {};
/** Initialize the toolbar (create a widget in the right side toolbox) */
/// Initialize the toolbar (create a widget in the right side toolbox)
bool initializeToolbox(QWidget*& _widget);
/// Name of the Plugin
......@@ -77,10 +74,6 @@ public :
/// Description of the Plugin
QString description() { return (QString("Mesh Decimation ...")); };
/// User selected plugins Toolbox
void toolboxActivated( bool /*_activated*/ ) {};
private :
/// Widget for Toolbox
......@@ -88,11 +81,23 @@ private :
private slots:
/// decimating called from button in toolbox
void slot_decimate();
//===========================================================================
/** @name Scripting Functions
* @{ */
//===========================================================================
public slots:
void decimate(int _objID, QString _constraints, QString _values);
public slots:
QString version() { return QString("1.0"); };
/** @} */
};
#endif //DECIMATERPLUGIN_HH
......@@ -127,22 +127,6 @@ bool MovePlugin::initializeToolbox(QWidget*& _widget)
}
//------------------------------------------------------------------------------
/** \brief Toolbox state changes
*
* @param _activated new state
*/
void MovePlugin::toolboxActivated( bool _activated )
{
toolboxActive_ = _activated;
showManipulators();
emit updateView();
}
/*******************************************************************************
MouseInterface implementation
*******************************************************************************/
......
......@@ -95,9 +95,6 @@ class MovePlugin : public QObject, BaseInterface, MouseInterface, PickingInterfa
/// Description of the Plugin
QString description() { return (QString("Moves Meshes with Manipulators")); };
/// User selected plugins Toolbox
void toolboxActivated( bool _activated );
//===========================================================================
/** @name ToolBox
* @{ */
......
......@@ -150,7 +150,6 @@ class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInter
~SelectionPlugin() {};
//Toolbox Interface
bool initializeToolbox(QWidget*& _widget);
void toolboxActivated( bool /*_activated*/ ){};
//BaseInterface
QString name() { return (QString("Selections")); };
QString description( ) { return (QString("Allows to select parts of Objects")); };
......
......@@ -31,123 +31,128 @@
#include <QtGui>
#include <QSpacerItem>
#include "SmootherPlugin.hh"
#include <iostream>
#include <ACG/GL/GLState.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
bool SmootherPlugin::initializeToolbox(QWidget*& _widget)
bool SmootherPlugin::initializeToolbox(QWidget*& _widget)
{
// Create the Toolbox Widget
tool_ = new QWidget();
_widget = tool_;
QSize size(300, 300);
tool_->resize(size);
MeshDialogLayout_ = new QGridLayout( tool_);
QWidget* toolBox = new QWidget();
_widget = toolBox;
QGridLayout* layout = new QGridLayout(toolBox);
smoothButton_ = new QPushButton("&Smooth",tool_);
QPushButton* smoothButton = new QPushButton("&Smooth",toolBox);
iterationsSpinbox_ = new QSpinBox(tool_) ;
iterationsSpinbox_ = new QSpinBox(toolBox) ;
iterationsSpinbox_->setMinimum(1);
iterationsSpinbox_->setMaximum(1000);
iterationsSpinbox_->setSingleStep(1);
smootherTypeBox_ = new QComboBox();
smootherTypeBox_->addItem("Simple Laplace");
QLabel* label = new QLabel("Iterations:");
layout->addWidget( label , 0, 0);
layout->addWidget( smoothButton , 1, 1);
layout->addWidget( iterationsSpinbox_, 0, 1);
MeshDialogLayout_->addWidget( smootherTypeBox_,0 , 0 , 1 , 2 , Qt::AlignTop );
MeshDialogLayout_->addWidget( smoothButton_ , 1, 0 , Qt::AlignTop );
MeshDialogLayout_->addWidget( iterationsSpinbox_, 1, 1 , Qt::AlignTop );
MeshDialogLayout_->addItem(new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Expanding),2,0,1,2);
layout->addItem(new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Expanding),2,0,1,2);
connect(smoothButton_,SIGNAL(clicked()),this,SLOT(slotSmooth()));
connect( smoothButton, SIGNAL(clicked()), this, SLOT(simpleLaplace()) );
return true;
}
/** \brief
*
*/
void SmootherPlugin::simpleLaplace() {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_TRIANGLE_MESH) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
// Get the mesh to work on
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) {
// Get the mesh to work on
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
// Property for the active mesh to store original point positions
OpenMesh::VPropHandleT< TriMesh::Point > origPositions;
// Add a property to the mesh to store original vertex positions
mesh->add_property( orig_pos_, "SmootherPlugin_Original_Positions" );
mesh->add_property( origPositions, "SmootherPlugin_Original_Positions" );
for ( int i = 0 ; i < iterationsSpinbox_->value() ; ++i ) {
// Copy original positions to backup ( in Vertex property )
TriMesh::VertexIter v_it, v_end=mesh->vertices_end();
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
mesh->property( orig_pos_ , v_it ) = mesh->point(v_it);
}
// Do one smoothing step (For each point of the mesh ... )
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
// Copy original positions to backup ( in Vertex property )
TriMesh::VertexIter v_it, v_end=mesh->vertices_end();
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
mesh->property( origPositions, v_it ) = mesh->point(v_it);
}
// Do one smoothing step (For each point of the mesh ... )
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
TriMesh::Point point = TriMesh::Point(0.0,0.0,0.0);
// Flag, to skip boundary vertices
bool skip = false;
// ( .. for each Outoing halfedge .. )
TriMesh::VertexOHalfedgeIter voh_it(*mesh,v_it);
for ( ; voh_it; ++voh_it ) {
// .. add the (original) position of the Neighbour ( end of the outgoing halfedge )
point += mesh->property( orig_pos_ , mesh->to_vertex_handle(voh_it) );
// Check if the current Halfedge is a boundary halfedge
// If it is, abort and keep the current vertex position
if ( mesh->is_boundary( voh_it.handle() ) ) {
// .. add the (original) position of the Neighbour ( end of the outgoing halfedge )
point += mesh->property( origPositions, mesh->to_vertex_handle(voh_it) );
// Check if the current Halfedge is a boundary halfedge
// If it is, abort and keep the current vertex position
if ( mesh->is_boundary( voh_it.handle() ) ) {
skip = true;
break;
}
}
}
// Devide by the valence of the current vertex
point /= mesh->valence( v_it );
if ( ! skip ) {
// Set new position for the mesh if its not on the boundary
mesh->point(v_it) = point;
// Set new position for the mesh if its not on the boundary
mesh->point(v_it) = point;
}
}
}
}// Iterations end
// Remove the property
mesh->remove_property( orig_pos_);
mesh->remove_property( origPositions );
mesh->update_normals();
emit updatedObject( o_it->id() );
}
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_POLY_MESH) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
} else if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) {
// Get the mesh to work on
PolyMesh* mesh = dynamic_cast< MeshObject< PolyMesh,DATA_POLY_MESH >* > (*o_it)->mesh();
// Property for the active mesh to store original point positions
OpenMesh::VPropHandleT< TriMesh::Point > origPositions;
// Add a property to the mesh to store original vertex positions
mesh->add_property( orig_pos_, "SmootherPlugin_Original_Positions" );
mesh->add_property( origPositions, "SmootherPlugin_Original_Positions" );
for ( int i = 0 ; i < iterationsSpinbox_->value() ; ++i ) {
// Copy original positions to backup ( in Vertex property )
PolyMesh::VertexIter v_it, v_end=mesh->vertices_end();
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
mesh->property( orig_pos_ , v_it ) = mesh->point(v_it);
mesh->property( origPositions, v_it ) = mesh->point(v_it);
}
// Do one smoothing step (For each point of the mesh ... )
......@@ -162,7 +167,7 @@ void SmootherPlugin::simpleLaplace() {
PolyMesh::VertexOHalfedgeIter voh_it(*mesh,v_it);
for ( ; voh_it; ++voh_it ) {
// .. add the (original) position of the Neighbour ( end of the outgoing halfedge )
point += mesh->property( orig_pos_ , mesh->to_vertex_handle(voh_it) );
point += mesh->property( origPositions, mesh->to_vertex_handle(voh_it) );
// Check if the current Halfedge is a boundary halfedge
// If it is, abort and keep the current vertex position
......@@ -185,23 +190,16 @@ void SmootherPlugin::simpleLaplace() {
}// Iterations end
// Remove the property
mesh->remove_property( orig_pos_);
mesh->remove_property( origPositions );
mesh->update_normals();
emit updatedObject( o_it->id() );
}
}
} else {
void SmootherPlugin::slotSmooth()
{
switch (smootherTypeBox_->currentIndex() ) {
case 0 :
simpleLaplace();
break;
default :
std::cerr << "Smoother : Smoother type error" << std::endl;
emit log(LOGERR, "DataType not supported.");
}
}
}
......
......@@ -35,61 +35,43 @@
#ifndef SMOOTHERPLUGIN_HH
#define SMOOTHERPLUGIN_HH
#include <QObject>
#include <QMenuBar>
#include <QSpinBox>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
class SmootherPlugin : public QObject, BaseInterface, ToolboxInterface
class SmootherPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ToolboxInterface)
signals:
void updateView();
void updatedObject(int);
public :
~SmootherPlugin() {};
bool initializeToolbox(QWidget*& _widget);
void toolboxActivated( bool /*_activated*/ ){ };
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(LoggingInterface)
QString name() { return (QString("Simple Smoother")); };
QString description( ) { return (QString("Smooths the active Mesh")); };
signals:
//BaseInterface
void updateView();
void updatedObject(int _id);
private :
//LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
/// Widget for Toolbox
QWidget* tool_;
public:
/// Layout for Toolbox
QGridLayout* MeshDialogLayout_;
// ToolboxInterface
bool initializeToolbox(QWidget*& _widget);
/// Button for slotTransfer
QPushButton* smoothButton_;
// BaseInterface
QString name() { return (QString("Simple Smoother")); };
QString description( ) { return (QString("Smooths the active Mesh")); };
/// SpinBox for Number of iterations
QSpinBox* iterationsSpinbox_;
private:
QComboBox* smootherTypeBox_;
/// Property for the active mesh to store original point positions
OpenMesh::VPropHandleT< TriMesh::Point > orig_pos_;
void simpleLaplace();
/// SpinBox for Number of iterations
QSpinBox* iterationsSpinbox_;
private slots:
void slotSmooth();
void simpleLaplace();
public slots:
QString version() { return QString("1.0"); };
......
......@@ -73,9 +73,6 @@ public :
/// Description of the Plugin
QString description() { return (QString("Mesh Smoothing ...")); };
/// User selected plugins Toolbox
void toolboxActivated( bool /*_activated*/ ) {};
private slots:
/// Second initialization stage
......
Supports Markdown
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