您的位置:首页 > 其它

Meshlab中IO插件编写_使用自已添加的external支持库

2012-11-03 19:54 330 查看
一、使用在external中自定义添加的第三方库,如何添加请参考:

/article/9183458.html

对于第三方库的使用,无非就是向当前的工程中添加包含目录,和库目录。在meshlab_mini.pro总工程下创建工程io_json.pro,并保存在src/my_plugins/io_json目录下,并对io_json.pro设置如下:

include(../../shared.pri)
TARGET=io_json
#thirdpartylibs
INCLUDEPATH+=../../external/jsoncpp-0.6.0-rc2/include
macx:LIBS             +=-L../../external/lib/macx-ljson
macx32:LIBS           +=-L../../external/lib/macx32-ljson
macx64:LIBS           +=-L../../external/lib/macx64-ljson
win32-msvc.net:LIBS   +=../../external/lib/win32-msvc.net/json.lib
win32-msvc2005:LIBS   +=../../external/lib/win32-msvc2005/json.lib
win32-msvc2008:LIBS   +=../../external/lib/win32-msvc2008/json.lib
win32-g++:LIBS        +=-L../../external/lib/win32-gcc-ljson
linux-g++:LIBS        +=-L../../external/lib/linux-g++-ljson
linux-g++-32:LIBS     +=-L../../external/lib/linux-g++-32-ljson
linux-g++-64:LIBS       +=-L../../external/lib/linux-g++-64-ljson


二、 Meshlab中IO插件的编写
编写IO插件,也是非常简单的,Meshlab提供了MeshIOInterface接口,只要实现该接口的open,save方法便可以了。下面就将三维模型的json格式的读写插件进行介绍,以及jsoncpp的使用。

MeshIOInterface提供的几个方法介绍如下,也就是需要重写的方法:

virtualQList<Format>importFormats()const=0;  //该方法用来定义可以导入的类型,如*.json
virtualQList<Format>exportFormats()const=0;  //该方法定义可以导出的类型,如*.json
virtualvoidinitPreOpenParameter(constQString&/*format*/,constQString&/*fileName*/,RichParameterSet&/*par*/){}  //该方法用来定义在打开文件(open)之前所需要的信息,比如,是否导入normal
virtualvoidinitOpenParameter(constQString&/*format*/,MeshModel&/*m*/,RichParameterSet&/*par*/){} // 该方法定义文件调入内存(open)后,所需要的处理,比如,是否对normal进行平滑处理
//Thisisthecorrespondingfunctionthatiscalledafterthemeshisloadedwiththeinitializedparameters
virtualvoidapplyOpenParameter(constQString&/*format*/,MeshModel&/*m*/,constRichParameterSet&/*par*/){} //该方法执行initOpenParameter所定义的处理
virtualvoidinitSaveParameter(constQString&/*format*/,MeshModel&/*m*/,RichParameterSet&/*par*/)   {}// 该方法在save之前调用,用来定义保存设置
virtualvoidGetExportMaskCapability(QString&format,int&capability,int&defaultBits)const=0; //该方法用来确定某文件类型,所能保存的模型的信息,比如json文件类型,是否具有保存normal的能力

///callbackusedtoactuallyloadameshfromafile
virtualboolopen(
constQString&format,                                                                                             ///theextensionoftheformate.g."PLY"
constQString&fileName,                                                                     ///Thenameofthefiletobeopened
MeshModel&m,                                                                                                                                                                                         ///Themeshthatisfilledwiththefilecontent
int&mask,                                                                                                                                                                                                                       ///abitmaskthatwillbefilledreportingwhatkindofdatawehavefoundinthefile(pervertexcolor,texturecoordsetc)
constRichParameterSet&par,///TheparametersthathavebeensetupintheinitPreOpenParameter()
vcg::CallBackPos*cb=0,                                                                                          ///standardcallbackforreportingprogressintheloading
QWidget*parent=0)=0;                                                                                                                 ///youshouldnotusethis...
virtualboolsave(
constQString&format,//theextensionoftheformate.g."PLY"
constQString&fileName,
MeshModel&m,
constintmask,       //abitmaskindicatingwhatkindofthedatapresentinthemeshshouldbesaved(e.g.youcouldnotwanttosavenormalsinplyfiles)
constRichParameterSet&par,
vcg::CallBackPos*cb=0,
QWidget*parent=0)=0;


下面给出JsonIOPlugin.cpp的代码,该IO插件,只支持JSON文件类型的读写,export_json.h和import_json.h见完整的工程,下载链接已给出。在这里只重写了几个必不可少的函数:

#include"jsonioplugin.h"
#include"export_json.h"
#include"import_json.h"

JsonIOPlugin::JsonIOPlugin(QObject*parent) :
QObject(parent),MeshIOInterface()
{
}

QList<MeshIOInterface::Format>JsonIOPlugin::exportFormats()const{
QList<Format> formatList;
formatList <<Format("JavaScriptJSON",tr("JSON"));
return formatList;
}

QList<MeshIOInterface::Format>JsonIOPlugin::importFormats()const{

QList<Format> formatList;
formatList << Format("JavaScriptJSON",tr("JSON"));
return formatList;
}
boolJsonIOPlugin::open(const QString &format, const QString &fileName,MeshModel &m, int &mask, const RichParameterSet &par,vcg::CallBackPos *cb, QWidget *parent){
QString errorMsgFormat = "Errorencountered while importing file %1:\n%2";
ImporterJSON<CMeshO>::open(m.cm,fileName.toStdString().c_str());
return true;
}
boolJsonIOPlugin::save(const QString &format, const QString &fileName,MeshModel &m, const int mask, const RichParameterSet &par,vcg::CallBackPos *cb, QWidget *parent){

QString errorMsgFormat = "Errorencountered while exporting file %1:\n%2";
std::string fName =QFile::encodeName(fileName).constData();
//QMessageBox::warning(parent,tr("SavingError"),errorMsgFormat.arg(fileName,tr("failed.")));
if(format.toUpper() ==tr("JSON")){
bool success =ExporterJSON<CMeshO>::Save(m.cm,fName.c_str(),mask,cb);

if(!success){
QMessageBox::warning(parent,tr("SavingError"),errorMsgFormat.arg(fileName,tr("failed.")));
return false;
}
return true;
}

}
voidJsonIOPlugin::GetExportMaskCapability(QString &format, int &capability,int &defaultBits) const{

capability = 0;
if(format.toUpper() ==tr("JSON")){
capability = defaultBits =ExporterJSON<CMeshO>::GetExportMaskCapability();
}
}

Q_EXPORT_PLUGIN(JsonIOPlugin)


如此就完成了Meshlab的IO插件的编写,很简单呀。

完整的IOPlugin工程代码在:http://download.csdn.net/detail/fightingbull/4728854

辉辉
(FightingBull Studio)

欢迎转载,但请注明出处:http://blog.csdn.net/fightingbull
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: