meshlab/web/filter.html
2005-12-27 10:04:58 +00:00

192 lines
11 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title>Meshlab Development</title>
<meta name="author" content="Paolo Cignoni">
<meta name="keywords" content="mesh 3d processing meshlab scanning">
<meta name="description" content="Course Web page">
<meta name="robots" content="all">
<link media="all" rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div id="leftcontent">
<h1>MeshLab:
Development page : Create a Filter-plugin</h1>
<br>
<h2><span style="font-weight: bold;">How to</span></h2>
<p>
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<span style="font-style: italic;"> "meshlab/interfaces.h".</span></p>
<p><span style="font-style: italic;"></span>Then you create a new class
filter which must inherit from the interface and from Object. This
involves you specifying the two keywords "<span style="font-style: italic; font-weight: bold;">Q_OBJECT</span>" and "<span style="font-style: italic; font-weight: bold;">Q_INTERFACES(MeshFilterInterface)</span>" before the method declaration to permit the moc'ing phases.</p>
<p>It is essential to import of the mesh definition found in "meshlab/meshmodel.h".<br>
<br>
The new filter plug-in class must have an action container like "<span style="text-decoration: underline;">QList &lt;QAction *&gt;</span>", where you can store all the actions you implement in your class; <span style="font-style: italic;">QList &lt;QAction*&gt;</span> must be populated in the constructor.<br>
<br>
Then you implement the following four pure virtual methods:<br>
<br>
<span style="font-weight: bold; font-style: italic;">QList&lt;QAction *&gt; actions()</span> // return the list of actions to create the menu on the toolbar<br>
<span style="font-weight: bold; font-style: italic;">virtual const ActionInfo &amp;Info(QAction *)</span>//?<br>
<span style="font-weight: bold; font-style: italic;">virtual const PluginInfo &amp;Info()</span>//?<br>
<span style="font-weight: bold; font-style: italic;">virtual bool applyFilter(QAction * </span><span style="font-style: italic;">/*filter*/</span><span style="font-weight: bold; font-style: italic;">, MeshModel &amp; </span><span style="font-style: italic;">/*m*/</span><span style="font-weight: bold; font-style: italic;">, QWidget * </span><span style="font-style: italic;">/*parent*/</span><span style="font-weight: bold; font-style: italic;">, vcg::CallBackPos* </span><span style="font-style: italic;">/*cb*/</span><span style="font-weight: bold; font-style: italic;">)</span><br>
// Discriminate on the filter to apply by the action name. Its parameters are:<br>
||&nbsp;&nbsp;&nbsp; * The filter action<br>
|| &nbsp;&nbsp; * The Mesh <br>
|| &nbsp;&nbsp; * The QWidget parent to possibly create the dialog to set some variables<br>
|| &nbsp;&nbsp; * The call-back function to update the progress-bar<br>
<br style="font-weight: bold;">
<span style="font-weight: bold;">Important:</span><br>
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.</p>
<h2><span style="font-style: italic;"></span>Example</h2>
<p><span style="font-style: italic;"></span><span style="text-decoration: underline; font-weight: bold;"> Example.h</span></p>
<p><span style="font-style: italic;">#ifndef EXAMPLEPLUGIN_H</span><br style="font-style: italic;">
<span style="font-style: italic;">#define EXAMPLEPLUGIN_H</span><br style="font-style: italic;">
<br style="font-style: italic;">
<span style="font-style: italic;">#include &lt;QObject&gt;</span><br style="font-style: italic;">
<span style="font-style: italic;">#include &lt;QStringList&gt;</span><br style="font-style: italic;">
<span style="font-style: italic;">#include &lt;QList&gt;</span><br style="font-style: italic;">
<br style="font-style: italic;">
<span style="font-style: italic;">class ExampleMeshFilterPlugin : public QObject, public MeshFilterInterface</span><br style="font-style: italic;">
<span style="font-style: italic;">{</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; Q_OBJECT</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; Q_INTERFACES(MeshFilterInterface)</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span><br style="font-style: italic;">
<span style="font-style: italic;">public:</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; ExampleMeshFilterPlugin();</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; virtual const ActionInfo &amp;Info(QAction *);</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; virtual const PluginInfo &amp;Info();</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; virtual QList&lt;QAction *&gt; actions() const;</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; bool applyFilter(QAction *filter, MeshModel &amp;m, QWidget *parent, vcg::CallBackPos * cb) ;</span><br style="font-style: italic;">
<br style="font-style: italic;">
<span style="font-style: italic;">protected:</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; QList &lt;QAction *&gt; actionList;</span><br style="font-style: italic;">
<span style="font-style: italic;">};</span><br style="font-style: italic;">
<br style="font-style: italic;">
<span style="font-style: italic;">#endif</span><br>
</p>
<p><br>
<br>
<span style="font-weight: bold; text-decoration: underline;">Example.cpp</span><br>
<br>
<span style="font-style: italic;">#include &lt;QtGui&gt;</span><br style="font-style: italic;">
<span style="font-style: italic;">#include &lt;stdlib.h&gt;</span><br style="font-style: italic;">
<span style="font-style: italic;">#include "meshfilter.h"</span><br style="font-style: italic;">
<span style="font-style: italic;">#include &lt;vcg/complex/trimesh/clean.h&gt;</span><br style="font-style: italic;">
<span style="font-style: italic;">#include &lt;vcg/complex/trimesh/smooth.h&gt;</span><br style="font-style: italic;">
<br style="font-style: italic;">
<span style="font-style: italic;">ExampleMeshFilterPlugin::ExampleMeshFilterPlugin()&nbsp;<br>
{</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; actionList &lt;&lt; new QAction("ExampleFilter", this);</span><br style="font-style: italic;">
<span style="font-style: italic;">}</span><br style="font-style: italic;">
<br style="font-style: italic;">
<span style="font-style: italic;">QList&lt;QAction *&gt; ExampleMeshFilterPlugin::actions() const&nbsp;<br>
{</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; return actionList;</span><br style="font-style: italic;">
<span style="font-style: italic;">}</span><br style="font-style: italic;">
<br style="font-style: italic;">
<span style="font-style: italic;">const ActionInfo &amp;ExampleMeshFilterPlugin::Info(QAction *action) </span><br style="font-style: italic;">
<span style="font-style: italic;">{</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp; ActionInfo ai; </span><br style="font-style: italic;">
<span style="font-style: italic;"> </span><span style="font-style: italic;">&nbsp;&nbsp;&nbsp; if( action-&gt;text() == tr("ExampleFilter") )</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ai.Help = tr("explain yuor method");</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ai.ShortHelp = tr("For tooltip");</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp; return ai;</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;}</span><br style="font-style: italic;">
<br style="font-style: italic;">
<span style="font-style: italic;">const PluginInfo &amp;ExampleMeshFilterPlugin::Info() </span><br style="font-style: italic;">
<span style="font-style: italic;">{</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp; static PluginInfo ai; </span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp; ai.Date=tr("__DATE__");</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;ai.Version = tr("Current version");</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;ai.Author = ("Yuor name");</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp; return ai;</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;}</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;</span><br style="font-style: italic;">
<span style="font-style: italic;">bool ExampleMeshFilterPlugin::applyFilter(QAction *filter, MeshModel &amp;m, QWidget *parent, vcg::CallBackPos *cb) </span><br style="font-style: italic;">
<span style="font-style: italic;">{</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; if(filter-&gt;text() == tr("ExampleFilter") )</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //call my filter method</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</span><br style="font-style: italic;">
<span style="font-style: italic;">&nbsp;&nbsp;&nbsp; return true;</span><br style="font-style: italic;">
<span style="font-style: italic;">}</span><br style="font-style: italic;">
<span style="font-style: italic;">Q_EXPORT_PLUGIN(ExampleMeshFilterPlugin)</span><br>
<br>
</p>
<br>
<span style="font-style: italic;">
<dl>
</dl>
</span></div>
<div id="rightcontent">
<br>
<a href="https://sourceforge.net/projects/meshlab/"><span style="font-style: italic;"></span><img src="http://sourceforge.net/sflogo.php?group_id=149444&amp;type=2" alt="SourceForge.net Logo" border="0" height="37" width="125"></a>
<p class="menu"><a href="http://meshlab.sourceforge.net">Main
Page&nbsp;</a></p>
<p class="menu"><a href="https://sourceforge.net/project/showfiles.php?group_id=149444">Download</a></p>
<p class="menu"><a href="http://cvs.sourceforge.net/viewcvs.py/meshlab/">CVS</a></p>
<p class="menu"><a href="https://sourceforge.net/pm/?group_id=149444">TASK</a></p>
<p class="menu"><a href="https://sourceforge.net/projects/meshlab/">SF project
page</a></p>
</div>
</body>
</html>