6 #ifndef __pinocchio_spatial_se3_tpl_hpp__ 
    7 #define __pinocchio_spatial_se3_tpl_hpp__ 
    9 #include "pinocchio/spatial/fwd.hpp" 
   10 #include "pinocchio/spatial/se3-base.hpp" 
   12 #include "pinocchio/math/quaternion.hpp" 
   13 #include "pinocchio/math/rotation.hpp" 
   14 #include "pinocchio/spatial/cartesian-axis.hpp" 
   16 #include <Eigen/Geometry> 
   20   template<
typename _Scalar, 
int _Options>
 
   29     typedef _Scalar Scalar;
 
   30     typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3;
 
   31     typedef Eigen::Matrix<Scalar, 4, 1, Options> Vector4;
 
   32     typedef Eigen::Matrix<Scalar, 6, 1, Options> Vector6;
 
   33     typedef Eigen::Matrix<Scalar, 3, 3, Options> Matrix3;
 
   34     typedef Eigen::Matrix<Scalar, 4, 4, Options> Matrix4;
 
   35     typedef Eigen::Matrix<Scalar, 6, 6, Options> Matrix6;
 
   36     typedef Matrix3 AngularType;
 
   37     typedef typename PINOCCHIO_EIGEN_REF_TYPE(Matrix3) AngularRef;
 
   38     typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Matrix3) ConstAngularRef;
 
   39     typedef Vector3 LinearType;
 
   40     typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector3) LinearRef;
 
   41     typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector3) ConstLinearRef;
 
   42     typedef Matrix6 ActionMatrixType;
 
   43     typedef Matrix4 HomogeneousMatrixType;
 
   47   template<
typename _Scalar, 
int _Options>
 
   50     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
 
   52     PINOCCHIO_SE3_TYPEDEF_TPL(
SE3Tpl);
 
   54     typedef Eigen::Quaternion<Scalar, Options> Quaternion;
 
   62     using Base::translation;
 
   68     template<
typename QuaternionLike, 
typename Vector3Like>
 
   70       const Eigen::QuaternionBase<QuaternionLike> & quat,
 
   71       const Eigen::MatrixBase<Vector3Like> & trans)
 
   75       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like, 3)
 
   78     template<
typename Matrix3Like, 
typename Vector3Like>
 
   79     SE3Tpl(
const Eigen::MatrixBase<Matrix3Like> & R, 
const Eigen::MatrixBase<Vector3Like> & trans)
 
   81     , trans(trans){EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3Like, 3)
 
   82                      EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3Like, 3, 3)}
 
   89     template<
typename S2, 
int O2>
 
   92       *
this = other.template cast<Scalar>();
 
   95     template<
typename Matrix4Like>
 
   96     explicit SE3Tpl(
const Eigen::MatrixBase<Matrix4Like> & m)
 
   97     : rot(m.template block<3, 3>(LINEAR, LINEAR))
 
   98     , trans(m.template block<3, 1>(LINEAR, ANGULAR))
 
  100       EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix4Like, 4, 4);
 
  104     : rot(AngularType::Identity())
 
  105     , trans(LinearType::Zero())
 
  111     : rot(clone.rotation())
 
  112     , trans(clone.translation())
 
  119       rot = other.rotation();
 
  120       trans = other.translation();
 
  131       rot = other.rotation();
 
  132       trans = other.translation();
 
  141     SE3Tpl & setIdentity()
 
  151       return SE3Tpl(rot.transpose(), -rot.transpose() * trans);
 
  156       return SE3Tpl().setRandom();
 
  169     HomogeneousMatrixType toHomogeneousMatrix_impl()
 const 
  171       HomogeneousMatrixType M;
 
  172       M.template block<3, 3>(LINEAR, LINEAR) = rot;
 
  173       M.template block<3, 1>(LINEAR, ANGULAR) = trans;
 
  174       M.template block<1, 3>(ANGULAR, LINEAR).setZero();
 
  180     template<
typename Matrix6Like>
 
  183       typedef Eigen::Block<Matrix6Like, 3, 3> Block3;
 
  185       Matrix6Like & M = action_matrix.const_cast_derived();
 
  186       M.template block<3, 3>(ANGULAR, ANGULAR) = M.template block<3, 3>(LINEAR, LINEAR) = rot;
 
  187       M.template block<3, 3>(ANGULAR, LINEAR).setZero();
 
  188       Block3 B = M.template block<3, 3>(LINEAR, ANGULAR);
 
  190       B.col(0) = trans.cross(rot.col(0));
 
  191       B.col(1) = trans.cross(rot.col(1));
 
  192       B.col(2) = trans.cross(rot.col(2));
 
  195     ActionMatrixType toActionMatrix_impl()
 const 
  197       ActionMatrixType res;
 
  198       toActionMatrix_impl(res);
 
  202     template<
typename Matrix6Like>
 
  204     toActionMatrixInverse_impl(
const Eigen::MatrixBase<Matrix6Like> & action_matrix_inverse)
 const 
  206       typedef Eigen::Block<Matrix6Like, 3, 3> Block3;
 
  208       Matrix6Like & M = action_matrix_inverse.const_cast_derived();
 
  209       M.template block<3, 3>(ANGULAR, ANGULAR) = M.template block<3, 3>(LINEAR, LINEAR) =
 
  211       Block3 C = M.template block<3, 3>(ANGULAR, LINEAR); 
 
  212       Block3 B = M.template block<3, 3>(LINEAR, ANGULAR);
 
  214 #define PINOCCHIO_INTERNAL_COMPUTATION(axis_id, v3_in, v3_out, R, res)                             \ 
  215   CartesianAxis<axis_id>::cross(v3_in, v3_out);                                                    \ 
  216   res.col(axis_id).noalias() = R.transpose() * v3_out; 
  218       PINOCCHIO_INTERNAL_COMPUTATION(0, trans, C.col(0), rot, B);
 
  219       PINOCCHIO_INTERNAL_COMPUTATION(1, trans, C.col(0), rot, B);
 
  220       PINOCCHIO_INTERNAL_COMPUTATION(2, trans, C.col(0), rot, B);
 
  222 #undef PINOCCHIO_INTERNAL_COMPUTATION 
  227     ActionMatrixType toActionMatrixInverse_impl()
 const 
  229       ActionMatrixType res;
 
  230       toActionMatrixInverse_impl(res);
 
  234     template<
typename Matrix6Like>
 
  235     void toDualActionMatrix_impl(
const Eigen::MatrixBase<Matrix6Like> & dual_action_matrix)
 const 
  237       typedef Eigen::Block<Matrix6Like, 3, 3> Block3;
 
  239       Matrix6Like & M = dual_action_matrix.const_cast_derived();
 
  240       M.template block<3, 3>(ANGULAR, ANGULAR) = M.template block<3, 3>(LINEAR, LINEAR) = rot;
 
  241       M.template block<3, 3>(LINEAR, ANGULAR).setZero();
 
  242       Block3 B = M.template block<3, 3>(ANGULAR, LINEAR);
 
  244       B.col(0) = trans.cross(rot.col(0));
 
  245       B.col(1) = trans.cross(rot.col(1));
 
  246       B.col(2) = trans.cross(rot.col(2));
 
  249     ActionMatrixType toDualActionMatrix_impl()
 const 
  251       ActionMatrixType res;
 
  252       toDualActionMatrix_impl(res);
 
  256     void disp_impl(std::ostream & os)
 const 
  258       os << 
"  R =\n" << rot << std::endl << 
"  p = " << trans.transpose() << std::endl;
 
  265     typename SE3GroupAction<D>::ReturnType 
act_impl(
const D & d)
 const 
  267       return d.se3Action(*
this);
 
  272     typename SE3GroupAction<D>::ReturnType 
actInv_impl(
const D & d)
 const 
  274       return d.se3ActionInverse(*
this);
 
  277     template<
typename EigenDerived>
 
  278     typename EigenDerived::PlainObject
 
  279     actOnEigenObject(
const Eigen::MatrixBase<EigenDerived> & p)
 const 
  281       return (rotation() * p + translation()).eval();
 
  284     template<
typename MapDerived>
 
  285     Vector3 actOnEigenObject(
const Eigen::MapBase<MapDerived> & p)
 const 
  287       return Vector3(rotation() * p + translation());
 
  290     template<
typename EigenDerived>
 
  291     typename EigenDerived::PlainObject
 
  292     actInvOnEigenObject(
const Eigen::MatrixBase<EigenDerived> & p)
 const 
  294       return (rotation().transpose() * (p - translation())).eval();
 
  297     template<
typename MapDerived>
 
  298     Vector3 actInvOnEigenObject(
const Eigen::MapBase<MapDerived> & p)
 const 
  300       return Vector3(rotation().transpose() * (p - translation()));
 
  303     Vector3 
act_impl(
const Vector3 & p)
 const 
  305       return Vector3(rotation() * p + translation());
 
  310       return Vector3(rotation().transpose() * (p - translation()));
 
  314     SE3Tpl 
act_impl(
const SE3Tpl<Scalar, O2> & m2)
 const 
  316       return SE3Tpl(rot * m2.rotation(), translation() + rotation() * m2.translation());
 
  320     SE3Tpl 
actInv_impl(
const SE3Tpl<Scalar, O2> & m2)
 const 
  323         rot.transpose() * m2.rotation(), rot.transpose() * (m2.translation() - translation()));
 
  327     SE3Tpl __mult__(
const SE3Tpl<Scalar, O2> & m2)
 const 
  333     bool isEqual(
const SE3Tpl<Scalar, O2> & m2)
 const 
  335       return (rotation() == m2.rotation() && translation() == m2.translation());
 
  340       const SE3Tpl<Scalar, O2> & m2,
 
  341       const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
 const 
  343       return rotation().isApprox(m2.rotation(), prec)
 
  344              && translation().isApprox(m2.translation(), prec);
 
  347     bool isIdentity(
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
 const 
  349       return rotation().isIdentity(prec) && translation().isZero(prec);
 
  352     ConstAngularRef rotation_impl()
 const 
  356     AngularRef rotation_impl()
 
  360     void rotation_impl(
const AngularType & R)
 
  364     ConstLinearRef translation_impl()
 const 
  368     LinearRef translation_impl()
 
  372     void translation_impl(
const LinearType & p)
 
  378     template<
typename NewScalar>
 
  382       ReturnType res(rot.template cast<NewScalar>(), trans.template cast<NewScalar>());
 
  386       internal::cast_call_normalize_method<SE3Tpl, NewScalar, Scalar>::run(res);
 
  390     bool isNormalized(
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
 const 
  400     PlainType normalized()
 const 
  402       PlainType res(*
this);
 
  419     template<
typename OtherScalar>
 
  430     template<
typename Scalar, 
int Options>
 
  431     struct cast_call_normalize_method<
SE3Tpl<Scalar, Options>, Scalar, Scalar>
 
  439     template<
typename Scalar, 
int Options, 
typename NewScalar>
 
  440     struct cast_call_normalize_method<SE3Tpl<Scalar, Options>, NewScalar, Scalar>
 
  443       static void run(T & 
self)
 
  446           pinocchio::cast<NewScalar>(Eigen::NumTraits<Scalar>::epsilon())
 
  447           > Eigen::NumTraits<NewScalar>::epsilon())
 
void uniformRandom(Eigen::QuaternionBase< Derived > &q)
Uniformly random quaternion sphere.
Main pinocchio namespace.
bool isUnitary(const Eigen::MatrixBase< MatrixLike > &mat, const typename MatrixLike::RealScalar &prec=Eigen::NumTraits< typename MatrixLike::Scalar >::dummy_precision())
Check whether the input matrix is Unitary within the given precision.
Matrix3 orthogonalProjection(const Eigen::MatrixBase< Matrix3 > &mat)
Orthogonal projection of a matrix on the SO(3) manifold.
Base class for rigid transformation.
void toActionMatrix_impl(const Eigen::MatrixBase< Matrix6Like > &action_matrix) const
Vb.toVector() = bXa.toMatrix() * Va.toVector()
SE3GroupAction< D >::ReturnType actInv_impl(const D &d) const
by = aXb.actInv(ay)
static SE3Tpl Interpolate(const SE3Tpl &A, const SE3Tpl &B, const OtherScalar &alpha)
Linear interpolation on the SE3 manifold.
SE3Tpl inverse() const
aXb = bXa.inverse()
SE3Tpl< NewScalar, Options > cast() const
SE3Tpl & operator=(const SE3Tpl &other)
Copy assignment operator.
SE3GroupAction< D >::ReturnType act_impl(const D &d) const
— GROUP ACTIONS ON M6, F6 and I6 —
Common traits structure to fully define base classes for CRTP.