LieGroup_SO3.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_LIE_GROUP_SO3_H
11 #define EIGEN_LGSM_LIE_GROUP_SO3_H
12 
13 /***************************************************************************
14 * Definition/implementation of LieGroupBase<Quaternion, Derived>
15 ***************************************************************************/
16 
27 template<class Derived>
28 class LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>
29 {
30 public:
31  /* List of typedef */
33  typedef typename internal::traits<Derived>::Scalar Scalar;
35  typedef Quaternion<Scalar> BaseType;
37  typedef typename internal::traits<Derived>::Coefficients Coefficients;
40 
42  typedef Matrix<Scalar, 3, 3> AdjointMatrix;
47 
49  EIGEN_STRONG_INLINE PlainObject inverse() const;
51  static PlainObject Identity();
53  template<class OtherDerived> EIGEN_STRONG_INLINE PlainObject operator*(const LieGroupBase<BaseType, OtherDerived>& other) const;
55  template<class OtherDerived> EIGEN_STRONG_INLINE Derived& operator*=(const LieGroupBase<BaseType, OtherDerived>& other);
57  template<class MatrixDerived> EIGEN_STRONG_INLINE Matrix<Scalar, 3, 1> operator*(const MatrixBase<MatrixDerived>& v) const {
58  return this->get() * v;
59  }
60 
62  inline AdjointMatrix adjoint(void) const;
64  template<class AlgebraDerived> inline Algebra adjoint(const LieAlgebraBase<Matrix<Scalar, 3, 1>, AlgebraDerived>& ) const; // not implemented yet
66  template<class AlgebraDualDerived> inline AlgebraDual adjointTr(const LieAlgebraDualBase<Matrix<Scalar, 3, 1>, AlgebraDualDerived>& ) const; // not implemented yet
67 
71  Algebra log(const Scalar precision = 1e-6) const;
72 
74  EIGEN_STRONG_INLINE LieGroupBase& operator=(const LieGroupBase& other);
76  template<class OtherDerived> EIGEN_STRONG_INLINE Derived& operator=(const LieGroupBase<BaseType, OtherDerived>& other);
78  template<class OtherDerived> Derived& operator=(const MatrixBase<OtherDerived>& m){ this->get() = m; return this->derived();}
79 
81  inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
83  inline Derived& derived() { return *static_cast<Derived*>(this); }
84 
85 
87  inline Scalar x() const { return this->get().x(); }
89  inline Scalar y() const { return this->get().y(); }
91  inline Scalar z() const { return this->get().z(); }
93  inline Scalar w() const { return this->get().w(); }
94 
96  inline Scalar& x() { return this->get().x(); }
98  inline Scalar& y() { return this->get().y(); }
100  inline Scalar& z() { return this->get().z(); }
102  inline Scalar& w() { return this->get().w(); }
103 
109  template<typename NewScalarType>
110  inline typename internal::cast_return_type<Derived, LieGroup<Quaternion<NewScalarType> > >::type cast() const
111  {
112  return typename internal::cast_return_type<Derived, LieGroup<Quaternion<NewScalarType> > >::type(
113  get().template cast<NewScalarType>());
114  }
115 
117  inline const VectorBlock<Coefficients,3> vec() const { return this->get().vec(); }
118 
120  inline VectorBlock<Coefficients,3> vec() { return this->get().vec(); }
121 
123  Coefficients& get() { return derived().get(); }
125  const Coefficients& get() const { return derived().get(); }
126 };
127 
128 /*****************************************************
129  * Implementation of LieGroupBase<Quaternion> methods
130  *****************************************************/
131 
132 // assignation
133 template<class Derived>
136 {
137  this->get() = other.get();
138  return *this;
139 }
140 
141 //assignation
142 template<class Derived>
143 template<class OtherDerived>
144 EIGEN_STRONG_INLINE Derived&
146 {
147  this->get() = other.get();
148  return derived();
149 }
150 
151 // inverse
152 template<class Derived>
155 {
156  return PlainObject(this->get().conjugate());
157 }
158 
159 // identity
160 template<class Derived>
163 {
164  return PlainObject(Quaternion<Scalar>::Identity());
165 }
166 
167 // composition
168 template<class Derived>
169 template<class OtherDerived> EIGEN_STRONG_INLINE typename LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::PlainObject
171 {
172  return PlainObject(this->get() * other.get());
173 }
174 
175 // composition
176 template<class Derived>
177 template<class OtherDerived>
178 EIGEN_STRONG_INLINE Derived&
180 {
181  this->get() *= other.get();
182  return derived();
183 }
184 
185 //log
186 template<class Derived>
189 {
190  const Scalar n2 = this->get().vec().squaredNorm();
191  const Scalar n = std::sqrt(n2);
192 
193  if (n < precision)
194  return Algebra((2 / this->get().w()) * this->get().vec());
195  else
196  return Algebra(std::atan2(2 * n * this->get().w(), this->get().w() * this->get().w() - n2) / n * this->get().vec());
197 }
198 
199 // adjoint
200 template<class Derived>
203 {
204  return this->get().toRotationMatrix();
205 }
206 
207 template<class Derived>
208 inline std::ostream& operator <<(std::ostream& os, const LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>& g)
209 {
210  os << g.w() << "\t" << g.x() << "\t" << g.y() << "\t" << g.z();
211  return os;
212 }
213 
214 /***************************************************************************
215 * Definition/implementation of LieGroup<quaternion<Scalar> >
216 ***************************************************************************/
217 
230 template<typename _Scalar> class LieGroup<Quaternion<_Scalar> > :
231  public LieGroupBase<Quaternion<_Scalar>, LieGroup<Quaternion<_Scalar> > >
232 {
233 protected:
236 public:
238  typedef _Scalar Scalar;
240  typedef typename internal::traits<LieGroup<Quaternion<Scalar> > >::Coefficients Coefficients;
241  // inherit assignement operator
242  EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(LieGroup)
243 
244 
245  inline LieGroup() : m_coeffs() {}
247  template<class OtherDerived> inline LieGroup(const LieGroupBase<typename Base::BaseType, OtherDerived>& g) : m_coeffs(g.get()) {}
249  //inline LieGroup(const LieGroup& g) : m_coeffs(g.get() ) {}
251  EIGEN_STRONG_INLINE LieGroup(const Coefficients& g) : m_coeffs(g) {}
252  EIGEN_STRONG_INLINE LieGroup(const AngleAxis<Scalar>& aa) : m_coeffs(aa) {}
255  template<class OtherDerived> inline LieGroup(Scalar w, const MatrixBase<OtherDerived>& vec)
256  : m_coeffs(w, vec.coeff(0), vec.coeff(1), vec.coeff(2))
257  {
258  // [XXX] check other size
259  }
260 
262  template<typename Derived>
263  explicit inline LieGroup(const MatrixBase<Derived> & other) { this->get() = other;}
264 
265  template<typename Derived>
266  explicit inline LieGroup(const Matrix<Scalar, 4, 1> & other) { this = other;}
267 
275  inline LieGroup(Scalar w, Scalar x, Scalar y, Scalar z) : m_coeffs(w, x, y, z) {}
276  inline LieGroup(Scalar w, const Matrix<Scalar, 3, 1> & v) : m_coeffs(w, v.x(), v.y(), v.z()) {}
277 
279  Coefficients& get() { return m_coeffs; }
281  const Coefficients& get() const { return m_coeffs; }
282 
283 protected:
285  Coefficients m_coeffs;
286 };
287 
288 /***************************************************************************
289 * Definition/implementation of Map<LieGroup<Quaternion<Scalar> > >
290 ***************************************************************************/
291 
292 // we don't need anything new
293 
294 #endif
LieGroup(Scalar w, const Matrix< Scalar, 3, 1 > &v)
Definition: LieGroup_SO3.h:276
Derived::Algebra Algebra
Definition: LieGroup.h:53
Class describing an element of a Lie Algebra.
Definition: LieAlgebra.h:168
internal::cast_return_type< Derived, LieGroup< Quaternion< NewScalarType > > >::type cast() const
Definition: LieGroup_SO3.h:110
LieGroup(const Matrix< Scalar, 4, 1 > &other)
Definition: LieGroup_SO3.h:266
CoAlgebra adjointTr(const CoAlgebra &) const
LieGroup(const LieGroupBase< typename Base::BaseType, OtherDerived > &g)
Definition: LieGroup_SO3.h:247
AdjointMatrix adjoint(void) const
internal::traits< LieGroup< Quaternion< Scalar > > >::Coefficients Coefficients
Definition: LieGroup_SO3.h:240
EIGEN_STRONG_INLINE Matrix< Scalar, 3, 1 > operator*(const MatrixBase< MatrixDerived > &v) const
Definition: LieGroup_SO3.h:57
const Derived & derived() const
Definition: LieGroup.h:80
PlainObject inverse() const
LieGroup(Scalar w, const MatrixBase< OtherDerived > &vec)
Definition: LieGroup_SO3.h:255
LieGroup(const MatrixBase< Derived > &other)
Definition: LieGroup_SO3.h:263
Base class for all Lie Group class.
Definition: LieGroup.h:39
internal::traits< Derived >::PlainObject PlainObject
Definition: LieGroup.h:49
LieGroupBase< Quaternion< _Scalar >, LieGroup< Quaternion< _Scalar > > > Base
Definition: LieGroup_SO3.h:235
Base class for all Lie Algebra class.
Definition: Displacement.h:139
LieGroup(Scalar w, Scalar x, Scalar y, Scalar z)
Definition: LieGroup_SO3.h:275
LieGroupBase & operator=(const LieGroupBase< G, OtherDerived > &)
Class describing an element of a Lie Group.
Definition: LieGroup.h:117
Class describing an element of a Lie algebra dual.
Definition: LieAlgebra.h:216
Coefficients & get()
Algebra log(const Scalar precision=1e-6) const
PlainObject operator*(const LieGroupBase< G, OtherDerived > &other) const
EIGEN_STRONG_INLINE LieGroup(const Coefficients &g)
Definition: LieGroup_SO3.h:251
static PlainObject Identity()
EIGEN_STRONG_INLINE LieGroup(const AngleAxis< Scalar > &aa)
Definition: LieGroup_SO3.h:252


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