GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/spatial/cartesian-axis.hpp Lines: 39 39 100.0 %
Date: 2024-04-26 13:14:21 Branches: 5 6 83.3 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2017-2018 CNRS
3
//
4
5
#ifndef __pinocchio_cartesian_axis_hpp__
6
#define __pinocchio_cartesian_axis_hpp__
7
8
#include "pinocchio/fwd.hpp"
9
10
namespace pinocchio
11
{
12
13
  template<int _axis>
14
  struct CartesianAxis
15
  {
16
    enum { axis = _axis, dim = 3 };
17
18
    template<typename V3_in, typename V3_out>
19
    inline static void cross(const Eigen::MatrixBase<V3_in> & vin,
20
                             const Eigen::MatrixBase<V3_out> & vout);
21
22
    template<typename V3>
23
2378
    static typename PINOCCHIO_EIGEN_PLAIN_TYPE(V3) cross(const Eigen::MatrixBase<V3> & vin)
24
    {
25
2378
      typename PINOCCHIO_EIGEN_PLAIN_TYPE(V3) res;
26
2378
      cross(vin,res);
27
2378
      return res;
28
    }
29
30
    template<typename Scalar, typename V3_in, typename V3_out>
31
    inline static void alphaCross(const Scalar & s,
32
                                  const Eigen::MatrixBase<V3_in> & vin,
33
                                  const Eigen::MatrixBase<V3_out> & vout);
34
35
    template<typename Scalar, typename V3>
36
6
    static typename PINOCCHIO_EIGEN_PLAIN_TYPE(V3) alphaCross(const Scalar & s,
37
                                                    const Eigen::MatrixBase<V3> & vin)
38
    {
39
6
      typename PINOCCHIO_EIGEN_PLAIN_TYPE(V3) res;
40
6
      alphaCross(s,vin,res);
41
6
      return res;
42
    }
43
44
    template<typename Scalar>
45
14
    Eigen::Matrix<Scalar,dim,1> operator*(const Scalar & s) const
46
    {
47
      typedef Eigen::Matrix<Scalar,dim,1> ReturnType;
48
14
      ReturnType res;
49
56
      for(Eigen::DenseIndex i = 0; i < dim; ++i)
50
42
        res[i] = i == axis ? s : Scalar(0);
51
52
14
      return res;
53
    }
54
55
    template<typename Scalar>
56
    friend inline Eigen::Matrix<Scalar,dim,1>
57
6
    operator*(const Scalar & s, const CartesianAxis &)
58
    {
59
6
      return CartesianAxis() * s;
60
    }
61
62
    template<typename Vector3Like>
63
    static void setTo(const Eigen::MatrixBase<Vector3Like> v3)
64
    {
65
      Vector3Like & v3_ = PINOCCHIO_EIGEN_CONST_CAST(Vector3Like,v3);
66
      typedef typename Vector3Like::Scalar Scalar;
67
68
      for(Eigen::DenseIndex i = 0; i < dim; ++i)
69
        v3_[i] = i == axis ? Scalar(1) : Scalar(0);
70
    }
71
72
  }; // struct CartesianAxis
73
74
  template<>
75
  template<typename V3_in, typename V3_out>
76
997
  inline void CartesianAxis<0>::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
997
    V3_out & vout_ = PINOCCHIO_EIGEN_CONST_CAST(V3_out,vout);
82
997
    vout_[0] = 0.; vout_[1] = -vin[2]; vout_[2] = vin[1];
83
997
  }
84
85
  template<>
86
  template<typename V3_in, typename V3_out>
87
1359
  inline void CartesianAxis<1>::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
1359
    V3_out & vout_ = PINOCCHIO_EIGEN_CONST_CAST(V3_out,vout);
93
1359
    vout_[0] = vin[2]; vout_[1] = 0.; vout_[2] = -vin[0];
94
1359
  }
95
96
  template<>
97
  template<typename V3_in, typename V3_out>
98
525
  inline void CartesianAxis<2>::cross(const Eigen::MatrixBase<V3_in> & vin,
99
                                      const Eigen::MatrixBase<V3_out> & vout)
100
  {
101
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_in,3)
102
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_out,3)
103
525
    V3_out & vout_ = PINOCCHIO_EIGEN_CONST_CAST(V3_out,vout);
104
525
    vout_[0] = -vin[1]; vout_[1] = vin[0]; vout_[2] = 0.;
105
525
  }
106
107
  template<>
108
  template<typename Scalar, typename V3_in, typename V3_out>
109
45597
  inline void CartesianAxis<0>::alphaCross(const Scalar & s,
110
                                           const Eigen::MatrixBase<V3_in> & vin,
111
                                           const Eigen::MatrixBase<V3_out> & vout)
112
  {
113
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_in,3)
114
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_out,3)
115
45597
    V3_out & vout_ = PINOCCHIO_EIGEN_CONST_CAST(V3_out,vout);
116
45597
    vout_[0] = 0.; vout_[1] = -s*vin[2]; vout_[2] = s*vin[1];
117
45597
  }
118
119
  template<>
120
  template<typename Scalar, typename V3_in, typename V3_out>
121
73851
  inline void CartesianAxis<1>::alphaCross(const Scalar & s,
122
                                           const Eigen::MatrixBase<V3_in> & vin,
123
                                           const Eigen::MatrixBase<V3_out> & vout)
124
  {
125
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_in,3)
126
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_out,3)
127
73851
    V3_out & vout_ = PINOCCHIO_EIGEN_CONST_CAST(V3_out,vout);
128
73851
    vout_[0] = s*vin[2]; vout_[1] = 0.; vout_[2] = -s*vin[0];
129
73851
  }
130
131
  template<>
132
  template<typename Scalar, typename V3_in, typename V3_out>
133
28433
  inline void CartesianAxis<2>::alphaCross(const Scalar & s,
134
                                           const Eigen::MatrixBase<V3_in> & vin,
135
                                           const Eigen::MatrixBase<V3_out> & vout)
136
  {
137
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_in,3)
138
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3_out,3)
139
28433
    V3_out & vout_ = PINOCCHIO_EIGEN_CONST_CAST(V3_out,vout);
140
28433
    vout_[0] = -s*vin[1]; vout_[1] = s*vin[0]; vout_[2] = 0.;
141
28433
  }
142
143
  typedef CartesianAxis<0> AxisX;
144
  typedef CartesianAxis<1> AxisY;
145
  typedef CartesianAxis<2> AxisZ;
146
147
}
148
149
#endif // __pinocchio_cartesian_axis_hpp__