OGS
MeshToolsLib::RasterDataToMesh Namespace Reference

Detailed Description

Adding pixel values from a raster onto nodes or cells of a mesh.

Functions

static bool checkMesh (MeshLib::Mesh const &mesh)
static double evaluatePixel (double const value, double const no_data, double const replacement)
bool projectToNodes (MeshLib::Mesh &mesh, GeoLib::Raster const &raster, double const default_replacement, std::string const &array_name)
bool projectToElements (MeshLib::Mesh &mesh, GeoLib::Raster const &raster, double const default_replacement, std::string const &array_name)

Function Documentation

◆ checkMesh()

bool MeshToolsLib::RasterDataToMesh::checkMesh ( MeshLib::Mesh const & mesh)
static

Definition at line 14 of file RasterDataToMesh.cpp.

15{
16 if (mesh.getDimension() > 2)
17 {
18 ERR("This functionality is currently only available for 2D meshes.");
19 return false;
20 }
21 return true;
22}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40

References ERR(), and MeshLib::Mesh::getDimension().

Referenced by projectToElements(), and projectToNodes().

◆ evaluatePixel()

double MeshToolsLib::RasterDataToMesh::evaluatePixel ( double const value,
double const no_data,
double const replacement )
static

Definition at line 24 of file RasterDataToMesh.cpp.

26{
27 if (std::abs(value - no_data) < std::numeric_limits<double>::epsilon())
28 {
29 return replacement;
30 }
31 return value;
32}

◆ projectToElements()

bool MeshToolsLib::RasterDataToMesh::projectToElements ( MeshLib::Mesh & mesh,
GeoLib::Raster const & raster,
double const default_replacement,
std::string const & array_name )

Definition at line 59 of file RasterDataToMesh.cpp.

62{
63 if (!checkMesh(mesh))
64 {
65 return false;
66 }
67
68 auto& elems = mesh.getElements();
69 auto& props = mesh.getProperties();
70 std::string const name =
71 BaseLib::getUniqueName(props.getPropertyVectorNames(), array_name);
72 auto vec = props.createNewPropertyVector<double>(
74 double const no_data = raster.getHeader().no_data;
75 std::transform(elems.cbegin(), elems.cend(), std::back_inserter(*vec),
76 [&](auto const elem)
77 {
78 auto node = getCenterOfGravity(*elem);
79 return evaluatePixel(raster.getValueAtPoint(node),
80 no_data, default_replacement);
81 });
82 return true;
83}
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:100
Properties & getProperties()
Definition Mesh.h:125
std::string getUniqueName(std::vector< std::string > const &existing_names, std::string const &input_name)
Append '-' and a number such that the name is unique.
static bool checkMesh(MeshLib::Mesh const &mesh)

References MeshLib::Cell, checkMesh(), MeshLib::Mesh::getElements(), GeoLib::Raster::getHeader(), MeshLib::Mesh::getProperties(), BaseLib::getUniqueName(), and GeoLib::RasterHeader::no_data.

Referenced by main(), and MeshView::openRasterDataToMeshDialog().

◆ projectToNodes()

bool MeshToolsLib::RasterDataToMesh::projectToNodes ( MeshLib::Mesh & mesh,
GeoLib::Raster const & raster,
double const default_replacement,
std::string const & array_name )

Definition at line 34 of file RasterDataToMesh.cpp.

37{
38 if (!checkMesh(mesh))
39 {
40 return false;
41 }
42
43 auto& nodes = mesh.getNodes();
44 auto& props = mesh.getProperties();
45 std::string const name =
46 BaseLib::getUniqueName(props.getPropertyVectorNames(), array_name);
47 auto vec = props.createNewPropertyVector<double>(
49 double const no_data = raster.getHeader().no_data;
50 std::transform(nodes.cbegin(), nodes.cend(), std::back_inserter(*vec),
51 [&](auto const node)
52 {
53 return evaluatePixel(raster.getValueAtPoint(*node),
54 no_data, default_replacement);
55 });
56 return true;
57}
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:97

References checkMesh(), GeoLib::Raster::getHeader(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getProperties(), BaseLib::getUniqueName(), GeoLib::RasterHeader::no_data, and MeshLib::Node.

Referenced by main(), and MeshView::openRasterDataToMeshDialog().