在MeshLab中对其功能的扩展是通过插件来实现的,通过实现不同的接口,可以将插件放在不同的菜单下或工具栏上,在这里只介绍Filter菜单下的插件实现,其他的类似。
1. 首先在meshlab/src目录下创建myplugins文件夹,然后用QCreator打开meshlab_mini.pro。创建一个新的子工程叫helloplugin,选择空Qt项目即可,并保存在myplugins文件下,如图1所示。
图1 创建的helloplugin空项目
2.MeshLab提供了一个公用的shared.pri,里面包含了通用的插件编译配置,只需在helloplugin.pro包含该文件即完成了插件编译的基本配置。在helloplugin.pro中包含该文件:include (../../shared.pri)。然后在该工程下创建一个HelloPlugin类,继承自QObject,如图2所示。
图2 创建HelloPlugin类
3.MeshLab提供了MeshFilterInterface接口,用于实现Filter菜单下的插件,因此需要实现该接口。
//helloplugin.h
#ifndef HELLOPLUGIN_H
#define HELLOPLUGIN_H
#include <QObject>
#include <common/interfaces.h>
class HelloPlugin : public QObject, public MeshFilterInterface
{
Q_OBJECT
Q_INTERFACES(MeshFilterInterface) //指名MeshFilterInterface为接口
public:
explicit HelloPlugin(QObject *parent = 0);
//……
};
#endif // HELLOPLUGIN_H
//helloplugin.cpp
#include "helloplugin.h"
HelloPlugin::HelloPlugin(QObject *parent) :
QObject(parent)
{
}
Q_EXPORT_PLUGIN(HelloPlugin) //导出插件
4.接下来逐步完成Filter菜单下的插件,是通过实现MeshFilterInterface接口中的功能来完成。下面介绍下几个核心函数和成员变量:
/**
\brief The MeshFilterInterface class provide the interface of the filter plugins.
*/
class MeshFilterInterface : public MeshCommonInterface
{
public:
/** The FilterClass enum represents the set of keywords that must be used to categorize a filter.
Each filter can belong to one or more filtering class, or-ed togheter.
*/
enum FilterClass
{
Generic =0x00000, /*!< Should be avoided if possible. */ //
Selection =0x00001, /*!< select or de-select something, basic operation on selections (like deleting)*/
Cleaning =0x00002, /*!< Filters that can be used to clean meshes (duplicated vertices etc)*/
Remeshing =0x00004, /*!< Simplification, Refinement, Reconstruction and mesh optimization*/
FaceColoring =0x00008,
VertexColoring =0x00010,
MeshCreation =0x00020,
Smoothing =0x00040, /*!< Stuff that does not change the topology, but just the vertex positions*/
Quality =0x00080,
Layer =0x00100, /*!< Layers, attributes */
RasterLayer =0x20000, /*!< Raster Layers, attributes */
Normal =0x00200, /*!< N