diff --git a/Applications/Utils/MeshEdit/CMakeLists.txt b/Applications/Utils/MeshEdit/CMakeLists.txt index 31b6669bc985b1851248694b76b05681c983c1ed..bfb8fc831c8885f38b4257f318cfe77dadeecfa6 100644 --- a/Applications/Utils/MeshEdit/CMakeLists.txt +++ b/Applications/Utils/MeshEdit/CMakeLists.txt @@ -26,6 +26,20 @@ if(QT4_FOUND) set_target_properties(moveMeshNodes PROPERTIES FOLDER Utilities) + add_executable(MapGeometryToMeshSurface + MapGeometryToMeshSurface.cpp ) + target_link_libraries(MapGeometryToMeshSurface + MeshLib + MeshGeoToolsLib + FileIO + InSituLib + ${CATALYST_LIBRARIES} + ${QT_LIBRARIES} + ) + ADD_CATALYST_DEPENDENCY(MapGeometryToMeshSurface) + +set_target_properties(MapGeometryToMeshSurface + PROPERTIES FOLDER Utilities) endif() # QT4_FOUND add_executable(removeMeshElements removeMeshElements.cpp) diff --git a/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp b/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..53611af3022b84307ac563a29abb1e146335ac22 --- /dev/null +++ b/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp @@ -0,0 +1,104 @@ + +/* + * \date 2015-04-20 + * \brief Map geometric objects to the surface of the given mesh. + * + * \copyright + * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + */ + +#include <algorithm> +#include <cstdlib> +#include <vector> + +// TCLAP +#include "tclap/CmdLine.h" + +// ThirdParty/logog +#include "logog/include/logog.hpp" + +// BaseLib +#include "BaseLib/LogogSimpleFormatter.h" + +// FileIO +#include "FileIO/readMeshFromFile.h" +#include "FileIO/XmlIO/Boost/BoostXmlGmlInterface.h" +#include "FileIO/XmlIO/Qt/XmlGmlInterface.h" + +// GeoLib +#include "GeoLib/GEOObjects.h" + +// MeshLib +#include "MeshLib/Mesh.h" + +// MeshGeoToolsLib +#include "MeshGeoToolsLib/GeoMapper.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("Maps geometric objects to the surface of a given mesh.", + ' ', "0.1"); + TCLAP::ValueArg<std::string> mesh_in("m", "mesh-file", + "the name of the file containing the mesh", true, + "", "file name"); + cmd.add(mesh_in); + TCLAP::ValueArg<std::string> input_geometry_fname("i", "input-geometry", + "the name of the file containing the input geometry", true, + "", "file name"); + cmd.add(input_geometry_fname); + TCLAP::ValueArg<bool> advanced_mapping("", "advanced-mapping", + "if true advanced mapping algorithm will be applied", false, + true, "boolean value"); + cmd.add(advanced_mapping); + TCLAP::ValueArg<std::string> output_geometry_fname("o", "output-geometry", + "the name of the file containing the input geometry", true, + "", "file name"); + cmd.add(output_geometry_fname); + cmd.parse(argc, argv); + + // *** read mesh + MeshLib::Mesh * mesh(FileIO::readMeshFromFile(mesh_in.getValue())); + + // *** read geometry + GeoLib::GEOObjects geometries; + { + FileIO::BoostXmlGmlInterface xml_io(geometries); + if (xml_io.readFile(input_geometry_fname.getValue())) { + INFO("Read geometry from file \"%s\".", + input_geometry_fname.getValue().c_str()); + } else { + delete mesh; + return EXIT_FAILURE; + } + } + + std::string geo_name; + { + std::vector<std::string> geo_names; + geometries.getGeometryNames(geo_names); + geo_name = geo_names[0]; + } + + std::string new_geo_name(geo_name); + MeshGeoToolsLib::GeoMapper geo_mapper(geometries, geo_name); + if (advanced_mapping.getValue()) { + new_geo_name += "-Mapped"; + geo_mapper.advancedMapOnMesh(mesh, new_geo_name); + } else { + geo_mapper.mapOnMesh(mesh); + } + + { + FileIO::XmlGmlInterface xml_io(geometries); + xml_io.setNameForExport(new_geo_name); + xml_io.writeToFile(output_geometry_fname.getValue()); + } + return EXIT_SUCCESS; +}