Skip to content
Snippets Groups Projects
Commit d801efed authored by Karsten Rink's avatar Karsten Rink
Browse files

used generalised method for writing files

parent c6533edf
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "GeoLib/AABB.h" #include "GeoLib/AABB.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h" #include "MeshLib/Mesh.h"
...@@ -75,7 +74,6 @@ int main (int argc, char* argv[]) ...@@ -75,7 +74,6 @@ int main (int argc, char* argv[])
INFO("Usage: %s <msh-file.msh> <keyword> [<value1>] [<value2>]", INFO("Usage: %s <msh-file.msh> <keyword> [<value1>] [<value2>]",
argv[0]); argv[0]);
INFO("Available keywords:"); INFO("Available keywords:");
//for (std::size_t i=0; i<keywords.size(); i++)
INFO( INFO(
"\t-ALL <value1> <value2> : changes the elevation of all mesh " "\t-ALL <value1> <value2> : changes the elevation of all mesh "
"nodes by <value2> in direction <value1> [x,y,z]."); "nodes by <value2> in direction <value1> [x,y,z].");
...@@ -209,7 +207,10 @@ int main (int argc, char* argv[]) ...@@ -209,7 +207,10 @@ int main (int argc, char* argv[])
} }
/**** add other keywords here ****/ /**** add other keywords here ****/
MeshLib::IO::VtuInterface vtu (mesh.get(), 0, false); std::string const new_mesh_name (msh_name.substr(0, msh_name.length() - 4) + "_new.vtu");
vtu.writeToFile(msh_name.substr(0, msh_name.length() - 4) + "_new.vtu"); if (MeshLib::IO::writeMeshToFile(*mesh, new_mesh_name) != 0)
return EXIT_FAILURE;
INFO ("Result successfully written.")
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
...@@ -22,19 +22,22 @@ namespace MeshLib ...@@ -22,19 +22,22 @@ namespace MeshLib
{ {
namespace IO namespace IO
{ {
void writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name) int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name)
{ {
if (BaseLib::hasFileExtension("msh", file_name)) if (BaseLib::hasFileExtension("msh", file_name))
{ {
MeshLib::IO::Legacy::MeshIO meshIO; MeshLib::IO::Legacy::MeshIO meshIO;
meshIO.setMesh(&mesh); meshIO.setMesh(&mesh);
meshIO.writeToFile(file_name); meshIO.writeToFile(file_name);
return 0;
} else if (BaseLib::hasFileExtension("vtu", file_name)) { } else if (BaseLib::hasFileExtension("vtu", file_name)) {
MeshLib::IO::VtuInterface writer(&mesh); MeshLib::IO::VtuInterface writer(&mesh);
writer.writeToFile(file_name); writer.writeToFile(file_name);
} else { return 0;
ERR("writeMeshToFile(): Unknown mesh file format in file %s.", file_name.c_str());
} }
ERR("writeMeshToFile(): Unknown mesh file format in file %s.", file_name.c_str());
return -1;
} }
} // end namespace IO } // end namespace IO
......
...@@ -16,7 +16,7 @@ namespace MeshLib ...@@ -16,7 +16,7 @@ namespace MeshLib
class Mesh; class Mesh;
namespace IO namespace IO
{ {
void writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name); int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment