RotationBase.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) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
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_ROTATIONBASE_H
11 #define EIGEN_ROTATIONBASE_H
12 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 // forward declaration
18 namespace internal {
19 template<typename RotationDerived, typename MatrixType, bool IsVector=MatrixType::IsVectorAtCompileTime>
20 struct rotation_base_generic_product_selector;
21 }
22 
30 template<typename Derived, int Dim_>
32 {
33  public:
34  enum { Dim = Dim_ };
36  typedef typename internal::traits<Derived>::Scalar Scalar;
37 
41 
42  public:
43  EIGEN_DEVICE_FUNC inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
44  EIGEN_DEVICE_FUNC inline Derived& derived() { return *static_cast<Derived*>(this); }
45 
47  EIGEN_DEVICE_FUNC inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); }
48 
52  EIGEN_DEVICE_FUNC inline RotationMatrixType matrix() const { return derived().toRotationMatrix(); }
53 
55  EIGEN_DEVICE_FUNC inline Derived inverse() const { return derived().inverse(); }
56 
59  { return Transform<Scalar,Dim,Isometry>(*this) * t; }
60 
63  { return toRotationMatrix() * s.factor(); }
64 
71  template<typename OtherDerived>
72  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::rotation_base_generic_product_selector<Derived,OtherDerived,OtherDerived::IsVectorAtCompileTime>::ReturnType
74  { return internal::rotation_base_generic_product_selector<Derived,OtherDerived>::run(derived(), e.derived()); }
75 
77  template<typename OtherDerived> friend
79  { return l.derived() * r.toRotationMatrix(); }
80 
83  {
85  res.linear().applyOnTheLeft(l);
86  return res;
87  }
88 
90  template<int Mode, int Options>
92  { return toRotationMatrix() * t; }
93 
94  template<typename OtherVectorType>
95  EIGEN_DEVICE_FUNC inline VectorType _transformVector(const OtherVectorType& v) const
96  { return toRotationMatrix() * v; }
97 };
98 
99 namespace internal {
100 
101 // implementation of the generic product rotation * matrix
102 template<typename RotationDerived, typename MatrixType>
103 struct rotation_base_generic_product_selector<RotationDerived,MatrixType,false>
104 {
105  enum { Dim = RotationDerived::Dim };
106  typedef Matrix<typename RotationDerived::Scalar,Dim,Dim> ReturnType;
107  EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const MatrixType& m)
108  { return r.toRotationMatrix() * m; }
109 };
110 
111 template<typename RotationDerived, typename Scalar, int Dim, int MaxDim>
112 struct rotation_base_generic_product_selector< RotationDerived, DiagonalMatrix<Scalar,Dim,MaxDim>, false >
113 {
114  typedef Transform<Scalar,Dim,Affine> ReturnType;
115  EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const DiagonalMatrix<Scalar,Dim,MaxDim>& m)
116  {
117  ReturnType res(r);
118  res.linear() *= m;
119  return res;
120  }
121 };
122 
123 template<typename RotationDerived,typename OtherVectorType>
124 struct rotation_base_generic_product_selector<RotationDerived,OtherVectorType,true>
125 {
126  enum { Dim = RotationDerived::Dim };
127  typedef Matrix<typename RotationDerived::Scalar,Dim,1> ReturnType;
128  EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE ReturnType run(const RotationDerived& r, const OtherVectorType& v)
129  {
130  return r._transformVector(v);
131  }
132 };
133 
134 } // end namespace internal
135 
140 template<typename Scalar_, int Rows_, int Cols_, int Storage_, int MaxRows_, int MaxCols_>
141 template<typename OtherDerived>
144 {
145  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
146  *this = r.toRotationMatrix();
147 }
148 
153 template<typename Scalar_, int Rows_, int Cols_, int Storage_, int MaxRows_, int MaxCols_>
154 template<typename OtherDerived>
158 {
159  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
160  return *this = r.toRotationMatrix();
161 }
162 
163 namespace internal {
164 
183 template<typename Scalar, int Dim>
185 {
186  EIGEN_STATIC_ASSERT(Dim==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
188 }
189 
190 template<typename Scalar, int Dim, typename OtherDerived>
192 {
193  return r.toRotationMatrix();
194 }
195 
196 template<typename Scalar, int Dim, typename OtherDerived>
198 {
199  EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime==Dim && OtherDerived::ColsAtCompileTime==Dim,
200  YOU_MADE_A_PROGRAMMING_MISTAKE)
201  return mat;
202 }
203 
204 } // end namespace internal
205 
206 } // end namespace Eigen
207 
208 #endif // EIGEN_ROTATIONBASE_H
Matrix3f m
Array< int, Dynamic, 1 > v
Array< double, 1, 3 > e(1./3., 0.5, 2.)
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
#define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS)
Definition: StaticAssert.h:56
Matrix< float, 1, Dynamic > MatrixType
Represents a diagonal matrix with its storage.
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition: Matrix.h:208
Matrix()
Default constructor.
Definition: Matrix.h:261
Represents a rotation/orientation in a 2 dimensional space.
Definition: Rotation2D.h:44
Matrix2 toRotationMatrix() const
Definition: Rotation2D.h:190
Common base class for compact rotation representations.
Definition: RotationBase.h:32
RotationMatrixType matrix() const
Definition: RotationBase.h:52
Derived & derived()
Definition: RotationBase.h:44
Transform< Scalar, Dim, Mode > operator*(const Transform< Scalar, Dim, Mode, Options > &t) const
Definition: RotationBase.h:91
Derived inverse() const
Definition: RotationBase.h:55
Matrix< Scalar, Dim, Dim > RotationMatrixType
Definition: RotationBase.h:39
friend RotationMatrixType operator*(const EigenBase< OtherDerived > &l, const Derived &r)
Definition: RotationBase.h:78
Matrix< Scalar, Dim, 1 > VectorType
Definition: RotationBase.h:40
friend Transform< Scalar, Dim, Affine > operator*(const DiagonalMatrix< Scalar, Dim > &l, const Derived &r)
Definition: RotationBase.h:82
VectorType _transformVector(const OtherVectorType &v) const
Definition: RotationBase.h:95
const Derived & derived() const
Definition: RotationBase.h:43
RotationMatrixType operator*(const UniformScaling< Scalar > &s) const
Definition: RotationBase.h:62
internal::traits< Derived >::Scalar Scalar
Definition: RotationBase.h:36
RotationMatrixType toRotationMatrix() const
Definition: RotationBase.h:47
internal::rotation_base_generic_product_selector< Derived, OtherDerived, OtherDerived::IsVectorAtCompileTime >::ReturnType operator*(const EigenBase< OtherDerived > &e) const
Definition: RotationBase.h:73
Transform< Scalar, Dim, Isometry > operator*(const Translation< Scalar, Dim > &t) const
Definition: RotationBase.h:58
Represents an homogeneous transformation in a N dimensional space.
Definition: Transform.h:207
Represents a translation transformation.
Definition: Translation.h:33
Represents a generic uniform scaling transformation.
Definition: Scaling.h:52
const Scalar & factor() const
Definition: Scaling.h:68
static Matrix< Scalar, 2, 2 > toRotationMatrix(const Scalar &s)
Definition: RotationBase.h:184
: InteropHeaders
Definition: Core:139
Derived & derived()
Definition: EigenBase.h:48