Commit 274517b1 authored by Jan Möbius's avatar Jan Möbius

Fixed examples



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13346 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 17398b88
......@@ -38,16 +38,23 @@
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
/*
* Initialize plugin
* Constructor
*/
void MouseAndKeyPlugin::initializePlugin() {
MouseAndKeyPlugin::MouseAndKeyPlugin() :
contextMenuEntry_(0),
tool_(0),
pickButton_(0),
activeObject_(-1),
axis_x_(ACG::Vec3d(1.0, 0.0, 0.0)),
axis_y_(ACG::Vec3d(0.0, 1.0, 0.0))
{
// Set active object to -1
activeObject_ = -1;
}
// Set rotation axes to x, y and z axis
axis_x_ = ACG::Vec3d(1.0, 0.0, 0.0);
axis_y_ = ACG::Vec3d(0.0, 1.0, 0.0);
/*
* Initialize plugin
*/
void MouseAndKeyPlugin::initializePlugin() {
// Register keys
emit registerKey(Qt::Key_W, Qt::NoModifier, "Rotate object down");
......@@ -55,31 +62,31 @@ void MouseAndKeyPlugin::initializePlugin() {
emit registerKey(Qt::Key_A, Qt::NoModifier, "Rotate object left");
emit registerKey(Qt::Key_D, Qt::NoModifier, "Rotate object right");
tool_ = new QWidget();
QSize size(300, 300);
tool_->resize(size);
// Create button that can be toggled
// to (de)activate plugin's picking mode
pickButton_ = new QPushButton(tr("Select object"));
pickButton_->setCheckable(true);
// Create label
QLabel* label = new QLabel();
label->setText("(De)activate pick mode");
// Set label to be above the button
QGridLayout* grid = new QGridLayout;
grid->addWidget(label, 0, 0);
grid->addWidget(pickButton_, 1, 0);
tool_->setLayout(grid);
// Connect button to slotButtonClicked()
connect( pickButton_, SIGNAL(clicked()), this, SLOT(slotButtonClicked()));
// Add the Toolbox
emit addToolbox( tr("Mouse and Key") , tool_ );
tool_ = new QWidget();
QSize size(300, 300);
tool_->resize(size);
// Create button that can be toggled
// to (de)activate plugin's picking mode
pickButton_ = new QPushButton(tr("Select object"));
pickButton_->setCheckable(true);
// Create label
QLabel* label = new QLabel();
label->setText("(De)activate pick mode");
// Set label to be above the button
QGridLayout* grid = new QGridLayout;
grid->addWidget(label, 0, 0);
grid->addWidget(pickButton_, 1, 0);
tool_->setLayout(grid);
// Connect button to slotButtonClicked()
connect(pickButton_, SIGNAL(clicked()), this, SLOT(slotButtonClicked()));
// Add the Toolbox
emit addToolbox(tr("Mouse and Key"), tool_);
} // End initializePlugin
......
......@@ -31,7 +31,7 @@ class MouseAndKeyPlugin: public QObject,
//BaseInterface
void updateView();
void updatedObject(int _id);
void updatedObject(int _identifier, const UpdateType& _type);
//LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
......@@ -39,12 +39,13 @@ class MouseAndKeyPlugin: public QObject,
void addContextMenuItem(QAction* _action , ContextMenuType _type);
void addContextMenuItem(QAction* _action , DataType _objectType , ContextMenuType _type );
//PickingInterface
void addPickMode(const std::string _mode);
void addHiddenPickMode(const std::string _mode);
void addPickMode(const std::string& _mode);
void addHiddenPickMode(const std::string& _mode);
//KeyInterface
void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
// ToolboxInterface
void addToolbox( QString _name , QWidget* _widget );
// ToolboxInterface
void addToolbox(QString _name, QWidget* _widget);
private slots:
......@@ -64,6 +65,8 @@ class MouseAndKeyPlugin: public QObject,
QString name() {return (QString("Mouse and Keyboard Plugin"));};
QString description() {return (QString("Shows some basic mouse and key embedding"));};
MouseAndKeyPlugin();
private:
// Transform geometry with given Matrix
......
......@@ -39,14 +39,20 @@
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
SmootherPlugin::SmootherPlugin() :
iterationsSpinbox_(0)
{
}
void SmootherPlugin::initializePlugin()
{
// Create the Toolbox Widget
QWidget* toolBox = new QWidget();
QPushButton* smoothButton = new QPushButton("&Smooth",toolBox);
QPushButton* smoothButton = new QPushButton("&Smooth", toolBox);
iterationsSpinbox_ = new QSpinBox(toolBox) ;
iterationsSpinbox_ = new QSpinBox(toolBox);
iterationsSpinbox_->setMinimum(1);
iterationsSpinbox_->setMaximum(1000);
iterationsSpinbox_->setSingleStep(1);
......@@ -55,146 +61,146 @@ void SmootherPlugin::initializePlugin()
QGridLayout* layout = new QGridLayout(toolBox);
layout->addWidget( label , 0, 0);
layout->addWidget( smoothButton , 1, 1);
layout->addWidget( iterationsSpinbox_, 0, 1);
layout->addWidget(label, 0, 0);
layout->addWidget(smoothButton, 1, 1);
layout->addWidget(iterationsSpinbox_, 0, 1);
layout->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(simpleLaplace()) );
connect(smoothButton, SIGNAL(clicked()), this, SLOT(simpleLaplace()));
emit addToolbox( tr("Smoother") , toolBox );
emit addToolbox(tr("Smoother"), toolBox);
}
/** \brief
*
*/
void SmootherPlugin::simpleLaplace() {
void SmootherPlugin::simpleLaplace()
{
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS);
o_it != PluginFunctions::objectsEnd(); ++o_it) {
for (PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS); o_it != PluginFunctions::objectsEnd();
++o_it) {
if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) {
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;
OpenMesh::VPropHandleT<TriMesh::Point> origPositions;
// Add a property to the mesh to store original vertex positions
mesh->add_property( origPositions, "SmootherPlugin_Original_Positions" );
mesh->add_property(origPositions, "SmootherPlugin_Original_Positions");
for ( int i = 0 ; i < iterationsSpinbox_->value() ; ++i ) {
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( origPositions, v_it ) = mesh->point(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) {
// 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);
TriMesh::Point point = TriMesh::Point(0.0, 0.0, 0.0);
// Flag, to skip boundary vertices
bool skip = false;
// Flag, to skip boundary vertices
bool skip = false;
// ( .. for each outgoing halfedge .. )
TriMesh::VertexOHalfedgeIter voh_it(*mesh,v_it);
// ( .. for each outgoing halfedge .. )
TriMesh::VertexOHalfedgeIter voh_it(*mesh, v_it);
for ( ; voh_it; ++voh_it ) {
for (; voh_it; ++voh_it) {
// .. add the (original) position of the neighbour ( end of the outgoing halfedge )
point += mesh->property( origPositions, mesh->to_vertex_handle(voh_it) );
// .. 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;
}
}
// 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 );
// 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;
}
}
if (!skip) {
// Set new position for the mesh if its not on the boundary
mesh->point(v_it) = point;
}
}
}// Iterations end
} // Iterations end
// Remove the property
mesh->remove_property( origPositions );
mesh->remove_property(origPositions);
mesh->update_normals();
emit updatedObject( o_it->id() );
emit updatedObject(o_it->id(),UPDATE_GEOMETRY);
} else if ( o_it->dataType( DATA_POLY_MESH ) ) {
} else if (o_it->dataType(DATA_POLY_MESH)) {
// Get the mesh to work on
PolyMesh* mesh = PluginFunctions::polyMesh(*o_it);
// Property for the active mesh to store original point positions
OpenMesh::VPropHandleT< PolyMesh::Point > origPositions;
OpenMesh::VPropHandleT<PolyMesh::Point> origPositions;
// Add a property to the mesh to store original vertex positions
mesh->add_property( origPositions, "SmootherPlugin_Original_Positions" );
mesh->add_property(origPositions, "SmootherPlugin_Original_Positions");
for ( int i = 0 ; i < iterationsSpinbox_->value() ; ++i ) {
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( origPositions, v_it ) = mesh->point(v_it);
}
// 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(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) {
// Do one smoothing step (For each point of the mesh ... )
for (v_it = mesh->vertices_begin(); v_it != v_end; ++v_it) {
PolyMesh::Point point = PolyMesh::Point(0.0,0.0,0.0);
PolyMesh::Point point = PolyMesh::Point(0.0, 0.0, 0.0);
// Flag, to skip boundary vertices
bool skip = false;
// Flag, to skip boundary vertices
bool skip = false;
// ( .. for each Outoing halfedge .. )
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( origPositions, mesh->to_vertex_handle(voh_it) );
// ( .. for each Outoing halfedge .. )
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(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;
}
// 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 );
// 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;
}
}
if (!skip) {
// Set new position for the mesh if its not on the boundary
mesh->point(v_it) = point;
}
}
}// Iterations end
} // Iterations end
// Remove the property
mesh->remove_property( origPositions );
mesh->remove_property(origPositions);
mesh->update_normals();
emit updatedObject( o_it->id() );
emit updatedObject(o_it->id(),UPDATE_GEOMETRY);
} else {
......@@ -204,6 +210,5 @@ void SmootherPlugin::simpleLaplace() {
}
}
Q_EXPORT_PLUGIN2( smootherplugin , SmootherPlugin );
Q_EXPORT_PLUGIN2( smootherplugin, SmootherPlugin);
......@@ -16,7 +16,7 @@ class SmootherPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingI
signals:
//BaseInterface
void updateView();
void updatedObject(int _id);
void updatedObject(int _identifier, const UpdateType& _type);
//LoggingInterface
void log(Logtype _type, QString _message);
......@@ -25,6 +25,8 @@ class SmootherPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingI
// ToolboxInterface
void addToolbox( QString _name, QWidget* _widget );
SmootherPlugin();
public:
// BaseInterface
......
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