Displacement.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) 2009-2013 CEA LIST (DIASI/LSI) <xde-support@saxifrage.cea.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_LGSM_DISPLACEMENT_H
11 #define EIGEN_LGSM_DISPLACEMENT_H
12 
13 /*******************************************************************************
14 * Definition/implementation of DisplacementBase
15 ********************************************************************************/
16 
27 template<class Derived>
28 class DisplacementBase : public LieGroupBase<Array<typename internal::traits<Derived>::Scalar, 7, 1>, Derived>{
29 public:
31  typedef typename internal::traits<Derived>::Scalar Scalar;
32 protected:
35 public:
36  // inherit the operator=
37  EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(DisplacementBase<Derived>)
38 
39 
40  typedef typename Base::BaseType BaseType;
42  typedef typename Base::PlainObject PlainObject;
43 
45  typedef Matrix<Scalar, 3, 1> Vector3;
47  typedef LieGroup<Quaternion<Scalar> > Rotation3D;
48 
50  inline Map<Rotation3D> getRotation(){ return Map<Rotation3D>(this->derived().get().template head<4>().data()); }
52  inline const Map<const Rotation3D> getRotation() const{ return Map<const Rotation3D>(this->derived().get().template head<4>().data()); }
54  inline Map<Vector3> getTranslation(){ return Map<Vector3>(this->derived().get().template tail<3>().data()); }
56  inline const Map<const Vector3> getTranslation() const { return Map<const Vector3>(this->get().template tail<3>().data()); }
57 
58 
60  inline Scalar x() const { return this->getTranslation().x(); }
62  inline Scalar y() const { return this->getTranslation().y(); }
64  inline Scalar z() const { return this->getTranslation().z(); }
66  inline Scalar qx() const { return this->getRotation().x(); }
68  inline Scalar qy() const { return this->getRotation().y(); }
70  inline Scalar qz() const { return this->getRotation().z(); }
72  inline Scalar qw() const { return this->getRotation().w(); }
73 
75  inline Scalar& x() { return this->getTranslation().x(); }
77  inline Scalar& y() { return this->getTranslation().y(); }
79  inline Scalar& z() { return this->getTranslation().z(); }
81  inline Scalar& qx() { return this->getRotation().x(); }
83  inline Scalar& qy() { return this->getRotation().y(); }
85  inline Scalar& qz() { return this->getRotation().z(); }
87  inline Scalar& qw() { return this->getRotation().w(); }
88 
89  inline void setRandom() {
90  this->get().setRandom();
91  this->getRotation().get().normalize();
92  }
93 
99  template<typename NewScalarType>
100  inline typename internal::cast_return_type<Derived, Displacement<NewScalarType> >::type cast() const
101  {
102  return typename internal::cast_return_type<Derived, Displacement<NewScalarType> >::type(
103  this->get().template cast<NewScalarType>());
104  }
105 
106  EIGEN_STRONG_INLINE DisplacementBase& operator=(const typename Base::PlainObject& g) //[XXX] Plain object must be a Displacement
107  {
108  this->derived().get() = g.get();
109  return *this;
110  }
111 
112  Matrix<Scalar, 4, 4> toHomogeneousMatrix() const;
113 
115  template<class OtherDerived>
116  friend std::ostream& operator <<(std::ostream& os, const DisplacementBase<OtherDerived>& d);
117 };
118 
119 template<class Derived> Matrix<typename internal::traits<Derived>::Scalar, 4, 4> DisplacementBase<Derived>::toHomogeneousMatrix() const
120 {
121  Matrix<Scalar, 4, 4> m;
122  //m << this->getRotation().get().toRotationMatrix(), Eigen::Matrix<Scalar, 3, 1>::Zero(), this->getTranslation().transpose(), 1.;
123  m << this->getRotation().get().toRotationMatrix(), this->getTranslation(), Eigen::Matrix<Scalar, 1, 3>::Zero(), 1.;
124 
125  return m;
126 }
127 
128 template<class Derived>
129 inline std::ostream& operator <<(std::ostream& os, const DisplacementBase<Derived>& d)
130 {
131  os << d.x() << "\t" << d.y() << "\t" << d.z() << "\t" << d.qw() << "\t" << d.qx() << "\t" << d.qy() << "\t" << d.qz();
132  return os;
133 }
134 
135 /*********************************
136  * Implementation of Displacement
137  *********************************/
138 
139 namespace internal {
140  template<typename _Scalar>
141  struct traits<Displacement<_Scalar> > : traits<LieGroup<Array<_Scalar, 7, 1> > >
142  {
144  typedef _Scalar Scalar;
145  };
146 }
147 
158 template<typename _Scalar>
159 class Displacement : public DisplacementBase<Displacement<_Scalar> >{
160 public:
162  typedef _Scalar Scalar;
163 protected:
166 public:
168  typedef typename internal::traits<Displacement>::Coefficients Coefficients;
169  // inherit assignement operator
170  EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Displacement<Scalar>)
171 
172 
173  inline Displacement() : m_coeffs() {}
175  inline Displacement(const Displacement& other) : m_coeffs(other.get() ) {}
176  //EIGEN_STRONG_INLINE Displacement(const typename Base::PlainObject& g) : m_coeffs(g.get() ) {} // [XXX] Plain object must be a Displacement
178  template<typename Derived>
179  inline Displacement(const DisplacementBase<Derived>& other) : m_coeffs(other.get() ) {}
181  inline Displacement(const Array<Scalar, 7, 1>& g) : m_coeffs(g) {}
182  template<typename Derived>
183  explicit inline Displacement(const MatrixBase<Derived>& other) { *this = other; }
190  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) {
191  // m_coeffs << qx, qy, qz, qw, x, y, z // operator<< is not inlined
192  m_coeffs[0] = qx;
193  m_coeffs[1] = qy;
194  m_coeffs[2] = qz;
195  m_coeffs[3] = qw;
196  m_coeffs[4] = x;
197  m_coeffs[5] = y;
198  m_coeffs[6] = z;
199  }
200 
201 
203  EIGEN_STRONG_INLINE Displacement(const typename Base::Vector3& v, const typename Base::Rotation3D& r/* = Base::Rotation3D::Identity()*/) {
204  this->getTranslation() = v;
205  this->getRotation() = r;
206  }
207 
209  inline Coefficients& get() { return m_coeffs; }
211  inline const Coefficients& get() const { return m_coeffs; }
212 
213 protected:
215  Coefficients m_coeffs;
216 };
217 
222 
223 /**************************************
224  * Implementation of Map<Displacement>
225  **************************************/
226 
227 namespace internal {
228  template<typename _Scalar, int MapOptions, typename StrideType>
229  struct traits<Map<Displacement<_Scalar>, MapOptions, StrideType> > : Map<LieGroup<Array<_Scalar, 7, 1> >, MapOptions, StrideType>
230  {
232  typedef _Scalar Scalar;
233  };
234 }
245 template<typename _Scalar, int MapOptions, typename StrideType>
246 class Map<Displacement<_Scalar>, MapOptions, StrideType> : public DisplacementBase<Map<Displacement<_Scalar>, MapOptions, StrideType> >{
247  protected:
248  typedef _Scalar Scalar;
250  public:
251 
252  EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Map)
253  typedef typename internal::traits<Map>::Coefficients Coefficients;
254 
255  inline Map(const Displacement<_Scalar>& d) : m_coeffs(d.get()) {};
256  template<int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
257  inline Map(const Array<Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& g) : m_coeffs(g.data()) {};
258 
259  inline Map(Scalar* data) : m_coeffs(data) {};
260  inline Map(const Map& m) : m_coeffs(m.get()) {};
261 
262  inline Coefficients& get() { return m_coeffs; }
263  inline const Coefficients& get() const { return m_coeffs; }
264 
265  protected:
266  Coefficients m_coeffs;
267 };
268 
269 #endif
270 
Scalar qw() const
Definition: Displacement.h:72
Scalar & qx()
Definition: Displacement.h:81
Scalar qz() const
Definition: Displacement.h:70
Base class describing a rigid Displacement or a 3D Frame position.
Definition: Displacement.h:28
Displacement(const DisplacementBase< Derived > &other)
Definition: Displacement.h:179
Displacement(const MatrixBase< Derived > &other)
Definition: Displacement.h:183
DisplacementBase< Map< Displacement< Scalar > > > Base
Definition: Displacement.h:249
_Scalar Scalar
Definition: Displacement.h:162
Scalar x() const
Definition: Displacement.h:60
EIGEN_STRONG_INLINE Displacement(const typename Base::Vector3 &v, const typename Base::Rotation3D &r)
Definition: Displacement.h:203
Scalar & x()
Definition: Displacement.h:75
internal::traits< Displacement >::Coefficients Coefficients
Definition: Displacement.h:168
Scalar & z()
Definition: Displacement.h:79
Scalar & qy()
Definition: Displacement.h:83
Scalar & qz()
Definition: Displacement.h:85
Map< Vector3 > getTranslation()
Definition: Displacement.h:54
Displacement(const Displacement &other)
Definition: Displacement.h:175
DisplacementBase< Displacement< Scalar > > Base
Definition: Displacement.h:165
Displacement(const Array< Scalar, 7, 1 > &g)
Definition: Displacement.h:181
const Map< const Rotation3D > getRotation() const
Definition: Displacement.h:52
Base class for all Lie Group class.
Definition: LieGroup.h:39
Displacement< double > Displacementd
Definition: Displacement.h:219
internal::traits< Derived >::PlainObject PlainObject
Definition: LieGroup.h:49
Map< Rotation3D > getRotation()
Definition: Displacement.h:50
Coefficients m_coeffs
Definition: Displacement.h:215
Scalar & qw()
Definition: Displacement.h:87
internal::cast_return_type< Derived, Displacement< NewScalarType > >::type cast() const
Definition: Displacement.h:100
Base class for all Lie Algebra class.
Definition: Displacement.h:139
Map(const Array< Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &g)
Definition: Displacement.h:257
LieGroupBase< Array< Scalar, 7, 1 >, Derived > Base
Definition: Displacement.h:34
Scalar qy() const
Definition: Displacement.h:68
Scalar y() const
Definition: Displacement.h:62
Displacement< float > Displacementf
Definition: Displacement.h:221
Scalar qx() const
Definition: Displacement.h:66
Matrix< Scalar, 4, 4 > toHomogeneousMatrix() const
Definition: Displacement.h:119
Class describing an element of a Lie Group.
Definition: LieGroup.h:117
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)
Definition: Displacement.h:190
EIGEN_STRONG_INLINE DisplacementBase & operator=(const typename Base::PlainObject &g)
Definition: Displacement.h:106
Scalar z() const
Definition: Displacement.h:64
internal::traits< Derived >::Scalar Scalar
Definition: Displacement.h:31
const Map< const Vector3 > getTranslation() const
Definition: Displacement.h:56
Scalar & y()
Definition: Displacement.h:77
Class describing a rigid Displacement or a 3D Frame position.
Definition: Displacement.h:159


lgsm
Author(s): Roberto Martín-Martín
autogenerated on Mon Jun 10 2019 14:05:58