From b2d104feb054ab35ffee556a80eea9a68b5aa240 Mon Sep 17 00:00:00 2001 From: "Joseph E. Weaver" Date: Tue, 30 Apr 2019 23:25:45 -0400 Subject: [PATCH 1/3] Add rough framework for saving ASCII STL Figured out the plumbing to add a new sub parameter command line option, where it hooks into the the export code in the server, and how to set the right flag in the parameter set for the IO object --- src/meshlabserver/mainserver.cpp | 47 ++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/meshlabserver/mainserver.cpp b/src/meshlabserver/mainserver.cpp index 37bbbb231..10f23e9f4 100644 --- a/src/meshlabserver/mainserver.cpp +++ b/src/meshlabserver/mainserver.cpp @@ -202,7 +202,7 @@ public: return true; } - bool exportMesh(MeshModel *mm, const int mask, const QString& fileName,FILE* fp = stdout) + bool exportMesh(MeshModel *mm, const int mask, const QString& fileName,bool writebinary,FILE* fp = stdout) { QFileInfo fi(fileName); // this change of dir is needed for subsequent textures/materials loading @@ -225,6 +225,25 @@ public: // optional saving parameters (like ascii/binary encoding) RichParameterSet savePar; pCurrentIOPlugin->initSaveParameter(extension, *mm, savePar); + if(savePar.hasParameter("Binary")){ + printf("Binary is a parameter\n"); + if(savePar.getBool("Binary")){ + printf("Binary is set\n"); + } + else{ + printf("Binary is not set\n"); + } + + } + + printf("Got here\n"); + if(writebinary){ + printf("Write in binary\n"); + } + else{ + printf("Write ascii\n"); + savePar.setValue("Binary",BoolValue(false)); + } int formatmask = 0; int defbits = 0; pCurrentIOPlugin->GetExportMaskCapability(extension,formatmask,defbits); @@ -295,7 +314,7 @@ public: m->setFileName(outfilename); QFileInfo of(outfilename); m->setLabel(of.fileName()); - exportMesh(m,m->dataMask(),outfilename); + exportMesh(m,m->dataMask(),outfilename,true); } } @@ -604,6 +623,7 @@ namespace commandline const char log('l'); const char dump('d'); const char script('s'); + const char ascii('a'); void usage() { @@ -634,7 +654,7 @@ namespace commandline QString outputmeshExpression() { - QString options("(" + QString(vertex) + "|" + QString(face) + "|" + QString(wedge) + "|" + QString(mesh) + ")(" + QString(color) + "|" + QString(quality) + "|" + QString(flags) + "|" + QString(normal) + "|" + QString(radius) + "|" + QString(texture) + "|" + QString(polygon) + ")"); + QString options("(" + QString(vertex) + "|" + QString(face) + "|" + QString(wedge) + "|" + QString(mesh) + "|" +QString(ascii) + ")(" + QString(color) + "|" + QString(quality) + "|" + QString(flags) + "|" + QString(normal) + "|" + QString(radius) + "|" + QString(texture) + "|" + QString(polygon) + "|" + QString(ascii) + ")"); QString optionslist(options + "(\\s+" + options + ")*"); QString savingmask("-" + QString(mask) + "\\s+" + optionslist); QString layernumber("\\d+"); @@ -664,9 +684,10 @@ namespace commandline struct OutFileMesh { + OutFileMesh() : writebinary(true) {} QString filename; int mask; - + bool writebinary; /*WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ /*we need these two constant values because when we parse the command line we don't know yet how many layers will have the current document and which will be the current one. Opening a project and/or importing a file happens after the parsing of the commandline is completed*/ static const int lastlayerconst = -2; @@ -750,7 +771,7 @@ int main(int argc, char *argv[]) MeshLabServer server(&shared); server.loadPlugins(); - + bool writebinary = true; int i = 1; while(i < argc) { @@ -917,6 +938,19 @@ int main(int argc, char *argv[]) break; } + case commandline::ascii : + { + switch( argv[i][1]) + { + case commandline::ascii: + { + writebinary = false; + i++; + break; + } + } + break; + } case commandline::mesh : { switch (argv[i][1]) @@ -933,6 +967,7 @@ int main(int argc, char *argv[]) else ++i; outfl.mask = mask; + outfl.writebinary = writebinary; outmeshlist << outfl; break; } @@ -1030,7 +1065,7 @@ int main(int argc, char *argv[]) { MeshModel* meshmod = meshDocument.meshList[layertobesaved]; if (meshmod != NULL) - exported = server.exportMesh(meshDocument.meshList[layertobesaved], outmeshlist[ii].mask, outmeshlist[ii].filename, logfp); + exported = server.exportMesh(meshDocument.meshList[layertobesaved], outmeshlist[ii].mask, outmeshlist[ii].filename, outmeshlist[ii].writebinary, logfp); if (exported) fprintf(logfp, "Mesh %s saved as %s (%i vn %i fn)\n", qUtf8Printable(meshmod->fullName()), qUtf8Printable(outmeshlist[ii].filename), meshmod->cm.vn, meshmod->cm.fn); else From a93af4f279ff5d9547f54e971da40aaf7d871319 Mon Sep 17 00:00:00 2001 From: "Joseph E. Weaver" Date: Tue, 30 Apr 2019 23:35:51 -0400 Subject: [PATCH 2/3] Add ability to save STL as ASCII Should also work with other formats that use the Binary parameter in their save parameter set. Not sure if this works with projects, since that looks like it might be a different code path and I only work with one STL at a time --- src/meshlabserver/mainserver.cpp | 17 ++++++++++++++--- src/meshlabserver/meshlabserver.txt | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/meshlabserver/mainserver.cpp b/src/meshlabserver/mainserver.cpp index 10f23e9f4..0e7cac05c 100644 --- a/src/meshlabserver/mainserver.cpp +++ b/src/meshlabserver/mainserver.cpp @@ -225,7 +225,11 @@ public: // optional saving parameters (like ascii/binary encoding) RichParameterSet savePar; pCurrentIOPlugin->initSaveParameter(extension, *mm, savePar); - if(savePar.hasParameter("Binary")){ + +/* The commented code below is me just hacking around getting a feel for + * how to use RichParameter sets */ + +/* if(savePar.hasParameter("Binary")){ printf("Binary is a parameter\n"); if(savePar.getBool("Binary")){ printf("Binary is set\n"); @@ -244,6 +248,12 @@ public: printf("Write ascii\n"); savePar.setValue("Binary",BoolValue(false)); } +*/ + + if(savePar.hasParameter("Binary")){ + savePar.setValue("Binary",BoolValue(writebinary)); + } + int formatmask = 0; int defbits = 0; pCurrentIOPlugin->GetExportMaskCapability(extension,formatmask,defbits); @@ -623,6 +633,7 @@ namespace commandline const char log('l'); const char dump('d'); const char script('s'); + const char saveparam('s'); const char ascii('a'); void usage() @@ -654,7 +665,7 @@ namespace commandline QString outputmeshExpression() { - QString options("(" + QString(vertex) + "|" + QString(face) + "|" + QString(wedge) + "|" + QString(mesh) + "|" +QString(ascii) + ")(" + QString(color) + "|" + QString(quality) + "|" + QString(flags) + "|" + QString(normal) + "|" + QString(radius) + "|" + QString(texture) + "|" + QString(polygon) + "|" + QString(ascii) + ")"); + QString options("(" + QString(vertex) + "|" + QString(face) + "|" + QString(wedge) + "|" + QString(mesh) + "|" +QString(saveparam) + ")(" + QString(color) + "|" + QString(quality) + "|" + QString(flags) + "|" + QString(normal) + "|" + QString(radius) + "|" + QString(texture) + "|" + QString(polygon) + "|" + QString(ascii) + ")"); QString optionslist(options + "(\\s+" + options + ")*"); QString savingmask("-" + QString(mask) + "\\s+" + optionslist); QString layernumber("\\d+"); @@ -938,7 +949,7 @@ int main(int argc, char *argv[]) break; } - case commandline::ascii : + case commandline::saveparam : { switch( argv[i][1]) { diff --git a/src/meshlabserver/meshlabserver.txt b/src/meshlabserver/meshlabserver.txt index 16f0df27e..083d72aa9 100644 --- a/src/meshlabserver/meshlabserver.txt +++ b/src/meshlabserver/meshlabserver.txt @@ -52,7 +52,8 @@ meshlabserver [logargs] [args] wn-> wedge normals, wt -> wedge texture coords, mp -> polygonal mesh info - + sa -> save in ascii format + -s filename the script to be applied From 6590ebd99c452beaeaf7451a3d87e14c97a19d02 Mon Sep 17 00:00:00 2001 From: jmespadero Date: Fri, 13 Dec 2019 11:52:02 +0100 Subject: [PATCH 3/3] code cleanups --- src/meshlabserver/mainserver.cpp | 33 ++++---------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/src/meshlabserver/mainserver.cpp b/src/meshlabserver/mainserver.cpp index 0e7cac05c..3efdd3b6d 100644 --- a/src/meshlabserver/mainserver.cpp +++ b/src/meshlabserver/mainserver.cpp @@ -133,7 +133,7 @@ public: // Opening files in a transparent form (IO plugins contribution is hidden to user) QStringList filters; - // HashTable storing all supported formats togheter with + // HashTable storing all supported formats together with // the (1-based) index of first plugin which is able to open it QHash allKnownFormats; @@ -145,7 +145,7 @@ public: QDir::setCurrent(fi.absolutePath()); QString extension = fi.suffix(); - qDebug("Opening a file with extention %s", qUtf8Printable(extension)); + qDebug("Opening a file with extension %s", qUtf8Printable(extension)); // retrieving corresponding IO plugin MeshIOInterface* pCurrentIOPlugin = PM.allKnowInputFormats[extension.toLower()]; if (pCurrentIOPlugin == 0) @@ -225,31 +225,6 @@ public: // optional saving parameters (like ascii/binary encoding) RichParameterSet savePar; pCurrentIOPlugin->initSaveParameter(extension, *mm, savePar); - -/* The commented code below is me just hacking around getting a feel for - * how to use RichParameter sets */ - -/* if(savePar.hasParameter("Binary")){ - printf("Binary is a parameter\n"); - if(savePar.getBool("Binary")){ - printf("Binary is set\n"); - } - else{ - printf("Binary is not set\n"); - } - - } - - printf("Got here\n"); - if(writebinary){ - printf("Write in binary\n"); - } - else{ - printf("Write ascii\n"); - savePar.setValue("Binary",BoolValue(false)); - } -*/ - if(savePar.hasParameter("Binary")){ savePar.setValue("Binary",BoolValue(writebinary)); } @@ -399,7 +374,7 @@ public: } assert(parameterSet.paramList.size() == required.paramList.size()); RichParameter* parameter = parameterSet.paramList[i]; - //if this is a mesh paramter and the index is valid + //if this is a mesh parameter and the index is valid if(parameter->val->isMesh()) { RichMesh* md = reinterpret_cast(parameter); @@ -1087,7 +1062,7 @@ int main(int argc, char *argv[]) } else fprintf(logfp, "Invalid layer number %i. Last layer in the current document is the number %i. Output mesh %s will not be saved\n", outmeshlist[ii].layerposition, meshDocument.meshList.size() - 1, qUtf8Printable(outmeshlist[ii].filename)); - } + }//for(int ii if((logfp != NULL) && (logfp != stdout))