pinocchio  UNKNOWN
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 // This file is part of Pinocchio
6 // Pinocchio is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // Pinocchio is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // Pinocchio If not, see
17 // <http://www.gnu.org/licenses/>.
18 
19 #ifndef __se3_motion_tpl_hpp__
20 #define __se3_motion_tpl_hpp__
21 
22 namespace se3
23 {
24  template<typename _Scalar, int _Options>
25  struct traits< MotionTpl<_Scalar, _Options> >
26  {
27  typedef _Scalar Scalar;
28  typedef Eigen::Matrix<Scalar,3,1,_Options> Vector3;
29  typedef Eigen::Matrix<Scalar,6,1,_Options> Vector6;
30  typedef Eigen::Matrix<Scalar,6,6,_Options> Matrix6;
31  typedef Matrix6 ActionMatrixType;
32  typedef typename EIGEN_REF_CONSTTYPE(Vector6) ToVectorConstReturnType;
33  typedef typename EIGEN_REF_TYPE(Vector6) ToVectorReturnType;
34  typedef typename Vector6::template FixedSegmentReturnType<3>::Type LinearType;
35  typedef typename Vector6::template FixedSegmentReturnType<3>::Type AngularType;
36  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinearType;
37  typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngularType;
39  enum {
40  LINEAR = 0,
41  ANGULAR = 3,
42  Options = _Options
43  };
44 
46  }; // traits MotionTpl
47 
48  template<typename _Scalar, int _Options>
49  class MotionTpl : public MotionDense< MotionTpl< _Scalar, _Options > >
50  {
51  public:
52  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53  typedef MotionDense<MotionTpl> Base;
54  MOTION_TYPEDEF_TPL(MotionTpl);
55 
56  using Base::operator=;
57  using Base::linear;
58  using Base::angular;
59 
60  using Base::__plus__;
61  using Base::__opposite__;
62  using Base::__minus__;
63  using Base::__pequ__;
64  using Base::__mequ__;
65  using Base::__mult__;
66 
67  // Constructors
68  MotionTpl() : data() {}
69 
70  template<typename V1,typename V2>
71  MotionTpl(const Eigen::MatrixBase<V1> & v, const Eigen::MatrixBase<V2> & w)
72  {
73  assert(v.size() == 3);
74  assert(w.size() == 3);
75  data << v, w;
76  }
77 
78  template<typename V6>
79  explicit MotionTpl(const Eigen::MatrixBase<V6> & v)
80  : data(v)
81  {
82  EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6);
83  assert(v.size() == 6);
84  }
85 
86  template<typename S2,int O2>
87  explicit MotionTpl(const MotionTpl<S2,O2> & clone)
88  : data(clone.toVector())
89  {}
90 
91  template<typename M2>
92  explicit MotionTpl(const MotionDense<M2> & clone)
93  { linear() = clone.linear(); angular() = clone.angular(); }
94 
95  // initializers
96  static MotionTpl Zero() { return MotionTpl(Vector6::Zero()); }
97  static MotionTpl Random() { return MotionTpl(Vector6::Random()); }
98 
99  ToVectorConstReturnType toVector_impl() const { return data; }
100  ToVectorReturnType toVector_impl() { return data; }
101 
102  // Getters
103  ConstAngularType angular_impl() const { return data.template segment<3> (ANGULAR); }
104  ConstLinearType linear_impl() const { return data.template segment<3> (LINEAR); }
105  AngularType angular_impl() { return data.template segment<3> (ANGULAR); }
106  LinearType linear_impl() { return data.template segment<3> (LINEAR); }
107 
108  template<typename V3>
109  void angular_impl(const Eigen::MatrixBase<V3> & w)
110  {
111  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
112  angular_impl()=w;
113  }
114  template<typename V3>
115  void linear_impl(const Eigen::MatrixBase<V3> & v)
116  {
117  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3,3);
118  linear_impl()=v;
119  }
120 
121  // Specific operators for MotionTpl and MotionRef
122  template<typename S2, int O2>
123  MotionPlain __plus__(const MotionTpl<S2,O2> & v) const
124  { return MotionPlain(data+v.toVector()); }
125 
126  template<typename Vector6ArgType>
127  MotionPlain __plus__(const MotionRef<Vector6ArgType> & v) const
128  { return MotionPlain(data+v.toVector()); }
129 
130  template<typename S2, int O2>
131  MotionPlain __minus__(const MotionTpl<S2,O2> & v) const
132  { return MotionPlain(data-v.toVector()); }
133 
134  template<typename Vector6ArgType>
135  MotionPlain __minus__(const MotionRef<Vector6ArgType> & v) const
136  { return MotionPlain(data-v.toVector()); }
137 
138  template<typename S2, int O2>
139  MotionTpl & __pequ__(const MotionTpl<S2,O2> & v)
140  { data += v.toVector(); return *this; }
141 
142  template<typename Vector6ArgType>
143  MotionTpl & __pequ__(const MotionRef<Vector6ArgType> & v)
144  { data += v.toVector(); return *this; }
145 
146  template<typename S2, int O2>
147  MotionTpl & __mequ__(const MotionTpl<S2,O2> & v)
148  { data -= v.toVector(); return *this; }
149 
150  template<typename Vector6ArgType>
151  MotionTpl & __mequ__(const MotionRef<Vector6ArgType> & v)
152  { data -= v.toVector(); return *this; }
153 
154  template<typename OtherScalar>
155  MotionPlain __mult__(const OtherScalar & alpha) const
156  { return MotionPlain(alpha*data); }
157 
158  MotionRef<Vector6> ref() { return MotionRef<Vector6>(data); }
159 
160  protected:
161  Vector6 data;
162 
163  }; // class MotionTpl
164 
165 } // namespace se3
166 
167 #endif // ifndef __se3_motion_tpl_hpp__