From 7beb678806b91cf6e72913eb6c160e1245f31208 Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Fri, 19 Sep 2014 19:26:52 +0200 Subject: [PATCH] changes based on pr comments --- FileIO/AsciiRasterInterface.cpp | 14 ++++++++------ Gui/DataView/GeoMapper.cpp | 2 +- ...faceMapper.cpp => LayeredMeshGenerator.cpp} | 18 +++++++++--------- ...bsurfaceMapper.h => LayeredMeshGenerator.h} | 14 +++++++------- MeshLib/MeshGenerators/LayeredVolume.h | 4 ++-- MeshLib/MeshGenerators/MeshLayerMapper.cpp | 4 ---- MeshLib/MeshGenerators/MeshLayerMapper.h | 8 ++++---- 7 files changed, 31 insertions(+), 33 deletions(-) rename MeshLib/MeshGenerators/{SubsurfaceMapper.cpp => LayeredMeshGenerator.cpp} (77%) rename MeshLib/MeshGenerators/{SubsurfaceMapper.h => LayeredMeshGenerator.h} (93%) diff --git a/FileIO/AsciiRasterInterface.cpp b/FileIO/AsciiRasterInterface.cpp index 3a64861a31c..4de045757f1 100644 --- a/FileIO/AsciiRasterInterface.cpp +++ b/FileIO/AsciiRasterInterface.cpp @@ -13,6 +13,8 @@ #include "AsciiRasterInterface.h" +#include <cctype> + // ThirdParty/logog #include "logog/include/logog.hpp" @@ -27,7 +29,7 @@ namespace FileIO { GeoLib::Raster* AsciiRasterInterface::readRaster(std::string const& fname) { std::string ext (BaseLib::getFileExtension(fname)); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + std::transform(ext.begin(), ext.end(), ext.begin(), std::tolower); if (ext.compare("asc") == 0) return getRasterFromASCFile(fname); if (ext.compare("grd") == 0) @@ -41,7 +43,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn if (!in.is_open()) { WARN("Raster::getRasterFromASCFile(): Could not open file %s.", fname.c_str()); - return NULL; + return nullptr; } // header information @@ -52,7 +54,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn double* values = new double[n_cols*n_rows]; std::string s; // read the data into the double-array - for (size_t j(0); j < n_rows; ++j) { + for (std::size_t j(0); j < n_rows; ++j) { const size_t idx ((n_rows - j - 1) * n_cols); for (size_t i(0); i < n_cols; ++i) { in >> s; @@ -67,7 +69,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn return raster; } else { WARN("Raster::getRasterFromASCFile(): Could not read header of file %s", fname.c_str()); - return NULL; + return nullptr; } } @@ -121,7 +123,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& if (!in.is_open()) { ERR("Raster::getRasterFromSurferFile() - Could not open file %s", fname.c_str()); - return NULL; + return nullptr; } // header information @@ -151,7 +153,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& return raster; } else { ERR("Raster::getRasterFromASCFile() - could not read header of file %s", fname.c_str()); - return NULL; + return nullptr; } } diff --git a/Gui/DataView/GeoMapper.cpp b/Gui/DataView/GeoMapper.cpp index 923838f4425..9541cb730bd 100644 --- a/Gui/DataView/GeoMapper.cpp +++ b/Gui/DataView/GeoMapper.cpp @@ -132,7 +132,7 @@ void GeoMapper::mapData() float GeoMapper::getDemElevation(GeoLib::Point const& pnt) const { double const elevation (_raster->getValueAtPoint(pnt)); - if (elevation-_raster->getNoDataValue() < std::numeric_limits<double>::epsilon()) + if (std::abs(elevation-_raster->getNoDataValue()) < std::numeric_limits<double>::epsilon()) return 0.0; return static_cast<float>(elevation); } diff --git a/MeshLib/MeshGenerators/SubsurfaceMapper.cpp b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp similarity index 77% rename from MeshLib/MeshGenerators/SubsurfaceMapper.cpp rename to MeshLib/MeshGenerators/LayeredMeshGenerator.cpp index 5be832c812c..d16106a875b 100644 --- a/MeshLib/MeshGenerators/SubsurfaceMapper.cpp +++ b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp @@ -1,5 +1,5 @@ /** - * \file SubsurfaceMapper.cpp + * \file LayeredMeshGenerator.cpp * \author Karsten Rink * \date 2014-09-18 * \brief Implementation of the SubsurfaceMapper class. @@ -12,7 +12,7 @@ * */ -#include "SubsurfaceMapper.h" +#include "LayeredMeshGenerator.h" #include <vector> #include <fstream> @@ -26,12 +26,12 @@ #include "Elements/Element.h" #include "MeshQuality/MeshValidation.h" -SubsurfaceMapper::SubsurfaceMapper() +LayeredMeshGenerator::LayeredMeshGenerator() : _elevation_epsilon(0.0001) { } -bool SubsurfaceMapper::createLayers(MeshLib::Mesh const& mesh, std::vector<std::string> const& raster_paths, double noDataReplacementValue) +bool LayeredMeshGenerator::createLayers(MeshLib::Mesh const& mesh, std::vector<std::string> const& raster_paths, double noDataReplacementValue) { if (mesh.getDimension() != 2 || !allRastersExist(raster_paths)) return false; @@ -43,10 +43,10 @@ bool SubsurfaceMapper::createLayers(MeshLib::Mesh const& mesh, std::vector<std:: bool result = createRasterLayers(mesh, rasters, noDataReplacementValue); std::for_each(rasters.begin(), rasters.end(), [](GeoLib::Raster const*const raster){ delete raster; }); - return true; + return result; } -MeshLib::Mesh* SubsurfaceMapper::getMesh(std::string const& mesh_name) const +MeshLib::Mesh* LayeredMeshGenerator::getMesh(std::string const& mesh_name) const { if (_nodes.empty() || _elements.empty()) return nullptr; @@ -56,14 +56,14 @@ MeshLib::Mesh* SubsurfaceMapper::getMesh(std::string const& mesh_name) const return result; } -double SubsurfaceMapper::calcEpsilon(GeoLib::Raster const& high, GeoLib::Raster const& low) +double LayeredMeshGenerator::calcEpsilon(GeoLib::Raster const& high, GeoLib::Raster const& low) { const double max (*std::max_element(high.begin(), high.end())); const double min (*std::min_element( low.begin(), low.end())); return ((max-min)*1e-07); } -bool SubsurfaceMapper::allRastersExist(std::vector<std::string> const& raster_paths) const +bool LayeredMeshGenerator::allRastersExist(std::vector<std::string> const& raster_paths) const { for (auto raster = raster_paths.begin(); raster != raster_paths.end(); ++raster) { @@ -75,7 +75,7 @@ bool SubsurfaceMapper::allRastersExist(std::vector<std::string> const& raster_pa return true; } -void SubsurfaceMapper::cleanUpOnError() +void LayeredMeshGenerator::cleanUpOnError() { std::for_each(_nodes.begin(), _nodes.end(), [](MeshLib::Node *node) { delete node; }); std::for_each(_elements.begin(), _elements.end(), [](MeshLib::Element *elem) { delete elem; }); diff --git a/MeshLib/MeshGenerators/SubsurfaceMapper.h b/MeshLib/MeshGenerators/LayeredMeshGenerator.h similarity index 93% rename from MeshLib/MeshGenerators/SubsurfaceMapper.h rename to MeshLib/MeshGenerators/LayeredMeshGenerator.h index fc0ae9bb6c6..15de05364e5 100644 --- a/MeshLib/MeshGenerators/SubsurfaceMapper.h +++ b/MeshLib/MeshGenerators/LayeredMeshGenerator.h @@ -1,5 +1,5 @@ /** - * \file SubsurfaceMapper.h + * \file LayeredMeshGenerator.h * \author Karsten Rink * \date 2014-09-18 * \brief Definition of the SubsurfaceMapper class @@ -12,8 +12,8 @@ * */ -#ifndef SUBSURFACEMAPPER_H -#define SUBSURFACEMAPPER_H +#ifndef LAYEREDMESHGENERATOR_H +#define LAYEREDMESHGENERATOR_H #include <string> #include <vector> @@ -31,7 +31,7 @@ namespace MeshLib { /** * \brief Base class for creation of 3D subsurface meshes based on raster data */ -class SubsurfaceMapper +class LayeredMeshGenerator { public: /** @@ -56,8 +56,8 @@ public: MeshLib::Mesh* getMesh(std::string const& mesh_name) const; protected: - SubsurfaceMapper(); - ~SubsurfaceMapper() {} + LayeredMeshGenerator(); + ~LayeredMeshGenerator() {} /// Adds another layer to the subsurface mesh virtual void addLayerToMesh(MeshLib::Mesh const& mesh_layer, unsigned layer_id, GeoLib::Raster const& raster) = 0; @@ -76,4 +76,4 @@ protected: std::vector<MeshLib::Element*> _elements; }; -#endif //SUBSURFACEMAPPER_H +#endif //LAYEREDMESHGENERATOR_H diff --git a/MeshLib/MeshGenerators/LayeredVolume.h b/MeshLib/MeshGenerators/LayeredVolume.h index 5d6eeecae00..9d6a2560df4 100644 --- a/MeshLib/MeshGenerators/LayeredVolume.h +++ b/MeshLib/MeshGenerators/LayeredVolume.h @@ -19,7 +19,7 @@ #include <vector> #include "Node.h" -#include "SubsurfaceMapper.h" +#include "LayeredMeshGenerator.h" namespace GeoLib { class GEOObjects; @@ -29,7 +29,7 @@ namespace GeoLib { /** * \brief Creates a volume geometry from 2D mesh layers based on raster data. */ -class LayeredVolume : public SubsurfaceMapper +class LayeredVolume : public LayeredMeshGenerator { public: LayeredVolume() {} diff --git a/MeshLib/MeshGenerators/MeshLayerMapper.cpp b/MeshLib/MeshGenerators/MeshLayerMapper.cpp index 58bb399bab5..c56b846d708 100644 --- a/MeshLib/MeshGenerators/MeshLayerMapper.cpp +++ b/MeshLib/MeshGenerators/MeshLayerMapper.cpp @@ -139,7 +139,6 @@ void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned lay std::size_t const nNodes = dem_mesh.getNNodes(); std::vector<MeshLib::Node*> const& nodes = dem_mesh.getNodes(); int const last_layer_node_offset = (layer_id-1) * nNodes; - unsigned const layer_node_offset = layer_id * nNodes; double const no_data_value (raster.getNoDataValue()); // add nodes for new layer @@ -228,14 +227,11 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, GeoLib::Raster const const double y0(raster.getOrigin()[1]); const double delta(raster.getRasterPixelSize()); const double no_data(raster.getNoDataValue()); - double const*const elevation(raster.begin()); const std::pair<double, double> xDim(x0, x0 + raster.getNCols() * delta); // extension in x-dimension const std::pair<double, double> yDim(y0, y0 + raster.getNRows() * delta); // extension in y-dimension const size_t nNodes (new_mesh.getNNodes()); - - const double half_delta = 0.5*delta; const std::vector<MeshLib::Node*> &nodes = new_mesh.getNodes(); for (unsigned i = 0; i < nNodes; ++i) { diff --git a/MeshLib/MeshGenerators/MeshLayerMapper.h b/MeshLib/MeshGenerators/MeshLayerMapper.h index fa164ac36b8..cb17e764adb 100644 --- a/MeshLib/MeshGenerators/MeshLayerMapper.h +++ b/MeshLib/MeshGenerators/MeshLayerMapper.h @@ -15,19 +15,19 @@ #ifndef MESHLAYERMAPPER_H #define MESHLAYERMAPPER_H -#include "SubsurfaceMapper.h" +#include "LayeredMeshGenerator.h" /** * \brief Manipulating and adding prism element layers to an existing 2D mesh */ -class MeshLayerMapper : public SubsurfaceMapper +class MeshLayerMapper : public LayeredMeshGenerator { public: MeshLayerMapper() {} ~MeshLayerMapper() {} /** - * Based on a 2D triangle-or quad mesh this method creates a 3D mesh with with a given number of prism- or hex-layers + * Based on a 2D triangle-or quad mesh this method creates a 3D mesh with a given number of prism- or hex-layers * \param mesh The triangle/quad mesh that is the basis for the new prism/hex mesh * \param nLayers The number of layers of prism/hex elements that will be extruded from the triangle/quad elements of the original mesh * \param thickness The thickness of each of these newly added layers @@ -37,7 +37,7 @@ public: MeshLib::Mesh* createStaticLayers(MeshLib::Mesh const& mesh, std::vector<float> const& layer_thickness_vector, std::string const& mesh_name = "SubsurfaceMesh") const; /** - * Based on a 2D triangle mesh this method creates a 3D mesh with with a given number of prism-layers. + * Based on a 2D triangle mesh this method creates a 3D mesh with a given number of prism-layers. * Note: While this method would technically also work with quad meshes, this is discouraged as quad elements will most likely not * be coplanar after the mapping process which result in invaled mesh elements. * \param mesh The 2D triangle mesh that is the basis for the new 3D prism mesh -- GitLab