diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index c1fd34e4cb3776b3d4d32ee9dcd34785ac2baea8..19accd45c5b52443684ea235ea103a21c102a4c6 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -821,7 +821,7 @@ void MainWindow::mapGeometry(const std::string &geo_name) settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); } - GeoMapper geo_mapper(*_project.getGEOObjects(), geo_name); + MeshGeoToolsLib::GeoMapper geo_mapper(*_project.getGEOObjects(), geo_name); QFileInfo fi(file_name); if (choice == 1) // load raster from file { diff --git a/Applications/Utils/MeshEdit/CMakeLists.txt b/Applications/Utils/MeshEdit/CMakeLists.txt index 31b6669bc985b1851248694b76b05681c983c1ed..4593518cc698f9d1fc1ccdd51000b2e8ae824c52 100644 --- a/Applications/Utils/MeshEdit/CMakeLists.txt +++ b/Applications/Utils/MeshEdit/CMakeLists.txt @@ -26,6 +26,19 @@ 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} + ) + 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..b1a14b92cb8cd53aa8df72686fb8de5f44c391f2 --- /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" + +// 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> additional_insert_mapping("a", "additional-insert-mapping", + "if true advanced mapping algorithm will be applied, i.e. a new " + "geometry will be created and possibly new points will be inserted.", false, + true, "boolean value"); + cmd.add(additional_insert_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 (additional_insert_mapping.getValue()) { + new_geo_name += "-Mapped"; + geo_mapper.advancedMapOnMesh(mesh, new_geo_name); + } else { + geo_mapper.mapOnMesh(mesh); + } + + { + FileIO::BoostXmlGmlInterface xml_io(geometries); + xml_io.setNameForExport(new_geo_name); + xml_io.writeToFile(output_geometry_fname.getValue()); + } + return EXIT_SUCCESS; +} diff --git a/MeshGeoToolsLib/GeoMapper.cpp b/MeshGeoToolsLib/GeoMapper.cpp index 9a50b71337f39718174d506f1aab63d06c8cc7f0..4a6131b00561a1d1076d430e33b82cbd7bd3f710 100644 --- a/MeshGeoToolsLib/GeoMapper.cpp +++ b/MeshGeoToolsLib/GeoMapper.cpp @@ -34,6 +34,8 @@ #include "MeshLib/MeshSurfaceExtraction.h" #include "MeshLib/MeshEditing/projectMeshOntoPlane.h" +namespace MeshGeoToolsLib { + GeoMapper::GeoMapper(GeoLib::GEOObjects &geo_objects, const std::string &geo_name) : _geo_objects(geo_objects), _geo_name(const_cast<std::string&>(geo_name)), _mesh(nullptr), _grid(nullptr), _raster(nullptr) { @@ -366,8 +368,5 @@ double GeoMapper::getMaxSegmentLength(const std::vector<GeoLib::Polyline*> &line return max_segment_length; } - - - - +} // end namespace MeshGeoToolsLib diff --git a/MeshGeoToolsLib/GeoMapper.h b/MeshGeoToolsLib/GeoMapper.h index 14bd26c44977600009973ba84cacf67bda16f83d..8090fd56ffe7d4a88c387df9b79f6a9e1e387e0c 100644 --- a/MeshGeoToolsLib/GeoMapper.h +++ b/MeshGeoToolsLib/GeoMapper.h @@ -34,6 +34,8 @@ namespace GeoLib { class Raster; } +namespace MeshGeoToolsLib { + /** * \brief A set of tools for mapping the elevation of geometric objects */ @@ -49,12 +51,24 @@ public: /// Maps geometry based on a mesh file void mapOnMesh(const std::string &file_name); - /// Maps geometry based on a mesh + /** + * Maps the geometry based on the given mesh file. The elevation value of all geometric + * points are modified such that they are located on the mesh surface. + */ void mapOnMesh(const MeshLib::Mesh* mesh); - /// Maps geometry to constant elevation value + /// Maps geometry to a constant elevation value void mapToConstantValue(double value); + /** + * Maps the geometry based on the given mesh file. A new geometry is created where all + * geometric points are assigned an elevation value on the mesh surface. Additional points are + * inserted whenever a polyline from the original geometry intersects a mesh node or the edge + * of a mesh element. + * \param mesh Mesh the geometry is mapped on + * \param new_geo_name Name of the newly created geometry + * \result A new geometry with the given name is inserted into _geo_objects + */ void advancedMapOnMesh(const MeshLib::Mesh* mesh, const std::string &new_geo_name); private: @@ -89,7 +103,8 @@ private: /// only necessary for mapping on DEM GeoLib::Raster *_raster; - }; +} // end namespace MeshGeoToolsLib + #endif //GEOMAPPER_H