From 32f3723869d48444576d6ba0fa68fc37b93f43ff Mon Sep 17 00:00:00 2001 From: Alessandro Muntoni Date: Thu, 13 Jul 2023 11:03:37 +0200 Subject: [PATCH] fix pymeshlab issue 137 - filter plymc uses tmp dir to save temporary files --- .../filter_plymc/filter_plymc.cpp | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/meshlabplugins/filter_plymc/filter_plymc.cpp b/src/meshlabplugins/filter_plymc/filter_plymc.cpp index e3730ad71..e5031ab1d 100644 --- a/src/meshlabplugins/filter_plymc/filter_plymc.cpp +++ b/src/meshlabplugins/filter_plymc/filter_plymc.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include using namespace vcg; @@ -142,13 +143,21 @@ std::map PlyMCPlugin::applyFilter( case FP_PLYMC: { srand(time(NULL)); - - //check if folder is writable - QTemporaryFile file("./_tmp_XXXXXX.tmp"); - if (!file.open()) - { - log("ERROR - current folder is not writable. VCG Merging needs to save intermediate files in the current working folder. Project and meshes must be in a write-enabled folder. Please save your data in a suitable folder before applying."); - throw MLException("current folder is not writable.
VCG Merging needs to save intermediate files in the current working folder.
Project and meshes must be in a write-enabled folder.
Please save your data in a suitable folder before applying."); + + QDir currDir = QDir::current(); + + //Using tmp dir + QTemporaryDir tmpdir; + QTemporaryFile file(tmpdir.path()); + if (!file.open()) { + log("ERROR - tmp folder is not writable. VCG Merging needs to save intermediate files " + "in the tmp folder."); + throw MLException( + "tmp folder is not writable.
VCG Merging needs to save intermediate files in " + "the tmp folder."); + } + else { + QDir::setCurrent(tmpdir.path()); } tri::PlyMC > pmc; @@ -170,10 +179,8 @@ std::map PlyMCPlugin::applyFilter( p.FullyPreprocessedFlag=true; p.MergeColor=p.VertSplatFlag=par.getBool("mergeColor"); p.SimplificationFlag = par.getBool("simplification"); - for(MeshModel& mm: md.meshIterator()) - { - if(mm.isVisible()) - { + for(MeshModel& mm: md.meshIterator()) { + if(mm.isVisible()) { SMesh sm; mm.updateDataMask(MeshModel::MM_FACEQUALITY); tri::Append::Mesh(sm, mm.cm/*,false,p.VertSplatFlag*/); // note the last parameter of the append to prevent removal of unreferenced vertices... @@ -189,8 +196,7 @@ std::map PlyMCPlugin::applyFilter( QString mshTmpPath=QString("__TMP")+QString(mm.shortName())+QString(".vmi"); qDebug("Saving tmp file %s",qUtf8Printable(mshTmpPath)); int retVal = tri::io::ExporterVMI::Save(sm,qUtf8Printable(mshTmpPath) ); - if(retVal!=0) - { + if(retVal!=0) { qDebug("Failed to write vmi temp file %s",qUtf8Printable(mshTmpPath)); log("ERROR - Failed to write vmi temp file %s", qUtf8Printable(mshTmpPath)); @@ -201,14 +207,12 @@ std::map PlyMCPlugin::applyFilter( } } - if(pmc.Process(cb)==false) - { + if(pmc.Process(cb)==false) { throw MLException(pmc.errorMessage.c_str()); } - if(par.getBool("openResult")) - { + if(par.getBool("openResult")) { for(size_t i=0;i PlyMCPlugin::applyFilter( for(int i=0;i