10 #ifndef EIGEN_LGSM_LIE_SE3_H 11 #define EIGEN_LGSM_LIE_SE3_H 14 template<
typename Other,
15 int OtherRows=Other::RowsAtCompileTime,
16 int OtherCols=Other::ColsAtCompileTime>
36 template<
class Derived>
42 typedef typename internal::traits<Derived>::Scalar
Scalar;
46 typedef typename internal::traits<Derived>::Coefficients
Coefficients;
48 typedef typename internal::traits<Derived>::PlainObject
PlainObject;
63 EIGEN_STRONG_INLINE PlainObject inverse()
const;
65 static PlainObject Identity();
71 template<
class OtherDerived>
inline Vector3 operator*(
const MatrixBase<OtherDerived>& d)
const;
74 AdjointMatrix adjoint(
void)
const;
76 template<
class AlgebraDerived>
inline Algebra adjoint(
const LieAlgebraBase<Matrix<Scalar, 6, 1>, AlgebraDerived>& )
const;
78 template<
class AlgebraDualDerived>
inline AlgebraDual adjointTr(
const LieAlgebraDualBase<Matrix<Scalar, 6, 1>, AlgebraDualDerived>& )
const;
83 inline Algebra log(
const Scalar precision = 1e-6)
const;
90 template<
class OtherDerived> Derived& operator=(
const MatrixBase<OtherDerived>& m);
93 inline const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
95 inline Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
98 inline Map<SO3Element>
getSO3Element(){
return Map<SO3Element>(this->derived().get().template head<4>().data()); }
100 inline Map<const SO3Element>
getSO3Element()
const{
return Map<const SO3Element>(this->derived().get().template head<4>().data()); }
103 inline Map<Vector3>
getR3Element(){
return Map<Vector3>(this->
get().
template tail<3>().data()); }
105 inline Map<const Vector3>
getR3Element()
const {
return Map<const Vector3>(this->
get().
template tail<3>().data()); }
108 Coefficients&
get() {
return derived().get(); }
110 const Coefficients&
get()
const {
return derived().get(); }
113 template<
class OtherDerived>
114 friend std::ostream& operator <<(std::ostream& os, const LieGroupBase<Array<typename internal::traits<Derived>::Scalar, 7, 1>, Derived>& g);
122 template<
class Derived>
126 this->
get() = other.
get();
130 template<
class Derived>
131 template<
class OtherDerived>
135 this->
get() = other.
get();
139 template<
class Derived>
140 template<
class MatrixDerived>
144 EIGEN_STATIC_ASSERT((internal::is_same<typename Derived::Scalar, typename MatrixDerived::Scalar>::value),
145 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
152 template<
class Derived>
156 return PlainObject(-(this->getSO3Element().inverse().
operator*(this->getR3Element()))
157 , this->getSO3Element().inverse());
161 template<
class Derived>
172 template<
class Derived>
173 template<
class OtherDerived> EIGEN_STRONG_INLINE
177 return PlainObject(this->getSO3Element() * other.getR3Element() + this->getR3Element()
178 , this->getSO3Element() * other.getSO3Element());
182 template<
class Derived>
183 template<
class OtherDerived> EIGEN_STRONG_INLINE
187 this->getR3Element() = this->getSO3Element() * other.getR3Element() + this->getR3Element();
188 this->getSO3Element() *= other.getSO3Element();
196 template<
class Derived>
197 template<
class OtherDerived> EIGEN_STRONG_INLINE
201 return Vector3(this->getSO3Element() * vec + this->getR3Element());
205 template<
class Derived>
211 const Scalar n2 = ang.squaredNorm();
214 return Algebra(ang, this->getR3Element());
217 const Scalar n = std::sqrt(n2);
219 #ifndef USE_RLAB_LOG_FUNCTION //Set in Lgsm file 220 const Scalar sn = std::sin(n);
224 Vector3 lin = -0.5*ang.cross(this->getR3Element());
225 lin += (
Scalar(1.0) - val * n2 ) * this->getR3Element();
226 lin += val * ang.dot(this->getR3Element()) * ang;
236 const Scalar n_div2 = n/2.0;
237 const Scalar s = std::sin(n_div2) / n_div2;
238 const Scalar c = std::cos(n_div2);
239 const Scalar gamma = c / s;
241 Eigen::Matrix<double, 3, 3> dexpinv = Eigen::Matrix<double, 3, 3>::Identity();
247 Eigen::Matrix<double, 3, 3> w_ceil = Eigen::Matrix<double, 3, 3>::Zero();
255 Eigen::Matrix<double, 3, 3> w_ceil_sqr = Eigen::Matrix<double, 3, 3>::Zero();
256 double v1sqr = v1 * v1;
257 double v2sqr = v2 * v2;
258 double v3sqr = v3 * v3;
259 double v12 = v1 * v2;
260 double v13 = v1 * v3;
261 double v23 = v2 * v3;
263 w_ceil_sqr(0, 0) = -v2sqr - v3sqr;
264 w_ceil_sqr(0, 1) = v12;
265 w_ceil_sqr(0, 2) = v13;
266 w_ceil_sqr(1, 0) = v12;
267 w_ceil_sqr(1, 1) = -v1sqr - v3sqr;
268 w_ceil_sqr(1, 2) = v23;
269 w_ceil_sqr(2, 0) = v13;
270 w_ceil_sqr(2, 1) = v23;
271 w_ceil_sqr(2, 2) = -v1sqr - v2sqr;
273 dexpinv += -0.5 * w_ceil + (1 - gamma) / n2 * w_ceil_sqr;
275 Vector3 lin = dexpinv*this->getR3Element();
316 template<
class Derived>
322 res.template block<3,3>(0,0) = this->getSO3Element().
adjoint();
323 res.template block<3,3>(3,3) = res.template block<3,3>(0,0);
326 res.template block<3,3>(3,0) = (Matrix<Scalar,3,3>() <<
327 0, -this->getR3Element()[2], this->getR3Element()[1],
328 this->getR3Element()[2], 0, -this->getR3Element()[0],
329 -this->getR3Element()[1], this->getR3Element()[0], 0)
330 .finished()*res.template block<3,3>(0,0);
332 (res.template block<3,3>(0,3)).setZero();
341 template<
class Derived>
342 template<
class AlgebraDerived>
346 Vector3 Rw = this->getSO3Element() * a.getso3Element();
349 Vector3 lin = this->getR3Element().cross(Rw) + this->getSO3Element() * a.getR3Element();
358 template<
class Derived>
359 template<
class AlgebraDualDerived>
363 return AlgebraDual(this->getSO3Element().inverse() * (ca.getR3Element().cross(this->getR3Element() ) + ca.getso3Element()),
364 this->getSO3Element().inverse() * ca.getR3Element());
383 template<
typename _Scalar>
class LieGroup<Array<_Scalar, 7, 1> > :
384 public LieGroupBase<Array<_Scalar, 7, 1>, LieGroup<Array<_Scalar, 7, 1> > >
395 EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(
LieGroup)
402 inline LieGroup(
const Array<Scalar, 7, 1>& g) : m_coeffs(g) {}
410 inline LieGroup(Scalar x, Scalar y, Scalar z, Scalar qw, Scalar qx, Scalar qy, Scalar qz) {
421 EIGEN_STRONG_INLINE
LieGroup(
const typename Base::Vector3& v,
const typename Base::SO3Element& r) {
422 this->getR3Element() = v;
423 this->getSO3Element() = r;
425 template<
typename Derived>
426 explicit inline LieGroup(
const MatrixBase<Derived>& other) {
this = other;}
429 Coefficients&
get() {
return m_coeffs; }
431 const Coefficients&
get()
const {
return m_coeffs; }
440 template<
typename Other>
445 template<
class Derived>
inline static void run(
LieGroupBase<Array<
typename internal::traits<Derived>::Scalar, 7, 1>, Derived>& q,
const Other& m)
447 q.getSO3Element().get() = m.template topLeftCorner<3,3>();
448 q.getR3Element() = m.template topRightCorner<3,1>();
453 template<
typename Other>
458 template<
class Derived>
inline static void run(
LieGroupBase<Array<
typename internal::traits<Derived>::Scalar, 7, 1>, Derived>& q,
const Other& vec)
460 q.getR3Element() = vec;
internal::traits< Derived >::Scalar Scalar
LieAlgebraDual< Matrix< Scalar, 6, 1 > > AlgebraDual
EIGEN_STRONG_INLINE LieGroup(const typename Base::Vector3 &v, const typename Base::SO3Element &r)
internal::traits< Derived >::Coefficients Coefficients
Matrix< Scalar, 3, 1 > Vector3
LieGroup(const Array< Scalar, 7, 1 > &g)
LieGroup< G >::Algebra Algebra
Class describing an element of a Lie Algebra.
Array< Scalar, 7, 1 > BaseType
LieAlgebra< Matrix< Scalar, 6, 1 > > Algebra
AdjointMatrix adjoint(void) const
Map< Vector3 > getR3Element()
const Derived & derived() const
LieGroup(const MatrixBase< Derived > &other)
Base class for all Lie Group class.
LieGroup(const LieGroup &g)
static void run(LieGroupBase< Array< typename internal::traits< Derived >::Scalar, 7, 1 >, Derived > &q, const Other &vec)
internal::traits< Derived >::PlainObject PlainObject
Base class for all Lie Algebra class.
static void run(LieGroupBase< Array< typename internal::traits< Derived >::Scalar, 7, 1 >, Derived > &q, const Other &m)
internal::traits< LieGroup< Array< _Scalar, 7, 1 > > >::Coefficients Coefficients
Map< const Vector3 > getR3Element() const
Map< SO3Element > getSO3Element()
Class describing an element of a Lie Group.
Class describing an element of a Lie algebra dual.
Algebra log(const Scalar precision=1e-6) const
Map< const SO3Element > getSO3Element() const
Matrix< Scalar, 6, 6 > AdjointMatrix
LieGroupBase< Array< _Scalar, 7, 1 >, LieGroup< Array< _Scalar, 7, 1 > > > Base
LieGroup(Scalar x, Scalar y, Scalar z, Scalar qw, Scalar qx, Scalar qy, Scalar qz)
LieGroup< Quaternion< Scalar > > SO3Element