hpp-pinocchio  4.9.1
Wrapping of the kinematic/dynamic chain Pinocchio for HPP.
vector-space.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of hpp-pinocchio.
5 // hpp-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 // hpp-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 // hpp-pinocchio. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HPP_PINOCCHIO_LIEGROUP_VECTOR_SPACE_OPERATION_HH
18 #define HPP_PINOCCHIO_LIEGROUP_VECTOR_SPACE_OPERATION_HH
19 
20 #include <pinocchio/multibody/liegroup/vector-space.hpp>
21 
22 #include <hpp/util/exception-factory.hh>
23 
24 #include <hpp/pinocchio/fwd.hh>
25 
26 namespace hpp {
27  namespace pinocchio {
28  namespace liegroup {
30  namespace details {
31  template <bool Test> struct assign_if {
32  template <class D1, class D2> static void run(
33  const Eigen::MatrixBase<D1> & /*Jin*/,
34  const Eigen::MatrixBase<D2> & /*Jout*/)
35  {}
36  };
37  template <> struct assign_if<true> {
38  template <class D1, class D2> static void run(
39  const Eigen::MatrixBase<D1> & Jin,
40  const Eigen::MatrixBase<D2> & Jout)
41  {
42  const_cast<Eigen::MatrixBase<D2>&> (Jout) = Jin;
43  }
44  };
45  }
47 
48  template<int Size, bool rot>
50  {
51  typedef ::pinocchio::VectorSpaceOperationTpl<Size, value_type> Base;
52  enum {
53  BoundSize = Size,
54  NR = (rot ? Size : 0),
55  NT = (rot ? 0 : Size)
56  };
57 
61  VectorSpaceOperation (int size = Size) : Base (size)
62  {
63  }
64 
65  template <class ConfigL_t, class ConfigR_t>
67  const Eigen::MatrixBase<ConfigL_t> & q0,
68  const Eigen::MatrixBase<ConfigR_t> & q1)
69  {
70  return Base::squaredDistance(q0, q1);
71  }
72 
73  template <class ConfigL_t, class ConfigR_t>
75  const Eigen::MatrixBase<ConfigL_t> & q0,
76  const Eigen::MatrixBase<ConfigR_t> & q1,
77  const typename ConfigL_t::Scalar& w)
78  {
79  if (rot) return w * squaredDistance(q0, q1);
80  else return squaredDistance(q0, q1);
81  }
82 
83  template <class ConfigIn_t, class ConfigOut_t>
84  static void setBound(
85  const Eigen::MatrixBase<ConfigIn_t > & bounds,
86  const Eigen::MatrixBase<ConfigOut_t> & out)
87  {
88  if (bounds.size() != BoundSize) {
89  HPP_THROW(std::invalid_argument, "Expected vector of size " <<
90  (int)BoundSize << ", got size " << bounds.size());
91  }
92  const_cast<Eigen::MatrixBase<ConfigOut_t>&> (out) = bounds;
93  }
94 
95  template <class JacobianIn_t, class JacobianOut_t>
97  const Eigen::MatrixBase<JacobianIn_t > & Jin,
98  const Eigen::MatrixBase<JacobianOut_t> & Jout)
99  {
100  details::assign_if<rot>::run(Jin, Jout);
101  }
102 
103  template <class ConfigIn_t>
104  static bool isNormalized(const Eigen::MatrixBase<ConfigIn_t > &, const value_type&)
105  {
106  return true;
107  }
108  };
109  } // namespace liegroup
110  } // namespace pinocchio
111 } // namespace hpp
112 
113 namespace pinocchio {
114  template<int Size, bool rot>
115  struct traits<hpp::pinocchio::liegroup::VectorSpaceOperation<Size, rot> > :
116  public traits<typename hpp::pinocchio::liegroup::VectorSpaceOperation<Size, rot>::Base>
117  {};
118 }
119 
120 #endif // HPP_PINOCCHIO_LIEGROUP_VECTOR_SPACE_OPERATION_HH
::pinocchio::VectorSpaceOperationTpl< Size, value_type > Base
Definition: vector-space.hh:51
#define HPP_THROW(TYPE, MSG)
Utility functions.
static void setBound(const Eigen::MatrixBase< ConfigIn_t > &bounds, const Eigen::MatrixBase< ConfigOut_t > &out)
Definition: vector-space.hh:84
double squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1, const typename ConfigL_t::Scalar &w)
Definition: vector-space.hh:74
double value_type
Definition: fwd.hh:40
VectorSpaceOperation(int size=Size)
Definition: vector-space.hh:61
FCL_REAL size() const
static bool isNormalized(const Eigen::MatrixBase< ConfigIn_t > &, const value_type &)
Definition: vector-space.hh:104
static void getRotationSubJacobian(const Eigen::MatrixBase< JacobianIn_t > &Jin, const Eigen::MatrixBase< JacobianOut_t > &Jout)
Definition: vector-space.hh:96
double squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1)
Definition: vector-space.hh:66