mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-16 09:34:36 +00:00
New sample plugins for io and filtering
This commit is contained in:
parent
e65b7b8704
commit
e8ee72708b
106
src/meshlabplugins/sampleplugins/samplefilter.cpp
Normal file
106
src/meshlabplugins/sampleplugins/samplefilter.cpp
Normal file
@ -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 <QtGui>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <meshlab/meshmodel.h>
|
||||
#include <meshlab/interfaces.h>
|
||||
|
||||
#include <vcg/complex/trimesh/clean.h>
|
||||
#include <vcg/complex/trimesh/update/normal.h>
|
||||
#include <vcg/complex/trimesh/update/bounding.h>
|
||||
|
||||
|
||||
#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<CMeshO>::PerVertexNormalizedPerFace(m.cm);
|
||||
vcg::tri::UpdateBounding<CMeshO>::Box(m.cm);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(ExtraSamplePlugin)
|
||||
58
src/meshlabplugins/sampleplugins/samplefilter.h
Normal file
58
src/meshlabplugins/sampleplugins/samplefilter.h
Normal file
@ -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 <QObject>
|
||||
|
||||
#include <meshlab/meshmodel.h>
|
||||
#include <meshlab/interfaces.h>
|
||||
|
||||
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
|
||||
22
src/meshlabplugins/sampleplugins/samplefilter.pro
Normal file
22
src/meshlabplugins/sampleplugins/samplefilter.pro
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
118
src/meshlabplugins/sampleplugins/sampleio.cpp
Normal file
118
src/meshlabplugins/sampleplugins/sampleio.cpp
Normal file
@ -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 <Qt>
|
||||
#include <QtGui>
|
||||
|
||||
#include "sampleio.h"
|
||||
|
||||
#include <wrap/io_trimesh/export_smf.h>
|
||||
#include <wrap/io_trimesh/import_smf.h>
|
||||
#include <wrap/io_trimesh/export.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
|
||||
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<CMeshO>::Open(m.cm, filenm);
|
||||
if (result != vcg::tri::io::ImporterSMF<CMeshO>::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<CMeshO>::Save(m.cm,filenm,mask);
|
||||
if(result!=0)
|
||||
{
|
||||
QMessageBox::warning(parent, tr("Saving Error"), errorMsgFormat.arg(fileName, vcg::tri::io::Exporter<CMeshO>::ErrorMsg(result)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
returns the list of the file's type which can be imported
|
||||
*/
|
||||
QList<MeshIOInterface::Format> SampleIOPlugin::importFormats() const
|
||||
{
|
||||
QList<Format> formatList;
|
||||
formatList << Format("Simple Model Format", tr("SMF"));
|
||||
return formatList;
|
||||
}
|
||||
|
||||
/*
|
||||
returns the list of the file's type which can be exported
|
||||
*/
|
||||
QList<MeshIOInterface::Format> SampleIOPlugin::exportFormats() const
|
||||
{
|
||||
QList<Format> 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)
|
||||
53
src/meshlabplugins/sampleplugins/sampleio.h
Normal file
53
src/meshlabplugins/sampleplugins/sampleio.h
Normal file
@ -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 <QObject>
|
||||
|
||||
#include <meshlab/meshmodel.h>
|
||||
#include <meshlab/interfaces.h>
|
||||
|
||||
class SampleIOPlugin : public QObject, public MeshIOInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(MeshIOInterface)
|
||||
|
||||
|
||||
public:
|
||||
QList<Format> importFormats() const;
|
||||
QList<Format> 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
|
||||
20
src/meshlabplugins/sampleplugins/sampleio.pro
Normal file
20
src/meshlabplugins/sampleplugins/sampleio.pro
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user