Skip to content
Snippets Groups Projects
Commit 7beb6788 authored by Karsten Rink's avatar Karsten Rink
Browse files

changes based on pr comments

parent 59df2412
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "AsciiRasterInterface.h" #include "AsciiRasterInterface.h"
#include <cctype>
// ThirdParty/logog // ThirdParty/logog
#include "logog/include/logog.hpp" #include "logog/include/logog.hpp"
...@@ -27,7 +29,7 @@ namespace FileIO { ...@@ -27,7 +29,7 @@ namespace FileIO {
GeoLib::Raster* AsciiRasterInterface::readRaster(std::string const& fname) GeoLib::Raster* AsciiRasterInterface::readRaster(std::string const& fname)
{ {
std::string ext (BaseLib::getFileExtension(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) if (ext.compare("asc") == 0)
return getRasterFromASCFile(fname); return getRasterFromASCFile(fname);
if (ext.compare("grd") == 0) if (ext.compare("grd") == 0)
...@@ -41,7 +43,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn ...@@ -41,7 +43,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn
if (!in.is_open()) { if (!in.is_open()) {
WARN("Raster::getRasterFromASCFile(): Could not open file %s.", fname.c_str()); WARN("Raster::getRasterFromASCFile(): Could not open file %s.", fname.c_str());
return NULL; return nullptr;
} }
// header information // header information
...@@ -52,7 +54,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn ...@@ -52,7 +54,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn
double* values = new double[n_cols*n_rows]; double* values = new double[n_cols*n_rows];
std::string s; std::string s;
// read the data into the double-array // 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); const size_t idx ((n_rows - j - 1) * n_cols);
for (size_t i(0); i < n_cols; ++i) { for (size_t i(0); i < n_cols; ++i) {
in >> s; in >> s;
...@@ -67,7 +69,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn ...@@ -67,7 +69,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn
return raster; return raster;
} else { } else {
WARN("Raster::getRasterFromASCFile(): Could not read header of file %s", fname.c_str()); 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& ...@@ -121,7 +123,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const&
if (!in.is_open()) { if (!in.is_open()) {
ERR("Raster::getRasterFromSurferFile() - Could not open file %s", fname.c_str()); ERR("Raster::getRasterFromSurferFile() - Could not open file %s", fname.c_str());
return NULL; return nullptr;
} }
// header information // header information
...@@ -151,7 +153,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& ...@@ -151,7 +153,7 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const&
return raster; return raster;
} else { } else {
ERR("Raster::getRasterFromASCFile() - could not read header of file %s", fname.c_str()); ERR("Raster::getRasterFromASCFile() - could not read header of file %s", fname.c_str());
return NULL; return nullptr;
} }
} }
......
...@@ -132,7 +132,7 @@ void GeoMapper::mapData() ...@@ -132,7 +132,7 @@ void GeoMapper::mapData()
float GeoMapper::getDemElevation(GeoLib::Point const& pnt) const float GeoMapper::getDemElevation(GeoLib::Point const& pnt) const
{ {
double const elevation (_raster->getValueAtPoint(pnt)); 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 0.0;
return static_cast<float>(elevation); return static_cast<float>(elevation);
} }
......
/** /**
* \file SubsurfaceMapper.cpp * \file LayeredMeshGenerator.cpp
* \author Karsten Rink * \author Karsten Rink
* \date 2014-09-18 * \date 2014-09-18
* \brief Implementation of the SubsurfaceMapper class. * \brief Implementation of the SubsurfaceMapper class.
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
*/ */
#include "SubsurfaceMapper.h" #include "LayeredMeshGenerator.h"
#include <vector> #include <vector>
#include <fstream> #include <fstream>
...@@ -26,12 +26,12 @@ ...@@ -26,12 +26,12 @@
#include "Elements/Element.h" #include "Elements/Element.h"
#include "MeshQuality/MeshValidation.h" #include "MeshQuality/MeshValidation.h"
SubsurfaceMapper::SubsurfaceMapper() LayeredMeshGenerator::LayeredMeshGenerator()
: _elevation_epsilon(0.0001) : _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)) if (mesh.getDimension() != 2 || !allRastersExist(raster_paths))
return false; return false;
...@@ -43,10 +43,10 @@ bool SubsurfaceMapper::createLayers(MeshLib::Mesh const& mesh, std::vector<std:: ...@@ -43,10 +43,10 @@ bool SubsurfaceMapper::createLayers(MeshLib::Mesh const& mesh, std::vector<std::
bool result = createRasterLayers(mesh, rasters, noDataReplacementValue); bool result = createRasterLayers(mesh, rasters, noDataReplacementValue);
std::for_each(rasters.begin(), rasters.end(), [](GeoLib::Raster const*const raster){ delete raster; }); 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()) if (_nodes.empty() || _elements.empty())
return nullptr; return nullptr;
...@@ -56,14 +56,14 @@ MeshLib::Mesh* SubsurfaceMapper::getMesh(std::string const& mesh_name) const ...@@ -56,14 +56,14 @@ MeshLib::Mesh* SubsurfaceMapper::getMesh(std::string const& mesh_name) const
return result; 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 max (*std::max_element(high.begin(), high.end()));
const double min (*std::min_element( low.begin(), low.end())); const double min (*std::min_element( low.begin(), low.end()));
return ((max-min)*1e-07); 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) 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 ...@@ -75,7 +75,7 @@ bool SubsurfaceMapper::allRastersExist(std::vector<std::string> const& raster_pa
return true; return true;
} }
void SubsurfaceMapper::cleanUpOnError() void LayeredMeshGenerator::cleanUpOnError()
{ {
std::for_each(_nodes.begin(), _nodes.end(), [](MeshLib::Node *node) { delete node; }); std::for_each(_nodes.begin(), _nodes.end(), [](MeshLib::Node *node) { delete node; });
std::for_each(_elements.begin(), _elements.end(), [](MeshLib::Element *elem) { delete elem; }); std::for_each(_elements.begin(), _elements.end(), [](MeshLib::Element *elem) { delete elem; });
......
/** /**
* \file SubsurfaceMapper.h * \file LayeredMeshGenerator.h
* \author Karsten Rink * \author Karsten Rink
* \date 2014-09-18 * \date 2014-09-18
* \brief Definition of the SubsurfaceMapper class * \brief Definition of the SubsurfaceMapper class
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
* *
*/ */
#ifndef SUBSURFACEMAPPER_H #ifndef LAYEREDMESHGENERATOR_H
#define SUBSURFACEMAPPER_H #define LAYEREDMESHGENERATOR_H
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -31,7 +31,7 @@ namespace MeshLib { ...@@ -31,7 +31,7 @@ namespace MeshLib {
/** /**
* \brief Base class for creation of 3D subsurface meshes based on raster data * \brief Base class for creation of 3D subsurface meshes based on raster data
*/ */
class SubsurfaceMapper class LayeredMeshGenerator
{ {
public: public:
/** /**
...@@ -56,8 +56,8 @@ public: ...@@ -56,8 +56,8 @@ public:
MeshLib::Mesh* getMesh(std::string const& mesh_name) const; MeshLib::Mesh* getMesh(std::string const& mesh_name) const;
protected: protected:
SubsurfaceMapper(); LayeredMeshGenerator();
~SubsurfaceMapper() {} ~LayeredMeshGenerator() {}
/// Adds another layer to the subsurface mesh /// Adds another layer to the subsurface mesh
virtual void addLayerToMesh(MeshLib::Mesh const& mesh_layer, unsigned layer_id, GeoLib::Raster const& raster) = 0; virtual void addLayerToMesh(MeshLib::Mesh const& mesh_layer, unsigned layer_id, GeoLib::Raster const& raster) = 0;
...@@ -76,4 +76,4 @@ protected: ...@@ -76,4 +76,4 @@ protected:
std::vector<MeshLib::Element*> _elements; std::vector<MeshLib::Element*> _elements;
}; };
#endif //SUBSURFACEMAPPER_H #endif //LAYEREDMESHGENERATOR_H
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <vector> #include <vector>
#include "Node.h" #include "Node.h"
#include "SubsurfaceMapper.h" #include "LayeredMeshGenerator.h"
namespace GeoLib { namespace GeoLib {
class GEOObjects; class GEOObjects;
...@@ -29,7 +29,7 @@ namespace GeoLib { ...@@ -29,7 +29,7 @@ namespace GeoLib {
/** /**
* \brief Creates a volume geometry from 2D mesh layers based on raster data. * \brief Creates a volume geometry from 2D mesh layers based on raster data.
*/ */
class LayeredVolume : public SubsurfaceMapper class LayeredVolume : public LayeredMeshGenerator
{ {
public: public:
LayeredVolume() {} LayeredVolume() {}
......
...@@ -139,7 +139,6 @@ void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned lay ...@@ -139,7 +139,6 @@ void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned lay
std::size_t const nNodes = dem_mesh.getNNodes(); std::size_t const nNodes = dem_mesh.getNNodes();
std::vector<MeshLib::Node*> const& nodes = dem_mesh.getNodes(); std::vector<MeshLib::Node*> const& nodes = dem_mesh.getNodes();
int const last_layer_node_offset = (layer_id-1) * nNodes; 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()); double const no_data_value (raster.getNoDataValue());
// add nodes for new layer // add nodes for new layer
...@@ -228,14 +227,11 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, GeoLib::Raster const ...@@ -228,14 +227,11 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, GeoLib::Raster const
const double y0(raster.getOrigin()[1]); const double y0(raster.getOrigin()[1]);
const double delta(raster.getRasterPixelSize()); const double delta(raster.getRasterPixelSize());
const double no_data(raster.getNoDataValue()); 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> 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 std::pair<double, double> yDim(y0, y0 + raster.getNRows() * delta); // extension in y-dimension
const size_t nNodes (new_mesh.getNNodes()); const size_t nNodes (new_mesh.getNNodes());
const double half_delta = 0.5*delta;
const std::vector<MeshLib::Node*> &nodes = new_mesh.getNodes(); const std::vector<MeshLib::Node*> &nodes = new_mesh.getNodes();
for (unsigned i = 0; i < nNodes; ++i) for (unsigned i = 0; i < nNodes; ++i)
{ {
......
...@@ -15,19 +15,19 @@ ...@@ -15,19 +15,19 @@
#ifndef MESHLAYERMAPPER_H #ifndef MESHLAYERMAPPER_H
#define MESHLAYERMAPPER_H #define MESHLAYERMAPPER_H
#include "SubsurfaceMapper.h" #include "LayeredMeshGenerator.h"
/** /**
* \brief Manipulating and adding prism element layers to an existing 2D mesh * \brief Manipulating and adding prism element layers to an existing 2D mesh
*/ */
class MeshLayerMapper : public SubsurfaceMapper class MeshLayerMapper : public LayeredMeshGenerator
{ {
public: public:
MeshLayerMapper() {} MeshLayerMapper() {}
~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 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 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 * \param thickness The thickness of each of these newly added layers
...@@ -37,7 +37,7 @@ public: ...@@ -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; 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 * 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. * 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 * \param mesh The 2D triangle mesh that is the basis for the new 3D prism mesh
......
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