RotationBase.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_ROTATIONBASE_H
00026 #define EIGEN_ROTATIONBASE_H
00027 
00028 // forward declaration
00029 namespace internal {
00030 template<typename RotationDerived, typename MatrixType, bool IsVector=MatrixType::IsVectorAtCompileTime>
00031 struct rotation_base_generic_product_selector;
00032 }
00033 
00041 template<typename Derived, int _Dim>
00042 class RotationBase
00043 {
00044   public:
00045     enum { Dim = _Dim };
00047     typedef typename internal::traits<Derived>::Scalar Scalar;
00048 
00050     typedef Matrix<Scalar,Dim,Dim> RotationMatrixType;
00051     typedef Matrix<Scalar,Dim,1> VectorType;
00052 
00053   public:
00054     inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
00055     inline Derived& derived() { return *static_cast<Derived*>(this); }
00056 
00058     inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); }
00059 
00063     inline RotationMatrixType matrix() const { return derived().toRotationMatrix(); }
00064 
00066     inline Derived inverse() const { return derived().inverse(); }
00067 
00069     inline Transform<Scalar,Dim,Isometry> operator*(const Translation<Scalar,Dim>& t) const
00070     { return Transform<Scalar,Dim,Isometry>(*this) * t; }
00071 
00073     inline RotationMatrixType operator*(const UniformScaling<Scalar>& s) const
00074     { return toRotationMatrix() * s.factor(); }
00075 
00082     template<typename OtherDerived>
00083     EIGEN_STRONG_INLINE typename internal::rotation_base_generic_product_selector<Derived,OtherDerived,OtherDerived::IsVectorAtCompileTime>::ReturnType
00084     operator*(const EigenBase<OtherDerived>& e) const
00085     { return internal::rotation_base_generic_product_selector<Derived,OtherDerived>::run(derived(), e.derived()); }
00086 
00088     template<typename OtherDerived> friend
00089     inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r)
00090     { return l.derived() * r.toRotationMatrix(); }
00091 
00093     friend inline Transform<Scalar,Dim,Affine> operator*(const DiagonalMatrix<Scalar,Dim>& l, const Derived& r)
00094     { 
00095       Transform<Scalar,Dim,Affine> res(r);
00096       res.linear().applyOnTheLeft(l);
00097       return res;
00098     }
00099 
00101     template<int Mode, int Options>
00102     inline Transform<Scalar,Dim,Mode> operator*(const Transform<Scalar,Dim,Mode,Options>& t) const
00103     { return toRotationMatrix() * t; }
00104 
00105     template<typename OtherVectorType>
00106     inline VectorType _transformVector(const OtherVectorType& v) const
00107     { return toRotationMatrix() * v; }
00108 };
00109 
00110 namespace internal {
00111 
00112 // implementation of the generic product rotation * matrix
00113 template<typename RotationDerived, typename MatrixType>
00114 struct rotation_base_generic_product_selector<RotationDerived,MatrixType,false>
00115 {
00116   enum { Dim = RotationDerived::Dim };
00117   typedef Matrix<typename RotationDerived::Scalar,Dim,Dim> ReturnType;
00118   inline static ReturnType run(const RotationDerived& r, const MatrixType& m)
00119   { return r.toRotationMatrix() * m; }
00120 };
00121 
00122 template<typename RotationDerived, typename Scalar, int Dim, int MaxDim>
00123 struct rotation_base_generic_product_selector< RotationDerived, DiagonalMatrix<Scalar,Dim,MaxDim>, false >
00124 {
00125   typedef Transform<Scalar,Dim,Affine> ReturnType;
00126   inline static ReturnType run(const RotationDerived& r, const DiagonalMatrix<Scalar,Dim,MaxDim>& m)
00127   {
00128     ReturnType res(r);
00129     res.linear() *= m;
00130     return res;
00131   }
00132 };
00133 
00134 template<typename RotationDerived,typename OtherVectorType>
00135 struct rotation_base_generic_product_selector<RotationDerived,OtherVectorType,true>
00136 {
00137   enum { Dim = RotationDerived::Dim };
00138   typedef Matrix<typename RotationDerived::Scalar,Dim,1> ReturnType;
00139   EIGEN_STRONG_INLINE static ReturnType run(const RotationDerived& r, const OtherVectorType& v)
00140   {
00141     return r._transformVector(v);
00142   }
00143 };
00144 
00145 } // end namespace internal
00146 
00151 template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
00152 template<typename OtherDerived>
00153 Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
00154 ::Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
00155 {
00156   EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
00157   *this = r.toRotationMatrix();
00158 }
00159 
00164 template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
00165 template<typename OtherDerived>
00166 Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>&
00167 Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
00168 ::operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
00169 {
00170   EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
00171   return *this = r.toRotationMatrix();
00172 }
00173 
00174 namespace internal {
00175 
00194 template<typename Scalar, int Dim>
00195 inline static Matrix<Scalar,2,2> toRotationMatrix(const Scalar& s)
00196 {
00197   EIGEN_STATIC_ASSERT(Dim==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
00198   return Rotation2D<Scalar>(s).toRotationMatrix();
00199 }
00200 
00201 template<typename Scalar, int Dim, typename OtherDerived>
00202 inline static Matrix<Scalar,Dim,Dim> toRotationMatrix(const RotationBase<OtherDerived,Dim>& r)
00203 {
00204   return r.toRotationMatrix();
00205 }
00206 
00207 template<typename Scalar, int Dim, typename OtherDerived>
00208 inline static const MatrixBase<OtherDerived>& toRotationMatrix(const MatrixBase<OtherDerived>& mat)
00209 {
00210   EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime==Dim && OtherDerived::ColsAtCompileTime==Dim,
00211     YOU_MADE_A_PROGRAMMING_MISTAKE)
00212   return mat;
00213 }
00214 
00215 } // end namespace internal
00216 
00217 #endif // EIGEN_ROTATIONBASE_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:23