Displacement.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) 2009-2013 CEA LIST (DIASI/LSI) <xde-support@saxifrage.cea.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_LGSM_DISPLACEMENT_H
00011 #define EIGEN_LGSM_DISPLACEMENT_H
00012 
00013 /*******************************************************************************
00014 * Definition/implementation of DisplacementBase
00015 ********************************************************************************/
00016 
00027 template<class Derived> 
00028 class DisplacementBase : public LieGroupBase<Array<typename internal::traits<Derived>::Scalar, 7, 1>, Derived>{
00029 public:
00031   typedef typename internal::traits<Derived>::Scalar Scalar;
00032 protected:
00034   typedef LieGroupBase<Array<Scalar, 7, 1>, Derived> Base;
00035 public:
00036   // inherit the operator=
00037   EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(DisplacementBase<Derived>)
00038 
00039   
00040   typedef typename Base::BaseType BaseType;
00042   typedef typename Base::PlainObject PlainObject;
00043 
00045   typedef Matrix<Scalar, 3, 1> Vector3;
00047   typedef LieGroup<Quaternion<Scalar> > Rotation3D;
00048 
00050   inline Map<Rotation3D> getRotation(){ return Map<Rotation3D>(this->derived().get().template head<4>().data()); }
00052   inline const Map<const Rotation3D> getRotation() const{ return Map<const Rotation3D>(this->derived().get().template head<4>().data()); }
00054   inline Map<Vector3> getTranslation(){ return Map<Vector3>(this->derived().get().template tail<3>().data()); }
00056   inline const Map<const Vector3> getTranslation() const { return Map<const Vector3>(this->get().template tail<3>().data()); }
00057 
00058 
00060   inline Scalar x() const { return this->getTranslation().x(); }
00062   inline Scalar y() const { return this->getTranslation().y(); }
00064   inline Scalar z() const { return this->getTranslation().z(); }
00066   inline Scalar qx() const { return this->getRotation().x(); }
00068   inline Scalar qy() const { return this->getRotation().y(); }
00070   inline Scalar qz() const { return this->getRotation().z(); }
00072   inline Scalar qw() const { return this->getRotation().w(); }
00073 
00075   inline Scalar& x() { return this->getTranslation().x(); }
00077   inline Scalar& y() { return this->getTranslation().y(); }
00079   inline Scalar& z() { return this->getTranslation().z(); }
00081   inline Scalar& qx() { return this->getRotation().x(); }
00083   inline Scalar& qy() { return this->getRotation().y(); }
00085   inline Scalar& qz() { return this->getRotation().z(); }
00087   inline Scalar& qw() { return this->getRotation().w(); }
00088 
00089   inline void setRandom() {
00090     this->get().setRandom();
00091     this->getRotation().get().normalize();
00092   }
00093   
00099   template<typename NewScalarType>
00100   inline typename internal::cast_return_type<Derived, Displacement<NewScalarType> >::type cast() const
00101   {
00102     return typename internal::cast_return_type<Derived, Displacement<NewScalarType> >::type(
00103      this->get().template cast<NewScalarType>());
00104   }
00105 
00106   EIGEN_STRONG_INLINE DisplacementBase& operator=(const typename Base::PlainObject& g) //[XXX] Plain object must be a Displacement
00107   {
00108     this->derived().get() = g.get();
00109     return *this;
00110   }
00111   
00112   Matrix<Scalar, 4, 4> toHomogeneousMatrix() const;
00113 
00115   template<class OtherDerived>
00116   friend std::ostream& operator <<(std::ostream& os, const DisplacementBase<OtherDerived>& d);
00117 };
00118 
00119 template<class Derived> Matrix<typename internal::traits<Derived>::Scalar, 4, 4> DisplacementBase<Derived>::toHomogeneousMatrix() const
00120 {
00121         Matrix<Scalar, 4, 4> m;
00122         //m << this->getRotation().get().toRotationMatrix(), Eigen::Matrix<Scalar, 3, 1>::Zero(), this->getTranslation().transpose(), 1.;
00123         m << this->getRotation().get().toRotationMatrix(), this->getTranslation(), Eigen::Matrix<Scalar, 1, 3>::Zero(), 1.;
00124 
00125         return m;
00126 }
00127 
00128 template<class Derived>
00129 inline std::ostream& operator <<(std::ostream& os, const DisplacementBase<Derived>& d)
00130 {
00131   os << d.x() << "\t" << d.y() << "\t" << d.z() << "\t" << d.qw() << "\t" << d.qx() << "\t" << d.qy() << "\t" << d.qz();
00132   return os;
00133 }
00134 
00135 /*********************************
00136  * Implementation of Displacement
00137  *********************************/
00138 
00139 namespace internal {
00140   template<typename _Scalar>
00141     struct traits<Displacement<_Scalar> > : traits<LieGroup<Array<_Scalar, 7, 1> > >
00142     {
00143       typedef Displacement<_Scalar> PlainObject;
00144       typedef _Scalar Scalar;
00145     };
00146 }
00147 
00158 template<typename _Scalar>
00159 class Displacement : public DisplacementBase<Displacement<_Scalar> >{
00160 public:
00162   typedef _Scalar Scalar;
00163 protected:
00165   typedef DisplacementBase<Displacement<Scalar> > Base;
00166 public:
00168   typedef typename internal::traits<Displacement>::Coefficients Coefficients;
00169   // inherit assignement operator
00170   EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Displacement<Scalar>)
00171 
00172   
00173   inline Displacement() : m_coeffs() {}
00175   inline Displacement(const Displacement& other) : m_coeffs(other.get() ) {}
00176   //EIGEN_STRONG_INLINE Displacement(const typename Base::PlainObject& g) : m_coeffs(g.get() ) {}  // [XXX] Plain object must be a Displacement
00178   template<typename Derived>
00179   inline Displacement(const DisplacementBase<Derived>& other) : m_coeffs(other.get() ) {}
00181   inline Displacement(const Array<Scalar, 7, 1>& g) : m_coeffs(g) {}
00182   template<typename Derived>
00183   explicit inline Displacement(const MatrixBase<Derived>& other) { *this = other; }
00190   EIGEN_STRONG_INLINE Displacement(Scalar x, Scalar y, Scalar z, Scalar qw = (Scalar)1.0, Scalar qx = (Scalar)0.0, Scalar qy = (Scalar)0.0, Scalar qz = (Scalar)0.0) { 
00191     // m_coeffs << qx, qy, qz, qw, x, y, z // operator<< is not inlined
00192     m_coeffs[0] = qx;
00193     m_coeffs[1] = qy;
00194     m_coeffs[2] = qz;
00195     m_coeffs[3] = qw;
00196     m_coeffs[4] = x;
00197     m_coeffs[5] = y;
00198     m_coeffs[6] = z;
00199   }
00200 
00201 
00203   EIGEN_STRONG_INLINE Displacement(const typename Base::Vector3& v, const typename Base::Rotation3D& r/* = Base::Rotation3D::Identity()*/) {
00204     this->getTranslation() = v;
00205     this->getRotation() = r;
00206   }
00207 
00209   inline Coefficients& get() { return m_coeffs; }
00211   inline const Coefficients& get() const { return m_coeffs; }
00212 
00213 protected:
00215   Coefficients m_coeffs;
00216 };
00217 
00219 typedef Displacement<double> Displacementd;
00221 typedef Displacement<float> Displacementf;
00222 
00223 /**************************************
00224  * Implementation of Map<Displacement>
00225  **************************************/
00226 
00227 namespace internal {
00228   template<typename _Scalar, int MapOptions, typename StrideType>
00229     struct traits<Map<Displacement<_Scalar>, MapOptions, StrideType> > : Map<LieGroup<Array<_Scalar, 7, 1> >, MapOptions, StrideType>
00230     {
00231       typedef Displacement<_Scalar> PlainObject;
00232       typedef _Scalar Scalar;
00233     };
00234 }
00245 template<typename _Scalar, int MapOptions, typename StrideType>
00246 class Map<Displacement<_Scalar>, MapOptions, StrideType> : public DisplacementBase<Map<Displacement<_Scalar>, MapOptions, StrideType> >{
00247   protected:
00248     typedef _Scalar Scalar;
00249     typedef DisplacementBase<Map<Displacement<Scalar> > > Base;
00250   public:
00251 
00252     EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Map)
00253       typedef typename internal::traits<Map>::Coefficients Coefficients;
00254 
00255     inline Map(const Displacement<_Scalar>& d) : m_coeffs(d.get()) {};
00256     template<int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> 
00257       inline Map(const Array<Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& g) : m_coeffs(g.data()) {};
00258 
00259     inline Map(Scalar* data) : m_coeffs(data) {};
00260     inline Map(const Map& m) : m_coeffs(m.get()) {};
00261 
00262     inline Coefficients& get() { return m_coeffs; }
00263     inline const Coefficients& get() const { return m_coeffs; }
00264 
00265   protected:
00266     Coefficients m_coeffs;
00267 };
00268 
00269 #endif
00270 


lgsm
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:26:30