OGS
MeshGeoToolsLib::GeoMapper Class Reference

Detailed Description

A set of tools for mapping the elevation of geometric objects.

Definition at line 28 of file GeoMapper.h.

#include <GeoMapper.h>

Collaboration diagram for MeshGeoToolsLib::GeoMapper:
[legend]

Public Member Functions

 GeoMapper (GeoLib::GEOObjects &geo_objects, const std::string &geo_name)
 ~GeoMapper ()
void mapOnDEM (std::unique_ptr< GeoLib::Raster const > raster)
 Maps geometry based on a raster file.
void mapOnMesh (MeshLib::Mesh const *const mesh)
void mapToConstantValue (double value)
 Maps geometry to a constant elevation value.
void advancedMapOnMesh (MeshLib::Mesh const &mesh)

Private Member Functions

void mapStationData (std::vector< GeoLib::Point * > const &points)
 Mapping stations, boreholes on a raster or mesh.
void mapPointDataToDEM (std::vector< GeoLib::Point * > const &points) const
 Mapping points on a raster.
void mapPointDataToMeshSurface (std::vector< GeoLib::Point * > const &pnts)
 Mapping points on mesh.
double getMeshElevation (double x, double y, double min_val, double max_val) const
float getDemElevation (GeoLib::Point const &pnt) const
 Returns the elevation at Point (x,y) based on a raster.

Private Attributes

GeoLib::GEOObjects_geo_objects
std::string & _geo_name
MeshLib::Mesh_surface_mesh = nullptr
 only necessary for mapping on mesh
GeoLib::Grid< MeshLib::Node > * _grid = nullptr
std::unique_ptr< GeoLib::Raster const > _raster
 only necessary for mapping on DEM

Constructor & Destructor Documentation

◆ GeoMapper()

MeshGeoToolsLib::GeoMapper::GeoMapper ( GeoLib::GEOObjects & geo_objects,
const std::string & geo_name )

Definition at line 27 of file GeoMapper.cpp.

29 : _geo_objects(geo_objects),
30 _geo_name(const_cast<std::string&>(geo_name)),
31 _raster(nullptr)
32{
33}
std::string & _geo_name
Definition GeoMapper.h:74
GeoLib::GEOObjects & _geo_objects
Definition GeoMapper.h:73
std::unique_ptr< GeoLib::Raster const > _raster
only necessary for mapping on DEM
Definition GeoMapper.h:81

References _geo_name, _geo_objects, and _raster.

◆ ~GeoMapper()

MeshGeoToolsLib::GeoMapper::~GeoMapper ( )

Definition at line 35 of file GeoMapper.cpp.

36{
37 delete _surface_mesh;
38}
MeshLib::Mesh * _surface_mesh
only necessary for mapping on mesh
Definition GeoMapper.h:77

References _surface_mesh.

Member Function Documentation

◆ advancedMapOnMesh()

void MeshGeoToolsLib::GeoMapper::advancedMapOnMesh ( MeshLib::Mesh const & mesh)

Maps the geometry based on the given mesh file. I.e., 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. A new geometry with the given name is inserted into _geo_objects.

Parameters
meshMesh the geometry is mapped on

Definition at line 603 of file GeoMapper.cpp.

604{
605 // 1. extract surface
606 delete _surface_mesh;
607
608 if (mesh.getDimension() < 3)
609 {
610 _surface_mesh = new MeshLib::Mesh(mesh);
611 }
612 else
613 {
614 Eigen::Vector3d const dir({0, 0, -1});
616 mesh, dir, 90 + 1e-6);
617 }
618
619 // 2. compute mesh grid for surface
620 MeshLib::MeshElementGrid const mesh_element_grid(*_surface_mesh);
621
622 // 3. map each polyline
623 auto org_lines(_geo_objects.getPolylineVec(_geo_name));
624 auto org_points(_geo_objects.getPointVecObj(_geo_name));
625 for (auto org_line : *org_lines)
626 {
627 mapPolylineOnSurfaceMesh(*org_line, *org_points, mesh_element_grid);
628 }
629}
static MeshLib::Mesh * getMeshSurface(const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string_view subsfc_node_id_prop_name="", std::string_view subsfc_element_id_prop_name="", std::string_view face_id_prop_name="")
static void mapPolylineOnSurfaceMesh(GeoLib::Polyline &ply, GeoLib::PointVec &orig_points, MeshLib::MeshElementGrid const &mesh_element_grid)

References _geo_name, _geo_objects, _surface_mesh, advancedMapOnMesh(), MeshLib::Mesh::getDimension(), MeshToolsLib::MeshSurfaceExtraction::getMeshSurface(), and MeshGeoToolsLib::mapPolylineOnSurfaceMesh().

Referenced by advancedMapOnMesh(), main(), and MainWindow::mapGeometry().

◆ getDemElevation()

float MeshGeoToolsLib::GeoMapper::getDemElevation ( GeoLib::Point const & pnt) const
private

Returns the elevation at Point (x,y) based on a raster.

Definition at line 194 of file GeoMapper.cpp.

195{
196 double const elevation(_raster->getValueAtPoint(pnt));
197 if (std::abs(elevation - _raster->getHeader().no_data) <
198 std::numeric_limits<double>::epsilon())
199 {
200 return 0.0;
201 }
202 return static_cast<float>(elevation);
203}

References _raster.

Referenced by mapPointDataToDEM(), and mapStationData().

◆ getMeshElevation()

double MeshGeoToolsLib::GeoMapper::getMeshElevation ( double x,
double y,
double min_val,
double max_val ) const
private

Returns the elevation at Point (x,y) based on a mesh. This uses collision detection for triangles and nearest neighbor for quads. NOTE: This method only returns correct values if the node numbering of the elements is correct!

Definition at line 205 of file GeoMapper.cpp.

207{
208 const MeshLib::Node* pnt =
209 _grid->getNearestPoint(MathLib::Point3d{{{x, y, 0}}});
210 auto const elements(
211 _surface_mesh->getElementsConnectedToNode(pnt->getID()));
212 std::unique_ptr<GeoLib::Point> intersection;
213
214 for (auto const& element : elements)
215 {
216 if (intersection == nullptr &&
217 element->getGeomType() != MeshLib::MeshElemType::LINE)
218 {
220 *element->getNode(0), *element->getNode(1),
221 *element->getNode(2), GeoLib::Point(x, y, max_val),
222 GeoLib::Point(x, y, min_val));
223 }
224
225 if (intersection == nullptr &&
226 element->getGeomType() == MeshLib::MeshElemType::QUAD)
227 {
229 *element->getNode(0), *element->getNode(2),
230 *element->getNode(3), GeoLib::Point(x, y, max_val),
231 GeoLib::Point(x, y, min_val));
232 }
233 }
234 if (intersection)
235 {
236 return (*intersection)[2];
237 }
238 // if something goes wrong, simply take the elevation of the nearest mesh
239 // node
240 return (*(_surface_mesh->getNode(pnt->getID())))[2];
241}
std::size_t getID() const
GeoLib::Grid< MeshLib::Node > * _grid
Definition GeoMapper.h:78
std::unique_ptr< GeoLib::Point > triangleLineIntersection(MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, MathLib::Point3d const &p, MathLib::Point3d const &q)

References _grid, _surface_mesh, MathLib::Point3dWithID::getID(), MeshLib::LINE, MeshLib::QUAD, and GeoLib::triangleLineIntersection().

Referenced by mapPointDataToMeshSurface(), and mapStationData().

◆ mapOnDEM()

void MeshGeoToolsLib::GeoMapper::mapOnDEM ( std::unique_ptr< GeoLib::Raster const > raster)

Maps geometry based on a raster file.

Definition at line 40 of file GeoMapper.cpp.

41{
42 std::vector<GeoLib::Point*> const* pnts(
43 _geo_objects.getPointVec(_geo_name));
44 if (!pnts)
45 {
46 ERR("Geometry '{:s}' does not exist.", _geo_name);
47 return;
48 }
49 _raster = std::move(raster);
50
51 if (GeoLib::isStation((*pnts)[0]))
52 {
53 mapStationData(*pnts);
54 }
55 else
56 {
57 mapPointDataToDEM(*pnts);
58 }
59}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
void mapPointDataToDEM(std::vector< GeoLib::Point * > const &points) const
Mapping points on a raster.
void mapStationData(std::vector< GeoLib::Point * > const &points)
Mapping stations, boreholes on a raster or mesh.
bool isStation(GeoLib::Point const *pnt)
Definition Station.cpp:66

References _geo_name, _geo_objects, _raster, ERR(), GeoLib::isStation(), mapPointDataToDEM(), and mapStationData().

Referenced by MainWindow::mapGeometry().

◆ mapOnMesh()

void MeshGeoToolsLib::GeoMapper::mapOnMesh ( MeshLib::Mesh const *const 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.

Definition at line 61 of file GeoMapper.cpp.

62{
63 std::vector<GeoLib::Point*> const* pnts(
64 _geo_objects.getPointVec(_geo_name));
65 if (!pnts)
66 {
67 ERR("Geometry '{:s}' does not exist.", _geo_name);
68 return;
69 }
70
71 // the variable _surface_mesh is reused below, so first the existing
72 // _surface_mesh has to be cleaned up
73 delete _surface_mesh;
74
75 if (mesh->getDimension() < 3)
76 {
77 _surface_mesh = new MeshLib::Mesh(*mesh);
78 }
79 else
80 {
81 Eigen::Vector3d const dir(0, 0, -1);
84 }
85
86 // init grid
87 MathLib::Point3d origin(std::array<double, 3>{{0, 0, 0}});
88 std::vector<MeshLib::Node> flat_nodes;
89 flat_nodes.reserve(_surface_mesh->getNumberOfNodes());
90 // copy nodes and project the copied nodes to the x-y-plane, i.e. set
91 // z-coordinate to zero
92 for (auto n_ptr : _surface_mesh->getNodes())
93 {
94 flat_nodes.emplace_back(*n_ptr);
95 flat_nodes.back()[2] = 0.0;
96 }
97 _grid =
98 new GeoLib::Grid<MeshLib::Node>(flat_nodes.cbegin(), flat_nodes.cend());
99
100 if (GeoLib::isStation((*pnts)[0]))
101 {
102 mapStationData(*pnts);
103 }
104 else
105 {
107 }
108
109 delete _grid;
110}
void mapPointDataToMeshSurface(std::vector< GeoLib::Point * > const &pnts)
Mapping points on mesh.

References _geo_name, _geo_objects, _grid, _surface_mesh, ERR(), MeshLib::Mesh::getDimension(), MeshToolsLib::MeshSurfaceExtraction::getMeshSurface(), GeoLib::isStation(), mapPointDataToMeshSurface(), and mapStationData().

Referenced by createGeometries(), main(), and MainWindow::mapGeometry().

◆ mapPointDataToDEM()

void MeshGeoToolsLib::GeoMapper::mapPointDataToDEM ( std::vector< GeoLib::Point * > const & points) const
private

Mapping points on a raster.

Definition at line 159 of file GeoMapper.cpp.

161{
162 for (auto* pnt : points)
163 {
164 GeoLib::Point& p(*pnt);
165 p[2] = getDemElevation(p);
166 }
167}
float getDemElevation(GeoLib::Point const &pnt) const
Returns the elevation at Point (x,y) based on a raster.

References getDemElevation().

Referenced by mapOnDEM().

◆ mapPointDataToMeshSurface()

void MeshGeoToolsLib::GeoMapper::mapPointDataToMeshSurface ( std::vector< GeoLib::Point * > const & pnts)
private

Mapping points on mesh.

Definition at line 169 of file GeoMapper.cpp.

171{
172 GeoLib::AABB const aabb(_surface_mesh->getNodes().cbegin(),
173 _surface_mesh->getNodes().cend());
174 auto const [min, max] = aabb.getMinMaxPoints();
175
176 for (auto* pnt : pnts)
177 {
178 // check if pnt is inside of the bounding box of the _surface_mesh
179 // projected onto the y-x plane
180 GeoLib::Point& p(*pnt);
181 if (p[0] < min[0] || max[0] < p[0])
182 {
183 continue;
184 }
185 if (p[1] < min[1] || max[1] < p[1])
186 {
187 continue;
188 }
189
190 p[2] = getMeshElevation(p[0], p[1], min[2], max[2]);
191 }
192}
double getMeshElevation(double x, double y, double min_val, double max_val) const

References _surface_mesh, getMeshElevation(), and GeoLib::AABB::getMinMaxPoints().

Referenced by mapOnMesh().

◆ mapStationData()

void MeshGeoToolsLib::GeoMapper::mapStationData ( std::vector< GeoLib::Point * > const & points)
private

Mapping stations, boreholes on a raster or mesh.

Definition at line 125 of file GeoMapper.cpp.

126{
127 double min_val(0);
128 double max_val(0);
129 if (_surface_mesh)
130 {
131 GeoLib::AABB bounding_box(_surface_mesh->getNodes().begin(),
132 _surface_mesh->getNodes().end());
133 min_val = bounding_box.getMinPoint()[2];
134 max_val = bounding_box.getMaxPoint()[2];
135 }
136
137 for (auto* pnt : points)
138 {
139 double offset =
140 (_grid)
141 ? (getMeshElevation((*pnt)[0], (*pnt)[1], min_val, max_val) -
142 (*pnt)[2])
143 : getDemElevation(*pnt);
144
145 if (!GeoLib::isBorehole(pnt))
146 {
147 (*pnt)[2] = offset;
148 continue;
149 }
150 auto const& layers =
151 static_cast<GeoLib::StationBorehole*>(pnt)->getProfile();
152 for (auto* layer_pnt : layers)
153 {
154 (*layer_pnt)[2] = (*layer_pnt)[2] + offset;
155 }
156 }
157}
bool isBorehole(GeoLib::Point const *pnt)

References _grid, _surface_mesh, getDemElevation(), GeoLib::AABB::getMaxPoint(), getMeshElevation(), GeoLib::AABB::getMinPoint(), and GeoLib::isBorehole().

Referenced by mapOnDEM(), and mapOnMesh().

◆ mapToConstantValue()

void MeshGeoToolsLib::GeoMapper::mapToConstantValue ( double value)

Maps geometry to a constant elevation value.

Definition at line 112 of file GeoMapper.cpp.

113{
114 std::vector<GeoLib::Point*> const* points(
115 this->_geo_objects.getPointVec(this->_geo_name));
116 if (points == nullptr)
117 {
118 ERR("Geometry '{:s}' not found.", this->_geo_name);
119 return;
120 }
121 std::for_each(points->begin(), points->end(),
122 [value](GeoLib::Point* pnt) { (*pnt)[2] = value; });
123}

References _geo_name, _geo_objects, and ERR().

Member Data Documentation

◆ _geo_name

std::string& MeshGeoToolsLib::GeoMapper::_geo_name
private

Definition at line 74 of file GeoMapper.h.

Referenced by GeoMapper(), advancedMapOnMesh(), mapOnDEM(), mapOnMesh(), and mapToConstantValue().

◆ _geo_objects

GeoLib::GEOObjects& MeshGeoToolsLib::GeoMapper::_geo_objects
private

Definition at line 73 of file GeoMapper.h.

Referenced by GeoMapper(), advancedMapOnMesh(), mapOnDEM(), mapOnMesh(), and mapToConstantValue().

◆ _grid

GeoLib::Grid<MeshLib::Node>* MeshGeoToolsLib::GeoMapper::_grid = nullptr
private

Definition at line 78 of file GeoMapper.h.

Referenced by getMeshElevation(), mapOnMesh(), and mapStationData().

◆ _raster

std::unique_ptr<GeoLib::Raster const> MeshGeoToolsLib::GeoMapper::_raster
private

only necessary for mapping on DEM

Definition at line 81 of file GeoMapper.h.

Referenced by GeoMapper(), getDemElevation(), and mapOnDEM().

◆ _surface_mesh

MeshLib::Mesh* MeshGeoToolsLib::GeoMapper::_surface_mesh = nullptr
private

only necessary for mapping on mesh

Definition at line 77 of file GeoMapper.h.

Referenced by ~GeoMapper(), advancedMapOnMesh(), getMeshElevation(), mapOnMesh(), mapPointDataToMeshSurface(), and mapStationData().


The documentation for this class was generated from the following files: