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()

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

Definition at line 21 of file RasterDataToMesh.cpp.

22{
23 if (mesh.getDimension() > 2)
24 {
25 ERR("This functionality is currently only available for 2D meshes.");
26 return false;
27 }
28 return true;
29}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45

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

Referenced by projectToElements(), and projectToNodes().

◆ evaluatePixel()

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

Definition at line 31 of file RasterDataToMesh.cpp.

33{
34 if (std::abs(value - no_data) < std::numeric_limits<double>::epsilon())
35 {
36 return replacement;
37 }
38 return value;
39}

◆ projectToElements()

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

Definition at line 66 of file RasterDataToMesh.cpp.

69{
70 if (!checkMesh(mesh))
71 {
72 return false;
73 }
74
75 auto& elems = mesh.getElements();
76 auto& props = mesh.getProperties();
77 std::string const name =
78 BaseLib::getUniqueName(props.getPropertyVectorNames(), array_name);
79 auto vec = props.createNewPropertyVector<double>(
81 double const no_data = raster.getHeader().no_data;
82 std::transform(elems.cbegin(), elems.cend(), std::back_inserter(*vec),
83 [&](auto const elem)
84 {
85 auto node = getCenterOfGravity(*elem);
86 return evaluatePixel(raster.getValueAtPoint(node),
87 no_data, default_replacement);
88 });
89 return true;
90}
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
Properties & getProperties()
Definition Mesh.h:134
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 41 of file RasterDataToMesh.cpp.

44{
45 if (!checkMesh(mesh))
46 {
47 return false;
48 }
49
50 auto& nodes = mesh.getNodes();
51 auto& props = mesh.getProperties();
52 std::string const name =
53 BaseLib::getUniqueName(props.getPropertyVectorNames(), array_name);
54 auto vec = props.createNewPropertyVector<double>(
56 double const no_data = raster.getHeader().no_data;
57 std::transform(nodes.cbegin(), nodes.cend(), std::back_inserter(*vec),
58 [&](auto const node)
59 {
60 return evaluatePixel(raster.getValueAtPoint(*node),
61 no_data, default_replacement);
62 });
63 return true;
64}
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106

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().