Added new functinalities to the MeshLab project

- Added a new project type (.mlb) to save matrix and camera data in
binary format using Base64 encoding
- Added the saving of the rendering options of each mesh layer
- Bug fixed in the appendProject
This commit is contained in:
gianpaolopalma 2017-11-27 13:37:49 +01:00
parent e9a765ca65
commit ebad76f177
7 changed files with 287 additions and 58 deletions

View File

@ -7,13 +7,13 @@
#include "meshlabdocumentxml.h"
#include <wrap/qt/shot_qt.h>
bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers)
bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool binary, std::map<int, MLRenderingData>& rendOpt)
{
md.setFileName(filename);
QFileInfo fi(filename);
QDir tmpDir = QDir::current();
QDir::setCurrent(fi.absoluteDir().absolutePath());
QDomDocument doc = MeshDocumentToXML(md, onlyVisibleLayers);
QDomDocument doc = MeshDocumentToXML(md, onlyVisibleLayers, binary, rendOpt);
QFile file(filename);
file.open(QIODevice::WriteOnly);
QTextStream qstream(&file);
@ -36,7 +36,16 @@ QDomElement Matrix44mToXML(Matrix44m &m, QDomDocument &doc)
return matrixElem;
}
bool MeshDocumentFromXML(MeshDocument &md, QString filename)
QDomElement Matrix44mToBinaryXML(Matrix44m &m, QDomDocument &doc)
{
QDomElement matrixElem = doc.createElement("MLMatrix44");
QByteArray value = QByteArray::fromRawData((char *)m.V(), sizeof(Matrix44m::ScalarType) * 16).toBase64();
QDomText nd = doc.createTextNode(QString(value));
matrixElem.appendChild(nd);
return matrixElem;
}
bool MeshDocumentFromXML(MeshDocument &md, QString filename, bool binary, std::map<int, MLRenderingData>& rendOpt)
{
QFile qf(filename);
QFileInfo qfInfo(filename);
@ -67,21 +76,74 @@ bool MeshDocumentFromXML(MeshDocument &md, QString filename)
//return true;
filen = mesh.attributes().namedItem("filename").nodeValue();
label = mesh.attributes().namedItem("label").nodeValue();
/*MeshModel* mm = */md.addNewMesh(filen, label);
QDomNode tr = mesh.firstChild();
bool visible = true;
if (mesh.attributes().contains("visible"))
visible = (mesh.attributes().namedItem("visible").nodeValue().toInt() == 1);
MeshModel* mm = md.addNewMesh(filen, label);
mm->visible = visible;
/*if (mesh.attributes().contains("renderingOptions"))
{
QString value = mesh.attributes().namedItem("renderingOptions").nodeValue();
rendOpt.insert(std::pair<int, std::string>(mm->id(), value.toStdString()));
}*/
QDomNode tr = mesh.firstChildElement("MLMatrix44");
if (!tr.isNull() && QString::compare(tr.nodeName(), "MLMatrix44") == 0)
if (!tr.isNull())
{
vcg::Matrix44f trm;
if (tr.childNodes().size() == 1)
{
QStringList values = tr.firstChild().nodeValue().split(" ", QString::SkipEmptyParts);
for (int y = 0; y < 4; y++)
for (int x = 0; x < 4; x++)
md.mm()->cm.Tr[y][x] = values[x + 4 * y].toFloat();
if (!binary)
{
QStringList values = tr.firstChild().nodeValue().split(" ", QString::SkipEmptyParts);
for (int y = 0; y < 4; y++)
for (int x = 0; x < 4; x++)
md.mm()->cm.Tr[y][x] = values[x + 4 * y].toFloat();
}
else
{
QString str = tr.firstChild().nodeValue();
QByteArray value = QByteArray::fromBase64(str.toLocal8Bit());
memcpy(md.mm()->cm.Tr.V(), value.data(), sizeof(Matrix44m::ScalarType) * 16);
}
}
}
QDomNode renderingOpt = mesh.firstChildElement("RenderingOption");
if (!renderingOpt.isNull())
{
QString value = renderingOpt.firstChild().nodeValue();
MLRenderingData::GLOptionsType opt;
if (renderingOpt.attributes().contains("pointSize"))
opt._perpoint_pointsize = renderingOpt.attributes().namedItem("pointSize").nodeValue().toFloat();
if (renderingOpt.attributes().contains("wireWidth"))
opt._perwire_wirewidth = renderingOpt.attributes().namedItem("wireWidth").nodeValue().toFloat();
if (renderingOpt.attributes().contains("boxColor"))
{
QStringList values = renderingOpt.attributes().namedItem("boxColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perbbox_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("pointColor"))
{
QStringList values = renderingOpt.attributes().namedItem("pointColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perpoint_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("wireColor"))
{
QStringList values = renderingOpt.attributes().namedItem("wireColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perwire_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("solidColor"))
{
QStringList values = renderingOpt.attributes().namedItem("solidColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._persolid_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
MLRenderingData data;
data.set(opt);
if (data.deserialize(value.toStdString()))
rendOpt.insert(std::pair<int, MLRenderingData>(mm->id(), data));
}
mesh = mesh.nextSibling();
}
}
@ -97,7 +159,7 @@ bool MeshDocumentFromXML(MeshDocument &md, QString filename)
QString labelRaster = raster.attributes().namedItem("label").nodeValue();
md.rm()->setLabel(labelRaster);
QDomNode sh = raster.firstChild();
ReadShotFromQDomNode(md.rm()->shot, sh);
ReadShotFromQDomNode(md.rm()->shot, sh);
QDomElement el = raster.firstChildElement("Plane");
while (!el.isNull())
@ -120,20 +182,46 @@ bool MeshDocumentFromXML(MeshDocument &md, QString filename)
return true;
}
QDomElement MeshModelToXML(MeshModel *mp, QDomDocument &doc)
QDomElement MeshModelToXML(MeshModel *mp, QDomDocument &doc, bool binary, MLRenderingData* rendOpt = NULL)
{
QDomElement meshElem = doc.createElement("MLMesh");
meshElem.setAttribute("label", mp->label());
meshElem.setAttribute("filename", mp->relativePathName());
meshElem.appendChild(Matrix44mToXML(mp->cm.Tr, doc));
meshElem.setAttribute("visible", mp->isVisible());
if (binary)
meshElem.appendChild(Matrix44mToBinaryXML(mp->cm.Tr, doc));
else
meshElem.appendChild(Matrix44mToXML(mp->cm.Tr, doc));
if (rendOpt != NULL)
{
QDomElement renderingElem = doc.createElement("RenderingOption");
std::string text;
rendOpt->serialize(text);
QDomText nd = doc.createTextNode(QString(text.c_str()));
renderingElem.appendChild(nd);
MLRenderingData::GLOptionsType opt;
if (rendOpt->get(opt))
{
renderingElem.setAttribute("boxColor", QString("%1 %2 %3 %4").arg(opt._perbbox_fixed_color[0]).arg(opt._perbbox_fixed_color[1]).arg(opt._perbbox_fixed_color[2]).arg(opt._perbbox_fixed_color[3]));
renderingElem.setAttribute("pointColor", QString("%1 %2 %3 %4").arg(opt._perpoint_fixed_color[0]).arg(opt._perpoint_fixed_color[1]).arg(opt._perpoint_fixed_color[2]).arg(opt._perpoint_fixed_color[3]));
renderingElem.setAttribute("wireColor", QString("%1 %2 %3 %4").arg(opt._perwire_fixed_color[0]).arg(opt._perwire_fixed_color[1]).arg(opt._perwire_fixed_color[2]).arg(opt._perwire_fixed_color[3]));
renderingElem.setAttribute("solidColor", QString("%1 %2 %3 %4").arg(opt._persolid_fixed_color[0]).arg(opt._persolid_fixed_color[1]).arg(opt._persolid_fixed_color[2]).arg(opt._persolid_fixed_color[3]));
renderingElem.setAttribute("pointSize", opt._perpoint_pointsize);
renderingElem.setAttribute("wireWidth", opt._perwire_wirewidth);
}
meshElem.appendChild(renderingElem);
}
return meshElem;
}
QDomElement RasterModelToXML(RasterModel *mp, QDomDocument &doc)
QDomElement RasterModelToXML(RasterModel *mp, QDomDocument &doc, bool binary)
{
QDomElement rasterElem = doc.createElement("MLRaster");
rasterElem.setAttribute("label", mp->label());
rasterElem.appendChild(WriteShotToQDomNode(mp->shot, doc));
if (binary)
rasterElem.appendChild(WriteShotToQDomNodeBinary(mp->shot, doc));
else
rasterElem.appendChild(WriteShotToQDomNode(mp->shot, doc));
for (int ii = 0; ii < mp->planeList.size(); ++ii)
rasterElem.appendChild(PlaneToXML(mp->planeList[ii], mp->par->pathName(), doc));
return rasterElem;
@ -148,7 +236,7 @@ QDomElement PlaneToXML(Plane* pl, const QString& basePath, QDomDocument& doc)
return planeElem;
}
QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers)
QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool binary, std::map<int, MLRenderingData>& rendOpt)
{
QDomDocument ddoc("MeshLabDocument");
@ -160,7 +248,11 @@ QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers)
{
if ((!onlyVisibleLayers) || (mmp->visible))
{
QDomElement meshElem = MeshModelToXML(mmp, ddoc);
QDomElement meshElem;
if (rendOpt.find(mmp->id()) != rendOpt.end())
MeshModelToXML(mmp, ddoc, binary, &rendOpt[mmp->id()]);
else
MeshModelToXML(mmp, ddoc, binary);
mgroot.appendChild(meshElem);
}
}
@ -170,7 +262,7 @@ QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers)
foreach(RasterModel *rmp, md.rasterList)
{
QDomElement rasterElem = RasterModelToXML(rmp, ddoc);
QDomElement rasterElem = RasterModelToXML(rmp, ddoc, binary);
rgroot.appendChild(rasterElem);
}

View File

@ -1,9 +1,9 @@
#ifndef __MESHLABDOC_XML_H
#define __MESHLABDOC_XML_H
QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers);
bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers);
bool MeshDocumentFromXML(MeshDocument &md, QString filename);
QDomElement RasterModelToXML(RasterModel *mp,QDomDocument &doc);
QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool binary, std::map<int, MLRenderingData>& rendOpt = std::map<int, MLRenderingData>());
bool MeshDocumentToXMLFile(MeshDocument &md, QString filename, bool onlyVisibleLayers, bool binary, std::map<int, MLRenderingData>& rendOpt = std::map<int, MLRenderingData>());
bool MeshDocumentFromXML(MeshDocument &md, QString filename, bool binary, std::map<int, MLRenderingData>& rendOpt = std::map<int, MLRenderingData>());
QDomElement RasterModelToXML(RasterModel *mp,QDomDocument &doc, bool binary);
QDomElement PlaneToXML(Plane* pl,const QString& basePath,QDomDocument& doc);
#endif // __MESHLABDOC_XML_H

View File

@ -121,6 +121,86 @@ struct MLPerViewGLOptions : public vcg::RenderingModalityGLOptions
return (*this);
}
size_t serialize(std::string& str)
{
str.append(((_visible) ? "1" : "0"));
str.append(((_perbbox_quoted_info_enabled) ? "1" : "0"));
str.append(((_peredge_extra_enabled) ? "1" : "0"));
str.append(((_peredge_edgeboundary_enabled) ? "1" : "0"));
str.append(((_peredge_faceboundary_enabled) ? "1" : "0"));
str.append(((_peredge_edgemanifold_enabled) ? "1" : "0"));
str.append(((_peredge_vertmanifold_enabled) ? "1" : "0"));
str.append(((_peredge_text_boundary_enabled) ? "1" : "0"));
str.append(((_peredge_fauxwire_enabled) ? "1" : "0"));
str.append(((_peredge_wire_enabled) ? "1" : "0"));
str.append(((_back_face_cull) ? "1" : "0"));
str.append(((_single_side_lighting) ? "1" : "0"));
str.append(((_double_side_lighting) ? "1" : "0"));
str.append(((_fancy_lighting) ? "1" : "0"));
str.append(((_sel_enabled) ? "1" : "0"));
str.append(((_vertex_sel) ? "1" : "0"));
str.append(((_face_sel) ? "1" : "0"));
str.append(((_perbbox_enabled) ? "1" : "0"));
str.append(((_perbbox_fixed_color_enabled) ? "1" : "0"));
str.append(((_perpoint_fixed_color_enabled) ? "1" : "0"));
str.append(((_perwire_fixed_color_enabled) ? "1" : "0"));
str.append(((_persolid_fixed_color_enabled) ? "1" : "0"));
str.append(((_perbbox_mesh_color_enabled) ? "1" : "0"));
str.append(((_perpoint_mesh_color_enabled) ? "1" : "0"));
str.append(((_perwire_mesh_color_enabled) ? "1" : "0"));
str.append(((_persolid_mesh_color_enabled) ? "1" : "0"));
str.append(((_perpoint_dot_enabled) ? "1" : "0"));
str.append(((_perpoint_noshading) ? "1" : "0"));
str.append(((_perwire_noshading) ? "1" : "0"));
str.append(((_persolid_noshading) ? "1" : "0"));
str.append(((_perpoint_pointsmooth_enabled) ? "1" : "0"));
str.append(((_perpoint_pointattenuation_enabled) ? "1" : "0"));
return str.size();
}
void deserialize(std::string& str)
{
std::string s(str.rbegin(), str.rend());
std::bitset<32> bset(s);
_visible = bset[0];
_perbbox_quoted_info_enabled = bset[1];
_peredge_extra_enabled = bset[2];
_peredge_edgeboundary_enabled = bset[3];
_peredge_faceboundary_enabled = bset[4];
_peredge_edgemanifold_enabled = bset[5];
_peredge_vertmanifold_enabled = bset[6];
_peredge_text_boundary_enabled = bset[7];
_peredge_fauxwire_enabled = bset[8];
_peredge_wire_enabled = bset[9];
_back_face_cull = bset[10];
_single_side_lighting = bset[11];
_double_side_lighting = bset[12];
_fancy_lighting = bset[13];
_sel_enabled = bset[14];
_vertex_sel = bset[15];
_face_sel = bset[16];
_perbbox_enabled = bset[17];
_perbbox_fixed_color_enabled = bset[18];
_perpoint_fixed_color_enabled = bset[19];
_perwire_fixed_color_enabled = bset[20];
_persolid_fixed_color_enabled = bset[21];
_perbbox_mesh_color_enabled = bset[22];
_perpoint_mesh_color_enabled = bset[23];
_perwire_mesh_color_enabled = bset[24];
_persolid_mesh_color_enabled = bset[25];
_perpoint_dot_enabled = bset[26];
_perpoint_noshading = bset[27];
_perwire_noshading = bset[28];
_persolid_noshading = bset[29];
_perpoint_pointsmooth_enabled = bset[30];
_perpoint_pointattenuation_enabled = bset[31];
}
static float maxPointSize()
{
return 15.0f;
@ -165,7 +245,7 @@ private:
class MLRenderingData : public vcg::PerViewData<MLPerViewGLOptions>
{
public:
MLRenderingData();
MLRenderingData();
MLRenderingData(const MLRenderingData& dt);
bool set(MLRenderingData::PRIMITIVE_MODALITY pm, const MLRenderingData::RendAtts& atts);

View File

@ -61,7 +61,7 @@ int main(int argc, char *argv[])
"for a longer documentation\n"
);
if(QString(argv[1]).endsWith("mlp",Qt::CaseInsensitive) || QString(argv[1]).endsWith("aln",Qt::CaseInsensitive) || QString(argv[1]).endsWith("out",Qt::CaseInsensitive) || QString(argv[1]).endsWith("nvm",Qt::CaseInsensitive))
if(QString(argv[1]).endsWith("mlp",Qt::CaseInsensitive) || QString(argv[1]).endsWith("mlb", Qt::CaseInsensitive) || QString(argv[1]).endsWith("aln",Qt::CaseInsensitive) || QString(argv[1]).endsWith("out",Qt::CaseInsensitive) || QString(argv[1]).endsWith("nvm",Qt::CaseInsensitive))
window.openProject(argv[1]);
else
window.importMeshWithLayerManagement(argv[1]);

View File

@ -156,11 +156,11 @@ private slots:
public:
bool exportMesh(QString fileName,MeshModel* mod,const bool saveAllPossibleAttributes);
bool loadMesh(const QString& fileName,MeshIOInterface *pCurrentIOPlugin,MeshModel* mm,int& mask,RichParameterSet* prePar,const Matrix44m &mtr=Matrix44m::Identity(), bool isareload = false);
bool loadMesh(const QString& fileName,MeshIOInterface *pCurrentIOPlugin,MeshModel* mm,int& mask,RichParameterSet* prePar,const Matrix44m &mtr=Matrix44m::Identity(), bool isareload = false, MLRenderingData* rendOpt = NULL);
void computeRenderingDataOnLoading(MeshModel* mm,bool isareload);
void computeRenderingDataOnLoading(MeshModel* mm,bool isareload, MLRenderingData* rendOpt = NULL);
bool loadMeshWithStandardParams(QString& fullPath, MeshModel* mm, const Matrix44m &mtr = Matrix44m::Identity(),bool isareload = false);
bool loadMeshWithStandardParams(QString& fullPath, MeshModel* mm, const Matrix44m &mtr = Matrix44m::Identity(),bool isareload = false, MLRenderingData* rendOpt = NULL);
void defaultPerViewRenderingData(MLRenderingData& dt) const;
void getRenderingData(int mid,MLRenderingData& dt) const;

View File

@ -782,7 +782,7 @@ void MainWindow::dropEvent ( QDropEvent * event )
this->newProject();
}
if(path.endsWith("mlp",Qt::CaseInsensitive) || path.endsWith("aln",Qt::CaseInsensitive) || path.endsWith("out",Qt::CaseInsensitive) || path.endsWith("nvm",Qt::CaseInsensitive) )
if(path.endsWith("mlp",Qt::CaseInsensitive) || path.endsWith("mlb", Qt::CaseInsensitive) || path.endsWith("aln",Qt::CaseInsensitive) || path.endsWith("out",Qt::CaseInsensitive) || path.endsWith("nvm",Qt::CaseInsensitive) )
openProject(path);
else
{
@ -2119,7 +2119,7 @@ void MainWindow::saveProject()
}
}
}
QFileDialog* saveDiag = new QFileDialog(this,tr("Save Project File"),lastUsedDirectory.path().append(""), tr("MeshLab Project (*.mlp);;Align Project (*.aln)"));
QFileDialog* saveDiag = new QFileDialog(this,tr("Save Project File"),lastUsedDirectory.path().append(""), tr("MeshLab Project (*.mlp);;MeshLab Binary Project (*.mlb);;Align Project (*.aln)"));
#if defined(Q_OS_WIN)
saveDiag->setOption(QFileDialog::DontUseNativeDialog);
#endif
@ -2190,7 +2190,16 @@ void MainWindow::saveProject()
ret= ALNParser::SaveALN(qPrintable(fileName),meshNameVector,transfVector);
}
else
ret = MeshDocumentToXMLFile(*meshDoc(),fileName,onlyVisibleLayers->isChecked());
{
std::map<int, MLRenderingData> rendOpt;
foreach(MeshModel * mp, meshDoc()->meshList)
{
MLRenderingData ml;
getRenderingData(mp->id(), ml);
rendOpt.insert(std::pair<int, MLRenderingData>(mp->id(), ml));
}
ret = MeshDocumentToXMLFile(*meshDoc(), fileName, onlyVisibleLayers->isChecked(), QString(fi.suffix()).toLower() == "mlb", rendOpt);
}
if (saveAllFile->isChecked())
{
@ -2213,14 +2222,13 @@ bool MainWindow::openProject(QString fileName)
showLayerDlg(false);
globrendtoolbar->setEnabled(false);
if (fileName.isEmpty())
fileName = QFileDialog::getOpenFileName(this,tr("Open Project File"), lastUsedDirectory.path(), "All Project Files (*.mlp *.aln *.out *.nvm);;MeshLab Project (*.mlp);;Align Project (*.aln);;Bundler Output (*.out);;VisualSFM Output (*.nvm)");
fileName = QFileDialog::getOpenFileName(this,tr("Open Project File"), lastUsedDirectory.path(), tr("All Project Files (*.mlp *.mlb *.aln *.out *.nvm);;MeshLab Project (*.mlp);;MeshLab Binary Project (*.mlb);;Align Project (*.aln);;Bundler Output (*.out);;VisualSFM Output (*.nvm)"));
if (fileName.isEmpty()) return false;
QFileInfo fi(fileName);
lastUsedDirectory = fi.absoluteDir();
if((fi.suffix().toLower()!="aln") && (fi.suffix().toLower()!="mlp") && (fi.suffix().toLower()!="out") && (fi.suffix().toLower()!="nvm"))
if((fi.suffix().toLower()!="aln") && (fi.suffix().toLower()!="mlp") && (fi.suffix().toLower() != "mlb") && (fi.suffix().toLower()!="out") && (fi.suffix().toLower()!="nvm"))
{
QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unknown project file extension");
return false;
@ -2264,19 +2272,23 @@ bool MainWindow::openProject(QString fileName)
}
}
if (QString(fi.suffix()).toLower() == "mlp")
if (QString(fi.suffix()).toLower() == "mlp" || QString(fi.suffix()).toLower() == "mlb")
{
if (!MeshDocumentFromXML(*meshDoc(),fileName))
std::map<int, MLRenderingData> rendOpt;
if (!MeshDocumentFromXML(*meshDoc(), fileName, (QString(fi.suffix()).toLower() == "mlb"), rendOpt))
{
QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unable to open MLP file");
return false;
QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unable to open MeshLab Project file");
return false;
}
for (int i=0; i<meshDoc()->meshList.size(); i++)
{
QString fullPath = meshDoc()->meshList[i]->fullName();
//meshDoc()->setBusy(true);
Matrix44m trm = this->meshDoc()->meshList[i]->cm.Tr; // save the matrix, because loadMeshClear it...
if (!loadMeshWithStandardParams(fullPath,this->meshDoc()->meshList[i],trm))
MLRenderingData* ptr = NULL;
if (rendOpt.find(meshDoc()->meshList[i]->id()) != rendOpt.end())
ptr = &rendOpt[meshDoc()->meshList[i]->id()];
if (!loadMeshWithStandardParams(fullPath, this->meshDoc()->meshList[i], trm, false, ptr))
meshDoc()->delMesh(meshDoc()->meshList[i]);
}
}
@ -2323,6 +2335,7 @@ GLA()->setDrawMode(GLW::DMPoints);*/
GLA()->setDrawMode(GLW::DMPoints);*/
/////////////////////////////////////////////////////////
}
meshDoc()->setBusy(false);
if(this->GLA() == 0) return false;
@ -2338,7 +2351,7 @@ GLA()->setDrawMode(GLW::DMPoints);*/
saveRecentProjectList(fileName);
globrendtoolbar->setEnabled(true);
showLayerDlg(visiblelayer || (meshDoc()->meshList.size() > 0));
return true;
}
@ -2346,8 +2359,8 @@ bool MainWindow::appendProject(QString fileName)
{
QStringList fileNameList;
globrendtoolbar->setEnabled(false);
if (fileName.isEmpty())
fileNameList = QFileDialog::getOpenFileNames(this,tr("Append Project File"), lastUsedDirectory.path(), "All Project Files (*.mlp *.aln);;MeshLab Project (*.mlp);;Align Project (*.aln)");
if (fileName.isEmpty())
fileNameList = QFileDialog::getOpenFileNames(this, tr("Append Project File"), lastUsedDirectory.path(), "All Project Files (*.mlp *.mlb *.aln *.out *.nvm);;MeshLab Project (*.mlp);;MeshLab Binary Project (*.mlb);;Align Project (*.aln);;Bundler Output (*.out);;VisualSFM Output (*.nvm)");
else
fileNameList.append(fileName);
@ -2371,7 +2384,7 @@ bool MainWindow::appendProject(QString fileName)
QFileInfo fi(fileName);
lastUsedDirectory = fi.absoluteDir();
if((fi.suffix().toLower()!="aln") && (fi.suffix().toLower()!="mlp"))
if((fi.suffix().toLower()!="aln") && (fi.suffix().toLower()!="mlp") && (fi.suffix().toLower() != "mlb") && (fi.suffix().toLower() != "out") && (fi.suffix().toLower() != "nvm"))
{
QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unknown project file extension");
return false;
@ -2400,23 +2413,58 @@ bool MainWindow::appendProject(QString fileName)
}
}
if (QString(fi.suffix()).toLower() == "mlp")
if (QString(fi.suffix()).toLower() == "mlp" || QString(fi.suffix()).toLower() == "mlb")
{
int alreadyLoadedNum = meshDoc()->meshList.size();
if (!MeshDocumentFromXML(*meshDoc(),fileName))
int alreadyLoadedNum = meshDoc()->meshList.size();
std::map<int, MLRenderingData> rendOpt;
if (!MeshDocumentFromXML(*meshDoc(),fileName, QString(fi.suffix()).toLower() == "mlb", rendOpt))
{
QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unable to open MLP file");
QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unable to open MeshLab Project file");
return false;
}
for (int i = alreadyLoadedNum-1; i<meshDoc()->meshList.size(); i++)
for (int i = alreadyLoadedNum; i<meshDoc()->meshList.size(); i++)
{
QString fullPath = meshDoc()->meshList[i]->fullName();
meshDoc()->setBusy(true);
Matrix44m trm = this->meshDoc()->meshList[i]->cm.Tr; // save the matrix, because loadMeshClear it...
if(!loadMeshWithStandardParams(fullPath,this->meshDoc()->meshList[i],trm))
MLRenderingData* ptr = NULL;
if (rendOpt.find(meshDoc()->meshList[i]->id()) != rendOpt.end())
ptr = &rendOpt[meshDoc()->meshList[i]->id()];
if(!loadMeshWithStandardParams(fullPath,this->meshDoc()->meshList[i],trm, false, ptr))
meshDoc()->delMesh(meshDoc()->meshList[i]);
}
}
if (QString(fi.suffix()).toLower() == "out") {
QString cameras_filename = fileName;
QString image_list_filename;
QString model_filename;
image_list_filename = QFileDialog::getOpenFileName(
this, tr("Open image list file"),
QFileInfo(fileName).absolutePath(),
tr("Bundler images list file (*.txt)")
);
if (image_list_filename.isEmpty())
return false;
if (!MeshDocumentFromBundler(*meshDoc(), cameras_filename, image_list_filename, model_filename)) {
QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unable to open OUTs file");
return false;
}
}
if (QString(fi.suffix()).toLower() == "nvm") {
QString cameras_filename = fileName;
QString model_filename;
if (!MeshDocumentFromNvm(*meshDoc(), cameras_filename, model_filename)) {
QMessageBox::critical(this, tr("Meshlab Opening Error"), "Unable to open NVMs file");
return false;
}
}
}
globrendtoolbar->setEnabled(true);
@ -2641,7 +2689,7 @@ bool MainWindow::importRaster(const QString& fileImg)
return true;
}
bool MainWindow::loadMesh(const QString& fileName, MeshIOInterface *pCurrentIOPlugin, MeshModel* mm, int& mask,RichParameterSet* prePar, const Matrix44m &mtr, bool isareload)
bool MainWindow::loadMesh(const QString& fileName, MeshIOInterface *pCurrentIOPlugin, MeshModel* mm, int& mask,RichParameterSet* prePar, const Matrix44m &mtr, bool isareload, MLRenderingData* rendOpt)
{
if ((GLA() == NULL) || (mm == NULL))
return false;
@ -2743,7 +2791,7 @@ bool MainWindow::loadMesh(const QString& fileName, MeshIOInterface *pCurrentIOPl
QMessageBox::warning(this, "MeshLab Warning", QString("Warning mesh contains %1 vertices with NAN coords and %2 degenerated faces.\nCorrected.").arg(delVertNum).arg(delFaceNum) );
mm->cm.Tr = mtr;
computeRenderingDataOnLoading(mm,isareload);
computeRenderingDataOnLoading(mm,isareload, rendOpt);
updateLayerDialog();
@ -2752,7 +2800,7 @@ bool MainWindow::loadMesh(const QString& fileName, MeshIOInterface *pCurrentIOPl
return true;
}
void MainWindow::computeRenderingDataOnLoading(MeshModel* mm,bool isareload)
void MainWindow::computeRenderingDataOnLoading(MeshModel* mm,bool isareload, MLRenderingData* rendOpt)
{
MultiViewer_Container* mv = currentViewContainer();
if (mv != NULL)
@ -2761,7 +2809,9 @@ void MainWindow::computeRenderingDataOnLoading(MeshModel* mm,bool isareload)
if ((shared != NULL) && (mm != NULL))
{
MLRenderingData defdt;
MLPoliciesStandAloneFunctions::suggestedDefaultPerViewRenderingData(mm, defdt,mwsettings.minpolygonpersmoothrendering);
MLPoliciesStandAloneFunctions::suggestedDefaultPerViewRenderingData(mm, defdt,mwsettings.minpolygonpersmoothrendering);
if (rendOpt != NULL)
defdt = *rendOpt;
for (int glarid = 0; glarid < mv->viewerCounter(); ++glarid)
{
GLArea* ar = mv->getViewer(glarid);
@ -2924,15 +2974,22 @@ void MainWindow::openRecentProj()
if (action) openProject(action->data().toString());
}
bool MainWindow::loadMeshWithStandardParams(QString& fullPath, MeshModel* mm, const Matrix44m &mtr,bool isreload)
bool MainWindow::loadMeshWithStandardParams(QString& fullPath, MeshModel* mm, const Matrix44m &mtr, bool isreload, MLRenderingData* rendOpt)
{
if ((meshDoc() == NULL) || (mm == NULL))
return false;
bool ret = false;
mm->Clear();
if (!mm->isVisible())
{
mm->Clear();
mm->visible = false;
}
else
mm->Clear();
QFileInfo fi(fullPath);
QString extension = fi.suffix();
MeshIOInterface *pCurrentIOPlugin = PM.allKnowInputFormats[extension.toLower()];
if(pCurrentIOPlugin != NULL)
{
RichParameterSet prePar;
@ -2940,7 +2997,7 @@ bool MainWindow::loadMeshWithStandardParams(QString& fullPath, MeshModel* mm, co
prePar = prePar.join(currentGlobalParams);
int mask = 0;
QTime t;t.start();
bool open = loadMesh(fullPath,pCurrentIOPlugin,mm,mask,&prePar,mtr,isreload);
bool open = loadMesh(fullPath,pCurrentIOPlugin,mm,mask,&prePar,mtr,isreload, rendOpt);
if(open)
{
GLA()->Logf(0,"Opened mesh %s in %i msec",qPrintable(fullPath),t.elapsed());

View File

@ -241,7 +241,7 @@ public:
{
QDir curDir = QDir::current();
QFileInfo fi(filename);
bool opened = MeshDocumentFromXML(md,fi.absoluteFilePath());
bool opened = MeshDocumentFromXML(md,fi.absoluteFilePath(), fi.suffix().toLower() == "mlb");
if (!opened)
return false;
QDir::setCurrent(fi.absolutePath());
@ -298,7 +298,7 @@ public:
}
QDir::setCurrent(curDir.absolutePath());
return MeshDocumentToXMLFile(md,filename,false);
return MeshDocumentToXMLFile(md,filename,false, outprojinfo.suffix().toLower() == "mlb");
}
bool script(MeshDocument &meshDocument,const QString& scriptfile,FILE* fp)