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;
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]);
268 [[nodiscard]]
static std::unique_ptr<UndoAction>
Compute(
Mesh& mesh, Transformation transformation) {
…}
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
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
bool IsValid(const double missingValue=constants::missing::doubleValue) const
Determines if one of the point coordinates equals to missingValue.
Definition Point.hpp:116
double x
X-coordinate.
Definition Point.hpp:43
double y
Y-coordinate.
Definition Point.hpp:44
A composition of translation and rotation transformations.
Definition MeshTransformation.hpp:191
Point operator()(const Point &pnt) const
Apply the transformation to a point in Cartesian coordinate system.
Definition MeshTransformation.hpp:239
RigidBodyTransformation()=default
Default constructor, default is no transformation.
void identity()
Reset transformation to identity transformation (i.e. no transformation)
Definition MeshTransformation.hpp:203
void compose(const Rotation &rot)
Compose rotation and transformation object.
Definition MeshTransformation.hpp:212
Vector operator()(const Vector &vec) const
Apply the transformation to a vector in Cartesian coordinate system.
Definition MeshTransformation.hpp:247
Projection TransformationProjection() const
Get the projection required for the transformation.
Definition MeshTransformation.hpp:197
void compose(const Translation &trans)
Compose translation and transformation object.
Definition MeshTransformation.hpp:221
const Translation & translation() const
Get the current translation.
Definition MeshTransformation.hpp:233
const Rotation & rotation() const
Get the current rotation.
Definition MeshTransformation.hpp:227
Apply a rotation transformation to a point or a vector.
Definition MeshTransformation.hpp:115
Point operator()(const Point &pnt) const
Apply the rotation to a point in Cartesian coordinate system.
Definition MeshTransformation.hpp:163
void reset(const double angle)
Reset the rotation to a new rotation angle.
Definition MeshTransformation.hpp:143
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
double angle() const
Get the current defined rotation angle in degrees.
Definition MeshTransformation.hpp:151
void identity()
Reset rotation to identity translation (i.e. no rotation, theta = 0)
Definition MeshTransformation.hpp:133
Projection TransformationProjection() const
Get the projection required for the rotation.
Definition MeshTransformation.hpp:127
Rotation()=default
Default constructor, default is theta = 0.
Vector operator()(const Vector &vec) const
Apply the rotation to a vector in Cartesian coordinate system.
Definition MeshTransformation.hpp:171
Apply a translation transformation to a point or a vector.
Definition MeshTransformation.hpp:58
Point operator()(const Point &pnt) const
Apply the translation to a point in Cartesian coordinate system.
Definition MeshTransformation.hpp:97
Translation compose(const Translation &trans) const
Compose two translation objects.
Definition MeshTransformation.hpp:91
Vector operator()(const Vector &vec) const
Apply the translation to a vector in Cartesian coordinate system.
Definition MeshTransformation.hpp:103
Translation()=default
Default constructor, default is no translation.
const Vector & vector() const
Get the current defined translation vector.
Definition MeshTransformation.hpp:85
Translation(const Vector &trans)
Construct with user defined translation.
Definition MeshTransformation.hpp:64
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 translation to identity translation (i.e. no translation)
Definition MeshTransformation.hpp:73
A class defining a vector.
Definition Vector.hpp:39
double y() const
Gets the y coordinate of the vector.
Definition Vector.hpp:66
double x() const
Gets the x coordinate of the vector.
Definition Vector.hpp:52
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
Projection
Enumerator describing the supported projections.
Definition Definitions.hpp:43
const std::string & ProjectionToString(Projection projection)
Get the string representation of the Projection enumeration values.