MeshLab: Development page : Create a Filter-plugin


How to

To create a new filter plug-in the first step is to considerate that you must implement the "MeshFilterInterface" interface; you can find it in "meshlab/interfaces.h".

Then you create a new class filter which must inherit from the interface and from Object. This involves you specifying the two keywords "Q_OBJECT" and "Q_INTERFACES(MeshFilterInterface)" before the method declaration to permit the moc'ing phases.

It is essential to import of the mesh definition found in "meshlab/meshmodel.h".

The new filter plug-in class must have an action container like "QList <QAction *>", where you can store all the actions you implement in your class; QList <QAction*> must be populated in the constructor.

Then you implement the following four pure virtual methods:

QList<QAction *> actions() // return the list of actions to create the menu on the toolbar
virtual const ActionInfo &Info(QAction *)//?
virtual const PluginInfo &Info()//?
virtual bool applyFilter(QAction * /*filter*/, MeshModel & /*m*/, QWidget * /*parent*/, vcg::CallBackPos* /*cb*/)
// Discriminate on the filter to apply by the action name. Its parameters are:
||    * The filter action
||    * The Mesh
||    * The QWidget parent to possibly create the dialog to set some variables
||    * The call-back function to update the progress-bar

Important:
Before performing a filter function call it is good practice to check that the characteristics of the mesh (topology, normal, texture and so on) are up to date; otherwise you should call the specific method.

Example

Example.h

#ifndef EXAMPLEPLUGIN_H
#define EXAMPLEPLUGIN_H

#include <QObject>
#include <QStringList>
#include <QList>

class ExampleMeshFilterPlugin : public QObject, public MeshFilterInterface
{
    Q_OBJECT
    Q_INTERFACES(MeshFilterInterface)
       
public:
    ExampleMeshFilterPlugin();
    virtual const ActionInfo &Info(QAction *);
    virtual const PluginInfo &Info();
    virtual QList<QAction *> actions() const;
    bool applyFilter(QAction *filter, MeshModel &m, QWidget *parent, vcg::CallBackPos * cb) ;

protected:
    QList <QAction *> actionList;
};

#endif



Example.cpp

#include <QtGui>
#include <stdlib.h>
#include "meshfilter.h"
#include <vcg/complex/trimesh/clean.h>
#include <vcg/complex/trimesh/smooth.h>

ExampleMeshFilterPlugin::ExampleMeshFilterPlugin() 
{

    actionList << new QAction("ExampleFilter", this);
}

QList<QAction *> ExampleMeshFilterPlugin::actions() const 
{

    return actionList;
}

const ActionInfo &ExampleMeshFilterPlugin::Info(QAction *action)
{
   ActionInfo ai;
    if( action->text() == tr("ExampleFilter") )
        {
            ai.Help = tr("explain yuor method");
            ai.ShortHelp = tr("For tooltip");
        }
   return ai;
 }

const PluginInfo &ExampleMeshFilterPlugin::Info()
{
   static PluginInfo ai;
   ai.Date=tr("__DATE__");
     ai.Version = tr("Current version");
     ai.Author = ("Yuor name");
   return ai;
 }
 
bool ExampleMeshFilterPlugin::applyFilter(QAction *filter, MeshModel &m, QWidget *parent, vcg::CallBackPos *cb)
{
    if(filter->text() == tr("ExampleFilter") )
        {
            //call my filter method
        }
    return true;
}
Q_EXPORT_PLUGIN(ExampleMeshFilterPlugin)



SourceForge.net Logo