pinocchio  2.1.3
motion-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_motion_tpl_hpp__
7 #define __pinocchio_motion_tpl_hpp__
8 
9 namespace pinocchio
10 {
11  template<typename _Scalar, int _Options>
12  struct traits< MotionTpl<_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 Matrix6 ActionMatrixType;
19  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType;
20  typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
21  typedef typename Vector6::template FixedSegmentReturnType<3>::Type LinearType;
22  typedef typename Vector6::template FixedSegmentReturnType<3>::Type AngularType;
23  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
24  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
26  enum {
27  LINEAR = 0,
28  ANGULAR = 3,
29  Options = _Options
30  };
31 
33  }; // traits MotionTpl
34 
35  template<typename _Scalar, int _Options>
36  class MotionTpl : public MotionDense< MotionTpl< _Scalar, _Options > >
37  {
38  public:
39  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
40  typedef MotionDense<MotionTpl> Base;
41  MOTION_TYPEDEF_TPL(MotionTpl);
42  enum { Options = _Options };
43 
44  using Base::operator=;
45  using Base::linear;
46  using Base::angular;
47 
48  using Base::__plus__;
49  using Base::__opposite__;
50  using Base::__minus__;
51  using Base::__pequ__;
52  using Base::__mequ__;
53  using Base::__mult__;
54 
55  // Constructors
56  MotionTpl() : m_data() {}
57 
58  template<typename V1,typename V2>
59  MotionTpl(const Eigen::MatrixBase<V1> & v, const Eigen::MatrixBase<V2> & w)
60  {
61  assert(v.size() == 3);
62  assert(w.size() == 3);
63  linear() = v; angular() = w;
64  }
65 
66  template<typename V6>
67  explicit MotionTpl(const Eigen::MatrixBase<V6> & v)
68  : m_data(v)
69  {
70  EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6);
71  assert(v.size() == 6);
72  }
73 
74  template<int O2>
75  explicit MotionTpl(const MotionTpl<Scalar,O2> & clone)
76  : m_data(clone.toVector())
77  {}
78 
79  template<typename M2>
80  explicit MotionTpl(const MotionDense<M2> & clone)
81  { linear() = clone.linear(); angular() = clone.angular(); }
82 
83  template<typename M2>
84  explicit MotionTpl(const MotionBase<M2> & clone)
85  { *this = clone; }
86 
87  // initializers
88  static MotionTpl Zero() { return MotionTpl(Vector6::Zero()); }
89  static MotionTpl Random() { return MotionTpl(Vector6::Random()); }
90 
91  ToVectorConstReturnType toVector_impl() const { return m_data; }
92  ToVectorReturnType toVector_impl() { return m_data; }
93 
94  // Getters
95  ConstAngularType angular_impl() const { return m_data.template segment<3> (ANGULAR); }
96  ConstLinearType linear_impl() const { return m_data.template segment<3> (LINEAR); }
97  AngularType angular_impl() { return m_data.template segment<3> (ANGULAR); }
98  LinearType linear_impl() { return m_data.template segment<3> (LINEAR); }
99 
100  template<typename V3>
101  void angular_impl(const Eigen::MatrixBase<V3> & w)
102  {
103  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
104  angular_impl()=w;
105  }
106  template<typename V3>
107  void linear_impl(const Eigen::MatrixBase<V3> & v)
108  {
109  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
110  linear_impl()=v;
111  }
112 
113  // Specific operators for MotionTpl and MotionRef
114  template<int O2>
115  MotionPlain __plus__(const MotionTpl<Scalar,O2> & v) const
116  { return MotionPlain(m_data+v.toVector()); }
117 
118  template<typename Vector6ArgType>
119  MotionPlain __plus__(const MotionRef<Vector6ArgType> & v) const
120  { return MotionPlain(m_data+v.toVector()); }
121 
122  template<int O2>
123  MotionPlain __minus__(const MotionTpl<Scalar,O2> & v) const
124  { return MotionPlain(m_data-v.toVector()); }
125 
126  template<typename Vector6ArgType>
127  MotionPlain __minus__(const MotionRef<Vector6ArgType> & v) const
128  { return MotionPlain(m_data-v.toVector()); }
129 
130  template<int O2>
131  MotionTpl & __pequ__(const MotionTpl<Scalar,O2> & v)
132  { m_data += v.toVector(); return *this; }
133 
134  template<typename Vector6ArgType>
135  MotionTpl & __pequ__(const MotionRef<Vector6ArgType> & v)
136  { m_data += v.toVector(); return *this; }
137 
138  template<int O2>
139  MotionTpl & __mequ__(const MotionTpl<Scalar,O2> & v)
140  { m_data -= v.toVector(); return *this; }
141 
142  template<typename Vector6ArgType>
143  MotionTpl & __mequ__(const MotionRef<Vector6ArgType> & v)
144  { m_data -= v.toVector(); return *this; }
145 
146  template<typename OtherScalar>
147  MotionPlain __mult__(const OtherScalar & alpha) const
148  { return MotionPlain(alpha*m_data); }
149 
150  MotionRef<Vector6> ref() { return MotionRef<Vector6>(m_data); }
151 
153  template<typename NewScalar>
155  {
156  typedef MotionTpl<NewScalar,Options> ReturnType;
157  ReturnType res(linear().template cast<NewScalar>(),
158  angular().template cast<NewScalar>());
159  return res;
160  }
161 
162  protected:
163  Vector6 m_data;
164 
165  }; // class MotionTpl
166 
167 } // namespace pinocchio
168 
169 #endif // ifndef __pinocchio_motion_tpl_hpp__
Main pinocchio namespace.
Definition: treeview.dox:24
Common traits structure to fully define base classes for CRTP.
Definition: spatial/fwd.hpp:29
MotionTpl< NewScalar, Options > cast() const
Definition: motion-tpl.hpp:154