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>
52 concept
ConversionFunctor = HasTransformationOperation<Operation> && HasConversionProjection<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)));
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]);
const std::string & ProjectionToString(Projection projection)
Get the string representation of the Projection enumeration values.
Apply a conversion to nodes of a mesh.
Definition: MeshConversion.hpp:55
const std::vector< Point > & Nodes() const
Get vector of all nodes.
Definition: Mesh.hpp:536
virtual void Administrate(CompoundUndoAction *undoAction=nullptr)
Perform complete administration.
static std::unique_ptr< UndoAction > Compute(Mesh &mesh, const Conversion &conversion)
Apply a conversion to nodes of a mesh.
Definition: MeshConversion.hpp:114
auto GetNumNodes() const
Get the number of valid nodes.
Definition: Mesh.hpp:145
concept ConversionFunctor
Ensure the MeshConversion template parameter has a valid interface.
Definition: MeshConversion.hpp:52
concept HasConversionProjection
Ensure any instantiation of the MeshConversion Compute function is able to determine source and targe...
Definition: MeshConversion.hpp:47
A struct describing a point in a two-dimensional space.
Definition: Point.hpp:40
const Point & Node(const UInt index) const
Get the node at the position.
Definition: Mesh.hpp:541
void SetNodes(const std::vector< Point > &newValues)
Set all nodes to a new set of values.
Definition: Mesh.hpp:551
Projection m_projection
The projection used.
Definition: Mesh.hpp:489
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
concept HasTransformationOperation
Ensure any instantiation of the MeshTransformation Compute function is with the correct operation.
Definition: MeshConversion.hpp:43
bool IsValid(const double missingValue=constants::missing::doubleValue) const
Determines if one of the point coordinates equals to missingValue.
Definition: Point.hpp:116
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
void SetNode(const UInt index, const Point &newValue)
Set a node to a new value, bypassing the undo action.
A class for throwing general MeshKernel exceptions.
Definition: Exceptions.hpp:141
A class describing an unstructured mesh. This class contains the shared functionality between 1d or 2...
Definition: Mesh.hpp:98