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