Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/eigen3/Eigen/src/Geometry/RotationBase.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_ROTATIONBASE_H
0011 #define EIGEN_ROTATIONBASE_H
0012 
0013 namespace Eigen { 
0014 
0015 // forward declaration
0016 namespace internal {
0017 template<typename RotationDerived, typename MatrixType, bool IsVector=MatrixType::IsVectorAtCompileTime>
0018 struct rotation_base_generic_product_selector;
0019 }
0020 
0021 /** \class RotationBase
0022   *
0023   * \brief Common base class for compact rotation representations
0024   *
0025   * \tparam Derived is the derived type, i.e., a rotation type
0026   * \tparam _Dim the dimension of the space
0027   */
0028 template<typename Derived, int _Dim>
0029 class RotationBase
0030 {
0031   public:
0032     enum { Dim = _Dim };
0033     /** the scalar type of the coefficients */
0034     typedef typename internal::traits<Derived>::Scalar Scalar;
0035 
0036     /** corresponding linear transformation matrix type */
0037     typedef Matrix<Scalar,Dim,Dim> RotationMatrixType;
0038     typedef Matrix<Scalar,Dim,1> VectorType;
0039 
0040   public:
0041     EIGEN_DEVICE_FUNC inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
0042     EIGEN_DEVICE_FUNC inline Derived& derived() { return *static_cast<Derived*>(this); }
0043 
0044     /** \returns an equivalent rotation matrix */
0045     EIGEN_DEVICE_FUNC inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); }
0046 
0047     /** \returns an equivalent rotation matrix 
0048       * This function is added to be conform with the Transform class' naming scheme.
0049       */
0050     EIGEN_DEVICE_FUNC inline RotationMatrixType matrix() const { return derived().toRotationMatrix(); }
0051 
0052     /** \returns the inverse rotation */
0053     EIGEN_DEVICE_FUNC inline Derived inverse() const { return derived().inverse(); }
0054 
0055     /** \returns the concatenation of the rotation \c *this with a translation \a t */
0056     EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Isometry> operator*(const Translation<Scalar,Dim>& t) const
0057     { return Transform<Scalar,Dim,Isometry>(*this) * t; }
0058 
0059     /** \returns the concatenation of the rotation \c *this with a uniform scaling \a s */
0060     EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const UniformScaling<Scalar>& s) const
0061     { return toRotationMatrix() * s.factor(); }
0062 
0063     /** \returns the concatenation of the rotation \c *this with a generic expression \a e
0064       * \a e can be:
0065       *  - a DimxDim linear transformation matrix
0066       *  - a DimxDim diagonal matrix (axis aligned scaling)
0067       *  - a vector of size Dim
0068       */
0069     template<typename OtherDerived>
0070     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::rotation_base_generic_product_selector<Derived,OtherDerived,OtherDerived::IsVectorAtCompileTime>::ReturnType
0071     operator*(const EigenBase<OtherDerived>& e) const
0072     { return internal::rotation_base_generic_product_selector<Derived,OtherDerived>::run(derived(), e.derived()); }
0073 
0074     /** \returns the concatenation of a linear transformation \a l with the rotation \a r */
0075     template<typename OtherDerived> friend
0076     EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r)
0077     { return l.derived() * r.toRotationMatrix(); }
0078 
0079     /** \returns the concatenation of a scaling \a l with the rotation \a r */
0080     EIGEN_DEVICE_FUNC friend inline Transform<Scalar,Dim,Affine> operator*(const DiagonalMatrix<Scalar,Dim>& l, const Derived& r)
0081     { 
0082       Transform<Scalar,Dim,Affine> res(r);
0083       res.linear().applyOnTheLeft(l);
0084       return res;
0085     }
0086 
0087     /** \returns the concatenation of the rotation \c *this with a transformation \a t */
0088     template<int Mode, int Options>
0089     EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode> operator*(const Transform<Scalar,Dim,Mode,Options>& t) const
0090     { return toRotationMatrix() * t; }
0091 
0092     template<typename OtherVectorType>
0093     EIGEN_DEVICE_FUNC inline VectorType _transformVector(const OtherVectorType& v) const
0094     { return toRotationMatrix() * v; }
0095 };
0096 
0097 namespace internal {
0098 
0099 // implementation of the generic product rotation * matrix
0100 template<typename RotationDerived, typename MatrixType>
0101 struct rotation_base_generic_product_selector<RotationDerived,MatrixType,false>
0102 {
0103   enum { Dim = RotationDerived::Dim };
0104   typedef Matrix<typename RotationDerived::Scalar,Dim,Dim> ReturnType;
0105   EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const MatrixType& m)
0106   { return r.toRotationMatrix() * m; }
0107 };
0108 
0109 template<typename RotationDerived, typename Scalar, int Dim, int MaxDim>
0110 struct rotation_base_generic_product_selector< RotationDerived, DiagonalMatrix<Scalar,Dim,MaxDim>, false >
0111 {
0112   typedef Transform<Scalar,Dim,Affine> ReturnType;
0113   EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const DiagonalMatrix<Scalar,Dim,MaxDim>& m)
0114   {
0115     ReturnType res(r);
0116     res.linear() *= m;
0117     return res;
0118   }
0119 };
0120 
0121 template<typename RotationDerived,typename OtherVectorType>
0122 struct rotation_base_generic_product_selector<RotationDerived,OtherVectorType,true>
0123 {
0124   enum { Dim = RotationDerived::Dim };
0125   typedef Matrix<typename RotationDerived::Scalar,Dim,1> ReturnType;
0126   EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE ReturnType run(const RotationDerived& r, const OtherVectorType& v)
0127   {
0128     return r._transformVector(v);
0129   }
0130 };
0131 
0132 } // end namespace internal
0133 
0134 /** \geometry_module
0135   *
0136   * \brief Constructs a Dim x Dim rotation matrix from the rotation \a r
0137   */
0138 template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
0139 template<typename OtherDerived>
0140 EIGEN_DEVICE_FUNC Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
0141 ::Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
0142 {
0143   EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
0144   *this = r.toRotationMatrix();
0145 }
0146 
0147 /** \geometry_module
0148   *
0149   * \brief Set a Dim x Dim rotation matrix from the rotation \a r
0150   */
0151 template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
0152 template<typename OtherDerived>
0153 EIGEN_DEVICE_FUNC Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>&
0154 Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
0155 ::operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
0156 {
0157   EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
0158   return *this = r.toRotationMatrix();
0159 }
0160 
0161 namespace internal {
0162 
0163 /** \internal
0164   *
0165   * Helper function to return an arbitrary rotation object to a rotation matrix.
0166   *
0167   * \tparam Scalar the numeric type of the matrix coefficients
0168   * \tparam Dim the dimension of the current space
0169   *
0170   * It returns a Dim x Dim fixed size matrix.
0171   *
0172   * Default specializations are provided for:
0173   *   - any scalar type (2D),
0174   *   - any matrix expression,
0175   *   - any type based on RotationBase (e.g., Quaternion, AngleAxis, Rotation2D)
0176   *
0177   * Currently toRotationMatrix is only used by Transform.
0178   *
0179   * \sa class Transform, class Rotation2D, class Quaternion, class AngleAxis
0180   */
0181 template<typename Scalar, int Dim>
0182 EIGEN_DEVICE_FUNC static inline Matrix<Scalar,2,2> toRotationMatrix(const Scalar& s)
0183 {
0184   EIGEN_STATIC_ASSERT(Dim==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
0185   return Rotation2D<Scalar>(s).toRotationMatrix();
0186 }
0187 
0188 template<typename Scalar, int Dim, typename OtherDerived>
0189 EIGEN_DEVICE_FUNC static inline Matrix<Scalar,Dim,Dim> toRotationMatrix(const RotationBase<OtherDerived,Dim>& r)
0190 {
0191   return r.toRotationMatrix();
0192 }
0193 
0194 template<typename Scalar, int Dim, typename OtherDerived>
0195 EIGEN_DEVICE_FUNC static inline const MatrixBase<OtherDerived>& toRotationMatrix(const MatrixBase<OtherDerived>& mat)
0196 {
0197   EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime==Dim && OtherDerived::ColsAtCompileTime==Dim,
0198     YOU_MADE_A_PROGRAMMING_MISTAKE)
0199   return mat;
0200 }
0201 
0202 } // end namespace internal
0203 
0204 } // end namespace Eigen
0205 
0206 #endif // EIGEN_ROTATIONBASE_H