From 992a2cfe421335a9448fcde7afac2682f581794d Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Tue, 20 Apr 2021 14:58:29 +0200 Subject: [PATCH] better management of io warnings --- src/common/plugins/interfaces/io_plugin.cpp | 6 ++++-- src/common/utilities/load_save.cpp | 18 +---------------- src/meshlab/mainwindow_RunTime.cpp | 22 +++++++++++++-------- src/meshlabplugins/io_3ds/meshio.cpp | 12 +++++++---- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/common/plugins/interfaces/io_plugin.cpp b/src/common/plugins/interfaces/io_plugin.cpp index 66584a40d..aaeb04743 100644 --- a/src/common/plugins/interfaces/io_plugin.cpp +++ b/src/common/plugins/interfaces/io_plugin.cpp @@ -39,8 +39,10 @@ void IOPlugin::open( void IOPlugin::reportWarning(const QString& warningMessage) const { - MeshLabPluginLogger::log(GLLogStream::WARNING, warningMessage.toStdString()); - warnString += "\n" + warningMessage; + if (!warningMessage.isEmpty()){ + MeshLabPluginLogger::log(GLLogStream::WARNING, warningMessage.toStdString()); + warnString += "\n" + warningMessage; + } } void IOPlugin::wrongOpenFormat(const QString& format) diff --git a/src/common/utilities/load_save.cpp b/src/common/utilities/load_save.cpp index eee63ae09..bff5b5d59 100644 --- a/src/common/utilities/load_save.cpp +++ b/src/common/utilities/load_save.cpp @@ -53,19 +53,12 @@ void loadMesh(const QString& fileName, IOPlugin* ioPlugin, const RichParameterLi throw e; } - QString warningError = ioPlugin->warningMessageString(); - - //saveRecentFileList(fileName); - auto itmesh = meshList.begin(); auto itmask = maskList.begin(); for (unsigned int i = 0; i < meshList.size(); ++i){ MeshModel* mm = *itmesh; int mask = *itmask; - //if (!(mm->cm.textures.empty())) - // updateTexture(mm->id()); - // In case of polygonal meshes the normal should be updated accordingly if( mask & vcg::tri::io::Mask::IOM_BITPOLYGONAL) { mm->updateDataMask(MeshModel::MM_POLYGONAL); // just to be sure. Hopefully it should be done in the plugin... @@ -98,21 +91,12 @@ void loadMesh(const QString& fileName, IOPlugin* ioPlugin, const RichParameterLi int delFaceNum = vcg::tri::Clean::RemoveDegenerateFace(mm->cm); vcg::tri::Allocator::CompactEveryVector(mm->cm); if(delVertNum>0 || delFaceNum>0 ) - ioPlugin->reportWarning(warningError + "\n" + QString("Warning mesh contains %1 vertices with NAN coords and %2 degenerated faces.\nCorrected.").arg(delVertNum).arg(delFaceNum)); - //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; + ioPlugin->reportWarning(QString("Warning mesh contains %1 vertices with NAN coords and %2 degenerated faces.\nCorrected.").arg(delVertNum).arg(delFaceNum)); //computeRenderingDataOnLoading(mm,isareload, rendOpt); ++itmesh; ++itmask; } - - //updateLayerDialog(); - - - //meshDoc()->setBusy(false); - QDir::setCurrent(origDir); // undo the change of directory before leaving } diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index b68eaad82..ff85fec93 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -1751,6 +1751,8 @@ bool MainWindow::openProject(QString fileName) meshlab::loadMeshWithStandardParameters(relativeToProj, *meshDoc(), QCallBack); meshDoc()->mm()->cm.Tr.Import(rm.transformation); computeRenderingDataOnLoading(meshDoc()->mm(), false, nullptr); + if (!(meshDoc()->mm()->cm.textures.empty())) + updateTexture(meshDoc()->mm()->id()); } catch (const MLException& e){ QMessageBox::critical(this, "Meshlab Opening Error", e.what()); @@ -1894,6 +1896,8 @@ bool MainWindow::appendProject(QString fileName) meshlab::loadMeshWithStandardParameters(relativeToProj, *meshDoc(), QCallBack); meshDoc()->mm()->cm.Tr.Import(rm.transformation); computeRenderingDataOnLoading(meshDoc()->mm(), false, nullptr); + if (!(meshDoc()->mm()->cm.textures.empty())) + updateTexture(meshDoc()->mm()->id()); } catch (const MLException& e){ QMessageBox::critical(this, "Meshlab Opening Error", e.what()); @@ -2438,8 +2442,11 @@ bool MainWindow::importMesh(QString fileName) meshlab::loadMesh(fileName, pCurrentIOPlugin, prePar, meshList, masks, QCallBack); saveRecentFileList(fileName); updateLayerDialog(); - for (MeshModel* mm : meshList) + for (MeshModel* mm : meshList) { computeRenderingDataOnLoading(mm, false, nullptr); + if (! (mm->cm.textures.empty())) + updateTexture(mm->id()); + } QString warningString = pCurrentIOPlugin->warningMessageString(); if (!warningString.isEmpty()){ QMessageBox::warning(this, "Meshlab Opening Warning", warningString); @@ -2942,17 +2949,19 @@ void MainWindow::updateTexture(int meshid) { QImage img; QFileInfo fi(mymesh->cm.textures[i].c_str()); + QFileInfo mfi(mymesh->fullName()); QString filename = fi.absoluteFilePath(); bool res = img.load(filename); - sometextfailed = sometextfailed || !res; if(!res) { - res = img.load(filename); + QString fn2 = mfi.absolutePath() + "/" + fi.fileName(); + res = img.load(fn2); if(!res) { QString errmsg = QString("Failure of loading texture %1").arg(fi.fileName()); meshDoc()->Log.log(GLLogStream::WARNING,qUtf8Printable(errmsg)); - unexistingtext += "" + filename + "
"; + unexistingtext += "" + fi.fileName() + "
"; + sometextfailed = sometextfailed || !res; } } @@ -2966,12 +2975,9 @@ void MainWindow::updateTexture(int meshid) /*PLEASE EXPLAIN ME!*********************************************************************************************************************************************************************************/ if (!res) - res = img.load(":/images/dummy.png"); + img.load(":/images/dummy.png"); GLuint textid = shared->allocateTexturePerMesh(meshid,img,singleMaxTextureSizeMpx); - if (sometextfailed) - QMessageBox::warning(this,"Texture file has not been correctly loaded",unexistingtext); - for(int tt = 0;tt < mvc->viewerCounter();++tt) { GLArea* ar = mvc->getViewer(tt); diff --git a/src/meshlabplugins/io_3ds/meshio.cpp b/src/meshlabplugins/io_3ds/meshio.cpp index 6bbeda306..2cce37448 100644 --- a/src/meshlabplugins/io_3ds/meshio.cpp +++ b/src/meshlabplugins/io_3ds/meshio.cpp @@ -174,12 +174,14 @@ void ExtraMeshIOPlugin::open( for ( unsigned textureIdx = 0; textureIdx < mm.cm.textures.size(); ++textureIdx) { FILE* pFile = fopen (mm.cm.textures[textureIdx].c_str(), "r"); - if (pFile == NULL) { + if (pFile == nullptr) { missingTextureFilesMsg.append("\n"); missingTextureFilesMsg.append(mm.cm.textures[textureIdx].c_str()); someTextureNotFound = true; } - fclose (pFile); + else { + fclose (pFile); + } } if (someTextureNotFound){ reportWarning("Missing texture files: " + missingTextureFilesMsg); @@ -216,13 +218,15 @@ void ExtraMeshIOPlugin::open( for ( unsigned textureIdx = 0; textureIdx < m.cm.textures.size(); ++textureIdx) { FILE* pFile = fopen (m.cm.textures[textureIdx].c_str(), "r"); - if (pFile == NULL) + if (pFile == nullptr) { missingTextureFilesMsg.append("\n"); missingTextureFilesMsg.append(m.cm.textures[textureIdx].c_str()); someTextureNotFound = true; } - fclose (pFile); + else { + fclose (pFile); + } } if (someTextureNotFound){ reportWarning("Missing texture files: " + missingTextureFilesMsg);