pinocchio  2.1.3
force-tpl.hpp
1 //
2 // Copyright (c) 2015-2018 CNRS
3 // Copyright (c) 2015-2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5 
6 #ifndef __pinocchio_force_tpl_hpp__
7 #define __pinocchio_force_tpl_hpp__
8 
9 namespace pinocchio
10 {
11  template<typename _Scalar, int _Options>
12  struct traits< ForceTpl<_Scalar, _Options> >
13  {
14  typedef _Scalar Scalar;
15  typedef Eigen::Matrix<Scalar,3,1,_Options> Vector3;
16  typedef Eigen::Matrix<Scalar,6,1,_Options> Vector6;
17  typedef Eigen::Matrix<Scalar,6,6,_Options> Matrix6;
18  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
19  typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
20  typedef typename Vector6::template FixedSegmentReturnType<3>::Type LinearType;
21  typedef typename Vector6::template FixedSegmentReturnType<3>::Type AngularType;
22  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
23  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
25  enum {
26  LINEAR = 0,
27  ANGULAR = 3,
28  Options = _Options
29  };
30 
32  }; // traits ForceTpl
33 
34  template<typename _Scalar, int _Options>
35  class ForceTpl : public ForceDense< ForceTpl<_Scalar, _Options> >
36  {
37  public:
38  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
39  typedef ForceDense<ForceTpl> Base;
40  FORCE_TYPEDEF_TPL(ForceTpl);
41  enum { Options = _Options };
42 
43  using Base::operator=;
44  using Base::linear;
45  using Base::angular;
46 
47  // Constructors
48  ForceTpl() : m_data() {}
49 
50  template<typename V1,typename V2>
51  ForceTpl(const Eigen::MatrixBase<V1> & v, const Eigen::MatrixBase<V2> & w)
52  {
53  assert(v.size() == 3);
54  assert(w.size() == 3);
55  linear() = v; angular() = w;
56  }
57 
58  template<typename V6>
59  explicit ForceTpl(const Eigen::MatrixBase<V6> & v)
60  : m_data(v)
61  {
62  EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6);
63  assert(v.size() == 6);
64  }
65 
66  template<int O2>
67  explicit ForceTpl(const ForceTpl<Scalar,O2> & clone)
68  : m_data(clone.toVector())
69  {}
70 
71  template<typename M2>
72  explicit ForceTpl(const ForceDense<M2> & clone)
73  { linear() = clone.linear(); angular() = clone.angular(); }
74 
75  // initializers
76  static ForceTpl Zero() { return ForceTpl(Vector6::Zero()); }
77  static ForceTpl Random() { return ForceTpl(Vector6::Random()); }
78 
79  ToVectorConstReturnType toVector_impl() const { return m_data; }
80  ToVectorReturnType toVector_impl() { return m_data; }
81 
82  // Getters
83  ConstAngularType angular_impl() const { return m_data.template segment<3> (ANGULAR); }
84  ConstLinearType linear_impl() const { return m_data.template segment<3> (LINEAR); }
85  AngularType angular_impl() { return m_data.template segment<3> (ANGULAR); }
86  LinearType linear_impl() { return m_data.template segment<3> (LINEAR); }
87 
88  template<typename V3>
89  void angular_impl(const Eigen::MatrixBase<V3> & w)
90  {
91  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
92  angular_impl()=w;
93  }
94  template<typename V3>
95  void linear_impl(const Eigen::MatrixBase<V3> & v)
96  {
97  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
98  linear_impl()=v;
99  }
100 
101  ForceRef<Vector6> ref() { return ForceRef<Vector6>(m_data); }
102 
104  template<typename NewScalar>
106  {
107  typedef ForceTpl<NewScalar,Options> ReturnType;
108  ReturnType res(linear().template cast<NewScalar>(),
109  angular().template cast<NewScalar>());
110  return res;
111  }
112 
113  protected:
114  Vector6 m_data;
115 
116  }; // class ForceTpl
117 
118 } // namespace pinocchio
119 
120 #endif // ifndef __pinocchio_force_tpl_hpp__
ConstAngularType angular() const
Return the angular part of the force vector.
Definition: force-base.hpp:40
ToVectorConstReturnType toVector() const
Return the force as an Eigen vector.
Definition: force-base.hpp:86
Main pinocchio namespace.
Definition: treeview.dox:24
Common traits structure to fully define base classes for CRTP.
Definition: spatial/fwd.hpp:29
ConstLinearType linear() const
Return the linear part of the force vector.
Definition: force-base.hpp:47
ForceTpl< NewScalar, Options > cast() const
Definition: force-tpl.hpp:105