pinocchio  UNKNOWN
liegroup-variant-visitors.hxx
1 //
2 // Copyright (c) 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_lie_group_variant_visitor_hxx__
19 #define __se3_lie_group_variant_visitor_hxx__
20 
21 #include "pinocchio/multibody/liegroup/operation-base.hpp"
22 #include "pinocchio/multibody/visitor.hpp"
23 
24 #include <string>
25 
26 #define LIE_GROUP_VISITOR(VISITOR) \
27 VISITOR(ArgsType & args) : args(args) {} \
28 ArgsType & args
29 
30 namespace se3
31 {
32 
33  namespace visitor
34  {
35  namespace bf = boost::fusion;
36 
37  template<typename Visitor>
38  struct LieGroupVisitorBase : public boost::static_visitor<>
39  {
40  template<typename D>
41  void operator() (const LieGroupBase<D> & lg) const
42  {
43  bf::invoke(&Visitor::template algo<D>,
44  bf::append(boost::ref(lg),
45  static_cast<const Visitor*>(this)->args));
46  }
47 
48  template<typename ArgsTmp>
49  static void run(const LieGroupVariant & lg,
50  ArgsTmp args)
51  {
52  return boost::apply_visitor(Visitor(args),lg);
53  }
54  };
55  }
59  struct LieGroupNqVisitor: public boost::static_visitor<int>
60  {
61  template<typename D>
62  int operator()(const LieGroupBase<D> & lg) const
63  { return lg.nq(); }
64 
65  static int run(const LieGroupVariant & lg)
66  { return boost::apply_visitor( LieGroupNqVisitor(), lg ); }
67  };
68  inline int nq(const LieGroupVariant & lg) { return LieGroupNqVisitor::run(lg); }
69 
73  struct LieGroupNvVisitor: public boost::static_visitor<int>
74  {
75  template<typename D>
76  int operator()(const LieGroupBase<D> & lg) const
77  { return lg.nv(); }
78 
79  static int run(const LieGroupVariant & lg)
80  { return boost::apply_visitor( LieGroupNvVisitor(), lg ); }
81  };
82  inline int nv(const LieGroupVariant & lg) { return LieGroupNvVisitor::run(lg); }
83 
87  struct LieGroupNameVisitor: public boost::static_visitor<std::string>
88  {
89  template<typename D>
90  std::string operator()(const LieGroupBase<D> & lg) const
91  { return lg.name(); }
92 
93  static std::string run(const LieGroupVariant & lg)
94  { return boost::apply_visitor( LieGroupNameVisitor(), lg ); }
95  };
96  inline std::string name(const LieGroupVariant & lg) { return LieGroupNameVisitor::run(lg); }
97 
101  template<typename Vector>
102  struct LieGroupNeutralVisitor: public boost::static_visitor<Vector>
103  {
104  template<typename D>
105  Vector operator()(const LieGroupBase<D> & lg) const
106  { return lg.neutral(); }
107 
108  static Vector run(const LieGroupVariant & lg)
109  { return boost::apply_visitor( LieGroupNeutralVisitor(), lg ); }
110  };
111 
112  inline Eigen::VectorXd neutral(const LieGroupVariant & lg)
114 
118  template <class ConfigIn_t, class Tangent_t, class ConfigOut_t>
119  struct LieGroupIntegrateVisitor : visitor::LieGroupVisitorBase< LieGroupIntegrateVisitor<ConfigIn_t,Tangent_t,ConfigOut_t> >
120  {
121  typedef boost::fusion::vector<const ConfigIn_t &,
122  const Tangent_t &,
123  ConfigOut_t &> ArgsType;
124 
125  LIE_GROUP_VISITOR(LieGroupIntegrateVisitor);
126 
127  template<typename LieGroupDerived>
128  static void algo(const LieGroupBase<LieGroupDerived> & lg,
129  const Eigen::MatrixBase<ConfigIn_t> & q,
130  const Eigen::MatrixBase<Tangent_t> & v,
131  const Eigen::MatrixBase<ConfigOut_t>& qout)
132  {
133  ConfigOut_t & qout_ = const_cast< ConfigOut_t& >(qout.derived());
134  lg.integrate(Eigen::Ref<const typename LieGroupDerived::ConfigVector_t>(q),
135  Eigen::Ref<const typename LieGroupDerived::TangentVector_t>(v),
136  Eigen::Ref<typename LieGroupDerived::ConfigVector_t>(qout_));
137  }
138  };
139 
140  template <class ConfigIn_t, class Tangent_t, class ConfigOut_t>
141  inline void integrate(const LieGroupVariant & lg,
142  const Eigen::MatrixBase<ConfigIn_t> & q,
143  const Eigen::MatrixBase<Tangent_t> & v,
144  const Eigen::MatrixBase<ConfigOut_t>& qout)
145  {
146  EIGEN_STATIC_ASSERT_VECTOR_ONLY(ConfigIn_t)
147  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Tangent_t)
148  EIGEN_STATIC_ASSERT_VECTOR_ONLY(ConfigOut_t)
149 
151  assert(q.size() == nq(lg));
152  assert(v.size() == nv(lg));
153  assert(qout.size() == nq(lg));
154 
155  ConfigOut_t & qout_ = const_cast< ConfigOut_t& >(qout.derived());
156  Operation::run(lg,typename Operation::ArgsType(q.derived(),v.derived(),qout_.derived()));
157  }
158 }
159 
160 #endif // ifndef __se3_lie_group_variant_visitor_hxx__
161 
std::string name(const LieGroupVariant &lg)
Visit a LieGroupVariant to get the name of it.
void integrate(const Eigen::MatrixBase< ConfigIn_t > &q, const Eigen::MatrixBase< Tangent_t > &v, const Eigen::MatrixBase< ConfigOut_t > &qout) const
Integrate a joint&#39;s configuration with a tangent vector during one unit time duration.
std::string name() const
Get name of instance.
Index nq() const
Visitor of the Lie Group neutral element.
Eigen::VectorXd neutral(const Model &model)
Return the neutral configuration element related to the model configuration space.
Lie Group visitor of the dimension of the configuration space nq.
Lie Group visitor of the dimension of the tangent space nv.
int nq(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNqVisitor to get the dimension of the joint configuration spac...
Eigen::VectorXd integrate(const Model &model, const Eigen::VectorXd &q, const Eigen::VectorXd &v)
Integrate a configuration for the specified model for a tangent vector during one unit time...
int nv(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNvVisitor to get the dimension of the joint tangent space...
Index nv() const
Get dimension of Lie Group tangent space.
ConfigVector_t neutral() const
Get neutral element as a vector.
Visitor of the Lie Group name.
Visitor of the Lie Group integrate method.