To create a new filter plug-in the first step is to considerate that you must implement the "MeshFilterInterface", you can find it in "meshlab/interfaces.h".
Then you create a new class filter which
must inherit from the interface and from QObject. This involves you specifying
the two keywords
Q_OBJECT
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".
Then you implement the following four pure virtual methods:
virtual const QString ST(FilterType filter);
// Return a string that explane the filter's behaviour
virtual const ActionInfo &Info(QAction *);
virtual const PluginInfo &Info();
virtual bool applyFilter(QAction * /*filter*/, MeshModel & /*m*/, FilterParameter & /*par*/, vcg::CallBackPos* /*cb*/);
// Discriminate on the filter to apply by the action name. Its parameters are:
|| * The Filter Action
|| * The Mesh
|| * The Filter Parameters
|| * 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.
Download:
You can download here a sample code
FilterPlugins.zip
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 QString ST(FilterType filter);
virtual bool applyFilter(QAction *filter, MeshModel &m, FilterParameter &par, vcg::CallBackPos * cb);
};
#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);
}
QString ExampleMeshFilterPlugin::ST(FilterType filter)
{
switch(filter){
case "TYPE": return QString("...");
...
}
return QString("error");
}
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, FilterParameter &par, vcg::CallBackPos *cb)
{
if(filter->text() == tr("ExampleFilter") )
{
//call my filter method
}
return true;
}
Q_EXPORT_PLUGIN(ExampleMeshFilterPlugin)