OGS
MeshGeoToolsLib::GeoMapper Class Reference

Detailed Description

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

Definition at line 39 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 37 of file GeoMapper.cpp.

39 : _geo_objects(geo_objects),
40 _geo_name(const_cast<std::string&>(geo_name)),
41 _surface_mesh(nullptr),
42 _grid(nullptr),
43 _raster(nullptr)
44{
45}
std::string & _geo_name
Definition GeoMapper.h:85
GeoLib::GEOObjects & _geo_objects
Definition GeoMapper.h:84
std::unique_ptr< GeoLib::Raster const > _raster
only necessary for mapping on DEM
Definition GeoMapper.h:92
MeshLib::Mesh * _surface_mesh
only necessary for mapping on mesh
Definition GeoMapper.h:88
GeoLib::Grid< MeshLib::Node > * _grid
Definition GeoMapper.h:89

◆ ~GeoMapper()

MeshGeoToolsLib::GeoMapper::~GeoMapper ( )

Definition at line 47 of file GeoMapper.cpp.

48{
49 delete _surface_mesh;
50}

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

616{
617 // 1. extract surface
618 delete _surface_mesh;
619
620 if (mesh.getDimension() < 3)
621 {
622 _surface_mesh = new MeshLib::Mesh(mesh);
623 }
624 else
625 {
626 Eigen::Vector3d const dir({0, 0, -1});
628 mesh, dir, 90 + 1e-6);
629 }
630
631 // 2. compute mesh grid for surface
632 MeshLib::MeshElementGrid const mesh_element_grid(*_surface_mesh);
633
634 // 3. map each polyline
635 auto org_lines(_geo_objects.getPolylineVec(_geo_name));
636 auto org_points(_geo_objects.getPointVecObj(_geo_name));
637 for (auto org_line : *org_lines)
638 {
639 mapPolylineOnSurfaceMesh(*org_line, *org_points, mesh_element_grid);
640 }
641}
const PointVec * getPointVecObj(const std::string &name) const
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
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 MeshLib::Mesh::getDimension(), MeshToolsLib::MeshSurfaceExtraction::getMeshSurface(), and MeshGeoToolsLib::mapPolylineOnSurfaceMesh().

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

207{
208 double const elevation(_raster->getValueAtPoint(pnt));
209 if (std::abs(elevation - _raster->getHeader().no_data) <
210 std::numeric_limits<double>::epsilon())
211 {
212 return 0.0;
213 }
214 return static_cast<float>(elevation);
215}

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

219{
220 const MeshLib::Node* pnt =
222 auto const elements(
224 std::unique_ptr<GeoLib::Point> intersection;
225
226 for (auto const& element : elements)
227 {
228 if (intersection == nullptr &&
229 element->getGeomType() != MeshLib::MeshElemType::LINE)
230 {
232 *element->getNode(0), *element->getNode(1),
233 *element->getNode(2), GeoLib::Point(x, y, max_val),
234 GeoLib::Point(x, y, min_val));
235 }
236
237 if (intersection == nullptr &&
238 element->getGeomType() == MeshLib::MeshElemType::QUAD)
239 {
241 *element->getNode(0), *element->getNode(2),
242 *element->getNode(3), GeoLib::Point(x, y, max_val),
243 GeoLib::Point(x, y, min_val));
244 }
245 }
246 if (intersection)
247 {
248 return (*intersection)[2];
249 }
250 // if something goes wrong, simply take the elevation of the nearest mesh
251 // node
252 return (*(_surface_mesh->getNode(pnt->getID())))[2];
253}
POINT * getNearestPoint(P const &pnt) const
Definition Grid.h:469
std::size_t getID() const
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition Mesh.h:91
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition Mesh.cpp:256
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, MeshLib::Mesh::getElementsConnectedToNode(), MathLib::Point3dWithID::getID(), GeoLib::Grid< POINT >::getNearestPoint(), MeshLib::Mesh::getNode(), 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 52 of file GeoMapper.cpp.

53{
54 std::vector<GeoLib::Point*> const* pnts(
56 if (!pnts)
57 {
58 ERR("Geometry '{:s}' does not exist.", _geo_name);
59 return;
60 }
61 _raster = std::move(raster);
62
63 if (GeoLib::isStation((*pnts)[0]))
64 {
65 mapStationData(*pnts);
66 }
67 else
68 {
69 mapPointDataToDEM(*pnts);
70 }
71}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
const std::vector< Point * > * getPointVec(const std::string &name) const
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:77

References _geo_name, _geo_objects, _raster, ERR(), GeoLib::GEOObjects::getPointVec(), 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 73 of file GeoMapper.cpp.

74{
75 std::vector<GeoLib::Point*> const* pnts(
77 if (!pnts)
78 {
79 ERR("Geometry '{:s}' does not exist.", _geo_name);
80 return;
81 }
82
83 // the variable _surface_mesh is reused below, so first the existing
84 // _surface_mesh has to be cleaned up
85 delete _surface_mesh;
86
87 if (mesh->getDimension() < 3)
88 {
89 _surface_mesh = new MeshLib::Mesh(*mesh);
90 }
91 else
92 {
93 Eigen::Vector3d const dir(0, 0, -1);
96 }
97
98 // init grid
99 MathLib::Point3d origin(std::array<double, 3>{{0, 0, 0}});
100 std::vector<MeshLib::Node> flat_nodes;
101 flat_nodes.reserve(_surface_mesh->getNumberOfNodes());
102 // copy nodes and project the copied nodes to the x-y-plane, i.e. set
103 // z-coordinate to zero
104 for (auto n_ptr : _surface_mesh->getNodes())
105 {
106 flat_nodes.emplace_back(*n_ptr);
107 flat_nodes.back()[2] = 0.0;
108 }
109 _grid =
110 new GeoLib::Grid<MeshLib::Node>(flat_nodes.cbegin(), flat_nodes.cend());
111
112 if (GeoLib::isStation((*pnts)[0]))
113 {
114 mapStationData(*pnts);
115 }
116 else
117 {
119 }
120
121 delete _grid;
122}
std::vector< std::size_t > getNodes(GeoLib::Point const &pnt, std::vector< MeshLib::Node * > const &nodes, MeshLib::PropertyVector< int > const &mat_ids, std::pair< int, int > const &mat_limits, std::pair< double, double > const &elevation_limits, MeshLib::Mesh const &mesh)
void mapPointDataToMeshSurface(std::vector< GeoLib::Point * > const &pnts)
Mapping points on mesh.
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:100

References _geo_name, _geo_objects, _grid, _surface_mesh, ERR(), MeshLib::Mesh::getDimension(), MeshToolsLib::MeshSurfaceExtraction::getMeshSurface(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfNodes(), GeoLib::GEOObjects::getPointVec(), 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 171 of file GeoMapper.cpp.

173{
174 for (auto* pnt : points)
175 {
176 GeoLib::Point& p(*pnt);
177 p[2] = getDemElevation(p);
178 }
179}
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 181 of file GeoMapper.cpp.

183{
184 GeoLib::AABB const aabb(_surface_mesh->getNodes().cbegin(),
185 _surface_mesh->getNodes().cend());
186 auto const [min, max] = aabb.getMinMaxPoints();
187
188 for (auto* pnt : pnts)
189 {
190 // check if pnt is inside of the bounding box of the _surface_mesh
191 // projected onto the y-x plane
192 GeoLib::Point& p(*pnt);
193 if (p[0] < min[0] || max[0] < p[0])
194 {
195 continue;
196 }
197 if (p[1] < min[1] || max[1] < p[1])
198 {
199 continue;
200 }
201
202 p[2] = getMeshElevation(p[0], p[1], min[2], max[2]);
203 }
204}
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
double getMeshElevation(double x, double y, double min_val, double max_val) const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106

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

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

138{
139 double min_val(0);
140 double max_val(0);
141 if (_surface_mesh)
142 {
143 GeoLib::AABB bounding_box(_surface_mesh->getNodes().begin(),
144 _surface_mesh->getNodes().end());
145 min_val = bounding_box.getMinPoint()[2];
146 max_val = bounding_box.getMaxPoint()[2];
147 }
148
149 for (auto* pnt : points)
150 {
151 double offset =
152 (_grid)
153 ? (getMeshElevation((*pnt)[0], (*pnt)[1], min_val, max_val) -
154 (*pnt)[2])
155 : getDemElevation(*pnt);
156
157 if (!GeoLib::isBorehole(pnt))
158 {
159 (*pnt)[2] = offset;
160 continue;
161 }
162 auto const& layers =
163 static_cast<GeoLib::StationBorehole*>(pnt)->getProfile();
164 for (auto* layer_pnt : layers)
165 {
166 (*layer_pnt)[2] = (*layer_pnt)[2] + offset;
167 }
168 }
169}
A borehole as a geometric object.
bool isBorehole(GeoLib::Point const *pnt)

References _grid, _surface_mesh, getDemElevation(), GeoLib::AABB::getMaxPoint(), getMeshElevation(), GeoLib::AABB::getMinPoint(), MeshLib::Mesh::getNodes(), 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 124 of file GeoMapper.cpp.

125{
126 std::vector<GeoLib::Point*> const* points(
127 this->_geo_objects.getPointVec(this->_geo_name));
128 if (points == nullptr)
129 {
130 ERR("Geometry '{:s}' not found.", this->_geo_name);
131 return;
132 }
133 std::for_each(points->begin(), points->end(),
134 [value](GeoLib::Point* pnt) { (*pnt)[2] = value; });
135}

References _geo_name, _geo_objects, ERR(), and GeoLib::GEOObjects::getPointVec().

Member Data Documentation

◆ _geo_name

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

Definition at line 85 of file GeoMapper.h.

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

◆ _geo_objects

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

Definition at line 84 of file GeoMapper.h.

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

◆ _grid

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

Definition at line 89 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 92 of file GeoMapper.h.

Referenced by getDemElevation(), and mapOnDEM().

◆ _surface_mesh

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

only necessary for mapping on mesh

Definition at line 88 of file GeoMapper.h.

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


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