mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-17 18:14:38 +00:00
filter which exports all layers as a raw binary data file (points+normals) BNPTS to be used with the streaming out-of-core poisson reconstructor - first implementation
This commit is contained in:
parent
de7cd592b6
commit
cd4ae66017
171
src/meshlabplugins/filter_bnpts/filter_bnpts.cpp
Normal file
171
src/meshlabplugins/filter_bnpts/filter_bnpts.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
/****************************************************************************
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "filter_bnpts.h"
|
||||
|
||||
#include <vcg/complex/trimesh/clean.h>
|
||||
#include<vcg/complex/trimesh/append.h>
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace vcg;
|
||||
|
||||
// Constructor
|
||||
FilterBnptsPlugin::FilterBnptsPlugin()
|
||||
{
|
||||
typeList <<
|
||||
FP_BNPTSGEN;
|
||||
|
||||
foreach(FilterIDType tt , types())
|
||||
actionList << new QAction(filterName(tt), this);
|
||||
}
|
||||
|
||||
// ST() return the very short string describing each filtering action
|
||||
QString FilterBnptsPlugin::filterName(FilterIDType filterId) const
|
||||
{
|
||||
switch(filterId) {
|
||||
case FP_BNPTSGEN : return QString("generate a BNPTS file for out-of-core poisson");
|
||||
default : assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Info() return the longer string describing each filtering action
|
||||
QString FilterBnptsPlugin::filterInfo(FilterIDType filterId) const
|
||||
{
|
||||
switch(filterId) {
|
||||
case FP_BNPTSGEN : return QString("generate a BNPTS file using data from all layers. This file contains points+normals and it is used with the external tool for out-of-core poisson merging");
|
||||
default : assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
// This function define the needed parameters for each filter.
|
||||
void FilterBnptsPlugin::initParameterSet(QAction *action, MeshDocument &md, RichParameterSet & parlst)
|
||||
{
|
||||
MeshModel *mm=md.mm();
|
||||
|
||||
switch(ID(action))
|
||||
{
|
||||
case FP_BNPTSGEN :
|
||||
{
|
||||
parlst.addParam(new RichBool ("onlyvisible",
|
||||
true,
|
||||
"Use only visible layers",
|
||||
"If true, only visible layers are used for generating the BNPTS"));
|
||||
parlst.addParam(new RichBool ("append",
|
||||
false,
|
||||
"append to existing file",
|
||||
"If true and the output files already exist, appends data to \n\n"
|
||||
"the existing BNPTS"));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default: break; // do not add any parameter for the other filters
|
||||
}
|
||||
}
|
||||
|
||||
// Core Function doing the actual mesh processing.
|
||||
bool FilterBnptsPlugin::applyFilter(QAction *filter, MeshDocument &md, RichParameterSet & par, vcg::CallBackPos *cb)
|
||||
{
|
||||
CMeshO::FaceIterator fi;
|
||||
|
||||
switch(ID(filter))
|
||||
{
|
||||
|
||||
case FP_BNPTSGEN :
|
||||
{
|
||||
bool onlyvisiblelayers = par.getBool("onlyvisible");
|
||||
bool appendexisting = par.getBool("append");
|
||||
CMeshO::VertexIterator vi;
|
||||
|
||||
// destination file
|
||||
QString filename = QFileDialog::getSaveFileName((QWidget*)NULL,tr("Export BNPTS File"), QDir::currentPath(), tr("BNPTS file (*.Bnpts )"));
|
||||
FILE* outfile=NULL;
|
||||
|
||||
if(appendexisting)
|
||||
outfile = fopen(qPrintable(filename), "wba");
|
||||
else
|
||||
outfile = fopen(qPrintable(filename), "wb");
|
||||
|
||||
if(outfile==NULL)
|
||||
return false;
|
||||
|
||||
int cnt=0;
|
||||
foreach(MeshModel *mmp, md.meshList)
|
||||
{
|
||||
++cnt;
|
||||
|
||||
// visible ?
|
||||
if(mmp->visible || !onlyvisiblelayers)
|
||||
{
|
||||
float buff[6];
|
||||
|
||||
// the mesh has to be correctly transformed before exporting
|
||||
tri::UpdatePosition<CMeshO>::Matrix(mmp->cm,mmp->cm.Tr,true);
|
||||
|
||||
for(vi=mmp->cm.vert.begin();vi!=mmp->cm.vert.end();++vi)
|
||||
if(!(*vi).IsD())
|
||||
{
|
||||
buff[0]=vi->P().X();
|
||||
buff[1]=vi->P().Y();
|
||||
buff[2]=vi->P().Z();
|
||||
buff[3]=vi->N().X();
|
||||
buff[4]=vi->N().Y();
|
||||
buff[5]=vi->N().Z();
|
||||
|
||||
fwrite(buff,sizeof(float),6,outfile);
|
||||
}
|
||||
|
||||
// the mesh has to return to its original position
|
||||
tri::UpdatePosition<CMeshO>::Matrix(mmp->cm,Inverse(mmp->cm.Tr),true);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(outfile);
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FilterBnptsPlugin::FilterClass FilterBnptsPlugin::getClass(QAction *a)
|
||||
{
|
||||
switch(ID(a))
|
||||
{
|
||||
case FP_BNPTSGEN :
|
||||
return MeshFilterInterface::Layer;
|
||||
default : assert(0);
|
||||
return MeshFilterInterface::Generic;
|
||||
}
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(FilterBnptsPlugin)
|
||||
48
src/meshlabplugins/filter_bnpts/filter_bnpts.h
Normal file
48
src/meshlabplugins/filter_bnpts/filter_bnpts.h
Normal file
@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef FILTER_BNPTS_H
|
||||
#define FILTER_BNPTS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <common/interfaces.h>
|
||||
|
||||
class FilterBnptsPlugin : public QObject, public MeshFilterInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(MeshFilterInterface)
|
||||
|
||||
public:
|
||||
enum { FP_BNPTSGEN };
|
||||
|
||||
FilterBnptsPlugin();
|
||||
|
||||
virtual QString filterName(FilterIDType filter) const;
|
||||
virtual QString filterInfo(FilterIDType filter) const;
|
||||
virtual FilterClass getClass(QAction *);
|
||||
virtual void initParameterSet(QAction *,MeshDocument &/*m*/, RichParameterSet & /*parent*/);
|
||||
virtual bool applyFilter(QAction *filter, MeshDocument &md, RichParameterSet & /*parent*/, vcg::CallBackPos * cb) ;
|
||||
};
|
||||
|
||||
#endif
|
||||
5
src/meshlabplugins/filter_bnpts/filter_bnpts.pro
Normal file
5
src/meshlabplugins/filter_bnpts/filter_bnpts.pro
Normal file
@ -0,0 +1,5 @@
|
||||
include (../../shared.pri)
|
||||
|
||||
HEADERS += filter_bnpts.h
|
||||
SOURCES += filter_bnpts.cpp
|
||||
TARGET = filter_bnpts
|
||||
Loading…
x
Reference in New Issue
Block a user