6 #ifndef __pinocchio_se3_tpl_hpp__ 7 #define __pinocchio_se3_tpl_hpp__ 9 #include <Eigen/Geometry> 10 #include "pinocchio/math/quaternion.hpp" 14 template<
typename _Scalar,
int _Options>
22 typedef _Scalar Scalar;
23 typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
24 typedef Eigen::Matrix<Scalar,4,1,Options> Vector4;
25 typedef Eigen::Matrix<Scalar,6,1,Options> Vector6;
26 typedef Eigen::Matrix<Scalar,3,3,Options> Matrix3;
27 typedef Eigen::Matrix<Scalar,4,4,Options> Matrix4;
28 typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
29 typedef Matrix3 AngularType;
30 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Matrix3) AngularRef;
31 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Matrix3) ConstAngularRef;
32 typedef Vector3 LinearType;
33 typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector3) LinearRef;
34 typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector3) ConstLinearRef;
35 typedef Matrix6 ActionMatrixType;
36 typedef Matrix4 HomogeneousMatrixType;
39 template<
typename _Scalar,
int _Options>
42 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43 PINOCCHIO_SE3_TYPEDEF_TPL(
SE3Tpl);
45 typedef Eigen::Quaternion<Scalar,Options> Quaternion;
53 using Base::translation;
55 SE3Tpl(): rot(), trans() {};
57 template<
typename Matrix3Like,
typename Vector3Like>
58 SE3Tpl(
const Eigen::MatrixBase<Matrix3Like> & R,
59 const Eigen::MatrixBase<Vector3Like> & p)
62 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like,3)
63 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3Like,3,3)
66 template<
typename Matrix4Like>
67 explicit SE3Tpl(
const Eigen::MatrixBase<Matrix4Like> & m)
68 : rot(m.template block<3,3>(LINEAR,LINEAR))
69 , trans(m.template block<3,1>(LINEAR,ANGULAR))
71 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix4Like,4,4);
75 : rot(AngularType::Identity())
76 , trans(LinearType::Zero())
81 : rot(clone.rotation()),trans(clone.translation()) {}
86 rot = other.rotation();
87 trans = other.translation();
91 static SE3Tpl Identity()
96 SE3Tpl & setIdentity()
97 { rot.setIdentity (); trans.setZero ();
return *
this;}
102 return SE3Tpl(rot.transpose(), -rot.transpose()*trans);
105 static SE3Tpl Random()
107 return SE3Tpl().setRandom();
119 HomogeneousMatrixType toHomogeneousMatrix_impl()
const 121 HomogeneousMatrixType M;
122 M.template block<3,3>(LINEAR,LINEAR) = rot;
123 M.template block<3,1>(LINEAR,ANGULAR) = trans;
124 M.template block<1,3>(ANGULAR,LINEAR).setZero();
132 typedef Eigen::Block<ActionMatrixType,3,3> Block3;
134 M.template block<3,3>(ANGULAR,ANGULAR)
135 = M.template block<3,3>(LINEAR,LINEAR) = rot;
136 M.template block<3,3>(ANGULAR,LINEAR).setZero();
137 Block3 B = M.template block<3,3>(LINEAR,ANGULAR);
139 B.col(0) = trans.cross(rot.col(0));
140 B.col(1) = trans.cross(rot.col(1));
141 B.col(2) = trans.cross(rot.col(2));
145 ActionMatrixType toDualActionMatrix_impl()
const 147 typedef Eigen::Block<ActionMatrixType,3,3> Block3;
149 M.template block<3,3>(ANGULAR,ANGULAR)
150 = M.template block<3,3>(LINEAR,LINEAR) = rot;
151 M.template block<3,3>(LINEAR,ANGULAR).setZero();
152 Block3 B = M.template block<3,3>(ANGULAR,LINEAR);
154 B.col(0) = trans.cross(rot.col(0));
155 B.col(1) = trans.cross(rot.col(1));
156 B.col(2) = trans.cross(rot.col(2));
160 void disp_impl(std::ostream & os)
const 163 <<
" R =\n" << rot << std::endl
164 <<
" p = " << trans.transpose() << std::endl;
174 return d.se3Action(*
this);
181 return d.se3ActionInverse(*
this);
184 template<
typename EigenDerived>
185 typename EigenDerived::PlainObject
186 actOnEigenObject(
const Eigen::MatrixBase<EigenDerived> & p)
const 187 {
return (rotation()*p+translation()).eval(); }
189 template<
typename MapDerived>
190 Vector3 actOnEigenObject(
const Eigen::MapBase<MapDerived> & p)
const 191 {
return Vector3(rotation()*p+translation()); }
193 template<
typename EigenDerived>
194 typename EigenDerived::PlainObject
195 actInvOnEigenObject(
const Eigen::MatrixBase<EigenDerived> & p)
const 196 {
return (rotation().transpose()*(p-translation())).eval(); }
198 template<
typename MapDerived>
199 Vector3 actInvOnEigenObject(
const Eigen::MapBase<MapDerived> & p)
const 200 {
return Vector3(rotation().transpose()*(p-translation())); }
202 Vector3 act_impl(
const Vector3 & p)
const 203 {
return Vector3(rotation()*p+translation()); }
205 Vector3 actInv_impl(
const Vector3 & p)
const 206 {
return Vector3(rotation().transpose()*(p-translation())); }
210 {
return SE3Tpl(rot*m2.rotation()
211 ,translation()+rotation()*m2.translation());}
215 {
return SE3Tpl(rot.transpose()*m2.rotation(),
216 rot.transpose()*(m2.translation()-translation()));}
220 {
return this->act_impl(m2);}
225 return (rotation() == m2.rotation() && translation() == m2.translation());
230 const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 232 return rotation().isApprox(m2.rotation(), prec)
233 && translation().isApprox(m2.translation(), prec);
236 bool isIdentity(
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 238 return rotation().isIdentity(prec) && translation().isZero(prec);
241 ConstAngularRef rotation_impl()
const {
return rot; }
242 AngularRef rotation_impl() {
return rot; }
243 void rotation_impl(
const AngularType & R) { rot = R; }
244 ConstLinearRef translation_impl()
const {
return trans;}
245 LinearRef translation_impl() {
return trans;}
246 void translation_impl(
const LinearType & p) { trans = p; }
249 template<
typename NewScalar>
253 ReturnType res(rot.template cast<NewScalar>(),
254 trans.template cast<NewScalar>());
266 #endif // ifndef __pinocchio_se3_tpl_hpp__
SE3Tpl inverse() const
aXb = bXa.inverse()
internal::SE3GroupAction< D >::ReturnType act_impl(const D &d) const
— GROUP ACTIONS ON M6, F6 and I6 —
internal::SE3GroupAction< D >::ReturnType actInv_impl(const D &d) const
by = aXb.actInv(ay)
void uniformRandom(const Eigen::QuaternionBase< Derived > &q)
Uniformly random quaternion sphere.
Main pinocchio namespace.
SE3Tpl< NewScalar, Options > cast() const
Common traits structure to fully define base classes for CRTP.
ActionMatrixType toActionMatrix_impl() const
Vb.toVector() = bXa.toMatrix() * Va.toVector()