diff --git a/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp b/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp index 329b88a0685be8661631a0d02087bced553f7e26..d138365c0e0c5d566e4b9be89b8d62e11372b20f 100644 --- a/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp +++ b/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp @@ -43,7 +43,7 @@ const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::di const MathLib::Vector3 dir(0,0,-1); const std::vector<GeoLib::Point*> surface_nodes(MeshLib::MeshSurfaceExtraction::getSurfaceNodes(mesh, dir, 90) ); const std::size_t nNodes(surface_nodes.size()); - const double no_data (raster->getNoDataValue()); + const double no_data (raster->getHeader().no_data); _direct_values.reserve(nNodes); for (std::size_t i=0; i<nNodes; i++) { @@ -78,18 +78,13 @@ const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::di return _direct_values; } - MathLib::Vector3 const dir(0.0, 0.0, -1.0); - double const angle(90); - std::string const prop_name("OriginalSubsurfaceNodeIDs"); - std::unique_ptr<MeshLib::Mesh> surface_mesh( - MeshLib::MeshSurfaceExtraction::getMeshSurface( - mesh, dir, angle, prop_name)); - + const MathLib::Vector3 dir(0,0,-1); + MeshLib::Mesh* sfc_mesh (MeshLib::MeshSurfaceExtraction::getMeshSurface(mesh, dir, true)); std::vector<double> node_area_vec = - MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes(*surface_mesh); - const std::vector<MeshLib::Node*> &surface_nodes(surface_mesh->getNodes()); - const std::size_t nNodes(surface_mesh->getNNodes()); - const double no_data(raster->getNoDataValue()); + MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes(*sfc_mesh); + const std::vector<MeshLib::Node*> &surface_nodes (sfc_mesh->getNodes()); + const std::size_t nNodes(sfc_mesh->getNNodes()); + const double no_data (raster->getHeader().no_data); boost::optional<MeshLib::PropertyVector<int> const&> opt_node_id_pv( surface_mesh->getProperties().getPropertyVector<int>(prop_name)); @@ -105,9 +100,9 @@ const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::di _direct_values.reserve(nNodes); for (std::size_t i=0; i<nNodes; ++i) { - double val(raster->getValueAtPoint(*surface_nodes[i])); + double val (raster->getValueAtPoint(*surface_nodes[i])); val = (val == no_data) ? 0 : ((val*node_area_vec[i])/scaling); - _direct_values.push_back(std::pair<std::size_t, double>(node_id_pv[i], val)); + _direct_values.push_back (std::pair<std::size_t, double>(surface_nodes[i]->getID(), val)); } return _direct_values; diff --git a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp index ad5378d4ce9dcb53da97850b6df9ddd14c86c3a7..a0dda8a9e5ce2d8e32e4c1cc703c408a5bae0852 100644 --- a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp +++ b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp @@ -204,7 +204,7 @@ void VtkVisPipelineView::showImageToMeshConversionDialog() constructMeshFromImage(dlg.getNewMeshName(), dlg.getElementSelection(), dlg.getIntensitySelection()); } -void VtkVisPipelineView::constructMeshFromImage(std::string msh_name, MeshLib::MeshElemType element_type, MeshLib::UseIntensityAs intensity_type) +void VtkVisPipelineView::constructMeshFromImage(std::string const& msh_name, MeshLib::MeshElemType element_type, MeshLib::UseIntensityAs intensity_type) { vtkSmartPointer<vtkAlgorithm> algorithm = static_cast<VtkVisPipelineItem*>(static_cast<VtkVisPipeline*>(this->model())-> diff --git a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.h b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.h index dcc0a0fdf0cb7a0e326ba10617494dfdd507d336..004fb0e502240dabd542689570a0a33ba71ff14c 100644 --- a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.h +++ b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.h @@ -58,7 +58,7 @@ private: /// Calls the conversion method for creating an OGS Mesh from a vtkImageData object. void constructMeshFromImage( - std::string msh_name, + std::string const& msh_name, MeshLib::MeshElemType element_type, MeshLib::UseIntensityAs intensity_type); diff --git a/FileIO/AsciiRasterInterface.cpp b/FileIO/AsciiRasterInterface.cpp index bfa3f081163013924daf33aeae8c1274236e3831..7db2da8b19f0b05b7258571c69fc3adecba8f845 100644 --- a/FileIO/AsciiRasterInterface.cpp +++ b/FileIO/AsciiRasterInterface.cpp @@ -188,9 +188,10 @@ bool AsciiRasterInterface::readSurferHeader(std::ifstream &in, GeoLib::RasterHea void AsciiRasterInterface::writeRasterAsASC(GeoLib::Raster const& raster, std::string const& file_name) { - GeoLib::Point const& origin (raster.getOrigin()); - unsigned const nCols (raster.getNCols()); - unsigned const nRows (raster.getNRows()); + GeoLib::RasterHeader header (raster.getHeader()); + MathLib::Point3d const& origin (header.origin); + unsigned const nCols (header.n_cols); + unsigned const nRows (header.n_rows); // write header std::ofstream out(file_name); @@ -198,8 +199,8 @@ void AsciiRasterInterface::writeRasterAsASC(GeoLib::Raster const& raster, std::s 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"; + out << "cellsize " << header.cell_size << "\n"; + out << "NODATA_value " << header.no_data << "\n"; // write data double const*const elevation(raster.begin()); diff --git a/GeoLib/Raster.cpp b/GeoLib/Raster.cpp index e5a2f079462a099f6620cd266158f518e96e04e1..bdb197417c5fcbf24d897fa9abc975e7106ec8a3 100644 --- a/GeoLib/Raster.cpp +++ b/GeoLib/Raster.cpp @@ -55,21 +55,6 @@ Raster::~Raster() delete [] _raster_data; } -void Raster::setCellSize(double cell_size) -{ - _header.cell_size = cell_size; -} - -void Raster::setNoDataVal (double no_data_val) -{ - _header.no_data = no_data_val; -} - -GeoLib::Point const Raster::getOrigin() const -{ - return GeoLib::Point(_header.origin,0); -} - Raster* Raster::getRasterFromSurface(Surface const& sfc, double cell_size, double no_data_val) { MathLib::Point3d const& ll(sfc.getAABB().getMinPoint()); diff --git a/GeoLib/Raster.h b/GeoLib/Raster.h index 78183ee72f5f431b950be74cbd3b1ed1ec976f87..5f78009d3ee0dfe822d1a7786dba6774ae54214d 100644 --- a/GeoLib/Raster.h +++ b/GeoLib/Raster.h @@ -64,33 +64,11 @@ public: /// Returns the complete header information RasterHeader const& getHeader() const { return _header; } - /** - * get the number of columns for the raster - */ - std::size_t getNCols() const { return _header.n_cols; } - /** - * get the number of rows for the raster - */ - std::size_t getNRows() const { return _header.n_rows; } - - /** - * get the distance between raster pixels - */ - double getRasterPixelSize() const { return _header.cell_size; } - - /** - * get the origin of lower left raster cell - * @return the origin of the raster - */ - GeoLib::Point const getOrigin() const; - /** * Refine the raster using scaling as a refinement parameter. */ void refineRaster(std::size_t scaling); - double getNoDataValue() const { return _header.no_data; } - /** * Constant iterator that is pointing to the first raster pixel value. * @return constant iterator diff --git a/MeshGeoToolsLib/GeoMapper.cpp b/MeshGeoToolsLib/GeoMapper.cpp index 9ff1e4e333f49c4eb56923ffb952eeb8daedc388..ced1e0578329124617f8704bcf8033e0f14fca0d 100644 --- a/MeshGeoToolsLib/GeoMapper.cpp +++ b/MeshGeoToolsLib/GeoMapper.cpp @@ -189,7 +189,7 @@ void GeoMapper::mapPointDataToMeshSurface(std::vector<GeoLib::Point*> const& pnt float GeoMapper::getDemElevation(GeoLib::Point const& pnt) const { double const elevation (_raster->getValueAtPoint(pnt)); - if (std::abs(elevation-_raster->getNoDataValue()) < std::numeric_limits<double>::epsilon()) + if (std::abs(elevation-_raster->getHeader().no_data) < std::numeric_limits<double>::epsilon()) return 0.0; return static_cast<float>(elevation); } diff --git a/MeshLib/MeshGenerators/ConvertRasterToMesh.cpp b/MeshLib/MeshGenerators/ConvertRasterToMesh.cpp index 42f099ee4f9d9ae1125ae6ad1b6f44cf40389787..f7c6c076aa9b4d146ce63a668d31f13fcea39d81 100644 --- a/MeshLib/MeshGenerators/ConvertRasterToMesh.cpp +++ b/MeshLib/MeshGenerators/ConvertRasterToMesh.cpp @@ -29,26 +29,26 @@ ConvertRasterToMesh::~ConvertRasterToMesh() MeshLib::Mesh* ConvertRasterToMesh::execute() const { - const std::size_t height(_raster.getNRows()+1); - const std::size_t width(_raster.getNCols()+1); - const std::size_t size(height*width); - double* pix_vals(new double[size]); - bool* vis_nodes(new bool[size]); + GeoLib::RasterHeader const& header (_raster.getHeader()); + const std::size_t height(header.n_rows+1); + const std::size_t width(header.n_cols+1); + double* pix_vals(new double[height*width]); + bool* vis_nodes(new bool[height*width]); // determine a valid value for substitution of no data values double substitution(getExistingValue(_raster.begin(), _raster.end())); // fill first row with non visual nodes - for (std::size_t j = 0; j < _raster.getNCols(); j++) { + for (std::size_t j = 0; j < width; j++) { pix_vals[j] = 0; vis_nodes[j] = false; } GeoLib::Raster::const_iterator raster_it(_raster.begin()); - for (std::size_t i = 0; i < _raster.getNRows(); ++i) { - for (std::size_t j = 0; j < _raster.getNCols(); ++j) { + for (std::size_t i = 0; i < height; ++i) { + for (std::size_t j = 0; j < width; ++j) { const std::size_t index = (i+1) * width + j; - if (*raster_it == _raster.getNoDataValue()) { + if (*raster_it == header.no_data) { pix_vals[index] = substitution; vis_nodes[index] = false; } else { @@ -72,12 +72,11 @@ MeshLib::Mesh* ConvertRasterToMesh::execute() const MeshLib::Mesh* ConvertRasterToMesh::constructMesh(const double* pix_vals, const bool* vis_nodes) const { - const std::size_t height = _raster.getNRows()+1; - const std::size_t width = _raster.getNCols()+1; + GeoLib::RasterHeader const& header (_raster.getHeader()); + const std::size_t height (header.n_rows+1); + const std::size_t width (header.n_cols+1); std::size_t node_idx_count(0); - const double distance(_raster.getRasterPixelSize()); - const double x_offset(_raster.getOrigin()[0]); // - distance / 2.0); - const double y_offset(_raster.getOrigin()[1]); // - distance / 2.0); + const double distance(header.cell_size); const std::size_t size(height*width); int* node_idx_map(new int[size]); @@ -89,33 +88,20 @@ MeshLib::Mesh* ConvertRasterToMesh::constructMesh(const double* pix_vals, const for (std::size_t i = 0; i < height; i++) { for (std::size_t j = 0; j < width; j++) { const std::size_t index = i * width + j; - -// bool set_node(true); -// bool set_node(false); -// if (j == 0 && i == height) -// set_node = vis_nodes[index]; -// else if (j == 0) -// set_node = (vis_nodes[index] || vis_nodes[index + height]); -// else if (i == width) -// set_node = (vis_nodes[index] || vis_nodes[index - 1]); -// else set_node = (vis_nodes[index] || vis_nodes[index - 1] || vis_nodes[index + height] -// || vis_nodes[index + height - 1]); -// if (set_node) { - double zValue = (_intensity_type == UseIntensityAs::ELEVATION) ? pix_vals[index] - : _raster.getOrigin()[2]; - MeshLib::Node* node(new MeshLib::Node(x_offset + (distance * j), y_offset - + (distance * i), zValue)); - nodes.push_back(node); - node_idx_map[index] = node_idx_count; - node_idx_count++; -// } + double zValue = (_intensity_type == UseIntensityAs::ELEVATION) ? + pix_vals[index] : header.origin[2]; + MeshLib::Node* node(new MeshLib::Node(header.origin[0] + (distance * j), + header.origin[1] + (distance * i), zValue)); + nodes.push_back(node); + node_idx_map[index] = node_idx_count; + node_idx_count++; } } std::vector<int> mat_ids; // set mesh elements - for (std::size_t i = 0; i < _raster.getNRows(); i++) { - for (std::size_t j = 0; j < _raster.getNCols(); j++) { + for (std::size_t i = 0; i < height; i++) { + for (std::size_t j = 0; j < width; j++) { const int index = i * width + j; if ((node_idx_map[index] != -1) && (node_idx_map[index + 1] != -1) && (node_idx_map[index + width] != -1) @@ -169,10 +155,11 @@ MeshLib::Mesh* ConvertRasterToMesh::constructMesh(const double* pix_vals, const double ConvertRasterToMesh::getExistingValue(GeoLib::Raster::const_iterator first, GeoLib::Raster::const_iterator last) const { + double const no_data (_raster.getHeader().no_data); for (GeoLib::Raster::const_iterator it(first); it != last; ++it) { - if (*it != _raster.getNoDataValue()) + if (*it != no_data) return *it; } - return _raster.getNoDataValue(); + return no_data; } } // end namespace MeshLib diff --git a/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp index 6a7bfba8e024c0fc01b1e59dd0b190c5142e409a..dbd84ab8040b117ef3ac68a5f3b24ee715b2d712 100644 --- a/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp +++ b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp @@ -100,7 +100,7 @@ MeshLib::Node* LayeredMeshGenerator::getNewLayerNode(MeshLib::Node const& dem_no { double const elevation = std::min(raster.interpolateValueAtPoint(dem_node), dem_node[2]); - if ((std::abs(elevation - raster.getNoDataValue()) < std::numeric_limits<double>::epsilon()) || + if ((std::abs(elevation - raster.getHeader().no_data) < std::numeric_limits<double>::epsilon()) || (elevation - last_layer_node[2] < _minimum_thickness)) return new MeshLib::Node(last_layer_node); else diff --git a/MeshLib/MeshGenerators/MeshLayerMapper.cpp b/MeshLib/MeshGenerators/MeshLayerMapper.cpp index 72008c297870b92341fda5de79739281890c2921..43bb1eb457818110359077b753e86cde0acb8afe 100644 --- a/MeshLib/MeshGenerators/MeshLayerMapper.cpp +++ b/MeshLib/MeshGenerators/MeshLayerMapper.cpp @@ -251,13 +251,13 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, GeoLib::Raster const return false; } - const double x0(raster.getOrigin()[0]); - const double y0(raster.getOrigin()[1]); - const double delta(raster.getRasterPixelSize()); - const double no_data(raster.getNoDataValue()); + GeoLib::RasterHeader const& header (raster.getHeader()); + const double x0(header.origin[0]); + const double y0(header.origin[1]); + const double delta(header.cell_size); - 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> xDim(x0, x0 + header.n_cols * delta); // extension in x-dimension + const std::pair<double, double> yDim(y0, y0 + header.n_rows * delta); // extension in y-dimension const std::size_t nNodes (new_mesh.getNNodes()); const std::vector<MeshLib::Node*> &nodes = new_mesh.getNodes(); @@ -271,7 +271,7 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, GeoLib::Raster const } double elevation (raster.interpolateValueAtPoint(*nodes[i])); - if (std::abs(elevation - no_data) < std::numeric_limits<double>::epsilon()) + if (std::abs(elevation - header.no_data) < std::numeric_limits<double>::epsilon()) elevation = noDataReplacementValue; nodes[i]->updateCoordinates((*nodes[i])[0], (*nodes[i])[1], elevation); }