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)
static MathLib::Point3d const & evaluationPoint (MeshLib::Node const &node)
 The point at which the raster is sampled for a mesh item.
static MathLib::Point3d evaluationPoint (MeshLib::Element const &element)
template<typename MeshItems>
static bool projectToMeshItems (MeshLib::Mesh &mesh, GeoLib::Raster const &raster, double const default_replacement, std::string const &array_name, MeshLib::MeshItemType const item_type, MeshItems const &mesh_items)
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 17 of file RasterDataToMesh.cpp.

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

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

Referenced by projectToMeshItems().

◆ evaluatePixel()

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

Definition at line 27 of file RasterDataToMesh.cpp.

29{
30 if (std::abs(value - no_data) < std::numeric_limits<double>::epsilon())
31 {
32 return replacement;
33 }
34 return value;
35}

◆ evaluationPoint() [1/2]

MathLib::Point3d MeshToolsLib::RasterDataToMesh::evaluationPoint ( MeshLib::Element const & element)
static

Definition at line 43 of file RasterDataToMesh.cpp.

44{
45 return getCenterOfGravity(element);
46}

◆ evaluationPoint() [2/2]

MathLib::Point3d const & MeshToolsLib::RasterDataToMesh::evaluationPoint ( MeshLib::Node const & node)
static

The point at which the raster is sampled for a mesh item.

Definition at line 38 of file RasterDataToMesh.cpp.

39{
40 return node;
41}

◆ projectToElements()

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

Definition at line 96 of file RasterDataToMesh.cpp.

99{
100 return projectToMeshItems(mesh, raster, default_replacement, array_name,
102}
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:101
static bool projectToMeshItems(MeshLib::Mesh &mesh, GeoLib::Raster const &raster, double const default_replacement, std::string const &array_name, MeshLib::MeshItemType const item_type, MeshItems const &mesh_items)

References MeshLib::Cell, MeshLib::Mesh::getElements(), and projectToMeshItems().

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

◆ projectToMeshItems()

template<typename MeshItems>
bool MeshToolsLib::RasterDataToMesh::projectToMeshItems ( MeshLib::Mesh & mesh,
GeoLib::Raster const & raster,
double const default_replacement,
std::string const & array_name,
MeshLib::MeshItemType const item_type,
MeshItems const & mesh_items )
static

Creates a new property vector of the given item_type on mesh and fills it with the raster values sampled at the evaluation point of each of the mesh_items.

Definition at line 52 of file RasterDataToMesh.cpp.

58{
59 if (!checkMesh(mesh))
60 {
61 return false;
62 }
63
64 auto& props = mesh.getProperties();
65 std::string const name =
66 BaseLib::getUniqueName(props.getPropertyVectorNames(), array_name);
67 auto* const values = props.createNewPropertyVector<double>(
68 name, item_type, mesh_items.size(), 1);
69 if (values == nullptr)
70 {
71 // MeshLib::Properties keys its property vectors by name alone, and the
72 // name above is unique among the existing ones, so this is a broken
73 // invariant rather than malformed input.
74 OGS_FATAL("Could not create the property vector '{:s}'.", name);
75 }
76
77 double const no_data = raster.getHeader().no_data;
78 ranges::transform(mesh_items, values->begin(),
79 [&](auto const item)
80 {
81 return evaluatePixel(
82 raster.getValueAtPoint(evaluationPoint(*item)),
83 no_data, default_replacement);
84 });
85 return true;
86}
#define OGS_FATAL(...)
Definition Error.h:10
Properties & getProperties()
Definition Mesh.h:127
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 checkMesh(), GeoLib::Raster::getHeader(), MeshLib::Mesh::getProperties(), BaseLib::getUniqueName(), GeoLib::RasterHeader::no_data, and OGS_FATAL.

Referenced by projectToElements(), and projectToNodes().

◆ projectToNodes()

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

Definition at line 88 of file RasterDataToMesh.cpp.

91{
92 return projectToMeshItems(mesh, raster, default_replacement, array_name,
94}
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:98

References MeshLib::Mesh::getNodes(), MeshLib::Node, and projectToMeshItems().

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