diff --git a/src/common/plugins/interfaces/io_plugin.h b/src/common/plugins/interfaces/io_plugin.h index dfab58df5..165604d46 100644 --- a/src/common/plugins/interfaces/io_plugin.h +++ b/src/common/plugins/interfaces/io_plugin.h @@ -31,6 +31,8 @@ #include "../../utilities/file_format.h" #include "../../ml_document/raster_model.h" +class MLRenderingData; + /** * @brief The IOPlugin is the base class for meshes, images and projects loading * and saving. @@ -341,17 +343,22 @@ public: * @param fileName: the name of the file from which load the project (including its path) * @param md: MeshDocument on which store the content of the loaded project * note: the document could not be empty! + * @param rendOpt: rendering options that may be loaded from the project file, + * if it supports them. They are not required. If you can support + * rendering options, the rendOpt vector must have the same size of + * the MeshModel vector returned by the openProject function. * @param cb: standard callback for reporting progresso in the loading * @return the list of MeshModel that have been loaded from the given project */ - virtual std::list openProject( + virtual std::vector openProject( const QString& format, const QStringList& /*filenames*/, MeshDocument& /*md*/, + std::vector& /*rendOpt*/, vcg::CallBackPos* /*cb*/ = nullptr) { wrongOpenFormat(format); - return std::list(); + return std::vector(); } /************************** diff --git a/src/common/utilities/load_save.cpp b/src/common/utilities/load_save.cpp index aa27273b4..115b46627 100644 --- a/src/common/utilities/load_save.cpp +++ b/src/common/utilities/load_save.cpp @@ -336,10 +336,11 @@ void loadRaster(const QString& filename, RasterModel& rm, GLLogStream* log, vcg: // End of EXIF reading } -std::list loadProject( +std::vector loadProject( const QStringList& filenames, IOPlugin* ioPlugin, MeshDocument& md, + std::vector& rendOpt, GLLogStream* log, vcg::CallBackPos* cb) { @@ -347,10 +348,10 @@ std::list loadProject( QString extension = fi.suffix(); ioPlugin->setLog(log); - return ioPlugin->openProject(extension, filenames, md, cb); + return ioPlugin->openProject(extension, filenames, md, rendOpt, cb); } -std::list loadProject( +std::vector loadProject( const QStringList& filenames, MeshDocument& md, GLLogStream* log, @@ -375,11 +376,11 @@ std::list loadProject( ") is different from the expected one (" + QString::number(additionalFiles.size() +1)); } - - return loadProject(filenames, ioPlugin, md, log, cb); + std::vector rendOpt; + return loadProject(filenames, ioPlugin, md, rendOpt, log, cb); } -std::list loadProject( +std::vector loadProject( const QString& filename, MeshDocument& md, GLLogStream* log, diff --git a/src/common/utilities/load_save.h b/src/common/utilities/load_save.h index a9760f003..382f34b7d 100644 --- a/src/common/utilities/load_save.h +++ b/src/common/utilities/load_save.h @@ -72,20 +72,21 @@ void loadRaster( GLLogStream* log = nullptr, vcg::CallBackPos *cb = nullptr); -std::list loadProject( +std::vector loadProject( const QStringList& filenames, IOPlugin* ioPlugin, MeshDocument& md, + std::vector& rendOpt, GLLogStream* log = nullptr, vcg::CallBackPos *cb = nullptr); -std::list loadProject( +std::vector loadProject( const QStringList& filenames, MeshDocument& md, GLLogStream* log = nullptr, vcg::CallBackPos *cb = nullptr); -std::list loadProject( +std::vector loadProject( const QString& filename, MeshDocument& md, GLLogStream* log = nullptr, diff --git a/src/meshlab/mainwindow.h b/src/meshlab/mainwindow.h index 6dde35de7..760ed7664 100644 --- a/src/meshlab/mainwindow.h +++ b/src/meshlab/mainwindow.h @@ -125,7 +125,6 @@ public slots: bool importMeshWithLayerManagement(QString fileName=QString()); bool importRaster(const QString& fileImg = QString()); bool openProject(QString fileName=QString(), bool append = false); - void loadMLPRenderingOptions(QString fileName, const std::list& meshLsit); bool appendProject(QString fileName=QString()); void updateCustomSettings(); void updateLayerDialog(); diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index b64ad29cb..35b794d30 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -1753,9 +1753,10 @@ bool MainWindow::openProject(QString fileName, bool append) QDir::setCurrent(fi.absoluteDir().absolutePath()); qb->show(); - std::list meshList; + std::vector meshList; + std::vector rendOptions; try { - meshList = meshlab::loadProject(filenames, ioPlugin, *meshDoc(), &meshDoc()->Log, QCallBack); + meshList = meshlab::loadProject(filenames, ioPlugin, *meshDoc(), rendOptions, &meshDoc()->Log, QCallBack); } catch (const MLException& e) { QMessageBox::critical(this, tr("Meshlab Opening Error"), e.what()); @@ -1766,16 +1767,13 @@ bool MainWindow::openProject(QString fileName, bool append) QMessageBox::warning(this, "Warning", warningString); } - for (MeshModel* mm : meshList){ - computeRenderingDataOnLoading(mm, false, nullptr); - if (!(mm->cm.textures.empty())) - updateTexture(mm->id()); - } - - if (QString(fi.suffix()).toLower() == "mlp" || QString(fi.suffix()).toLower() == "mlb") - { - loadMLPRenderingOptions(fileName, meshList); - GLA()->updateMeshSetVisibilities(); + for (unsigned int i = 0; i < meshList.size(); i++){ + MLRenderingData* ptr = nullptr; + if (rendOptions.size() == meshList.size()) + ptr = &rendOptions[i]; + computeRenderingDataOnLoading(meshList[i], false, ptr); + if (!(meshList[i]->cm.textures.empty())) + updateTexture(meshList[i]->id()); } meshDoc()->setBusy(false); @@ -1797,83 +1795,6 @@ bool MainWindow::openProject(QString fileName, bool append) return true; } -void MainWindow::loadMLPRenderingOptions(QString fileName, const std::list& meshLsit) -{ - std::map rendOpt; - QFile qf(fileName); - QFileInfo qfInfo(fileName); - QDir tmpDir = QDir::current(); - QDir::setCurrent(qfInfo.absoluteDir().absolutePath()); - if (!qf.open(QIODevice::ReadOnly)) - return; - QString project_path = qfInfo.absoluteFilePath(); - - QDomDocument doc("MeshLabDocument"); //It represents the XML document - if (!doc.setContent(&qf)) - return; - - QDomElement root = doc.documentElement(); - - QDomNode node; - - node = root.firstChild(); - //Devices - while (!node.isNull()) { - if (QString::compare(node.nodeName(), "MeshGroup") == 0) - { - QDomNode mesh; - mesh = node.firstChild(); - auto it = meshLsit.begin(); - while (!mesh.isNull()) { - 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((*it)->id(), data)); - } - mesh = mesh.nextSibling(); - ++it; - } - } - node = node.nextSibling(); - } - for (MeshModel* mm : meshDoc()->meshIterator()) - { - MLRenderingData* ptr = nullptr; - if (rendOpt.find(mm->id()) != rendOpt.end()) - ptr = &rendOpt[mm->id()]; - computeRenderingDataOnLoading(mm, false, ptr); - } -} - bool MainWindow::appendProject(QString fileName) { QStringList fileNameList; diff --git a/src/meshlabplugins/io_base/baseio.cpp b/src/meshlabplugins/io_base/baseio.cpp index 91f9d38be..fee5b5df1 100644 --- a/src/meshlabplugins/io_base/baseio.cpp +++ b/src/meshlabplugins/io_base/baseio.cpp @@ -563,13 +563,15 @@ void BaseMeshIOPlugin::saveImage( } } -std::list BaseMeshIOPlugin::openProject( +std::vector BaseMeshIOPlugin::openProject( const QString& format, const QStringList& filenames, MeshDocument& md, + std::vector& rendOpt, CallBackPos* cb) { - std::list meshList; + std::vector meshList; + rendOpt.clear(); if (format.toUpper() == "ALN") { meshList = loadALN(filenames.first(), md, cb); } @@ -583,7 +585,7 @@ std::list BaseMeshIOPlugin::openProject( meshList = loadNVM(filenames.first(), md, unloadedImgs, cb); } else if (format.toUpper() =="MLP" || format.toUpper() == "MLB") { - meshList = loadMLP(filenames.first(), md, unloadedImgs, cb); + meshList = loadMLP(filenames.first(), md, rendOpt, unloadedImgs, cb); } if (unloadedImgs.size() > 0){ QString msg = "Unable to load the following " + diff --git a/src/meshlabplugins/io_base/baseio.h b/src/meshlabplugins/io_base/baseio.h index 312f68c5e..aab19f5d3 100644 --- a/src/meshlabplugins/io_base/baseio.h +++ b/src/meshlabplugins/io_base/baseio.h @@ -78,15 +78,18 @@ public: int quality, vcg::CallBackPos* cb); - std::list openProject( + std::vector openProject( const QString& format, const QStringList& filenames, MeshDocument& md, + std::vector& rendOpt, vcg::CallBackPos* cb); std::list projectFileRequiresAdditionalFiles( - const QString& format, - const QString& filename); + const QString& format, + const QString& filename); + + void initPreOpenParameter(const QString &formatName, RichParameterList &parlst); void initSaveParameter(const QString &format, const MeshModel &/*m*/, RichParameterList & par); diff --git a/src/meshlabplugins/io_base/load_project.cpp b/src/meshlabplugins/io_base/load_project.cpp index 63832a676..99754681d 100644 --- a/src/meshlabplugins/io_base/load_project.cpp +++ b/src/meshlabplugins/io_base/load_project.cpp @@ -10,12 +10,12 @@ #include #include -std::list loadALN( +std::vector loadALN( const QString& filename, MeshDocument& md, vcg::CallBackPos* cb) { - std::list meshList; + std::vector meshList; std::vector rmv; int retVal = ALNParser::ParseALN(rmv, qUtf8Printable(filename)); if(retVal != ALNParser::NoError) { @@ -40,14 +40,14 @@ std::list loadALN( return meshList; } -std::list loadOUT( +std::vector loadOUT( const QString& filename, const QString& imageListFile, MeshDocument& md, std::vector& unloadedImgList, vcg::CallBackPos*) { - std::list meshList; + std::vector meshList; unloadedImgList.clear(); QFileInfo fi(filename); @@ -105,13 +105,13 @@ std::list loadOUT( return meshList; } -std::list loadNVM( +std::vector loadNVM( const QString& filename, MeshDocument& md, std::vector& unloadedImgList, vcg::CallBackPos*) { - std::list meshList; + std::vector meshList; unloadedImgList.clear(); QFileInfo fi(filename); @@ -153,13 +153,14 @@ std::list loadNVM( return meshList; } -std::list loadMLP( +std::vector loadMLP( const QString& filename, MeshDocument& md, + std::vector& rendOpt, std::vector& unloadedImgList, - vcg::CallBackPos* cb) + vcg::CallBackPos*) { - std::list meshList; + std::vector meshList; unloadedImgList.clear(); QFile qf(filename); @@ -171,8 +172,6 @@ std::list loadMLP( if (!qf.open(QIODevice::ReadOnly)) throw MLException("File not found."); - QString project_path = qfInfo.absoluteFilePath(); - QDomDocument doc("MeshLabDocument"); //It represents the XML document if (!doc.setContent(&qf)) @@ -187,7 +186,8 @@ std::list loadMLP( //Devices while (!node.isNull()) { if (QString::compare(node.nodeName(), "MeshGroup") == 0) { - QDomNode mesh; QString filen, label; + QDomNode mesh; + QString filen, label; mesh = node.firstChild(); while (!mesh.isNull()) { //return true; @@ -252,6 +252,41 @@ std::list loadMLP( } } + 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.push_back(data); + } + mesh = mesh.nextSibling(); } } @@ -294,5 +329,9 @@ std::list loadMLP( QDir::setCurrent(tmpDir.absolutePath()); qf.close(); + if (rendOpt.size() != meshList.size()){ + std::cerr << "cannot load rend options\n"; + } + return meshList; } diff --git a/src/meshlabplugins/io_base/load_project.h b/src/meshlabplugins/io_base/load_project.h index 89b5e6b33..b184734fe 100644 --- a/src/meshlabplugins/io_base/load_project.h +++ b/src/meshlabplugins/io_base/load_project.h @@ -3,26 +3,26 @@ #include -std::list loadALN( +std::vector loadALN( const QString& filename, MeshDocument& md, vcg::CallBackPos* cb); -std::list loadOUT(const QString& filename, +std::vector loadOUT(const QString& filename, const QString& imageListFile, MeshDocument& md, std::vector& unloadedImgList, vcg::CallBackPos* cb); -std::list loadNVM( +std::vector loadNVM( const QString& filename, MeshDocument& md, std::vector& unloadedImgList, vcg::CallBackPos* cb); -std::list loadMLP( - const QString& filename, +std::vector loadMLP(const QString& filename, MeshDocument& md, + std::vector& rendOpt, std::vector& unloadedImgList, vcg::CallBackPos* cb);