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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 // forward declaration
19 namespace internal {
20 template <typename RotationDerived, typename MatrixType, bool IsVector = MatrixType::IsVectorAtCompileTime>
22 }
23 
31 template <typename Derived, int Dim_>
32 class RotationBase {
33  public:
34  enum { Dim = Dim_ };
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  }
61 
64  return toRotationMatrix() * s.factor();
65  }
66 
73  template <typename OtherDerived>
75  typename internal::rotation_base_generic_product_selector<Derived, OtherDerived,
76  OtherDerived::IsVectorAtCompileTime>::ReturnType
79  }
80 
82  template <typename OtherDerived>
83  friend EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r) {
84  return l.derived() * r.toRotationMatrix();
85  }
86 
89  const Derived& r) {
91  res.linear().applyOnTheLeft(l);
92  return res;
93  }
94 
96  template <int Mode, int Options>
99  return toRotationMatrix() * t;
100  }
101 
102  template <typename OtherVectorType>
103  EIGEN_DEVICE_FUNC inline VectorType _transformVector(const OtherVectorType& v) const {
104  return toRotationMatrix() * v;
105  }
106 };
107 
108 namespace internal {
109 
110 // implementation of the generic product rotation * matrix
111 template <typename RotationDerived, typename MatrixType>
112 struct rotation_base_generic_product_selector<RotationDerived, MatrixType, false> {
115  EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const MatrixType& m) {
116  return r.toRotationMatrix() * m;
117  }
118 };
119 
120 template <typename RotationDerived, typename Scalar, int Dim, int MaxDim>
121 struct rotation_base_generic_product_selector<RotationDerived, DiagonalMatrix<Scalar, Dim, MaxDim>, false> {
123  EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r,
125  ReturnType res(r);
126  res.linear() *= m;
127  return res;
128  }
129 };
130 
131 template <typename RotationDerived, typename OtherVectorType>
132 struct rotation_base_generic_product_selector<RotationDerived, OtherVectorType, true> {
135  EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE ReturnType run(const RotationDerived& r, const OtherVectorType& v) {
136  return r._transformVector(v);
137  }
138 };
139 
140 } // end namespace internal
141 
146 template <typename Scalar_, int Rows_, int Cols_, int Storage_, int MaxRows_, int MaxCols_>
147 template <typename OtherDerived>
151  *this = r.toRotationMatrix();
152 }
153 
158 template <typename Scalar_, int Rows_, int Cols_, int Storage_, int MaxRows_, int MaxCols_>
159 template <typename OtherDerived>
164  return *this = r.toRotationMatrix();
165 }
166 
167 namespace internal {
168 
187 template <typename Scalar, int Dim>
189  EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
191 }
192 
193 template <typename Scalar, int Dim, typename OtherDerived>
195  return r.toRotationMatrix();
196 }
197 
198 template <typename Scalar, int Dim, typename OtherDerived>
200  EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime == Dim && OtherDerived::ColsAtCompileTime == Dim,
201  YOU_MADE_A_PROGRAMMING_MISTAKE)
202  return mat;
203 }
204 
205 } // end namespace internal
206 
207 } // end namespace Eigen
208 
209 #endif // EIGEN_ROTATIONBASE_H
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
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
#define EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(TYPE, ROWS, COLS)
Definition: StaticAssert.h:55
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Represents a diagonal matrix with its storage.
Definition: DiagonalMatrix.h:172
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 constexpr EIGEN_STRONG_INLINE Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition: Eigen/Eigen/src/Core/Matrix.h:210
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Matrix()=default
Default constructor.
Represents a rotation/orientation in a 2 dimensional space.
Definition: Rotation2D.h:44
EIGEN_DEVICE_FUNC Matrix2 toRotationMatrix() const
Definition: Rotation2D.h:191
Common base class for compact rotation representations.
Definition: RotationBase.h:32
Matrix< Scalar, Dim, 1 > VectorType
Definition: RotationBase.h:40
EIGEN_DEVICE_FUNC VectorType _transformVector(const OtherVectorType &v) const
Definition: RotationBase.h:103
EIGEN_DEVICE_FUNC RotationMatrixType toRotationMatrix() const
Definition: RotationBase.h:47
EIGEN_DEVICE_FUNC Derived inverse() const
Definition: RotationBase.h:55
EIGEN_DEVICE_FUNC RotationMatrixType operator*(const UniformScaling< Scalar > &s) const
Definition: RotationBase.h:63
EIGEN_DEVICE_FUNC const Derived & derived() const
Definition: RotationBase.h:43
EIGEN_DEVICE_FUNC Derived & derived()
Definition: RotationBase.h:44
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::rotation_base_generic_product_selector< Derived, OtherDerived, OtherDerived::IsVectorAtCompileTime >::ReturnType operator*(const EigenBase< OtherDerived > &e) const
Definition: RotationBase.h:77
Matrix< Scalar, Dim, Dim > RotationMatrixType
Definition: RotationBase.h:39
EIGEN_DEVICE_FUNC friend Transform< Scalar, Dim, Affine > operator*(const DiagonalMatrix< Scalar, Dim > &l, const Derived &r)
Definition: RotationBase.h:88
internal::traits< Derived >::Scalar Scalar
Definition: RotationBase.h:36
EIGEN_DEVICE_FUNC RotationMatrixType matrix() const
Definition: RotationBase.h:52
@ Dim
Definition: RotationBase.h:34
EIGEN_DEVICE_FUNC Transform< Scalar, Dim, Mode > operator*(const Transform< Scalar, Dim, Mode, Options > &t) const
Definition: RotationBase.h:97
EIGEN_DEVICE_FUNC Transform< Scalar, Dim, Isometry > operator*(const Translation< Scalar, Dim > &t) const
Definition: RotationBase.h:58
friend EIGEN_DEVICE_FUNC RotationMatrixType operator*(const EigenBase< OtherDerived > &l, const Derived &r)
Definition: RotationBase.h:83
Represents an homogeneous transformation in a N dimensional space.
Definition: Transform.h:192
Represents a translation transformation.
Definition: Translation.h:33
Represents a generic uniform scaling transformation.
Definition: Eigen/src/Geometry/Scaling.h:47
RealScalar s
Definition: level1_cplx_impl.h:130
int * m
Definition: level2_cplx_impl.h:294
static EIGEN_DEVICE_FUNC Matrix< Scalar, 2, 2 > toRotationMatrix(const Scalar &s)
Definition: RotationBase.h:188
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
static const unsigned Dim
Problem dimension.
Definition: two_d_tilted_square.cc:62
r
Definition: UniformPSDSelfTest.py:20
Definition: Eigen_Colamd.h:49
t
Definition: plotPSD.py:36
Definition: EigenBase.h:33
constexpr EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:49
static EIGEN_DEVICE_FUNC ReturnType run(const RotationDerived &r, const DiagonalMatrix< Scalar, Dim, MaxDim > &m)
Definition: RotationBase.h:123
Matrix< typename RotationDerived::Scalar, Dim, Dim > ReturnType
Definition: RotationBase.h:114
static EIGEN_DEVICE_FUNC ReturnType run(const RotationDerived &r, const MatrixType &m)
Definition: RotationBase.h:115
Matrix< typename RotationDerived::Scalar, Dim, 1 > ReturnType
Definition: RotationBase.h:134
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ReturnType run(const RotationDerived &r, const OtherVectorType &v)
Definition: RotationBase.h:135
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