From 7ff1f812ca4c85e6d52bdf86e7434d8a042eb189 Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Tue, 9 Sep 2014 15:41:09 +0200 Subject: [PATCH] changed static methods in MeshLayerMapper to non-static --- Gui/DataView/MeshLayerEditDialog.cpp | 13 ++-- MeshLib/MeshGenerators/LayeredVolume.cpp | 3 +- MeshLib/MeshGenerators/MeshLayerMapper.cpp | 19 +++--- MeshLib/MeshGenerators/MeshLayerMapper.h | 73 +++++++++++----------- MeshLib/Node.h | 6 +- 5 files changed, 58 insertions(+), 56 deletions(-) diff --git a/Gui/DataView/MeshLayerEditDialog.cpp b/Gui/DataView/MeshLayerEditDialog.cpp index 5e7e3c0cc31..88a92f4f681 100644 --- a/Gui/DataView/MeshLayerEditDialog.cpp +++ b/Gui/DataView/MeshLayerEditDialog.cpp @@ -188,7 +188,8 @@ MeshLib::Mesh* MeshLayerEditDialog::createPrismMesh() layer_thickness.push_back(thickness); } - MeshLib::Mesh* new_mesh = MeshLayerMapper::CreateLayers(*_msh, layer_thickness); + MeshLayerMapper const mapper; + MeshLib::Mesh* new_mesh = mapper.createLayers(*_msh, layer_thickness); if (_use_rasters) { @@ -196,7 +197,7 @@ MeshLib::Mesh* MeshLayerEditDialog::createPrismMesh() { const std::string imgPath ( this->_edits[i+1]->text().toStdString() ); const double noDataReplacement = (i==0) ? 0.0 : -9999.0; - if (!MeshLayerMapper::LayerMapping(*new_mesh, imgPath, nLayers, i, noDataReplacement)) + if (!mapper.layerMapping(*new_mesh, imgPath, nLayers, i, noDataReplacement)) { delete new_mesh; return nullptr; @@ -204,7 +205,7 @@ MeshLib::Mesh* MeshLayerEditDialog::createPrismMesh() } if (this->_edits[0]->text().length()>0) { - MeshLib::Mesh* final_mesh = MeshLayerMapper::blendLayersWithSurface(*new_mesh, nLayers, this->_edits[0]->text().toStdString()); + MeshLib::Mesh* final_mesh = mapper.blendLayersWithSurface(*new_mesh, nLayers, this->_edits[0]->text().toStdString()); delete new_mesh; new_mesh = final_mesh; } @@ -246,7 +247,8 @@ 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()); - tg_mesh = MeshLayerMapper::CreateLayers(*_msh, layer_thickness); + MeshLayerMapper const mapper; + tg_mesh = mapper.createLayers(*_msh, layer_thickness); std::vector<MeshLib::Node> tg_attr; FileIO::TetGenInterface tetgen_interface; tetgen_interface.writeTetGenSmesh(filename.toStdString(), *tg_mesh, tg_attr); @@ -291,7 +293,8 @@ 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(); - if (!MeshLayerMapper::LayerMapping(*new_mesh, imgPath, nLayers, 0, noDataReplacementValue)) + MeshLayerMapper const mapper; + if (!mapper.layerMapping(*new_mesh, imgPath, nLayers, 0, noDataReplacementValue)) { delete new_mesh; return; diff --git a/MeshLib/MeshGenerators/LayeredVolume.cpp b/MeshLib/MeshGenerators/LayeredVolume.cpp index 409538ad06b..0e9665b9b12 100644 --- a/MeshLib/MeshGenerators/LayeredVolume.cpp +++ b/MeshLib/MeshGenerators/LayeredVolume.cpp @@ -71,11 +71,12 @@ bool LayeredVolume::createGeoVolumes(const MeshLib::Mesh &mesh, const std::vecto mesh_layer = new MeshLib::Mesh(mesh); // map each layer and attach to subsurface mesh + MeshLayerMapper const mapper; const std::size_t nRasters (rasters.size()); for (size_t i=0; i<nRasters; ++i) { const double replacement_value = (i==(nRasters-1)) ? noDataReplacementValue : _invalid_value; - if (!MeshLayerMapper::LayerMapping(*mesh_layer, *rasters[i], 0, 0, replacement_value)) + if (!mapper.layerMapping(*mesh_layer, *rasters[i], 0, 0, replacement_value)) { this->cleanUpOnError(); return false; diff --git a/MeshLib/MeshGenerators/MeshLayerMapper.cpp b/MeshLib/MeshGenerators/MeshLayerMapper.cpp index b302c5e113b..038535da871 100644 --- a/MeshLib/MeshGenerators/MeshLayerMapper.cpp +++ b/MeshLib/MeshGenerators/MeshLayerMapper.cpp @@ -32,8 +32,7 @@ #include "MeshSurfaceExtraction.h" #include "MathTools.h" - -MeshLib::Mesh* MeshLayerMapper::CreateLayers(const MeshLib::Mesh &mesh, const std::vector<float> &layer_thickness_vector) +MeshLib::Mesh* MeshLayerMapper::createLayers(MeshLib::Mesh const& mesh, std::vector<float> const& layer_thickness_vector) const { std::vector<float> thickness; for (std::size_t i=0; i<layer_thickness_vector.size(); ++i) @@ -109,21 +108,21 @@ MeshLib::Mesh* MeshLayerMapper::CreateLayers(const MeshLib::Mesh &mesh, const st return new MeshLib::Mesh("SubsurfaceMesh", new_nodes, new_elems); } -bool MeshLayerMapper::LayerMapping(MeshLib::Mesh &new_mesh, const std::string &rasterfile, - const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue = 0.0) +bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, const std::string &rasterfile, + const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue = 0.0) const { const GeoLib::Raster *raster(GeoLib::Raster::getRasterFromASCFile(rasterfile)); if (! raster) { ERR("MshLayerMapper::LayerMapping - could not read raster file %s", rasterfile.c_str()); return false; } - const bool result = LayerMapping(new_mesh, *raster, nLayers, layer_id, noDataReplacementValue); + const bool result = layerMapping(new_mesh, *raster, nLayers, layer_id, noDataReplacementValue); delete raster; return result; } -bool MeshLayerMapper::LayerMapping(MeshLib::Mesh &new_mesh, const GeoLib::Raster &raster, - const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue = 0.0) +bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, const GeoLib::Raster &raster, + const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue = 0.0) const { if (nLayers < layer_id) { @@ -214,7 +213,7 @@ bool MeshLayerMapper::LayerMapping(MeshLib::Mesh &new_mesh, const GeoLib::Raster bool MeshLayerMapper::isNodeOnRaster(const MeshLib::Node &node, const std::pair<double, double> &xDim, - const std::pair<double, double> &yDim) + const std::pair<double, double> &yDim) const { if (node[0] < xDim.first || node[0] > xDim.second || node[1] < yDim.first || node[1] > yDim.second) return false; @@ -222,12 +221,12 @@ bool MeshLayerMapper::isNodeOnRaster(const MeshLib::Node &node, return true; } -MeshLib::Mesh* MeshLayerMapper::blendLayersWithSurface(MeshLib::Mesh &mesh, const unsigned nLayers, const std::string &dem_raster) +MeshLib::Mesh* MeshLayerMapper::blendLayersWithSurface(MeshLib::Mesh &mesh, const unsigned nLayers, const std::string &dem_raster) const { // construct surface mesh from DEM const MathLib::Vector3 dir(0,0,1); MeshLib::Mesh* dem = MeshLib::MeshSurfaceExtraction::getMeshSurface(mesh, dir); - MeshLayerMapper::LayerMapping(*dem, dem_raster, 0, 0); + this->layerMapping(*dem, dem_raster, 0, 0); const std::vector<MeshLib::Node*> &dem_nodes (dem->getNodes()); const std::vector<MeshLib::Node*> &mdl_nodes (mesh.getNodes()); diff --git a/MeshLib/MeshGenerators/MeshLayerMapper.h b/MeshLib/MeshGenerators/MeshLayerMapper.h index 33853f4045f..31f978ebcd6 100644 --- a/MeshLib/MeshGenerators/MeshLayerMapper.h +++ b/MeshLib/MeshGenerators/MeshLayerMapper.h @@ -21,55 +21,54 @@ class QImage; namespace MeshLib { - class Mesh; - class Node; + class Mesh; + class Node; } /** - * \brief Manipulating and adding layers to an existing mesh - */ +* \brief Manipulating and adding layers to an existing mesh +*/ class MeshLayerMapper { public: - MeshLayerMapper() {} - ~MeshLayerMapper() {} + MeshLayerMapper() {}; + ~MeshLayerMapper() {}; - /** - * Based on a triangle-or quad mesh this method creates a 3D mesh with 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 - * \return A mesh with the requested number of layers of prism/hex elements - */ - static MeshLib::Mesh* CreateLayers(const MeshLib::Mesh &mesh, const std::vector<float> &layer_thickness_vector); + /** + * Based on a triangle-or quad mesh this method creates a 3D mesh with 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 + * \return A mesh with the requested number of layers of prism/hex elements + */ + MeshLib::Mesh* createLayers(MeshLib::Mesh const& mesh, std::vector<float> const& layer_thickness_vector) const; - /** - * Maps the z-values of nodes in the designated layer of the given mesh according to the given raster. - * Note: This only results in a valid mesh if the layers don't intersect each other. - */ - static bool LayerMapping(MeshLib::Mesh &mesh, const std::string &rasterfile, - const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue); + /** + * Maps the z-values of nodes in the designated layer of the given mesh according to the given raster. + * Note: This only results in a valid mesh if the layers don't intersect each other. + */ + bool layerMapping(MeshLib::Mesh &mesh, const std::string &rasterfile, + const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue) const; - /** - * Maps the z-values of nodes in the designated layer of the given mesh according to the given raster. - * Note: This only results in a valid mesh if the layers don't intersect each other. - */ - static bool LayerMapping(MeshLib::Mesh &mesh, const GeoLib::Raster &raster, - const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue); + /** + * Maps the z-values of nodes in the designated layer of the given mesh according to the given raster. + * Note: This only results in a valid mesh if the layers don't intersect each other. + */ + bool layerMapping(MeshLib::Mesh &mesh, const GeoLib::Raster &raster, + const unsigned nLayers, const unsigned layer_id, double noDataReplacementValue) const; - /** - * Blends a mesh with the surface given by dem_raster. Nodes and elements above the surface are either removed or adapted to fit the surface. - * Note: It is unlikely but possible that the new nodes vector contains (very few) nodes that are not part of any element. This problem is - * remedied at the end of method upon creating the actual mesh from the new node- and element-vector as the mesh-constructor checks for such - * nodes and removes them. This note is just to call this issue to attention in case this methods is changed. - */ - static MeshLib::Mesh* blendLayersWithSurface(MeshLib::Mesh &mesh, const unsigned nLayers, const std::string &dem_raster); + /** + * Blends a mesh with the surface given by dem_raster. Nodes and elements above the surface are either removed or adapted to fit the surface. + * Note: It is unlikely but possible that the new nodes vector contains (very few) nodes that are not part of any element. This problem is + * remedied at the end of method upon creating the actual mesh from the new node- and element-vector as the mesh-constructor checks for such + * nodes and removes them. This note is just to call this issue to attention in case this methods is changed. + */ + MeshLib::Mesh* blendLayersWithSurface(MeshLib::Mesh &mesh, const unsigned nLayers, const std::string &dem_raster) const; private: - /// Checks if the given mesh is within the dimensions given by xDim and yDim. - static bool isNodeOnRaster(const MeshLib::Node &node, - const std::pair<double, double> &xDim, - const std::pair<double, double> &yDim); + /// Checks if the given mesh is within the dimensions given by xDim and yDim. + bool isNodeOnRaster(const MeshLib::Node &node, + const std::pair<double, double> &xDim, const std::pair<double, double> &yDim) const; }; #endif //MESHLAYERMAPPER_H diff --git a/MeshLib/Node.h b/MeshLib/Node.h index ae0a21165a6..ce4e783e122 100644 --- a/MeshLib/Node.h +++ b/MeshLib/Node.h @@ -36,9 +36,9 @@ class Element; class Node : public GeoLib::PointWithID { /* friend functions: */ - friend bool MeshLayerMapper::LayerMapping(MeshLib::Mesh &mesh, const GeoLib::Raster &raster, const unsigned nLayers, - const unsigned layer_id, double noDataReplacementValue); - friend MeshLib::Mesh* MeshLayerMapper::blendLayersWithSurface(MeshLib::Mesh &mesh, const unsigned nLayers, const std::string &dem_raster); + friend bool MeshLayerMapper::layerMapping(MeshLib::Mesh &mesh, const GeoLib::Raster &raster, const unsigned nLayers, + const unsigned layer_id, double noDataReplacementValue) const; + friend MeshLib::Mesh* MeshLayerMapper::blendLayersWithSurface(MeshLib::Mesh &mesh, const unsigned nLayers, const std::string &dem_raster) const; friend MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface(const MeshLib::Mesh &mesh, const MathLib::Vector3 &dir, bool keep3dMeshIds); /* friend classes: */ -- GitLab