19 #ifndef __se3_se3_hpp__ 20 #define __se3_se3_hpp__ 22 #include <Eigen/Geometry> 23 #include "pinocchio/spatial/fwd.hpp" 24 #include "pinocchio/spatial/skew.hpp" 25 #include "pinocchio/macros.hpp" 34 struct SE3GroupAction {
typedef D ReturnType; };
49 template<
class Derived>
54 typedef Derived Derived_t;
55 SPATIAL_TYPEDEF_TEMPLATE(Derived_t);
58 Derived_t & derived() {
return *
static_cast<Derived_t*
>(
this); }
59 const Derived_t& derived()
const {
return *
static_cast<const Derived_t*
>(
this); }
61 ConstAngular_t & rotation()
const {
return derived().rotation_impl(); }
62 ConstLinear_t & translation()
const {
return derived().translation_impl(); }
63 Angular_t & rotation() {
return derived().rotation_impl(); }
64 Linear_t & translation() {
return derived().translation_impl(); }
65 void rotation(
const Angular_t & R) { derived().rotation_impl(R); }
66 void translation(
const Linear_t & R) { derived().translation_impl(R); }
69 Matrix4 toHomogeneousMatrix()
const 71 return derived().toHomogeneousMatrix_impl();
73 operator Matrix4()
const {
return toHomogeneousMatrix(); }
75 Matrix6 toActionMatrix()
const 77 return derived().toActionMatrix_impl();
79 operator Matrix6()
const {
return toActionMatrix(); }
81 Matrix6 toDualActionMatrix()
const {
return derived().toDualActionMatrix_impl(); }
85 void disp(std::ostream & os)
const 87 static_cast<const Derived_t*
>(
this)->disp_impl(os);
90 Derived_t operator*(
const Derived_t & m2)
const {
return derived().__mult__(m2); }
94 typename internal::SE3GroupAction<D>::ReturnType
act (
const D & d)
const 96 return derived().act_impl(d);
100 template<
typename D>
typename internal::SE3GroupAction<D>::ReturnType
actInv(
const D & d)
const 102 return derived().actInv_impl(d);
106 Derived_t act (
const Derived_t& m2)
const {
return derived().act_impl(m2); }
107 Derived_t actInv(
const Derived_t& m2)
const {
return derived().actInv_impl(m2); }
110 bool operator==(
const Derived_t & other)
const {
return derived().__equal__(other); }
111 bool operator!=(
const Derived_t & other)
const {
return !(*
this == other); }
113 bool isApprox (
const Derived_t & other,
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 115 return derived().isApprox_impl(other, prec);
118 friend std::ostream & operator << (std::ostream & os,const SE3Base<Derived> & X)
129 return derived().isIdentity(prec);
135 template<
typename T,
int U>
139 typedef Eigen::Matrix<T,3,1,U> Vector3;
140 typedef Eigen::Matrix<T,4,1,U> Vector4;
141 typedef Eigen::Matrix<T,6,1,U> Vector6;
142 typedef Eigen::Matrix<T,3,3,U> Matrix3;
143 typedef Eigen::Matrix<T,4,4,U> Matrix4;
144 typedef Eigen::Matrix<T,6,6,U> Matrix6;
145 typedef Matrix3 Angular_t;
146 typedef const Matrix3 ConstAngular_t;
147 typedef Vector3 Linear_t;
148 typedef const Vector3 ConstLinear_t;
149 typedef Matrix6 ActionMatrix_t;
150 typedef Eigen::Quaternion<T,U> Quaternion_t;
161 template<
typename _Scalar,
int _Options>
166 friend class SE3Base< SE3Tpl< _Scalar, _Options > >;
167 SPATIAL_TYPEDEF_TEMPLATE(SE3Tpl);
168 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
171 SE3Tpl(): rot(), trans() {};
174 template<
typename M3,
typename v3>
175 SE3Tpl(
const Eigen::MatrixBase<M3> & R,
const Eigen::MatrixBase<v3> & p)
178 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(v3,3)
179 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M3,3,3)
182 template<
typename M4>
183 explicit SE3Tpl(
const Eigen::MatrixBase<M4> & m)
184 : rot(m.template block<3,3>(LINEAR,LINEAR)), trans(m.template block<3,1>(LINEAR,ANGULAR))
186 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(M4,4,4);
189 SE3Tpl(
int) : rot(Matrix3::Identity()), trans(Vector3::Zero()) {}
191 template<
typename S2,
int O2>
193 : rot(clone.rotation()),trans(clone.translation()) {}
196 template<
typename S2,
int O2>
199 rot = other.rotation ();
200 trans = other.translation ();
204 static SE3Tpl Identity()
209 SE3Tpl & setIdentity () { rot.setIdentity (); trans.setZero ();
return *
this;}
214 return SE3Tpl(rot.transpose(), -rot.transpose()*trans);
217 static SE3Tpl Random()
219 Quaternion_t q(Vector4::Random());
221 return SE3Tpl(q.matrix(),Vector3::Random());
224 SE3Tpl & setRandom ()
226 Quaternion_t q(Vector4::Random());
234 Matrix4 toHomogeneousMatrix_impl()
const 237 M.template block<3,3>(LINEAR,LINEAR) = rot;
238 M.template block<3,1>(LINEAR,ANGULAR) = trans;
239 M.template block<1,3>(ANGULAR,LINEAR).setZero();
247 typedef Eigen::Block<Matrix6,3,3> Block3;
249 M.template block<3,3>(ANGULAR,ANGULAR)
250 = M.template block<3,3>(LINEAR,LINEAR) = rot;
251 M.template block<3,3>(ANGULAR,LINEAR).setZero();
252 Block3 B = M.template block<3,3>(LINEAR,ANGULAR);
254 B.col(0) = trans.cross(rot.col(0));
255 B.col(1) = trans.cross(rot.col(1));
256 B.col(2) = trans.cross(rot.col(2));
260 Matrix6 toDualActionMatrix_impl()
const 262 typedef Eigen::Block<Matrix6,3,3> Block3;
264 M.template block<3,3>(ANGULAR,ANGULAR)
265 = M.template block<3,3>(LINEAR,LINEAR) = rot;
266 M.template block<3,3>(LINEAR,ANGULAR).setZero();
267 Block3 B = M.template block<3,3>(ANGULAR,LINEAR);
269 B.col(0) = trans.cross(rot.col(0));
270 B.col(1) = trans.cross(rot.col(1));
271 B.col(2) = trans.cross(rot.col(2));
275 void disp_impl(std::ostream & os)
const 277 os <<
" R =\n" << rot << std::endl
278 <<
" p = " << trans.transpose() << std::endl;
285 typename internal::SE3GroupAction<D>::ReturnType
act_impl (
const D & d)
const 287 return d.se3Action(*
this);
290 template<
typename D>
typename internal::SE3GroupAction<D>::ReturnType
actInv_impl(
const D & d)
const 292 return d.se3ActionInverse(*
this);
295 template<
typename EigenDerived>
296 typename EigenDerived::PlainObject actOnEigenObject(
const Eigen::MatrixBase<EigenDerived> & p)
const 297 {
return (rot*p+trans).eval(); }
299 template<
typename MapDerived>
300 Vector3 actOnEigenObject(
const Eigen::MapBase<MapDerived> & p)
const 301 {
return Vector3(rot*p+trans); }
303 template<
typename EigenDerived>
304 typename EigenDerived::PlainObject actInvOnEigenObject(
const Eigen::MatrixBase<EigenDerived> & p)
const 305 {
return (rot.transpose()*(p-trans)).eval(); }
307 template<
typename MapDerived>
308 Vector3 actInvOnEigenObject(
const Eigen::MapBase<MapDerived> & p)
const 309 {
return Vector3(rot.transpose()*(p-trans)); }
311 Vector3 act_impl (
const Vector3& p)
const {
return Vector3(rot*p+trans); }
312 Vector3 actInv_impl(
const Vector3& p)
const {
return Vector3(rot.transpose()*(p-trans)); }
314 SE3Tpl act_impl (
const SE3Tpl& m2)
const {
return SE3Tpl( rot*m2.rot,trans+rot*m2.trans);}
315 SE3Tpl actInv_impl (
const SE3Tpl& m2)
const {
return SE3Tpl( rot.transpose()*m2.rot, rot.transpose()*(m2.trans-trans));}
318 SE3Tpl __mult__(
const SE3Tpl & m2)
const {
return this->act(m2);}
320 bool __equal__(
const SE3Tpl & m2 )
const 322 return (rotation_impl() == m2.rotation() && translation_impl() == m2.translation());
325 bool isApprox_impl (
const SE3Tpl & m2,
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 327 return rot.isApprox(m2.rot, prec) && trans.isApprox(m2.trans, prec);
330 bool isIdentity(
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
const 332 return rot.isIdentity(prec) && trans.isZero(prec);
335 ConstAngular_t & rotation_impl()
const {
return rot; }
336 Angular_t & rotation_impl() {
return rot; }
337 void rotation_impl(
const Angular_t & R) { rot = R; }
338 ConstLinear_t & translation_impl()
const {
return trans;}
339 Linear_t & translation_impl() {
return trans;}
340 void translation_impl(
const Linear_t & p) { trans=p; }
350 #endif // ifndef __se3_se3_hpp__
Matrix6 toActionMatrix_impl() const
Vb.toVector() = bXa.toMatrix() * Va.toVector()
SE3Tpl inverse() const
aXb = bXa.inverse()
bool isIdentity(const typename traits< Derived >::Scalar &prec=Eigen::NumTraits< typename traits< Derived >::Scalar >::dummy_precision()) const
internal::SE3GroupAction< D >::ReturnType act_impl(const D &d) const
— GROUP ACTIONS ON M6, F6 and I6 —
internal::SE3GroupAction< D >::ReturnType act(const D &d) const
ay = aXb.act(by)
internal::SE3GroupAction< D >::ReturnType actInv(const D &d) const
by = aXb.actInv(ay)
internal::SE3GroupAction< D >::ReturnType actInv_impl(const D &d) const
by = aXb.actInv(ay)