32#include "MeshKernel/Definitions.hpp"
33#include "MeshKernel/Exceptions.hpp"
34#include "MeshKernel/Mesh.hpp"
35#include "MeshKernel/Point.hpp"
36#include "MeshKernel/UndoActions/MeshConversionAction.hpp"
42 template <
typename Operation>
46 template <
typename Operation>
48 { op.TargetProjection()} -> std::same_as<Projection>; };
51 template <
typename Operation>
59 template <ConversionFunctor Conversion>
60 [[nodiscard]]
static std::unique_ptr<UndoAction>
Compute(
const Mesh& sourceMesh,
Mesh& targetMesh,
const Conversion& conversion)
62 if (sourceMesh.
m_projection != conversion.SourceProjection())
64 throw MeshKernelError(
"Incorrect source mesh coordinate system, expecting '{}', found '{}'",
68 if (targetMesh.
m_projection != conversion.TargetProjection())
70 throw MeshKernelError(
"Incorrect target mesh coordinate system, expecting '{}', found '{}'",
76 throw MeshKernelError(
"Source and target meshes have different numbers of nodes, source = '{}', target = '{}'",
80 std::vector<Point> targetNodes(targetMesh.
Nodes());
81 std::unique_ptr<MeshConversionAction> undoAction = MeshConversionAction::Create(targetMesh);
83#pragma omp parallel for
84 for (
int i = 0; i < static_cast<int>(sourceMesh.
GetNumNodes()); ++i)
88 targetNodes[i] = conversion(sourceMesh.
Node(i));
92 targetNodes[i] = sourceMesh.
Node(i);
98 targetMesh.
SetNode(i, conversion(sourceMesh.
Node(i)));
60 [[nodiscard]]
static std::unique_ptr<UndoAction>
Compute(
const Mesh& sourceMesh,
Mesh& targetMesh,
const Conversion& conversion) {
…}
113 template <ConversionFunctor Conversion>
114 [[nodiscard]]
static std::unique_ptr<UndoAction>
Compute(
Mesh& mesh,
const Conversion& conversion)
118 throw MeshKernelError(
"Incorrect mesh coordinate system, expecting '{}', found '{}'",
122 std::vector<Point> nodes(mesh.
Nodes());
123 std::unique_ptr<MeshConversionAction> undoAction = MeshConversionAction::Create(mesh);
125#pragma omp parallel for
126 for (
int i = 0; i < static_cast<int>(mesh.
GetNumNodes()); ++i)
128 if (nodes[i].IsValid())
130 nodes[i] = conversion(nodes[i]);
114 [[nodiscard]]
static std::unique_ptr<UndoAction>
Compute(
Mesh& mesh,
const Conversion& conversion) {
…}
Apply a conversion to nodes of a mesh.
Definition MeshConversion.hpp:56
static std::unique_ptr< UndoAction > Compute(const Mesh &sourceMesh, Mesh &targetMesh, const Conversion &conversion)
Apply a conversion to nodes of a mesh.
Definition MeshConversion.hpp:60
static std::unique_ptr< UndoAction > Compute(Mesh &mesh, const Conversion &conversion)
Apply a conversion to nodes of a mesh.
Definition MeshConversion.hpp:114
A class describing an unstructured mesh. This class contains the shared functionality between 1d or 2...
Definition Mesh.hpp:99
Projection m_projection
The projection used.
Definition Mesh.hpp:477
void SetNode(const UInt index, const Point &newValue)
Set a node to a new value, bypassing the undo action.
virtual void Administrate(CompoundUndoAction *undoAction=nullptr)
Perform complete administration.
const Point & Node(const UInt index) const
Get the node at the position.
Definition Mesh.hpp:523
void SetNodes(const std::vector< Point > &newValues)
Set all nodes to a new set of values.
Definition Mesh.hpp:533
const std::vector< Point > & Nodes() const
Get vector of all nodes.
Definition Mesh.hpp:518
auto GetNumNodes() const
Get the number of valid nodes.
Definition Mesh.hpp:145
A class for throwing general MeshKernel exceptions.
Definition Exceptions.hpp:142
bool IsValid(const double missingValue=constants::missing::doubleValue) const
Determines if one of the point coordinates equals to missingValue.
Definition Point.hpp:116
Ensure the MeshConversion template parameter has a valid interface.
Definition MeshConversion.hpp:52
Ensure any instantiation of the MeshConversion Compute function is able to determine source and targe...
Definition MeshConversion.hpp:47
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
const std::string & ProjectionToString(Projection projection)
Get the string representation of the Projection enumeration values.