Skip to content
Snippets Groups Projects
Verified Commit 1e7bd1a0 authored by Karsten Rink's avatar Karsten Rink Committed by Lars Bilke
Browse files

[meshlib] added flag that allows ignoring nodata values during mesh mapping

parent ddcd99bd
No related branches found
No related tags found
No related merge requests found
...@@ -269,8 +269,10 @@ void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned lay ...@@ -269,8 +269,10 @@ void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned lay
bool MeshLayerMapper::layerMapping(MeshLib::Mesh const& mesh, bool MeshLayerMapper::layerMapping(MeshLib::Mesh const& mesh,
GeoLib::Raster const& raster, GeoLib::Raster const& raster,
double const noDataReplacementValue = 0.0) double const nodata_replacement,
bool const ignore_nodata)
{ {
if (mesh.getDimension() != 2) if (mesh.getDimension() != 2)
{ {
ERR("MshLayerMapper::layerMapping() - requires 2D mesh"); ERR("MshLayerMapper::layerMapping() - requires 2D mesh");
...@@ -289,18 +291,27 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh const& mesh, ...@@ -289,18 +291,27 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh const& mesh,
const std::vector<MeshLib::Node*> &nodes = mesh.getNodes(); const std::vector<MeshLib::Node*> &nodes = mesh.getNodes();
for (unsigned i = 0; i < nNodes; ++i) for (unsigned i = 0; i < nNodes; ++i)
{ {
if (!raster.isPntOnRaster(*nodes[i])) if (!ignore_nodata && !raster.isPntOnRaster(*nodes[i]))
{ {
// use either default value or elevation from layer above // use either default value or elevation from layer above
nodes[i]->updateCoordinates((*nodes[i])[0], (*nodes[i])[1], noDataReplacementValue); nodes[i]->updateCoordinates((*nodes[i])[0], (*nodes[i])[1],
nodata_replacement);
continue; continue;
} }
double elevation (raster.interpolateValueAtPoint(*nodes[i])); double elevation (raster.getValueAtPoint(*nodes[i]));
if (std::abs(elevation - header.no_data) < constexpr double eps = std::numeric_limits<double>::epsilon();
std::numeric_limits<double>::epsilon()) if (std::fabs(elevation - header.no_data) < eps)
{
if (ignore_nodata)
{
continue;
}
elevation = nodata_replacement;
}
else
{ {
elevation = noDataReplacementValue; elevation = raster.interpolateValueAtPoint(*nodes[i]);
} }
nodes[i]->updateCoordinates((*nodes[i])[0], (*nodes[i])[1], elevation); nodes[i]->updateCoordinates((*nodes[i])[0], (*nodes[i])[1], elevation);
} }
......
...@@ -59,7 +59,10 @@ public: ...@@ -59,7 +59,10 @@ public:
* locations where no information is given, node elevation is set to * locations where no information is given, node elevation is set to
* noDataReplacementValue. * noDataReplacementValue.
*/ */
static bool layerMapping(MeshLib::Mesh const &mesh, const GeoLib::Raster &raster, double noDataReplacementValue); static bool layerMapping(MeshLib::Mesh const& mesh,
const GeoLib::Raster& raster,
double nodata_replacement = 0.0,
bool const ignore_nodata = false);
/// Maps the elevation of all mesh nodes to the specified static value. /// Maps the elevation of all mesh nodes to the specified static value.
static bool mapToStaticValue(MeshLib::Mesh const& mesh, double value); static bool mapToStaticValue(MeshLib::Mesh const& mesh, double value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment