BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Transform3D.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Vector/Transform3D.h
6 //! @brief Declares class Transform3D.
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_BASE_VECTOR_TRANSFORM3D_H
16 #define BORNAGAIN_BASE_VECTOR_TRANSFORM3D_H
17 
18 #include "Base/Vector/EigenCore.h"
19 #include "Base/Vector/Vectors3D.h"
20 
21 #include <vector>
22 
23 //! Vector transformations in three dimensions.
24 //! @ingroup tools_internal
25 
26 class Transform3D {
27 public:
29 
30  //! Constructs unit transformation
31  Transform3D();
32 
33 #ifndef SWIG
34  //! Constructor from matrix (no checks if this is an element of SO(3)!)
35  Transform3D(const Eigen::Matrix3d& matrix);
36 #endif
37 
38  //! Destructor
40 
41  //! Clones the transformation
42  Transform3D* clone() const;
43 
44  //! Creates rotation around x-axis
45  static Transform3D createRotateX(double phi);
46 
47  //! Creates rotation around y-axis
48  static Transform3D createRotateY(double phi);
49 
50  //! Creates rotation around z-axis
51  static Transform3D createRotateZ(double phi);
52 
53  //! Creates rotation defined by Euler angles
54  static Transform3D createRotateEuler(double alpha, double beta, double gamma);
55 
56  //! Calculates the Euler angles corresponding to the rotation
57  void calculateEulerAngles(double* p_alpha, double* p_beta, double* p_gamma) const;
58 
59  //! Calculates the rotation angle for a rotation around the x-axis alone
60  //! Only meaningfull if the actual rotation is around the x-axis
61  double calculateRotateXAngle() const;
62 
63  //! Calculates the rotation angle for a rotation around the y-axis alone
64  //! Only meaningfull if the actual rotation is around the y-axis
65  double calculateRotateYAngle() const;
66 
67  //! Calculates the rotation angle for a rotation around the z-axis alone
68  //! Only meaningfull if the actual rotation is around the z-axis
69  double calculateRotateZAngle() const;
70 
71  //! Returns the inverse transformation.
72  Transform3D getInverse() const;
73 
74  //! Return transformed vector _v_.
75  template <class ivector_t> ivector_t transformed(const ivector_t& v) const;
76 
77  //! Return transformed vector _v_.
78  template <class ivector_t> ivector_t transformedInverse(const ivector_t& v) const;
79 
80  //! Composes two transformations
81  Transform3D operator*(const Transform3D& other) const;
82 
83  //! Provides equality operator
84  bool operator==(const Transform3D& other) const;
85 
86  //! Retrieve the rotation type (general, around x, y or z-axis)
88 
89  //! Determine if the transformation is trivial (identity)
90  bool isIdentity() const;
91 
92  friend std::ostream& operator<<(std::ostream& ostr, const Transform3D& m)
93  {
94  m.print(ostr);
95  return ostr;
96  }
97 
98  void print(std::ostream& ostr) const;
99 
100  bool isXRotation() const;
101  bool isYRotation() const;
102  bool isZRotation() const;
103 
104 private:
105 #ifndef SWIG
106  Eigen::Matrix3d m_matrix;
107  Eigen::Matrix3d m_inverse_matrix;
108 #endif
109 };
110 
111 #endif // BORNAGAIN_BASE_VECTOR_TRANSFORM3D_H
Include to deal with Eigen alignment centrally.
Defines basic vectors in Z^3, R^3, C^3.
Three-dimensional vector template, for use with integer, double, or complex components.
Definition: BasicVector3D.h:27
Vector transformations in three dimensions.
Definition: Transform3D.h:26
static Transform3D createRotateX(double phi)
Creates rotation around x-axis.
Definition: Transform3D.cpp:29
bool isIdentity() const
Determine if the transformation is trivial (identity)
bool isYRotation() const
Transform3D()
Constructs unit transformation.
Definition: Transform3D.cpp:18
bool isXRotation() const
double calculateRotateYAngle() const
Calculates the rotation angle for a rotation around the y-axis alone Only meaningfull if the actual r...
Definition: Transform3D.cpp:94
ivector_t transformed(const ivector_t &v) const
Return transformed vector v.
void calculateEulerAngles(double *p_alpha, double *p_beta, double *p_gamma) const
Calculates the Euler angles corresponding to the rotation.
Definition: Transform3D.cpp:76
static Transform3D createRotateEuler(double alpha, double beta, double gamma)
Creates rotation defined by Euler angles.
Definition: Transform3D.cpp:68
bool operator==(const Transform3D &other) const
Provides equality operator.
Transform3D * clone() const
Clones the transformation.
~Transform3D()
Destructor.
Definition: Transform3D.h:39
Transform3D getInverse() const
Returns the inverse transformation.
void print(std::ostream &ostr) const
Eigen::Matrix3d m_inverse_matrix
Definition: Transform3D.h:107
bool isZRotation() const
ERotationType getRotationType() const
Retrieve the rotation type (general, around x, y or z-axis)
ivector_t transformedInverse(const ivector_t &v) const
Return transformed vector v.
Eigen::Matrix3d m_matrix
Definition: Transform3D.h:106
double calculateRotateXAngle() const
Calculates the rotation angle for a rotation around the x-axis alone Only meaningfull if the actual r...
Definition: Transform3D.cpp:89
Transform3D operator*(const Transform3D &other) const
Composes two transformations.
static Transform3D createRotateZ(double phi)
Creates rotation around z-axis.
Definition: Transform3D.cpp:55
double calculateRotateZAngle() const
Calculates the rotation angle for a rotation around the z-axis alone Only meaningfull if the actual r...
Definition: Transform3D.cpp:99
friend std::ostream & operator<<(std::ostream &ostr, const Transform3D &m)
Definition: Transform3D.h:92
static Transform3D createRotateY(double phi)
Creates rotation around y-axis.
Definition: Transform3D.cpp:42