Eigen  5.0.1
 
Loading...
Searching...
No Matches
RotationBase.h
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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_ROTATIONBASE_H
12#define EIGEN_ROTATIONBASE_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19// forward declaration
20namespace internal {
21template <typename RotationDerived, typename MatrixType, bool IsVector = MatrixType::IsVectorAtCompileTime>
22struct rotation_base_generic_product_selector;
23}
24
32template <typename Derived, int Dim_>
34 public:
35 enum { Dim = Dim_ };
37 using Scalar = typename internal::traits<Derived>::Scalar;
38
41 using VectorType = Matrix<Scalar, Dim, 1>;
42
43 public:
44 EIGEN_DEVICE_FUNC inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
45 EIGEN_DEVICE_FUNC inline Derived& derived() { return *static_cast<Derived*>(this); }
46
48 EIGEN_DEVICE_FUNC inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); }
53 EIGEN_DEVICE_FUNC inline RotationMatrixType matrix() const { return derived().toRotationMatrix(); }
54
56 EIGEN_DEVICE_FUNC inline Derived inverse() const { return derived().inverse(); }
59 EIGEN_DEVICE_FUNC inline Transform<Scalar, Dim, Isometry> operator*(const Translation<Scalar, Dim>& t) const {
60 return Transform<Scalar, Dim, Isometry>(*this) * t;
61 }
62
64 EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const UniformScaling<Scalar>& s) const {
65 return toRotationMatrix() * s.factor();
66 }
67
74 template <typename OtherDerived>
75 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
76 typename internal::rotation_base_generic_product_selector<Derived, OtherDerived,
77 OtherDerived::IsVectorAtCompileTime>::ReturnType
79 return internal::rotation_base_generic_product_selector<Derived, OtherDerived>::run(derived(), e.derived());
80 }
81
83 template <typename OtherDerived>
84 friend EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r) {
85 return l.derived() * r.toRotationMatrix();
86 }
87
90 const Derived& r) {
92 res.linear().applyOnTheLeft(l);
93 return res;
94 }
95
97 template <int Mode, int Options>
98 EIGEN_DEVICE_FUNC inline Transform<Scalar, Dim, Mode> operator*(
100 return toRotationMatrix() * t;
101 }
102
103 template <typename OtherVectorType>
104 EIGEN_DEVICE_FUNC inline VectorType _transformVector(const OtherVectorType& v) const {
105 return toRotationMatrix() * v;
106 }
107};
108
109namespace internal {
110
111// implementation of the generic product rotation * matrix
112template <typename RotationDerived, typename MatrixType>
113struct rotation_base_generic_product_selector<RotationDerived, MatrixType, false> {
114 enum { Dim = RotationDerived::Dim };
115 using ReturnType = Matrix<typename RotationDerived::Scalar, Dim, Dim>;
116 EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const MatrixType& m) {
117 return r.toRotationMatrix() * m;
118 }
119};
120
121template <typename RotationDerived, typename Scalar, int Dim, int MaxDim>
122struct rotation_base_generic_product_selector<RotationDerived, DiagonalMatrix<Scalar, Dim, MaxDim>, false> {
123 using ReturnType = Transform<Scalar, Dim, Affine>;
124 EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r,
125 const DiagonalMatrix<Scalar, Dim, MaxDim>& m) {
126 ReturnType res(r);
127 res.linear() *= m;
128 return res;
129 }
130};
131
132template <typename RotationDerived, typename OtherVectorType>
133struct rotation_base_generic_product_selector<RotationDerived, OtherVectorType, true> {
134 enum { Dim = RotationDerived::Dim };
135 using ReturnType = Matrix<typename RotationDerived::Scalar, Dim, 1>;
136 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE ReturnType run(const RotationDerived& r, const OtherVectorType& v) {
137 return r._transformVector(v);
138 }
139};
140
141} // end namespace internal
142
147template <typename Scalar_, int Rows_, int Cols_, int Storage_, int MaxRows_, int MaxCols_>
148template <typename OtherDerived>
151 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix, int(OtherDerived::Dim), int(OtherDerived::Dim))
152 *this = r.toRotationMatrix();
153}
154
159template <typename Scalar_, int Rows_, int Cols_, int Storage_, int MaxRows_, int MaxCols_>
160template <typename OtherDerived>
164 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix, int(OtherDerived::Dim), int(OtherDerived::Dim))
165 return *this = r.toRotationMatrix();
166}
167
168namespace internal {
169
188template <typename Scalar, int Dim, typename OtherScalar,
189 std::enable_if_t<std::is_scalar<OtherScalar>::value, int> = 0>
190EIGEN_DEVICE_FUNC static inline Matrix<Scalar, 2, 2> toRotationMatrix(const OtherScalar& s) {
191 EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
192 return Rotation2D<Scalar>(static_cast<Scalar>(s)).toRotationMatrix();
193}
194
195template <typename Scalar, int Dim, typename OtherDerived,
196 std::enable_if_t<std::is_same<Scalar, typename OtherDerived::Scalar>::value, int> = 0>
197EIGEN_DEVICE_FUNC static inline typename OtherDerived::RotationMatrixType toRotationMatrix(
198 const RotationBase<OtherDerived, Dim>& r) {
199 return r.toRotationMatrix();
200}
201
202template <typename Scalar, int Dim, typename OtherDerived,
203 std::enable_if_t<!std::is_same<Scalar, typename OtherDerived::Scalar>::value, int> = 0>
204EIGEN_DEVICE_FUNC static inline Matrix<Scalar, Dim, Dim> toRotationMatrix(const RotationBase<OtherDerived, Dim>& r) {
205 return r.toRotationMatrix().template cast<Scalar>();
206}
207
208template <typename Scalar, int Dim, typename OtherDerived,
209 std::enable_if_t<std::is_same<Scalar, typename OtherDerived::Scalar>::value, int> = 0>
210EIGEN_DEVICE_FUNC static inline const OtherDerived& toRotationMatrix(const MatrixBase<OtherDerived>& mat) {
211 EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime == Dim && OtherDerived::ColsAtCompileTime == Dim,
212 YOU_MADE_A_PROGRAMMING_MISTAKE)
213 return mat.derived();
214}
215
216template <typename Scalar, int Dim, typename OtherDerived,
217 std::enable_if_t<!std::is_same<Scalar, typename OtherDerived::Scalar>::value, int> = 0>
218EIGEN_DEVICE_FUNC static inline auto toRotationMatrix(const MatrixBase<OtherDerived>& mat) {
219 EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime == Dim && OtherDerived::ColsAtCompileTime == Dim,
220 YOU_MADE_A_PROGRAMMING_MISTAKE)
221 return mat.template cast<Scalar>();
222}
223
224} // end namespace internal
225
226} // end namespace Eigen
227
228#endif // EIGEN_ROTATIONBASE_H
Represents a diagonal matrix with its storage.
Definition DiagonalMatrix.h:233
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
constexpr Matrix()=default
Default constructor.
constexpr Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition Matrix.h:212
Represents a rotation/orientation in a 2 dimensional space.
Definition Rotation2D.h:45
Matrix2 toRotationMatrix() const
Definition Rotation2D.h:192
Common base class for compact rotation representations.
Definition RotationBase.h:33
RotationMatrixType matrix() const
Definition RotationBase.h:53
internal::rotation_base_generic_product_selector< Derived, OtherDerived, OtherDerived::IsVectorAtCompileTime >::ReturnType operator*(const EigenBase< OtherDerived > &e) const
Definition RotationBase.h:78
Derived inverse() const
Definition RotationBase.h:56
Matrix< Scalar, Dim, Dim > RotationMatrixType
Definition RotationBase.h:40
friend RotationMatrixType operator*(const EigenBase< OtherDerived > &l, const Derived &r)
Definition RotationBase.h:84
Transform< Scalar, Dim, Isometry > operator*(const Translation< Scalar, Dim > &t) const
Definition RotationBase.h:59
Transform< Scalar, Dim, Mode > operator*(const Transform< Scalar, Dim, Mode, Options > &t) const
Definition RotationBase.h:98
RotationMatrixType operator*(const UniformScaling< Scalar > &s) const
Definition RotationBase.h:64
friend Transform< Scalar, Dim, Affine > operator*(const DiagonalMatrix< Scalar, Dim > &l, const Derived &r)
Definition RotationBase.h:89
typename internal::traits< AngleAxis< Scalar_ > >::Scalar Scalar
Definition RotationBase.h:37
RotationMatrixType toRotationMatrix() const
Definition RotationBase.h:48
Represents an homogeneous transformation in a N dimensional space.
Definition Transform.h:222
ConstLinearPart linear() const
Definition Transform.h:415
Represents a translation transformation.
Definition Translation.h:34
Represents a generic uniform scaling transformation.
Definition Scaling.h:48
Definition EigenBase.h:34
constexpr Derived & derived()
Definition EigenBase.h:50