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
 only necessary for mapping on mesh
GeoLib::Grid< MeshLib::Node > * _grid
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 26 of file GeoMapper.cpp.

28 : _geo_objects(geo_objects),
29 _geo_name(const_cast<std::string&>(geo_name)),
30 _surface_mesh(nullptr),
31 _grid(nullptr),
32 _raster(nullptr)
33{
34}
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
MeshLib::Mesh * _surface_mesh
only necessary for mapping on mesh
Definition GeoMapper.h:77
GeoLib::Grid< MeshLib::Node > * _grid
Definition GeoMapper.h:78

References _geo_name, _geo_objects, _grid, _raster, and _surface_mesh.

◆ ~GeoMapper()

MeshGeoToolsLib::GeoMapper::~GeoMapper ( )

Definition at line 36 of file GeoMapper.cpp.

37{
38 delete _surface_mesh;
39}

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 604 of file GeoMapper.cpp.

605{
606 // 1. extract surface
607 delete _surface_mesh;
608
609 if (mesh.getDimension() < 3)
610 {
611 _surface_mesh = new MeshLib::Mesh(mesh);
612 }
613 else
614 {
615 Eigen::Vector3d const dir({0, 0, -1});
617 mesh, dir, 90 + 1e-6);
618 }
619
620 // 2. compute mesh grid for surface
621 MeshLib::MeshElementGrid const mesh_element_grid(*_surface_mesh);
622
623 // 3. map each polyline
624 auto org_lines(_geo_objects.getPolylineVec(_geo_name));
625 auto org_points(_geo_objects.getPointVecObj(_geo_name));
626 for (auto org_line : *org_lines)
627 {
628 mapPolylineOnSurfaceMesh(*org_line, *org_points, mesh_element_grid);
629 }
630}
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 195 of file GeoMapper.cpp.

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

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 206 of file GeoMapper.cpp.

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

42{
43 std::vector<GeoLib::Point*> const* pnts(
44 _geo_objects.getPointVec(_geo_name));
45 if (!pnts)
46 {
47 ERR("Geometry '{:s}' does not exist.", _geo_name);
48 return;
49 }
50 _raster = std::move(raster);
51
52 if (GeoLib::isStation((*pnts)[0]))
53 {
54 mapStationData(*pnts);
55 }
56 else
57 {
58 mapPointDataToDEM(*pnts);
59 }
60}
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 62 of file GeoMapper.cpp.

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

162{
163 for (auto* pnt : points)
164 {
165 GeoLib::Point& p(*pnt);
166 p[2] = getDemElevation(p);
167 }
168}
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 170 of file GeoMapper.cpp.

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

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

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

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
private

Definition at line 78 of file GeoMapper.h.

Referenced by GeoMapper(), 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
private

only necessary for mapping on mesh

Definition at line 77 of file GeoMapper.h.

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


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