diff --git a/FileIO/AsciiRasterInterface.cpp b/FileIO/AsciiRasterInterface.cpp index fa47dfa29d3c48329b08fcd9966f0df2c5da186f..3a64861a31c98e5c5fae2f3eddb738b9245e14d9 100644 --- a/FileIO/AsciiRasterInterface.cpp +++ b/FileIO/AsciiRasterInterface.cpp @@ -196,23 +196,25 @@ void AsciiRasterInterface::writeRasterAsASC(GeoLib::Raster const& raster, std::s unsigned const nCols (raster.getNCols()); unsigned const nRows (raster.getNRows()); - // write header + // write header std::ofstream out(file_name); - out << "ncols " << nCols << "\n"; - out << "nrows " << nRows << "\n"; - out << "xllcorner " << origin[0] << "\n"; - out << "yllcorner " << origin[1] << "\n"; - out << "cellsize " << raster.getRasterPixelSize() << "\n"; - out << "NODATA_value " << raster.getNoDataValue() << "\n"; - - // write data + out << "ncols " << nCols << "\n"; + out << "nrows " << nRows << "\n"; + out << "xllcorner " << origin[0] << "\n"; + out << "yllcorner " << origin[1] << "\n"; + out << "cellsize " << raster.getRasterPixelSize() << "\n"; + out << "NODATA_value " << raster.getNoDataValue() << "\n"; + + // write data double const*const elevation(raster.begin()); - for (unsigned row(0); row < nRows; ++row) { - for (unsigned col(0); col < nCols; ++col) { - out << elevation[(nRows-row-1) * nCols + col] << " "; - } - out << "\n"; - } + for (unsigned row(0); row < nRows; ++row) + { + for (unsigned col(0); col < nCols; ++col) + { + out << elevation[(nRows-row-1) * nCols + col] << " "; + } + out << "\n"; + } out.close(); } diff --git a/Gui/DataView/MeshLayerEditDialog.cpp b/Gui/DataView/MeshLayerEditDialog.cpp index 3e1d0bb8f40ab1c017dc3e035de8150ef68e3d12..231275565f02e5cfb72321cca63a1a8057b9c506 100644 --- a/Gui/DataView/MeshLayerEditDialog.cpp +++ b/Gui/DataView/MeshLayerEditDialog.cpp @@ -178,30 +178,30 @@ void MeshLayerEditDialog::createMeshToolSelection() MeshLib::Mesh* MeshLayerEditDialog::createPrismMesh() { - const unsigned nLayers = _layerEdit->text().toInt(); - std::vector<float> layer_thickness; - for (unsigned i=0; i<nLayers; ++i) - { - // "100" is just a default size to have any value for extruding 2D elements. - // The actual mapping based on a raster file will be performed later. - const float thickness = (_use_rasters) ? 100 : (this->_edits[i]->text().toFloat()); - layer_thickness.push_back(thickness); - } + const unsigned nLayers = _layerEdit->text().toInt(); + std::vector<float> layer_thickness; + for (unsigned i=0; i<nLayers; ++i) + { + // "100" is just a default size to have any value for extruding 2D elements. + // The actual mapping based on a raster file will be performed later. + const float thickness = (_use_rasters) ? 100 : (this->_edits[i]->text().toFloat()); + layer_thickness.push_back(thickness); + } MeshLayerMapper mapper; - MeshLib::Mesh* new_mesh (nullptr); + MeshLib::Mesh* new_mesh (nullptr); - if (_use_rasters) - { + if (_use_rasters) + { std::vector<std::string> raster_paths; - for (int i=nLayers; i>=0; --i) + for (int i=nLayers; i>=0; --i) raster_paths.push_back(this->_edits[i]->text().toStdString()); if (mapper.createLayers(*_msh, raster_paths)) new_mesh= mapper.getMesh("SubsurfaceMesh"); - } + } else new_mesh = mapper.createStaticLayers(*_msh, layer_thickness); - return new_mesh; + return new_mesh; } MeshLib::Mesh* MeshLayerEditDialog::createTetMesh() @@ -238,7 +238,7 @@ MeshLib::Mesh* MeshLayerEditDialog::createTetMesh() std::vector<float> layer_thickness; for (unsigned i=0; i<nLayers; ++i) layer_thickness.push_back(this->_edits[i]->text().toFloat()); - MeshLayerMapper const mapper; + MeshLayerMapper const mapper; tg_mesh = mapper.createStaticLayers(*_msh, layer_thickness); std::vector<MeshLib::Node> tg_attr; FileIO::TetGenInterface tetgen_interface; @@ -284,7 +284,7 @@ void MeshLayerEditDialog::accept() new_mesh = new MeshLib::Mesh(*_msh); const std::string imgPath ( this->_edits[0]->text().toStdString() ); const double noDataReplacementValue = this->_noDataReplacementEdit->text().toDouble(); - MeshLayerMapper const mapper; + MeshLayerMapper const mapper; if (!mapper.layerMapping(*new_mesh, imgPath, noDataReplacementValue)) { delete new_mesh; diff --git a/MeshLib/MeshGenerators/LayeredVolume.cpp b/MeshLib/MeshGenerators/LayeredVolume.cpp index 509d314c23f2c9a2baa1eebd21ef55acbbcac944..3263dcb0343c30bc69accbfb9605e2c0e53c5409 100644 --- a/MeshLib/MeshGenerators/LayeredVolume.cpp +++ b/MeshLib/MeshGenerators/LayeredVolume.cpp @@ -65,7 +65,7 @@ void LayeredVolume::addLayerToMesh(const MeshLib::Mesh &mesh_layer, unsigned lay const std::size_t nNodes (layer_nodes.size()); const std::size_t node_id_offset (_nodes.size()); const std::size_t last_layer_offset (node_id_offset-nNodes); - const double no_data_value (raster.getNoDataValue()); + const double no_data_value (raster.getNoDataValue()); for (std::size_t i=0; i<nNodes; ++i) { diff --git a/MeshLib/MeshGenerators/LayeredVolume.h b/MeshLib/MeshGenerators/LayeredVolume.h index 172503a64bf3f7bf510061fd38cf91182e69a167..5d6eeecae00df6005a8cf0a2c8d0c7342fbc4aa9 100644 --- a/MeshLib/MeshGenerators/LayeredVolume.h +++ b/MeshLib/MeshGenerators/LayeredVolume.h @@ -32,7 +32,7 @@ namespace GeoLib { class LayeredVolume : public SubsurfaceMapper { public: - LayeredVolume() {} + LayeredVolume() {} ~LayeredVolume() {} /** diff --git a/MeshLib/MeshGenerators/MeshLayerMapper.cpp b/MeshLib/MeshGenerators/MeshLayerMapper.cpp index 2264191178d387fcb7f22d1fadb08d1b4ebbb828..58bb399bab54a73b6ee88ef5908e8b0c366b6942 100644 --- a/MeshLib/MeshGenerators/MeshLayerMapper.cpp +++ b/MeshLib/MeshGenerators/MeshLayerMapper.cpp @@ -72,14 +72,14 @@ MeshLib::Mesh* MeshLayerMapper::createStaticLayers(MeshLib::Mesh const& mesh, st unsigned node_offset (nNodes * layer_id); if (layer_id > 0) z_offset += thickness[layer_id-1]; - std::transform(nodes.cbegin(), nodes.cend(), new_nodes.begin() + node_offset, - [&z_offset](MeshLib::Node* node){ return new MeshLib::Node((*node)[0], (*node)[1], (*node)[2]-z_offset); }); + std::transform(nodes.cbegin(), nodes.cend(), new_nodes.begin() + node_offset, + [&z_offset](MeshLib::Node* node){ return new MeshLib::Node((*node)[0], (*node)[1], (*node)[2]-z_offset); }); // starting with 2nd layer create prism or hex elements connecting the last layer with the current one if (layer_id == 0) - continue; + continue; - node_offset -= nNodes; + node_offset -= nNodes; const unsigned mat_id (nLayers - layer_id); for (unsigned i = 0; i < nOrgElems; ++i) @@ -109,11 +109,11 @@ MeshLib::Mesh* MeshLayerMapper::createStaticLayers(MeshLib::Mesh const& mesh, st bool MeshLayerMapper::createRasterLayers(MeshLib::Mesh const& mesh, std::vector<GeoLib::Raster const*> const& rasters, double noDataReplacementValue) { const std::size_t nLayers(rasters.size()); - if (nLayers < 1 || mesh.getDimension() != 2) - { - ERR("MeshLayerMapper::createRasterLayers(): A 2D mesh and at least two rasters required as input."); - return nullptr; - } + if (nLayers < 1 || mesh.getDimension() != 2) + { + ERR("MeshLayerMapper::createRasterLayers(): A 2D mesh and at least two rasters required as input."); + return nullptr; + } MeshLib::Mesh* dem_mesh (new MeshLib::Mesh(mesh)); if (layerMapping(*dem_mesh, *rasters.back(), 0)) @@ -121,9 +121,9 @@ bool MeshLayerMapper::createRasterLayers(MeshLib::Mesh const& mesh, std::vector< std::size_t const nNodes = mesh.getNNodes(); _nodes.reserve(nLayers * nNodes); - // number of triangles in the original mesh - std::size_t const nElems (std::count_if(mesh.getElements().begin(), mesh.getElements().end(), - [](MeshLib::Element const* elem) { return (elem->getGeomType() == MeshElemType::TRIANGLE);})); + // number of triangles in the original mesh + std::size_t const nElems (std::count_if(mesh.getElements().begin(), mesh.getElements().end(), + [](MeshLib::Element const* elem) { return (elem->getGeomType() == MeshElemType::TRIANGLE);})); _elements.reserve(nElems * (nLayers-1)); for (std::size_t i=0; i<nLayers; ++i) @@ -137,12 +137,12 @@ bool MeshLayerMapper::createRasterLayers(MeshLib::Mesh const& mesh, std::vector< void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned layer_id, GeoLib::Raster const& raster) { 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; unsigned const layer_node_offset = layer_id * nNodes; double const no_data_value (raster.getNoDataValue()); - // add nodes for new layer + // add nodes for new layer for (std::size_t i=0; i<nNodes; ++i) { // min of dem elevation and layer elevation @@ -159,7 +159,7 @@ void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned lay if (layer_id == 0) return; - std::vector<MeshLib::Element*> const& elems = dem_mesh.getElements(); + std::vector<MeshLib::Element*> const& elems = dem_mesh.getElements(); std::size_t const nElems (dem_mesh.getNElements()); for (std::size_t i=0; i<nElems; ++i) @@ -219,9 +219,9 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, std::string const& r bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, GeoLib::Raster const& raster, double noDataReplacementValue = 0.0) { if (new_mesh.getDimension() != 2) - { - ERR("MshLayerMapper::layerMapping - requires 2D mesh"); - return false; + { + ERR("MshLayerMapper::layerMapping - requires 2D mesh"); + return false; } const double x0(raster.getOrigin()[0]); diff --git a/MeshLib/MeshGenerators/SubsurfaceMapper.cpp b/MeshLib/MeshGenerators/SubsurfaceMapper.cpp index 2d5a223fc12f87b90b39d040b05d9f7691e76aeb..5be832c812c766efb67babab862121ab04f43f7c 100644 --- a/MeshLib/MeshGenerators/SubsurfaceMapper.cpp +++ b/MeshLib/MeshGenerators/SubsurfaceMapper.cpp @@ -33,17 +33,17 @@ SubsurfaceMapper::SubsurfaceMapper() bool SubsurfaceMapper::createLayers(MeshLib::Mesh const& mesh, std::vector<std::string> const& raster_paths, double noDataReplacementValue) { - if (mesh.getDimension() != 2 || !allRastersExist(raster_paths)) - return false; + if (mesh.getDimension() != 2 || !allRastersExist(raster_paths)) + return false; - std::vector<GeoLib::Raster const*> rasters; - rasters.reserve(raster_paths.size()); - for (auto path = raster_paths.begin(); path != raster_paths.end(); ++path) - rasters.push_back(FileIO::AsciiRasterInterface::getRasterFromASCFile(*path)); + std::vector<GeoLib::Raster const*> rasters; + rasters.reserve(raster_paths.size()); + for (auto path = raster_paths.begin(); path != raster_paths.end(); ++path) + rasters.push_back(FileIO::AsciiRasterInterface::getRasterFromASCFile(*path)); - bool result = createRasterLayers(mesh, rasters, noDataReplacementValue); - std::for_each(rasters.begin(), rasters.end(), [](GeoLib::Raster const*const raster){ delete raster; }); - return result; + bool result = createRasterLayers(mesh, rasters, noDataReplacementValue); + std::for_each(rasters.begin(), rasters.end(), [](GeoLib::Raster const*const raster){ delete raster; }); + return true; } MeshLib::Mesh* SubsurfaceMapper::getMesh(std::string const& mesh_name) const @@ -58,25 +58,25 @@ MeshLib::Mesh* SubsurfaceMapper::getMesh(std::string const& mesh_name) const double SubsurfaceMapper::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); + 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 { - for (auto raster = raster_paths.begin(); raster != raster_paths.end(); ++raster) - { - std::ifstream file_stream (*raster, std::ifstream::in); - if (!file_stream.good()) - return false; - file_stream.close(); - } - return true; + for (auto raster = raster_paths.begin(); raster != raster_paths.end(); ++raster) + { + std::ifstream file_stream (*raster, std::ifstream::in); + if (!file_stream.good()) + return false; + file_stream.close(); + } + return true; } void SubsurfaceMapper::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; }); + 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/SubsurfaceMapper.h index ea29d23afc160b0fcb043027b1550231f0558e12..fc0ae9bb6c671cfb94fccc9a6c117e794e445eb1 100644 --- a/MeshLib/MeshGenerators/SubsurfaceMapper.h +++ b/MeshLib/MeshGenerators/SubsurfaceMapper.h @@ -23,9 +23,9 @@ namespace GeoLib { } namespace MeshLib { - class Mesh; + class Mesh; class Node; - class Element; + class Element; } /** @@ -34,46 +34,46 @@ namespace MeshLib { class SubsurfaceMapper { public: - /** - * Returns a subsurface representation of a region represented by a 2D by reading raster files and calling the appropriate construction method. - * @param mesh The 2D surface mesh that is used as a basis for the subsurface mesh - * @param raster_paths Containing all the raster-file-names for the subsurface layers from bottom to top (starting with the bottom of the oldest layer and ending with the DEM) - * @param noDataReplacementValue Default z-coordinate if there are mesh nodes not located on the DEM raster (i.e. raster_paths[0]) - * @result true if the subsurface representation has been created, false if there was an error - */ - virtual bool createLayers(MeshLib::Mesh const& mesh, std::vector<std::string> const& raster_paths, double noDataReplacementValue = 0.0) final; + /** + * Returns a subsurface representation of a region represented by a 2D by reading raster files and calling the appropriate construction method. + * @param mesh The 2D surface mesh that is used as a basis for the subsurface mesh + * @param raster_paths Containing all the raster-file-names for the subsurface layers from bottom to top (starting with the bottom of the oldest layer and ending with the DEM) + * @param noDataReplacementValue Default z-coordinate if there are mesh nodes not located on the DEM raster (i.e. raster_paths[0]) + * @result true if the subsurface representation has been created, false if there was an error + */ + virtual bool createLayers(MeshLib::Mesh const& mesh, std::vector<std::string> const& raster_paths, double noDataReplacementValue = 0.0) final; /** - * Constructs a subsurface representation based on a 2D mesh and a number of rasters representing subsurface layer boundaries. - * @param mesh The 2D surface mesh that is used as a basis for the subsurface mesh - * @param rasters Containing all the raster-data for the subsurface layers from bottom to top (starting with the bottom of the oldest layer and ending with the DEM) - * @param noDataReplacementValue Default z-coordinate if there are mesh nodes not located on the DEM raster (i.e. raster_paths[0]) - * @result true if the subsurface representation has been created, false if there was an error - */ - virtual bool createRasterLayers(MeshLib::Mesh const& mesh, std::vector<GeoLib::Raster const*> const& rasters, double noDataReplacementValue) = 0; + * Constructs a subsurface representation based on a 2D mesh and a number of rasters representing subsurface layer boundaries. + * @param mesh The 2D surface mesh that is used as a basis for the subsurface mesh + * @param rasters Containing all the raster-data for the subsurface layers from bottom to top (starting with the bottom of the oldest layer and ending with the DEM) + * @param noDataReplacementValue Default z-coordinate if there are mesh nodes not located on the DEM raster (i.e. raster_paths[0]) + * @result true if the subsurface representation has been created, false if there was an error + */ + virtual bool createRasterLayers(MeshLib::Mesh const& mesh, std::vector<GeoLib::Raster const*> const& rasters, double noDataReplacementValue) = 0; - /// Returns a mesh of the subsurface representation - MeshLib::Mesh* getMesh(std::string const& mesh_name) const; + /// Returns a mesh of the subsurface representation + MeshLib::Mesh* getMesh(std::string const& mesh_name) const; protected: - SubsurfaceMapper(); - ~SubsurfaceMapper() {} + SubsurfaceMapper(); + ~SubsurfaceMapper() {} - /// Adds another layer to the subsurface mesh - virtual void addLayerToMesh(MeshLib::Mesh const& mesh_layer, unsigned layer_id, GeoLib::Raster const& raster) = 0; + /// Adds another layer to the subsurface mesh + virtual void addLayerToMesh(MeshLib::Mesh const& mesh_layer, unsigned layer_id, GeoLib::Raster const& raster) = 0; - /// Calculates a data-dependent epsilon value - double calcEpsilon(GeoLib::Raster const& high, GeoLib::Raster const& low); + /// Calculates a data-dependent epsilon value + double calcEpsilon(GeoLib::Raster const& high, GeoLib::Raster const& low); - /// Checks if all raster files actually exist - bool allRastersExist(std::vector<std::string> const& raster_paths) const; + /// Checks if all raster files actually exist + bool allRastersExist(std::vector<std::string> const& raster_paths) const; - /// Cleans up the already created objects in case of an error - void cleanUpOnError(); + /// Cleans up the already created objects in case of an error + void cleanUpOnError(); - double _elevation_epsilon; - std::vector<MeshLib::Node*> _nodes; - std::vector<MeshLib::Element*> _elements; + double _elevation_epsilon; + std::vector<MeshLib::Node*> _nodes; + std::vector<MeshLib::Element*> _elements; }; #endif //SUBSURFACEMAPPER_H