diff --git a/MeshLib/MeshGenerators/LayeredVolume.cpp b/MeshLib/MeshGenerators/LayeredVolume.cpp index fcf40b56ea067c0764d2a5a9436a502a391c125b..5f5e484c0e6aeb7540f1514e020f84ae47833c44 100644 --- a/MeshLib/MeshGenerators/LayeredVolume.cpp +++ b/MeshLib/MeshGenerators/LayeredVolume.cpp @@ -32,10 +32,9 @@ const double LayeredVolume::_invalid_value = -9999; -const double LayeredVolume::_elevation_epsilon = 0.0001; LayeredVolume::LayeredVolume() -: _mesh(nullptr) +: _elevation_epsilon(0.0001), _mesh(nullptr) { } @@ -60,6 +59,8 @@ bool LayeredVolume::createGeoVolumes(const MeshLib::Mesh &mesh, const std::vecto if (mesh.getDimension() != 2) return false; + _elevation_epsilon = calcEpsilon(*rasters.back(), *rasters[0]); + // remove line elements, only tri + quad remain MeshLib::ElementExtraction ex(mesh); ex.searchByElementType(MeshElemType::LINE); @@ -204,6 +205,13 @@ bool LayeredVolume::exportToGeometry(GeoLib::GEOObjects &geo_objects) const return true; } +double LayeredVolume::calcEpsilon(const GeoLib::Raster &high, const GeoLib::Raster &low) +{ + const double max (*std::max_element(high.begin(), high.end())); + const double min (*std::min_element(high.begin(), high.end())); + return ((max-min)*1e-07); +} + bool LayeredVolume::allRastersExist(const std::vector<std::string> &raster_paths) const { for (auto raster = raster_paths.begin(); raster != raster_paths.end(); ++raster) diff --git a/MeshLib/MeshGenerators/LayeredVolume.h b/MeshLib/MeshGenerators/LayeredVolume.h index e9a48013f0ba034ff322e60493deef6fb4ffadea..49deb3ec6ea156fb9a950e3ddde14af08f57892b 100644 --- a/MeshLib/MeshGenerators/LayeredVolume.h +++ b/MeshLib/MeshGenerators/LayeredVolume.h @@ -77,6 +77,9 @@ private: /// Removes duplicate 2D elements (possible due to outcroppings) void removeCongruentElements(std::size_t nLayers, std::size_t nElementsPerLayer); + /// Calculates a data-dependent epsilon value + double calcEpsilon(const GeoLib::Raster &high, const GeoLib::Raster &low); + /// Checks if all raster files actually exist bool allRastersExist(const std::vector<std::string> &raster_paths) const; @@ -84,7 +87,7 @@ private: void cleanUpOnError(); static const double _invalid_value; - static const double _elevation_epsilon; + double _elevation_epsilon; std::vector<MeshLib::Node*> _nodes; std::vector<MeshLib::Element*> _elements; std::vector<MeshLib::Node> _attribute_points;