From e8ee72708bb9f2ca3c72bf86a7fa3e913d5fa5ec Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Mon, 16 Apr 2007 09:15:36 +0000 Subject: [PATCH] New sample plugins for io and filtering --- .../sampleplugins/samplefilter.cpp | 106 ++++++++++++++++ .../sampleplugins/samplefilter.h | 58 +++++++++ .../sampleplugins/samplefilter.pro | 22 ++++ src/meshlabplugins/sampleplugins/sampleio.cpp | 118 ++++++++++++++++++ src/meshlabplugins/sampleplugins/sampleio.h | 53 ++++++++ src/meshlabplugins/sampleplugins/sampleio.pro | 20 +++ 6 files changed, 377 insertions(+) create mode 100644 src/meshlabplugins/sampleplugins/samplefilter.cpp create mode 100644 src/meshlabplugins/sampleplugins/samplefilter.h create mode 100644 src/meshlabplugins/sampleplugins/samplefilter.pro create mode 100644 src/meshlabplugins/sampleplugins/sampleio.cpp create mode 100644 src/meshlabplugins/sampleplugins/sampleio.h create mode 100644 src/meshlabplugins/sampleplugins/sampleio.pro diff --git a/src/meshlabplugins/sampleplugins/samplefilter.cpp b/src/meshlabplugins/sampleplugins/samplefilter.cpp new file mode 100644 index 000000000..413f853b3 --- /dev/null +++ b/src/meshlabplugins/sampleplugins/samplefilter.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +* MeshLab o o * +* A versatile mesh processing toolbox o o * +* _ O _ * +* Copyright(C) 2005 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History +$Log: samplefilter.cpp,v $ +Revision 1.3 2006/11/29 00:59:20 cignoni +Cleaned plugins interface; changed useless help class into a plain string + +Revision 1.2 2006/11/27 06:57:21 cignoni +Wrong way of using the __DATE__ preprocessor symbol + +Revision 1.1 2006/09/25 09:24:39 e_cerisoli +add samplefilter + +****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + + +#include "samplefilter.h" + +// Constructor usually performs only two simple tasks of filling the two lists +// - typeList: with all the possible id of the filtering actions +// - actionList with the corresponding actions. If you want to add icons to your filtering actions you can do here by construction the QActions accordingly + +ExtraSamplePlugin::ExtraSamplePlugin() +{ + typeList << FP_MOVE_VERTEX; + + foreach(FilterType tt , types()) + actionList << new QAction(ST(tt), this); +} + +// The very short string describing each filtering action (this string is used also to define the menu entry) +const QString ExtraSamplePlugin::ST(FilterType filter) +{ + return QString("Random Vertex Displacement"); +} + +// The longer string describing each filtering action +// (this string is used in the About plugin dialog) +const QString ExtraSamplePlugin::Info(FilterType filter) +{ + return tr("Apply Filter Move Vertex"); +} + +const PluginInfo &ExtraSamplePlugin::Info() +{ + static PluginInfo ai; + ai.Date=tr(__DATE__); + ai.Version = tr("0.8"); + ai.Author = ("Elisa Cerisoli, Paolo Cignoni"); + return ai; + } + +//Move Vertex of random quantity +bool ExtraSamplePlugin::applyFilter(QAction *filter, MeshModel &m, FilterParameter & par, vcg::CallBackPos *cb) +{ + srand(time(NULL)); + const float max_displacement = m.cm.bbox.Diag()/100; + for(int i = 0; i< m.cm.vert.size(); i++){ + + float rndax = (float(rand())/RAND_MAX)*max_displacement; + float rnday = (float(rand())/RAND_MAX)*max_displacement; + float rndaz = (float(rand())/RAND_MAX)*max_displacement; + m.cm.vert[i].P() += vcg::Point3f(rndax,rnday,rndaz); + } + + vcg::tri::UpdateNormals::PerVertexNormalizedPerFace(m.cm); + vcg::tri::UpdateBounding::Box(m.cm); + + return true; +} + +Q_EXPORT_PLUGIN(ExtraSamplePlugin) diff --git a/src/meshlabplugins/sampleplugins/samplefilter.h b/src/meshlabplugins/sampleplugins/samplefilter.h new file mode 100644 index 000000000..619c08068 --- /dev/null +++ b/src/meshlabplugins/sampleplugins/samplefilter.h @@ -0,0 +1,58 @@ +/**************************************************************************** +* MeshLab o o * +* A versatile mesh processing toolbox o o * +* _ O _ * +* Copyright(C) 2005 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History +$Log: sampleplugins.h,v $ +Revision 1.2 2006/11/29 00:59:21 cignoni +Cleaned plugins interface; changed useless help class into a plain string + +Revision 1.1 2006/09/25 09:24:39 e_cerisoli +add sampleplugins + +****************************************************************************/ + +#ifndef SAMPLEFILTERSPLUGIN_H +#define SAMPLEFILTERSPLUGIN_H + +#include + +#include +#include + +class ExtraSamplePlugin : public QObject, public MeshFilterInterface +{ + Q_OBJECT + Q_INTERFACES(MeshFilterInterface) + +public: + enum { FP_MOVE_VERTEX } ; + + ExtraSamplePlugin(); + + virtual const QString ST(FilterType filter); + virtual const QString Info(FilterType filter); + virtual const PluginInfo &Info(); + virtual bool applyFilter(QAction *filter, MeshModel &m, FilterParameter & /*parent*/, vcg::CallBackPos * cb) ; +}; + +#endif \ No newline at end of file diff --git a/src/meshlabplugins/sampleplugins/samplefilter.pro b/src/meshlabplugins/sampleplugins/samplefilter.pro new file mode 100644 index 000000000..c87ea87f7 --- /dev/null +++ b/src/meshlabplugins/sampleplugins/samplefilter.pro @@ -0,0 +1,22 @@ +TEMPLATE = lib +CONFIG += plugin +INCLUDEPATH += ../.. ../../../../sf ../../../../code/lib/glew/include +HEADERS = samplefilter.h + +SOURCES = samplefilter.cpp + +TARGET = samplefilter +DESTDIR = ../../meshlab/plugins +# the following line is needed to avoid mismatch between +# the awful min/max macros of windows and the limits max +win32:DEFINES += NOMINMAX + +contains(TEMPLATE,lib) { + CONFIG(debug, debug|release) { + unix:TARGET = $$member(TARGET, 0)_debug + else:TARGET = $$member(TARGET, 0)d + } +} + + + diff --git a/src/meshlabplugins/sampleplugins/sampleio.cpp b/src/meshlabplugins/sampleplugins/sampleio.cpp new file mode 100644 index 000000000..69a2c0ecb --- /dev/null +++ b/src/meshlabplugins/sampleplugins/sampleio.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +* MeshLab o o * +* An extendible mesh processor o o * +* _ O _ * +* Copyright(C) 2005, 2006 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + $Log: meshio.cpp,v $ +*****************************************************************************/ +#include +#include + +#include "sampleio.h" + +#include +#include +#include + +#include +#include + +using namespace vcg; + +bool SampleIOPlugin::open(const QString &formatName, QString &fileName, MeshModel &m, int& mask, CallBackPos *cb, QWidget *parent) +{ + if (fileName.isEmpty()) + { + fileName = QFileDialog::getOpenFileName(parent,tr("Open File"),"../sample","Obj files (*.smf)"); + if (fileName.isEmpty()) + return false; + + QFileInfo fi(fileName); + // this change of dir is needed for subsequent textures/materials loading + QDir::setCurrent(fi.absoluteDir().absolutePath()); + } + string filename = fileName.toUtf8().data(); + const char *filenm = filename.c_str(); + int result = vcg::tri::io::ImporterSMF::Open(m.cm, filenm); + if (result != vcg::tri::io::ImporterSMF::E_NOERROR) + { + return false; + } + return true; +} + +bool SampleIOPlugin::save(const QString &formatName,QString &fileName, MeshModel &m, const int &mask, vcg::CallBackPos *cb, QWidget *parent) +{ + QString errorMsgFormat = "Error encountered while exportering file %1:\n%2"; + string filename = fileName.toUtf8().data(); + + const char* filenm = filename.c_str(); + + int result = vcg::tri::io::ExporterSMF::Save(m.cm,filenm,mask); + if(result!=0) + { + QMessageBox::warning(parent, tr("Saving Error"), errorMsgFormat.arg(fileName, vcg::tri::io::Exporter::ErrorMsg(result))); + return false; + } + return true; +} + +/* + returns the list of the file's type which can be imported +*/ +QList SampleIOPlugin::importFormats() const +{ + QList formatList; + formatList << Format("Simple Model Format", tr("SMF")); + return formatList; +} + +/* + returns the list of the file's type which can be exported +*/ +QList SampleIOPlugin::exportFormats() const +{ + QList formatList; + formatList << Format("Simple Model Format" ,tr("SMF")); + + return formatList; +} + +/* + returns the mask on the basis of the file's type. + otherwise it returns 0 if the file format is unknown +*/ +int SampleIOPlugin::GetExportMaskCapability(QString &format) const +{ + return 0; +} + +const PluginInfo &SampleIOPlugin::Info() +{ + static PluginInfo ai; + ai.Date=tr("September 2006"); + ai.Version = tr("0.6"); + ai.Author = ("Elisa Cerisoli, Paolo Cignoni"); + return ai; + } + +Q_EXPORT_PLUGIN(SampleIOPlugin) \ No newline at end of file diff --git a/src/meshlabplugins/sampleplugins/sampleio.h b/src/meshlabplugins/sampleplugins/sampleio.h new file mode 100644 index 000000000..29793384f --- /dev/null +++ b/src/meshlabplugins/sampleplugins/sampleio.h @@ -0,0 +1,53 @@ +/**************************************************************************** +* MeshLab o o * +* A versatile mesh processing toolbox o o * +* _ O _ * +* Copyright(C) 2005 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + + $Log: meshio.h,v $ + + *****************************************************************************/ +#ifndef SAMPLEIOPLUGIN_H +#define SAMPLEIOPLUGIN_H + +#include + +#include +#include + +class SampleIOPlugin : public QObject, public MeshIOInterface +{ + Q_OBJECT + Q_INTERFACES(MeshIOInterface) + + +public: + QList importFormats() const; + QList exportFormats() const; + virtual const PluginInfo &Info(); + int GetExportMaskCapability(QString &format) const; + + bool open(const QString &formatName, QString &fileName, MeshModel &m, int& mask, vcg::CallBackPos *cb=0, QWidget *parent=0); + bool save(const QString &formatName,QString &fileName, MeshModel &m, const int &mask, vcg::CallBackPos *cb, QWidget *parent); +}; + +#endif diff --git a/src/meshlabplugins/sampleplugins/sampleio.pro b/src/meshlabplugins/sampleplugins/sampleio.pro new file mode 100644 index 000000000..7337cea35 --- /dev/null +++ b/src/meshlabplugins/sampleplugins/sampleio.pro @@ -0,0 +1,20 @@ +TEMPLATE = lib +CONFIG += plugin +INCLUDEPATH += ../.. ../../../../sf ../../../../code/lib/glew/include +HEADERS = sampleio.h \ + +SOURCES = sampleio.cpp + +TARGET = sampleio +DESTDIR = ../../meshlab/plugins + +# the following line is needed to avoid mismatch between +# the awful min/max macros of windows and the limits max +win32:DEFINES += NOMINMAX + +contains(TEMPLATE,lib) { + CONFIG(debug, debug|release) { + unix:TARGET = $$member(TARGET, 0)_debug + else:TARGET = $$member(TARGET, 0)d + } +}