Commit cb79466d authored by Mike Kremer's avatar Mike Kremer
Browse files

Updated tutorial "Omplementing a mesh smoother plugin". Changed dynamic cast...

Updated tutorial "Omplementing a mesh smoother plugin". Changed dynamic cast of mesh to polymesh to proper PluginFunction::polyMesh and updated comments on how to add a toolbox to OpenFlipper (initializeToolbox() has been replaced by the signal addToolbox()).

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7320 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e68d4038
...@@ -66,41 +66,41 @@ void SmootherPlugin::initializePlugin() ...@@ -66,41 +66,41 @@ void SmootherPlugin::initializePlugin()
emit addToolbox( tr("Smoother") , toolBox ); emit addToolbox( tr("Smoother") , toolBox );
} }
/** \brief /** \brief
* *
*/ */
void SmootherPlugin::simpleLaplace() { void SmootherPlugin::simpleLaplace() {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS); for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS);
o_it != PluginFunctions::objectsEnd(); ++o_it) { 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 // Get the mesh to work on
TriMesh* mesh = PluginFunctions::triMesh(*o_it); TriMesh* mesh = PluginFunctions::triMesh(*o_it);
// Property for the active mesh to store original point positions // 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 // 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 ) // Copy original positions to backup ( in vertex property )
TriMesh::VertexIter v_it, v_end=mesh->vertices_end(); TriMesh::VertexIter v_it, v_end=mesh->vertices_end();
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) { for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
mesh->property( origPositions, 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 ... ) // Do one smoothing step (For each point of the mesh ... )
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) { 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 // Flag, to skip boundary vertices
bool skip = false; bool skip = false;
// ( .. for each outgoing halfedge .. ) // ( .. for each outgoing halfedge .. )
TriMesh::VertexOHalfedgeIter voh_it(*mesh,v_it); TriMesh::VertexOHalfedgeIter voh_it(*mesh,v_it);
...@@ -108,41 +108,41 @@ void SmootherPlugin::simpleLaplace() { ...@@ -108,41 +108,41 @@ void SmootherPlugin::simpleLaplace() {
// .. add the (original) position of the neighbour ( end of the outgoing halfedge ) // .. add the (original) position of the neighbour ( end of the outgoing halfedge )
point += mesh->property( origPositions, 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 // Check if the current Halfedge is a boundary halfedge
// If it is, abort and keep the current vertex position // If it is, abort and keep the current vertex position
if ( mesh->is_boundary( voh_it.handle() ) ) { if ( mesh->is_boundary( voh_it.handle() ) ) {
skip = true; skip = true;
break; break;
} }
} }
// Devide by the valence of the current vertex // Devide by the valence of the current vertex
point /= mesh->valence( v_it ); point /= mesh->valence( v_it );
if ( ! skip ) { if ( ! skip ) {
// Set new position for the mesh if its not on the boundary // Set new position for the mesh if its not on the boundary
mesh->point(v_it) = point; mesh->point(v_it) = point;
} }
} }
}// Iterations end }// Iterations end
// Remove the property // Remove the property
mesh->remove_property( origPositions ); mesh->remove_property( origPositions );
mesh->update_normals(); mesh->update_normals();
emit updatedObject( o_it->id() ); emit updatedObject( o_it->id() );
} else if ( o_it->dataType( DATA_POLY_MESH ) ) { } else if ( o_it->dataType( DATA_POLY_MESH ) ) {
// Get the mesh to work on // Get the mesh to work on
PolyMesh* mesh = dynamic_cast< MeshObject< PolyMesh,DATA_POLY_MESH >* > (*o_it)->mesh(); PolyMesh* mesh = PluginFunctions::polyMesh(*o_it);
// Property for the active mesh to store original point positions // Property for the active mesh to store original point positions
OpenMesh::VPropHandleT< TriMesh::Point > origPositions; OpenMesh::VPropHandleT< PolyMesh::Point > origPositions;
// Add a property to the mesh to store original vertex positions // 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" );
......
...@@ -21,13 +21,12 @@ class SmootherPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingI ...@@ -21,13 +21,12 @@ class SmootherPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingI
//LoggingInterface //LoggingInterface
void log(Logtype _type, QString _message); void log(Logtype _type, QString _message);
void log(QString _message); void log(QString _message);
// ToolboxInterface // ToolboxInterface
void addToolbox( QString _name , QWidget* _widget ); void addToolbox( QString _name, QWidget* _widget );
public: public:
// BaseInterface // BaseInterface
QString name() { return (QString("Simple Smoother")); }; QString name() { return (QString("Simple Smoother")); };
QString description( ) { return (QString("Smooths the active Mesh")); }; QString description( ) { return (QString("Smooths the active Mesh")); };
...@@ -38,11 +37,11 @@ class SmootherPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingI ...@@ -38,11 +37,11 @@ class SmootherPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingI
QSpinBox* iterationsSpinbox_; QSpinBox* iterationsSpinbox_;
private slots: private slots:
// BaseInterface // BaseInterface
void initializePlugin(); void initializePlugin();
void simpleLaplace(); void simpleLaplace();
public slots: public slots:
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* \subsection ex2Header Definition of the header * \subsection ex2Header Definition of the header
* *
* To start of we first have to add two additional header files. The first one is the \c ToolboxInterface. * To start off we first have to add two additional header files. The first one is the \c ToolboxInterface.
* We need this interface because we want to add a Toolbox to our plugin in order to be able to set parameters. * We need this interface because we want to add a Toolbox to our plugin in order to be able to set parameters.
* Additionally, we want to use the \c LoggingInterface so that we can inform the user of our plugin when something * Additionally, we want to use the \c LoggingInterface so that we can inform the user of our plugin when something
* went wrong. * went wrong.
...@@ -45,14 +45,13 @@ ...@@ -45,14 +45,13 @@
* \skipline void log( * \skipline void log(
* \skipline void log( * \skipline void log(
* *
* * The last Interface that's left over is the \c ToolboxInterface from which we are only implenting one signal:
* The last Interface that's left over is the \c ToolboxInterface from which we are only implenting one function:
* *
* \dontinclude example/SmootherPlugin.hh * \dontinclude example/SmootherPlugin.hh
* \skipline bool initializeToolbox * \skipline void addToolbox( QString _name , QWidget* _widget );
* *
* As we will see later, this function is used to setup a ToolBox (i.e. a \c QWidget ) and return a reference of this * As we will see later, this function is used to add a ToolBox (i.e. a \c QWidget ) to
* ToolBox to OpenFlipper so that it can be intergrated into the GUI. * the OpenFlipper user interface.
* *
* As a last step we have to add to include additional class members to control the parameter for the smoothing and * As a last step we have to add to include additional class members to control the parameter for the smoothing and
* to actually compute the smoothed mesh. * to actually compute the smoothed mesh.
...@@ -68,12 +67,13 @@ ...@@ -68,12 +67,13 @@
* *
* \subsection ex2Implemenation1 Implemention of the GUI * \subsection ex2Implemenation1 Implemention of the GUI
* *
* As we have already mentioned in \ref ex2Header, the ToolBox is generated inside the initializeToolbox() function. * As we have already mentioned in \ref ex2Header, the tool box is generated inside the pluginsInitialized() function
* So inside this function we begin with creating the elements of the ToolBox: * and then added by the addToolbox() signal passing a reference to our toolbox.
* So we begin by creating the elements of the ToolBox:
* *
* \dontinclude example/SmootherPlugin.cc * \dontinclude example/SmootherPlugin.cc
* \skipline QWidget * \skipline QWidget
* \until Iterations:"); * \until QLabel* label = new QLabel("Iterations:");
* *
* Later, the smoothButton is used to start the mesh smoothing and the iterationsSpinbox_ allows the user to control * Later, the smoothButton is used to start the mesh smoothing and the iterationsSpinbox_ allows the user to control
* the number of smoothing iterations that should be performed. * the number of smoothing iterations that should be performed.
...@@ -87,12 +87,12 @@ ...@@ -87,12 +87,12 @@
* Here, the SpacerItem, which is added last, only helps aligning the elements at the top of the toolbox. * Here, the SpacerItem, which is added last, only helps aligning the elements at the top of the toolbox.
* *
* We have to connect the smoothButton to the simpleLaplace() slot of our class, so that after clicking * We have to connect the smoothButton to the simpleLaplace() slot of our class, so that after clicking
* the button the slot is called. Finally, we return a reference to the new Toolbox by assigning it to _widget and * the button the slot is called. Finally, when the tool box has been
* return true because we succesfully created the Toolbox. * entirely created, we emit the signal to add the tool box to OpenFlipper:
* *
* \dontinclude example/SmootherPlugin.cc * \dontinclude example/SmootherPlugin.cc
* \skipline connect * \skipline connect
* \until true; * \until emit addToolbox( tr("Smoother") , toolBox );
* *
* *
* \subsection ex2Implemenation2 Implemention of the Smoother * \subsection ex2Implemenation2 Implemention of the Smoother
...@@ -147,6 +147,13 @@ ...@@ -147,6 +147,13 @@
* \skipline // Remove the propert * \skipline // Remove the propert
* \until mesh->update_normals(); * \until mesh->update_normals();
* *
* We now implement the same procedure for arbitrary polygonal meshes using the
* template types of OpenMesh. Starting at line (see \ref com_src_ex2 for the complete
* source code of this example plugin):
*
* \dontinclude example/SmootherPlugin.cc
* \skipline } else if ( o_it->dataType( DATA_POLY_MESH ) ) {
*
* The next step is to tell the OpenFlipper core that our plugin has updated an object in the scene. * The next step is to tell the OpenFlipper core that our plugin has updated an object in the scene.
* The affected object will then be redrawn. See \ref geometryData for information on how to handle geometry data in a plugin. * The affected object will then be redrawn. See \ref geometryData for information on how to handle geometry data in a plugin.
* *
...@@ -171,6 +178,6 @@ ...@@ -171,6 +178,6 @@
* SmootherPlugin.cc * SmootherPlugin.cc
* \include example/SmootherPlugin.cc * \include example/SmootherPlugin.cc
* *
* We use the qmake project file presented in \ref ex1b to build this plugin. * We use the cmake project file presented in \ref ex1c to build this plugin.
* * (Or you can also use the obsolete qmake project file presented in \ref ex1b.)
*/ */
\ No newline at end of file
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