pinocchio  UNKNOWN
cartesian-axis.hpp
1 //
2 // Copyright (c) 2017-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_cartesian_axis_hpp__
19 #define __se3_cartesian_axis_hpp__
20 
21 #include <Eigen/Core>
22 
23 namespace se3
24 {
25 
26  template<int _axis>
28  {
29  enum { axis = _axis, dim = 3 };
30 
31  template<typename V3_in, typename V3_out>
32  inline static void cross(const Eigen::MatrixBase<V3_in> & vin,
33  const Eigen::MatrixBase<V3_out> & vout);
34 
35  template<typename V3>
36  static typename EIGEN_PLAIN_TYPE(V3) cross(const Eigen::MatrixBase<V3> & vin)
37  {
38  typename EIGEN_PLAIN_TYPE(V3) res;
39  cross(vin,res);
40  return res;
41  }
42 
43  template<typename Scalar>
44  Eigen::Matrix<Scalar,dim,1> operator*(const Scalar & s) const
45  {
46  typedef Eigen::Matrix<Scalar,dim,1> ReturnType;
47  ReturnType res;
48  for(Eigen::DenseIndex i = 0; i < dim; ++i)
49  res[i] = i == axis ? s : Scalar(0);
50 
51  return res;
52  }
53 
54  template<typename Scalar>
55  friend inline Eigen::Matrix<Scalar,dim,1>
56  operator*(const Scalar & s, const CartesianAxis &)
57  {
58  return CartesianAxis() * s;
59  }
60 
61  }; // struct CartesianAxis
62 
63  template<>
64  template<typename V3_in, typename V3_out>
65  inline void CartesianAxis<0>::cross(const Eigen::MatrixBase<V3_in> & vin,
66  const Eigen::MatrixBase<V3_out> & vout)
67  {
68  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_in,3)
69  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_out,3)
70  V3_out & vout_ = const_cast<Eigen::MatrixBase<V3_out> &>(vout).derived();
71  vout_[0] = 0.; vout_[1] = -vin[2]; vout_[2] = vin[1];
72  }
73 
74  template<>
75  template<typename V3_in, typename V3_out>
76  inline void CartesianAxis<1>::cross(const Eigen::MatrixBase<V3_in> & vin,
77  const Eigen::MatrixBase<V3_out> & vout)
78  {
79  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_in,3)
80  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_out,3)
81  V3_out & vout_ = const_cast<Eigen::MatrixBase<V3_out> &>(vout).derived();
82  vout_[0] = vin[2]; vout_[1] = 0.; vout_[2] = -vin[0];
83  }
84 
85  template<>
86  template<typename V3_in, typename V3_out>
87  inline void CartesianAxis<2>::cross(const Eigen::MatrixBase<V3_in> & vin,
88  const Eigen::MatrixBase<V3_out> & vout)
89  {
90  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_in,3)
91  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_out,3)
92  V3_out & vout_ = const_cast<Eigen::MatrixBase<V3_out> &>(vout).derived();
93  vout_[0] = -vin[1]; vout_[1] = vin[0]; vout_[2] = 0.;
94  }
95 
96  typedef CartesianAxis<0> AxisX;
97  typedef CartesianAxis<1> AxisY;
98  typedef CartesianAxis<2> AxisZ;
99 
100 }
101 
102 #endif // __se3_cartesian_axis_hpp__