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. More...
 
void mapOnMesh (MeshLib::Mesh const *const mesh)
 
void mapToConstantValue (double value)
 Maps geometry to a constant elevation value. More...
 
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. More...
 
void mapPointDataToDEM (std::vector< GeoLib::Point * > const &points) const
 Mapping points on a raster. More...
 
void mapPointDataToMeshSurface (std::vector< GeoLib::Point * > const &pnts)
 Mapping points on mesh. More...
 
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. More...
 

Private Attributes

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

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:86
GeoLib::GEOObjects & _geo_objects
Definition: GeoMapper.h:85
std::unique_ptr< GeoLib::Raster const > _raster
only necessary for mapping on DEM
Definition: GeoMapper.h:93
MeshLib::Mesh * _surface_mesh
only necessary for mapping on mesh
Definition: GeoMapper.h:89
GeoLib::Grid< MeshLib::Node > * _grid
Definition: GeoMapper.h:90

◆ ~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.

Parameters
meshMesh the geometry is mapped on
Returns
A new geometry with the given name is inserted into _geo_objects

Definition at line 617 of file GeoMapper.cpp.

618 {
619  // 1. extract surface
620  delete _surface_mesh;
621 
622  if (mesh.getDimension() < 3)
623  {
624  _surface_mesh = new MeshLib::Mesh(mesh);
625  }
626  else
627  {
628  Eigen::Vector3d const dir({0, 0, -1});
630  mesh, dir, 90 + 1e-6);
631  }
632 
633  // 2. compute mesh grid for surface
634  MeshLib::MeshElementGrid const mesh_element_grid(*_surface_mesh);
635 
636  // 3. map each polyline
637  auto org_lines(_geo_objects.getPolylineVec(_geo_name));
638  auto org_points(_geo_objects.getPointVecObj(_geo_name));
639  for (auto org_line : *org_lines)
640  {
641  mapPolylineOnSurfaceMesh(*org_line, *org_points, mesh_element_grid);
642  }
643 }
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:84
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
Definition: GEOObjects.cpp:210
static MeshLib::Mesh * getMeshSurface(const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string const &subsfc_node_id_prop_name="", std::string const &subsfc_element_id_prop_name="", std::string const &face_id_prop_name="")
static void mapPolylineOnSurfaceMesh(GeoLib::Polyline &ply, GeoLib::PointVec &orig_points, MeshLib::MeshElementGrid const &mesh_element_grid)
Definition: GeoMapper.cpp:552

References MeshLib::Mesh::getDimension(), MeshLib::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 207 of file GeoMapper.cpp.

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

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

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

References _grid, _surface_mesh, MeshLib::Mesh::getElementsConnectedToNode(), MathLib::Point3dWithID::getID(), GeoLib::Grid< POINT >::getNearestPoint(), MeshLib::Mesh::getNode(), ProcessLib::ComponentTransport::intersection(), 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(char const *fmt, Args const &... args)
Definition: Logging.h:42
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:71
void mapPointDataToDEM(std::vector< GeoLib::Point * > const &points) const
Mapping points on a raster.
Definition: GeoMapper.cpp:171
void mapStationData(std::vector< GeoLib::Point * > const &points)
Mapping stations, boreholes on a raster or mesh.
Definition: GeoMapper.cpp:137
bool isStation(GeoLib::Point const *pnt)
Definition: Station.cpp:76

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 }
void mapPointDataToMeshSurface(std::vector< GeoLib::Point * > const &pnts)
Mapping points on mesh.
Definition: GeoMapper.cpp:181
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:89

References _geo_name, _geo_objects, _grid, _surface_mesh, ERR(), MeshLib::Mesh::getDimension(), MeshLib::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.
Definition: GeoMapper.cpp:207

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  double const min_val(aabb.getMinPoint()[2]);
187  double const max_val(aabb.getMaxPoint()[2]);
188 
189  for (auto* pnt : pnts)
190  {
191  // check if pnt is inside of the bounding box of the _surface_mesh
192  // projected onto the y-x plane
193  GeoLib::Point& p(*pnt);
194  if (p[0] < aabb.getMinPoint()[0] || aabb.getMaxPoint()[0] < p[0])
195  {
196  continue;
197  }
198  if (p[1] < aabb.getMinPoint()[1] || aabb.getMaxPoint()[1] < p[1])
199  {
200  continue;
201  }
202 
203  p[2] = getMeshElevation(p[0], p[1], min_val, max_val);
204  }
205 }
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition: AABB.h:49
double getMeshElevation(double x, double y, double min_val, double max_val) const
Definition: GeoMapper.cpp:218

References _surface_mesh, GeoLib::AABB::getMaxPoint(), getMeshElevation(), GeoLib::AABB::getMinPoint(), 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 86 of file GeoMapper.h.

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

◆ _geo_objects

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

Definition at line 85 of file GeoMapper.h.

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

◆ _grid

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

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

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


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