From fcb02612b164a1e1bc25e767e00fc47fc3cc37ed Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Sun, 7 Apr 2019 19:53:55 +0200 Subject: [PATCH] [A/U] Add ascii output to OGS2VTK and createLayeredMeshFromRaster. --- Applications/Utils/FileConverter/OGS2VTK.cpp | 12 ++++++++++-- .../Utils/MeshEdit/ExtractSurface.cpp | 12 ++++-------- .../MeshEdit/createLayeredMeshFromRasters.cpp | 19 ++++++++++++++++--- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Applications/Utils/FileConverter/OGS2VTK.cpp b/Applications/Utils/FileConverter/OGS2VTK.cpp index 6799fdbfd5e..fddf988cccc 100644 --- a/Applications/Utils/FileConverter/OGS2VTK.cpp +++ b/Applications/Utils/FileConverter/OGS2VTK.cpp @@ -44,6 +44,12 @@ int main (int argc, char* argv[]) "the name of the file the mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); + TCLAP::ValueArg<bool> use_ascii_arg( + "", "ascii_output", + "Use ascii format for data in the vtu output. Due to possible rounding " + "the ascii output could result in lower accuracy.", + false, false, "boolean value"); + cmd.add(use_ascii_arg); cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh const> mesh( @@ -55,8 +61,10 @@ int main (int argc, char* argv[]) INFO("Mesh read: %d nodes, %d elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); - MeshLib::IO::VtuInterface vtu(mesh.get()); - vtu.writeToFile(mesh_out.getValue()); + auto const data_mode = + use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary; + + MeshLib::IO::writeVtu(*mesh, mesh_out.getValue(), data_mode); return EXIT_SUCCESS; } diff --git a/Applications/Utils/MeshEdit/ExtractSurface.cpp b/Applications/Utils/MeshEdit/ExtractSurface.cpp index 75e31e621c8..30c55122398 100644 --- a/Applications/Utils/MeshEdit/ExtractSurface.cpp +++ b/Applications/Utils/MeshEdit/ExtractSurface.cpp @@ -120,13 +120,9 @@ int main (int argc, char* argv[]) out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu"; } - if (use_ascii_arg.getValue()) - { - MeshLib::IO::writeVtu(*surface_mesh, out_fname, vtkXMLWriter::Ascii); - } - else - { - MeshLib::IO::writeMeshToFile(*surface_mesh, out_fname); - } + auto const data_mode = + use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary; + MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode); + return EXIT_SUCCESS; } diff --git a/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp b/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp index ce0037029b6..016b49fa6c5 100644 --- a/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp +++ b/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp @@ -24,7 +24,7 @@ #include "BaseLib/FileTools.h" #include "MeshLib/IO/readMeshFromFile.h" -#include "MeshLib/IO/writeMeshToFile.h" +#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "Applications/FileIO/AsciiRasterInterface.h" #include "MeshLib/Mesh.h" @@ -98,6 +98,13 @@ int main (int argc, char* argv[]) false, min_thickness, "minimum layer thickness"); cmd.add(min_thickness_arg); + TCLAP::ValueArg<bool> use_ascii_arg( + "", "ascii_output", + "Use ascii format for data in the vtu output. Due to possible rounding " + "the ascii output could result in lower accuracy.", + false, false, "boolean value"); + cmd.add(use_ascii_arg); + cmd.parse(argc, argv); if (min_thickness_arg.isSet()) @@ -149,9 +156,15 @@ int main (int argc, char* argv[]) { output_name.append(".vtu"); } + INFO("Writing mesh '%s' ... ", output_name.c_str()); - MeshLib::IO::writeMeshToFile(*(mapper.getMesh("SubsurfaceMesh").release()), - output_name); + auto result_mesh = std::make_unique<MeshLib::Mesh>( + *(mapper.getMesh("SubsurfaceMesh").release())); + + auto const data_mode = + use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary; + + MeshLib::IO::writeVtu(*result_mesh, output_name, data_mode); INFO("done."); return EXIT_SUCCESS; -- GitLab