34 #include "MeshKernel/Definitions.hpp"
35 #include "MeshKernel/Exceptions.hpp"
36 #include "MeshKernel/Mesh.hpp"
37 #include "MeshKernel/Point.hpp"
38 #include "MeshKernel/UndoActions/NodeTranslationAction.hpp"
39 #include "MeshKernel/Vector.hpp"
45 template <
typename Function>
49 template <
typename Function>
53 template <
typename Function>
69 return Projection::cartesian;
75 m_translation = {0.0, 0.0};
81 m_translation = trans;
93 return Translation(m_translation + trans.m_translation);
99 return pnt + m_translation;
105 return vec + m_translation;
110 Vector m_translation{0.0, 0.0};
129 return Projection::cartesian;
146 m_cosTheta = std::cos(m_theta * constants::conversion::degToRad);
147 m_sinTheta = std::sin(m_theta * constants::conversion::degToRad);
159 return Rotation(m_theta + rot.m_theta);
165 Point result({m_cosTheta * pnt.
x - m_sinTheta * pnt.
y,
166 m_sinTheta * pnt.
x + m_cosTheta * pnt.
y});
173 Vector result({m_cosTheta * vec.
x() - m_sinTheta * vec.
y(),
174 m_sinTheta * vec.
x() + m_cosTheta * vec.
y()});
180 double m_theta = 0.0;
183 double m_cosTheta = 1.0;
186 double m_sinTheta = 0.0;
199 return Projection::cartesian;
214 m_rotation = rot.
compose(m_rotation);
223 m_translation = trans.
compose(m_translation);
235 return m_translation;
241 Point result = m_rotation(pnt);
242 result = m_translation(result);
249 Vector result = m_rotation(vec);
250 result = m_translation(result);
267 template <TransformationFunction Transformation>
268 [[nodiscard]]
static std::unique_ptr<UndoAction>
Compute(
Mesh& mesh, Transformation transformation)
270 if (mesh.
m_projection != transformation.TransformationProjection())
272 throw MeshKernelError(
"Incorrect mesh coordinate system, expecting '{}', found '{}'",
276 std::unique_ptr<NodeTranslationAction> undoAction = NodeTranslationAction::Create(mesh);
277 std::vector<Point> nodes(mesh.
Nodes());
279 #pragma omp parallel for
280 for (
int i = 0; i < static_cast<int>(mesh.
GetNumNodes()); ++i)
282 if (nodes[i].IsValid())
284 nodes[i] = transformation(nodes[i]);
Projection
Enumerator describing the supported projections.
Definition: Definitions.hpp:41
const std::string & ProjectionToString(Projection projection)
Get the string representation of the Projection enumeration values.
const Vector & vector() const
Get the current defined translation vector.
Definition: MeshTransformation.hpp:85
Translation()=default
Default constructor, default is no translation.
const std::vector< Point > & Nodes() const
Get vector of all nodes.
Definition: Mesh.hpp:536
void compose(const Rotation &rot)
Compose rotation and transformation object.
Definition: MeshTransformation.hpp:212
Projection TransformationProjection() const
Get the projection required for the transformation.
Definition: MeshTransformation.hpp:197
virtual void Administrate(CompoundUndoAction *undoAction=nullptr)
Perform complete administration.
Rotation()=default
Default constructor, default is theta = 0.
auto GetNumNodes() const
Get the number of valid nodes.
Definition: Mesh.hpp:145
Point operator()(const Point &pnt) const
Apply the transformation to a point in Cartesian coordinate system.
Definition: MeshTransformation.hpp:239
Projection TransformationProjection() const
Get the projection required for the rotation.
Definition: MeshTransformation.hpp:127
Apply a translation transformation to a point or a vector.
Definition: MeshTransformation.hpp:57
A struct describing a point in a two-dimensional space.
Definition: Point.hpp:40
Translation(const Vector &trans)
Construct with user defined translation.
Definition: MeshTransformation.hpp:64
double x
X-coordinate.
Definition: Point.hpp:43
const Translation & translation() const
Get the current translation.
Definition: MeshTransformation.hpp:233
A class defining a vector.
Definition: Vector.hpp:38
const Rotation & rotation() const
Get the current rotation.
Definition: MeshTransformation.hpp:227
void identity()
Reset translation to identity translation (i.e. no translation)
Definition: MeshTransformation.hpp:73
concept TransformationFunction
To ensure the MeshTransformation Compute template parameter has a valid interface.
Definition: MeshTransformation.hpp:54
const Point & Node(const UInt index) const
Get the node at the position.
Definition: Mesh.hpp:541
double y
Y-coordinate.
Definition: Point.hpp:44
void SetNodes(const std::vector< Point > &newValues)
Set all nodes to a new set of values.
Definition: Mesh.hpp:551
concept HasTransformationFunction
Ensure any instantiation of the MeshTransformation Compute function is with the correct operation.
Definition: MeshTransformation.hpp:46
Projection m_projection
The projection used.
Definition: Mesh.hpp:489
Point operator()(const Point &pnt) const
Apply the rotation to a point in Cartesian coordinate system.
Definition: MeshTransformation.hpp:163
Translation compose(const Translation &trans) const
Compose two translation objects.
Definition: MeshTransformation.hpp:91
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
bool IsValid(const double missingValue=constants::missing::doubleValue) const
Determines if one of the point coordinates equals to missingValue.
Definition: Point.hpp:116
double y() const
Gets the y coordinate of the vector.
Definition: Vector.hpp:66
void identity()
Reset rotation to identity translation (i.e. no rotation, theta = 0)
Definition: MeshTransformation.hpp:133
concept HasTransformationProjection
Ensure any instantiation of the MeshTransformation Compute function is able to determine the projecti...
Definition: MeshTransformation.hpp:50
double angle() const
Get the current defined rotation angle in degrees.
Definition: MeshTransformation.hpp:151
Projection TransformationProjection() const
Get the projection required for the translation.
Definition: MeshTransformation.hpp:67
void reset(const Vector &trans)
Reset the translation to a new translation quantity.
Definition: MeshTransformation.hpp:79
void identity()
Reset transformation to identity transformation (i.e. no transformation)
Definition: MeshTransformation.hpp:203
double x() const
Gets the x coordinate of the vector.
Definition: Vector.hpp:52
Rotation compose(const Rotation &rot) const
Compose two rotation objects.
Definition: MeshTransformation.hpp:157
Rotation(const double angle)
Construct with user defined rotation angle, in degrees.
Definition: MeshTransformation.hpp:121
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
void reset(const double angle)
Reset the rotation to a new rotation angle.
Definition: MeshTransformation.hpp:143
Vector operator()(const Vector &vec) const
Apply the rotation to a vector in Cartesian coordinate system.
Definition: MeshTransformation.hpp:171
Vector operator()(const Vector &vec) const
Apply the translation to a vector in Cartesian coordinate system.
Definition: MeshTransformation.hpp:103
RigidBodyTransformation()=default
Default constructor, default is no transformation.
Vector operator()(const Vector &vec) const
Apply the transformation to a vector in Cartesian coordinate system.
Definition: MeshTransformation.hpp:247
Apply a rotation transformation to a point or a vector.
Definition: MeshTransformation.hpp:114
void compose(const Translation &trans)
Compose translation and transformation object.
Definition: MeshTransformation.hpp:221
A class describing an unstructured mesh. This class contains the shared functionality between 1d or 2...
Definition: Mesh.hpp:98
A composition of translation and rotation transformations.
Definition: MeshTransformation.hpp:190
Point operator()(const Point &pnt) const
Apply the translation to a point in Cartesian coordinate system.
Definition: MeshTransformation.hpp:97