From f53c6d3ec3e8dd9c9f88a37851a97ec7c1ffedf0 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Wed, 30 Jan 2013 08:48:22 +0100 Subject: [PATCH] Added simple program to convert OGS meshes into vtk format. --- FileIO/RapidXmlIO/BoostVtuInterface.cpp | 5 +- Utils/FileConverter/CMakeLists.txt | 8 ++++ Utils/FileConverter/OGS2VTK.cpp | 63 +++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 Utils/FileConverter/OGS2VTK.cpp diff --git a/FileIO/RapidXmlIO/BoostVtuInterface.cpp b/FileIO/RapidXmlIO/BoostVtuInterface.cpp index e007502ef49..8333e3f7e84 100644 --- a/FileIO/RapidXmlIO/BoostVtuInterface.cpp +++ b/FileIO/RapidXmlIO/BoostVtuInterface.cpp @@ -90,7 +90,6 @@ MeshLib::Mesh* BoostVtuInterface::readVTUFile(const std::string &file_name) "UnstructuredGrid.Piece"); if (piece_node) { - const unsigned nNodes = static_cast<unsigned>(piece_node->get("<xmlattr>.NumberOfPoints", 0)); const unsigned nElems = @@ -180,7 +179,7 @@ MeshLib::Mesh* BoostVtuInterface::readVTUFile(const std::string &file_name) optional<std::string> const& format = getXmlAttribute("format", *types); if (*format == "ascii") { - for(unsigned i=0; i<nElems; i++) + for(unsigned i = 0; i < nElems; i++) iss >> cell_types[i]; } else if (*format == "appended") @@ -216,7 +215,7 @@ MeshLib::Mesh* BoostVtuInterface::readVTUFile(const std::string &file_name) INFO("BoostVtuInterface::readVTUFile(): \tfinished."); INFO("BoostVtuInterface::readVTUFile(): Nr. Nodes: %d", nodes.size()); - INFO("BoostVtuInterface::readVTUFile(): Nr. Elements: ", elements.size()); + INFO("BoostVtuInterface::readVTUFile(): Nr. Elements: %d", elements.size()); return new MeshLib::Mesh(BaseLib::extractBaseNameWithoutExtension(file_name), nodes, elements); diff --git a/Utils/FileConverter/CMakeLists.txt b/Utils/FileConverter/CMakeLists.txt index 214873abe50..be32d31afb7 100644 --- a/Utils/FileConverter/CMakeLists.txt +++ b/Utils/FileConverter/CMakeLists.txt @@ -83,3 +83,11 @@ TARGET_LINK_LIBRARIES (GMSH2OGS FileIO ) +ADD_EXECUTABLE (OGS2VTK OGS2VTK.cpp) +SET_TARGET_PROPERTIES(OGS2VTK PROPERTIES FOLDER Utilities) +TARGET_LINK_LIBRARIES (OGS2VTK + MeshLib + FileIO + zlib +) + diff --git a/Utils/FileConverter/OGS2VTK.cpp b/Utils/FileConverter/OGS2VTK.cpp new file mode 100644 index 00000000000..19ec71cbf85 --- /dev/null +++ b/Utils/FileConverter/OGS2VTK.cpp @@ -0,0 +1,63 @@ +/** + * @file OGS2VTK.cpp + * @author Thomas Fischer + * @date Jan 24, 2013 + * @brief Converts OGS mesh into VTK mesh. + * + * @copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/LICENSE.txt + */ + +// STL +#include <string> + +// TCLAP +#include "tclap/CmdLine.h" + +// ThirdParty/logog +#include "logog/include/logog.hpp" + +// BaseLib +#include "LogogSimpleFormatter.h" + +// FileIO +#include "RapidXmlIO/BoostVtuInterface.h" +#include "readMeshFromFile.h" + +// MeshLib +#include "Mesh.h" + +int main (int argc, char* argv[]) +{ + LOGOG_INITIALIZE(); + logog::Cout* logog_cout (new logog::Cout); + BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); + logog_cout->SetFormatter(*custom_format); + + TCLAP::CmdLine cmd("Converts OGS mesh into VTK mesh.", ' ', "0.1"); + TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", + "the name of the file containing the input mesh", true, + "", "file name of input mesh"); + cmd.add(mesh_in); + TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", + "the name of the file the mesh will be written to", true, + "", "file name of output mesh"); + cmd.add(mesh_out); + cmd.parse(argc, argv); + + MeshLib::Mesh* mesh (FileIO::readMeshFromFile(mesh_in.getValue())); + INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); + + FileIO::BoostVtuInterface vtu; + vtu.setMesh(mesh); + vtu.writeToFile(mesh_out.getValue()); + + delete custom_format; + delete logog_cout; + LOGOG_SHUTDOWN(); + + return 0; +} -- GitLab