pinocchio  2.1.3
motion-ref.hpp
1 //
2 // Copyright (c) 2017-2018 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_motion_ref_hpp__
6 #define __pinocchio_motion_ref_hpp__
7 
8 namespace pinocchio
9 {
10 
11  template<typename Vector6ArgType>
12  struct traits< MotionRef<Vector6ArgType> >
13  {
14  typedef typename Vector6ArgType::Scalar Scalar;
15  typedef typename PINOCCHIO_EIGEN_PLAIN_TYPE(Vector6ArgType) Vector6;
16  enum {
17  LINEAR = 0,
18  ANGULAR = 3,
19  Options = Vector6::Options
20  };
21  typedef Eigen::Matrix<Scalar,3,1,Options> Vector3;
22  typedef Eigen::Matrix<Scalar,6,6,Options> Matrix6;
23  typedef Matrix6 ActionMatrixType;
24  typedef typename Vector6ArgType::template FixedSegmentReturnType<3>::Type LinearType;
25  typedef typename Vector6ArgType::template FixedSegmentReturnType<3>::Type AngularType;
26  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
27  typedef typename Vector6ArgType::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
29  typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) DataRefType;
30  typedef DataRefType ToVectorReturnType;
31  typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) ConstDataRefType;
32  typedef ConstDataRefType ToVectorConstReturnType;
34 
35  }; // traits MotionRef
36 
37  namespace internal
38  {
39  template<typename Vector6ArgType>
40  struct SE3GroupAction< MotionRef<Vector6ArgType> >
41  {
42  typedef typename traits< MotionRef<Vector6ArgType> >::MotionPlain ReturnType;
43  };
44 
45  template<typename Vector6ArgType, typename MotionDerived>
46  struct MotionAlgebraAction< MotionRef<Vector6ArgType>, MotionDerived >
47  { typedef typename traits< MotionRef<Vector6ArgType> >::MotionPlain ReturnType; };
48 
49  }
50 
51  template<typename Vector6ArgType>
52  class MotionRef : public MotionDense< MotionRef<Vector6ArgType> >
53  {
54  public:
55  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
56  typedef MotionDense<MotionRef> Base;
57  typedef typename traits<MotionRef>::DataRefType DataRefType;
58  MOTION_TYPEDEF_TPL(MotionRef);
59 
60  using Base::operator=;
61  using Base::linear;
62  using Base::angular;
63 
64  using Base::__plus__;
65  using Base::__opposite__;
66  using Base::__minus__;
67  using Base::__pequ__;
68  using Base::__mequ__;
69  using Base::__mult__;
70 
71  MotionRef(typename PINOCCHIO_EIGEN_REF_TYPE(Vector6ArgType) v_like)
72  : m_ref(v_like)
73  {
74  EIGEN_STATIC_ASSERT(Vector6ArgType::ColsAtCompileTime == 1,
75  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
76  assert(v_like.size() == 6);
77  }
78 
79  ToVectorConstReturnType toVector_impl() const { return m_ref; }
80  ToVectorReturnType toVector_impl() { return m_ref; }
81 
82  // Getters
83  ConstAngularType angular_impl() const { return ConstAngularType(m_ref.derived(),ANGULAR); }
84  ConstLinearType linear_impl() const { return ConstLinearType(m_ref.derived(),LINEAR); }
85  AngularType angular_impl() { return m_ref.template segment<3> (ANGULAR); }
86  LinearType linear_impl() { return m_ref.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 
95  template<typename V3>
96  void linear_impl(const Eigen::MatrixBase<V3> & v)
97  {
98  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
99  linear_impl()=v;
100  }
101 
102  // Specific operators for MotionTpl and MotionRef
103  template<typename S1, int O1>
104  MotionPlain __plus__(const MotionTpl<S1,O1> & v) const
105  { return MotionPlain(m_ref+v.toVector()); }
106 
107  template<typename Vector6Like>
108  MotionPlain __plus__(const MotionRef<Vector6ArgType> & v) const
109  { return MotionPlain(m_ref+v.toVector()); }
110 
111  template<typename S1, int O1>
112  MotionPlain __minus__(const MotionTpl<S1,O1> & v) const
113  { return MotionPlain(m_ref-v.toVector()); }
114 
115  template<typename Vector6Like>
116  MotionPlain __minus__(const MotionRef<Vector6ArgType> & v) const
117  { return MotionPlain(m_ref-v.toVector()); }
118 
119  template<typename S1, int O1>
120  MotionRef & __pequ__(const MotionTpl<S1,O1> & v)
121  { m_ref += v.toVector(); return *this; }
122 
123  template<typename Vector6Like>
124  MotionRef & __pequ__(const MotionRef<Vector6ArgType> & v)
125  { m_ref += v.toVector(); return *this; }
126 
127  template<typename S1, int O1>
128  MotionRef & __mequ__(const MotionTpl<S1,O1> & v)
129  { m_ref -= v.toVector(); return *this; }
130 
131  template<typename Vector6Like>
132  MotionRef & __mequ__(const MotionRef<Vector6ArgType> & v)
133  { m_ref -= v.toVector(); return *this; }
134 
135  template<typename OtherScalar>
136  MotionPlain __mult__(const OtherScalar & alpha) const
137  { return MotionPlain(alpha*m_ref); }
138 
139  MotionRef & ref() { return *this; }
140 
141  protected:
142  DataRefType m_ref;
143 
144  }; // class MotionRef<Vector6Like>
145 
146  template<typename Vector6ArgType>
147  class MotionRef<const Vector6ArgType>
148  : public MotionDense< MotionRef<const Vector6ArgType> >
149  {
150  public:
151  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
153  typedef typename traits<MotionRef>::DataRefType DataRefType;
154  MOTION_TYPEDEF_TPL(MotionRef);
155 
156  using Base::operator=;
157  using Base::linear;
158  using Base::angular;
159 
160  using Base::__plus__;
161  using Base::__opposite__;
162  using Base::__minus__;
163  using Base::__mult__;
164 
165  MotionRef(typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6ArgType) v_like)
166  : m_ref(v_like)
167  {
168  EIGEN_STATIC_ASSERT(Vector6ArgType::ColsAtCompileTime == 1,
169  YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
170  assert(v_like.size() == 6);
171  }
172 
173  ToVectorConstReturnType toVector_impl() const { return m_ref; }
174 
175  // Getters
176  ConstAngularType angular_impl() const { return ConstAngularType(m_ref.derived(),ANGULAR); }
177  ConstLinearType linear_impl() const { return ConstLinearType(m_ref.derived(),LINEAR); }
178 
179  // Specific operators for MotionTpl and MotionRef
180  template<typename S1, int O1>
181  MotionPlain __plus__(const MotionTpl<S1,O1> & v) const
182  { return MotionPlain(m_ref+v.toVector()); }
183 
184  template<typename Vector6Like>
185  MotionPlain __plus__(const MotionRef<Vector6ArgType> & v) const
186  { return MotionPlain(m_ref+v.toVector()); }
187 
188  template<typename S1, int O1>
189  MotionPlain __minus__(const MotionTpl<S1,O1> & v) const
190  { return MotionPlain(m_ref-v.toVector()); }
191 
192  template<typename Vector6Like>
193  MotionPlain __minus__(const MotionRef<Vector6ArgType> & v) const
194  { return MotionPlain(m_ref-v.toVector()); }
195 
196  template<typename OtherScalar>
197  MotionPlain __mult__(const OtherScalar & alpha) const
198  { return MotionPlain(alpha*m_ref); }
199 
200  const MotionRef & ref() const { return *this; }
201 
202  protected:
203  DataRefType m_ref;
204 
205  }; // class MotionRef<const Vector6Like>
206 
207 } // namespace pinocchio
208 
209 #endif // ifndef __pinocchio_motion_ref_hpp__
Main pinocchio namespace.
Definition: treeview.dox:24
Common traits structure to fully define base classes for CRTP.
Definition: spatial/fwd.hpp:29