unsupported/Eigen/src/EulerAngles/EulerAngles.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2015 Tal Hadad <tal_hd@hotmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_EULERANGLESCLASS_H // TODO: Fix previous "EIGEN_EULERANGLES_H" definition?
11 #define EIGEN_EULERANGLESCLASS_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
102 template <typename Scalar_, class _System>
103 class EulerAngles : public RotationBase<EulerAngles<Scalar_, _System>, 3> {
104  public:
106 
108  typedef Scalar_ Scalar;
110 
112  typedef _System System;
113 
121  const Vector3& u = Vector3::Unit(System::AlphaAxisAbs - 1);
122  return System::IsAlphaOpposite ? -u : u;
123  }
124 
127  const Vector3& u = Vector3::Unit(System::BetaAxisAbs - 1);
128  return System::IsBetaOpposite ? -u : u;
129  }
130 
133  const Vector3& u = Vector3::Unit(System::GammaAxisAbs - 1);
134  return System::IsGammaOpposite ? -u : u;
135  }
136 
137  private:
139 
140  public:
145 
146  // TODO: Test this constructor
148  explicit EulerAngles(const Scalar* data) : m_angles(data) {}
149 
162  template <typename Derived>
163  explicit EulerAngles(const MatrixBase<Derived>& other) {
164  *this = other;
165  }
166 
178  template <typename Derived>
180  System::CalcEulerAngles(*this, rot.toRotationMatrix());
181  }
182 
183  /*EulerAngles(const QuaternionType& q)
184  {
185  // TODO: Implement it in a faster way for quaternions
186  // According to http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
187  // we can compute only the needed matrix cells and then convert to euler angles. (see ZYX example below)
188  // Currently we compute all matrix cells from quaternion.
189 
190  // Special case only for ZYX
191  //Scalar y2 = q.y() * q.y();
192  //m_angles[0] = std::atan2(2*(q.w()*q.z() + q.x()*q.y()), (1 - 2*(y2 + q.z()*q.z())));
193  //m_angles[1] = std::asin( 2*(q.w()*q.y() - q.z()*q.x()));
194  //m_angles[2] = std::atan2(2*(q.w()*q.x() + q.y()*q.z()), (1 - 2*(q.x()*q.x() + y2)));
195  }*/
196 
198  const Vector3& angles() const { return m_angles; }
200  Vector3& angles() { return m_angles; }
201 
203  Scalar alpha() const { return m_angles[0]; }
205  Scalar& alpha() { return m_angles[0]; }
206 
208  Scalar beta() const { return m_angles[1]; }
210  Scalar& beta() { return m_angles[1]; }
211 
213  Scalar gamma() const { return m_angles[2]; }
215  Scalar& gamma() { return m_angles[2]; }
216 
222  res.m_angles = -m_angles;
223  return res;
224  }
225 
229  EulerAngles operator-() const { return inverse(); }
230 
238  template <class Derived>
242  YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
243 
245  return *this;
246  }
247 
248  // TODO: Assign and construct from another EulerAngles (with different system)
249 
255  template <typename Derived>
257  System::CalcEulerAngles(*this, rot.toRotationMatrix());
258  return *this;
259  }
260 
265  bool isApprox(const EulerAngles& other, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const {
266  return angles().isApprox(other.angles(), prec);
267  }
268 
271  // TODO: Calc it faster
272  return static_cast<QuaternionType>(*this).toRotationMatrix();
273  }
274 
276  operator QuaternionType() const {
279  }
280 
281  friend std::ostream& operator<<(std::ostream& s, const EulerAngles<Scalar, System>& eulerAngles) {
282  s << eulerAngles.angles().transpose();
283  return s;
284  }
285 
287  template <typename NewScalarType>
290  e.angles() = angles().template cast<NewScalarType>();
291  return e;
292  }
293 };
294 
295 #define EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(AXES, SCALAR_TYPE, SCALAR_POSTFIX) \
296  \
297  typedef EulerAngles<SCALAR_TYPE, EulerSystem##AXES> EulerAngles##AXES##SCALAR_POSTFIX;
298 
299 #define EIGEN_EULER_ANGLES_TYPEDEFS(SCALAR_TYPE, SCALAR_POSTFIX) \
300  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XYZ, SCALAR_TYPE, SCALAR_POSTFIX) \
301  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XYX, SCALAR_TYPE, SCALAR_POSTFIX) \
302  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XZY, SCALAR_TYPE, SCALAR_POSTFIX) \
303  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(XZX, SCALAR_TYPE, SCALAR_POSTFIX) \
304  \
305  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YZX, SCALAR_TYPE, SCALAR_POSTFIX) \
306  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YZY, SCALAR_TYPE, SCALAR_POSTFIX) \
307  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YXZ, SCALAR_TYPE, SCALAR_POSTFIX) \
308  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(YXY, SCALAR_TYPE, SCALAR_POSTFIX) \
309  \
310  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZXY, SCALAR_TYPE, SCALAR_POSTFIX) \
311  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZXZ, SCALAR_TYPE, SCALAR_POSTFIX) \
312  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZYX, SCALAR_TYPE, SCALAR_POSTFIX) \
313  EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(ZYZ, SCALAR_TYPE, SCALAR_POSTFIX)
314 
317 
318 namespace internal {
319 template <typename Scalar_, class _System>
320 struct traits<EulerAngles<Scalar_, _System> > {
321  typedef Scalar_ Scalar;
322 };
323 
324 // set from a rotation matrix
325 template <class System, class Other>
326 struct eulerangles_assign_impl<System, Other, 3, 3> {
327  typedef typename Other::Scalar Scalar;
328  static void run(EulerAngles<Scalar, System>& e, const Other& m) { System::CalcEulerAngles(e, m); }
329 };
330 
331 // set from a vector of Euler angles
332 template <class System, class Other>
333 struct eulerangles_assign_impl<System, Other, 3, 1> {
334  typedef typename Other::Scalar Scalar;
335  static void run(EulerAngles<Scalar, System>& e, const Other& vec) { e.angles() = vec; }
336 };
337 } // namespace internal
338 } // namespace Eigen
339 
340 #endif // EIGEN_EULERANGLESCLASS_H
Array< double, 1, 3 > e(1./3., 0.5, 2.)
int data[]
Definition: Map_placement_new.cpp:1
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
SCALAR Scalar
Definition: bench_gemm.cpp:45
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
Definition: AngleAxis.h:52
Represents a rotation in a 3 dimensional space as three Euler angles.
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:103
EulerAngles & operator=(const RotationBase< Derived, 3 > &rot)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:256
EulerAngles & operator=(const MatrixBase< Derived > &other)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:239
_System System
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:112
static Vector3 GammaAxisVector()
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:132
Scalar alpha() const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:203
static Vector3 AlphaAxisVector()
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:120
EulerAngles< NewScalarType, System > cast() const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:288
Quaternion< Scalar > QuaternionType
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:116
EulerAngles(const Scalar &alpha, const Scalar &beta, const Scalar &gamma)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:144
const Vector3 & angles() const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:198
EulerAngles(const Scalar *data)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:148
Scalar & gamma()
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:215
AngleAxis< Scalar > AngleAxisType
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:117
Matrix3 toRotationMatrix() const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:270
friend std::ostream & operator<<(std::ostream &s, const EulerAngles< Scalar, System > &eulerAngles)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:281
NumTraits< Scalar >::Real RealScalar
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:109
Scalar gamma() const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:213
Scalar_ Scalar
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:108
static Vector3 BetaAxisVector()
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:126
Vector3 & angles()
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:200
Scalar beta() const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:208
EulerAngles inverse() const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:220
EulerAngles(const MatrixBase< Derived > &other)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:163
Scalar & beta()
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:210
EulerAngles operator-() const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:229
Vector3 m_angles
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:138
Matrix< Scalar, 3, 3 > Matrix3
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:114
EulerAngles(const RotationBase< Derived, 3 > &rot)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:179
bool isApprox(const EulerAngles &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:265
EulerAngles()
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:142
Scalar & alpha()
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:205
RotationBase< EulerAngles< Scalar_, _System >, 3 > Base
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:105
Matrix< Scalar, 3, 1 > Vector3
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:115
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC Matrix3 toRotationMatrix() const
Definition: Eigen/Eigen/src/Geometry/Quaternion.h:602
The quaternion class used to represent 3D orientations and rotations.
Definition: Eigen/Eigen/src/Geometry/Quaternion.h:285
Common base class for compact rotation representations.
Definition: RotationBase.h:32
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
RealScalar s
Definition: level1_cplx_impl.h:130
EIGEN_BLAS_FUNC() rot(int *n, Scalar *px, int *incx, Scalar *py, int *incy, Scalar *pc, Scalar *ps)
Definition: level1_real_impl.h:88
int * m
Definition: level2_cplx_impl.h:294
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
Definition: Eigen_Colamd.h:49
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Other::Scalar Scalar
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:334
static void run(EulerAngles< Scalar, System > &e, const Other &vec)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:335
Other::Scalar Scalar
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:327
static void run(EulerAngles< Scalar, System > &e, const Other &m)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:328
Definition: EulerSystem.h:40
Definition: Meta.h:205
Scalar_ Scalar
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:321
Definition: ForwardDeclarations.h:21
void run(const string &dir_name, LinearSolver *linear_solver_pt, const unsigned nel_1d, bool mess_up_order)
Definition: two_d_poisson_compare_solvers.cc:317
#define EIGEN_EULER_ANGLES_TYPEDEFS(SCALAR_TYPE, SCALAR_POSTFIX)
Definition: unsupported/Eigen/src/EulerAngles/EulerAngles.h:299