BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Rotations.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Scattering/Rotations.h
6 //! @brief Defines IRotation classes.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_SAMPLE_SCATTERING_ROTATIONS_H
16 #define BORNAGAIN_SAMPLE_SCATTERING_ROTATIONS_H
17 
18 #include "Base/Types/ICloneable.h"
19 #include "Param/Node/INode.h"
20 #include <heinz/Vectors3D.h>
21 
22 class RotMatrix;
23 
24 #ifndef USER_API
25 
26 //! Abstract base class for rotations.
27 //! @ingroup samples
28 
29 class IRotation : public ICloneable, public INode {
30 public:
31  static IRotation* createRotation(const RotMatrix& transform);
32 
33  IRotation(const std::vector<double>& PValues);
34 
35  IRotation* clone() const override = 0;
36 
37  //! Returns a new IRotation object that is the current object's inverse
38  virtual IRotation* createInverse() const = 0;
39 
40  //! Returns transformation.
41  virtual RotMatrix rotMatrix() const = 0;
42 
43  R3 transformed(const R3& v) const;
44 
45  //! Returns true if rotation matrix is identity matrix (no rotations)
46  virtual bool isIdentity() const;
47 
48  bool zInvariant() const;
49 };
50 
51 IRotation* createProduct(const IRotation& left, const IRotation& right);
52 
53 #endif // USER_API
54 
55 //! The identity rotation, which leaves everything in place.
56 
57 class IdentityRotation : public IRotation // TODO RECONSIDER: merge with class IRotation
58 {
59 public:
61 
62  IdentityRotation* clone() const override { return new IdentityRotation(); }
63  std::string className() const final { return "IdentityRotation"; }
64  // const auto tooltip = "Identity rotation, does nothing";
65  IdentityRotation* createInverse() const override { return new IdentityRotation(); }
66 
67  RotMatrix rotMatrix() const override;
68 
69  bool isIdentity() const override { return true; }
70 };
71 
72 //! A rotation about the x axis.
73 
74 class RotationX : public IRotation {
75 public:
76  RotationX(std::vector<double> P);
77  RotationX(double angle);
78 
79  RotationX* clone() const override { return new RotationX(m_angle); }
80  std::string className() const final { return "RotationX"; }
81  // const auto tooltip = "class_tooltip";
82  std::vector<ParaMeta> parDefs() const final
83  {
84  return {{"Angle", "rad", "Angle around x axis", -INF, +INF, 0}};
85  }
86  RotationX* createInverse() const override { return new RotationX(-m_angle); }
87 
88  double angle() const { return m_angle; }
89 
90  RotMatrix rotMatrix() const override;
91 
92 protected:
93  const double& m_angle;
94 };
95 
96 //! A rotation about the y axis.
97 
98 class RotationY : public IRotation {
99 public:
100  RotationY(std::vector<double> P);
101  RotationY(double angle);
102 
103  RotationY* clone() const override { return new RotationY(m_angle); }
104  std::string className() const final { return "RotationY"; }
105  // const auto tooltip = "class_tooltip";
106  std::vector<ParaMeta> parDefs() const final
107  {
108  return {{"Angle", "rad", "Angle around y axis", -INF, +INF, 0}};
109  }
110  RotationY* createInverse() const override { return new RotationY(-m_angle); }
111 
112  double angle() const { return m_angle; }
113 
114  RotMatrix rotMatrix() const override;
115 
116 protected:
117  const double& m_angle;
118 };
119 
120 //! A rotation about the z axis.
121 
122 class RotationZ : public IRotation {
123 public:
124  RotationZ(std::vector<double> P);
125  RotationZ(double angle);
126 
127  RotationZ* clone() const override { return new RotationZ(m_angle); }
128  std::string className() const final { return "RotationZ"; }
129  // const auto tooltip = "class_tooltip";
130  std::vector<ParaMeta> parDefs() const final
131  {
132  return {{"Angle", "rad", "Angle around z axis", -INF, +INF, 0}};
133  }
134  RotationZ* createInverse() const override { return new RotationZ(-m_angle); }
135 
136  double angle() const { return m_angle; }
137 
138  RotMatrix rotMatrix() const override;
139 
140 protected:
141  const double& m_angle;
142 };
143 
144 //! A sequence of rotations about the z-x'-z'' axes.
145 
146 class RotationEuler : public IRotation {
147 public:
148  RotationEuler(std::vector<double> P);
149  RotationEuler(double alpha, double beta, double gamma);
150 
151  RotationEuler* clone() const override { return new RotationEuler(m_alpha, m_beta, m_gamma); }
152  std::string className() const final { return "RotationEuler"; }
153  // const auto tooltip = "Sequence of three rotations around z-x'-z''";
154  std::vector<ParaMeta> parDefs() const final
155  {
156  return {{"Alpha", "rad", "First Euler angle, rotation around z axis", -INF, +INF, 0},
157  {"Beta", "rad", "Second Euler angle, rotation around x' axis", -INF, +INF, 0},
158  {"Gamma", "rad", "Third Euler angle, rotation around z'' axis", -INF, +INF, 0}};
159  }
160  IRotation* createInverse() const override;
161 
162  double alpha() const { return m_alpha; }
163  double beta() const { return m_beta; }
164  double gamma() const { return m_gamma; }
165 
166  RotMatrix rotMatrix() const override;
167 
168 protected:
170 };
171 
172 #endif // BORNAGAIN_SAMPLE_SCATTERING_ROTATIONS_H
Defines and implements the standard mix-in ICloneable.
Defines interface INode.
const double INF
Definition: INode.h:26
IRotation * createProduct(const IRotation &left, const IRotation &right)
Returns concatenated rotation (first right, then left).
Definition: Rotations.cpp:59
Interface for polymorphic classes that should not be copied, except by explicit cloning.
Definition: ICloneable.h:23
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:40
Abstract base class for rotations.
Definition: Rotations.h:29
IRotation * clone() const override=0
IRotation(const std::vector< double > &PValues)
Definition: Rotations.cpp:23
virtual RotMatrix rotMatrix() const =0
Returns transformation.
virtual IRotation * createInverse() const =0
Returns a new IRotation object that is the current object's inverse.
R3 transformed(const R3 &v) const
Definition: Rotations.cpp:42
virtual bool isIdentity() const
Returns true if rotation matrix is identity matrix (no rotations)
Definition: Rotations.cpp:47
static IRotation * createRotation(const RotMatrix &transform)
Definition: Rotations.cpp:28
bool zInvariant() const
Definition: Rotations.cpp:52
The identity rotation, which leaves everything in place.
Definition: Rotations.h:58
IdentityRotation * clone() const override
Definition: Rotations.h:62
RotMatrix rotMatrix() const override
Returns transformation.
Definition: Rotations.cpp:76
IdentityRotation * createInverse() const override
Returns a new IRotation object that is the current object's inverse.
Definition: Rotations.h:65
std::string className() const final
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Definition: Rotations.h:63
bool isIdentity() const override
Returns true if rotation matrix is identity matrix (no rotations)
Definition: Rotations.h:69
Rotation matrix in three dimensions. Represents group SO(3). Internal parameterization based on quate...
Definition: RotMatrix.h:25
A sequence of rotations about the z-x'-z'' axes.
Definition: Rotations.h:146
double m_beta
Definition: Rotations.h:169
double beta() const
Definition: Rotations.h:163
RotationEuler(std::vector< double > P)
Definition: Rotations.cpp:153
std::string className() const final
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Definition: Rotations.h:152
RotationEuler * clone() const override
Definition: Rotations.h:151
double m_gamma
Definition: Rotations.h:169
IRotation * createInverse() const override
Returns a new IRotation object that is the current object's inverse.
Definition: Rotations.cpp:167
double m_alpha
Definition: Rotations.h:169
double gamma() const
Definition: Rotations.h:164
std::vector< ParaMeta > parDefs() const final
Returns the parameter definitions, to be hard-coded in each leaf class.
Definition: Rotations.h:154
RotMatrix rotMatrix() const override
Returns transformation.
Definition: Rotations.cpp:173
double alpha() const
Definition: Rotations.h:162
A rotation about the x axis.
Definition: Rotations.h:74
double angle() const
Definition: Rotations.h:88
std::string className() const final
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Definition: Rotations.h:80
std::vector< ParaMeta > parDefs() const final
Returns the parameter definitions, to be hard-coded in each leaf class.
Definition: Rotations.h:82
RotationX(std::vector< double > P)
Constructor of rotation around x-axis.
Definition: Rotations.cpp:86
RotMatrix rotMatrix() const override
Returns transformation.
Definition: Rotations.cpp:98
RotationX * clone() const override
Definition: Rotations.h:79
const double & m_angle
Definition: Rotations.h:93
RotationX * createInverse() const override
Returns a new IRotation object that is the current object's inverse.
Definition: Rotations.h:86
A rotation about the y axis.
Definition: Rotations.h:98
std::string className() const final
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Definition: Rotations.h:104
RotationY(std::vector< double > P)
Constructor of rotation around y-axis.
Definition: Rotations.cpp:108
std::vector< ParaMeta > parDefs() const final
Returns the parameter definitions, to be hard-coded in each leaf class.
Definition: Rotations.h:106
RotationY * clone() const override
Definition: Rotations.h:103
double angle() const
Definition: Rotations.h:112
RotMatrix rotMatrix() const override
Returns transformation.
Definition: Rotations.cpp:120
const double & m_angle
Definition: Rotations.h:117
RotationY * createInverse() const override
Returns a new IRotation object that is the current object's inverse.
Definition: Rotations.h:110
A rotation about the z axis.
Definition: Rotations.h:122
std::vector< ParaMeta > parDefs() const final
Returns the parameter definitions, to be hard-coded in each leaf class.
Definition: Rotations.h:130
std::string className() const final
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Definition: Rotations.h:128
const double & m_angle
Definition: Rotations.h:141
RotationZ(std::vector< double > P)
Constructor of rotation around z-axis.
Definition: Rotations.cpp:132
RotMatrix rotMatrix() const override
Returns transformation.
Definition: Rotations.cpp:144
RotationZ * createInverse() const override
Returns a new IRotation object that is the current object's inverse.
Definition: Rotations.h:134
double angle() const
Definition: Rotations.h:136
RotationZ * clone() const override
Definition: Rotations.h:127