pinocchio  2.4.4
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
joint-unary-visitor.hpp
1 //
2 // Copyright (c) 2015-2019 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_multibody_visitior_joint_unary_visitor_hpp__
6 #define __pinocchio_multibody_visitior_joint_unary_visitor_hpp__
7 
8 #include <boost/variant.hpp>
9 
10 #include "pinocchio/multibody/joint/joint-base.hpp"
11 #include "pinocchio/multibody/visitor/fusion.hpp"
12 
13 namespace pinocchio
14 {
15  namespace fusion
16  {
17  namespace bf = boost::fusion;
18 
19  typedef boost::blank NoArg;
20 
26  template<typename JointVisitorDerived, typename ReturnType = void>
28  {
29 
30  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ArgsTmp>
31  static ReturnType run(const JointModelTpl<Scalar,Options,JointCollectionTpl> & jmodel,
33  ArgsTmp args)
34  {
35  InternalVisitorModelAndData<JointModelTpl<Scalar,Options,JointCollectionTpl>,ArgsTmp> visitor(jdata,args);
36  return boost::apply_visitor(visitor,jmodel);
37  }
38 
39  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
40  static ReturnType run(const JointModelTpl<Scalar,Options,JointCollectionTpl> & jmodel,
42  {
43  InternalVisitorModelAndData<JointModelTpl<Scalar,Options,JointCollectionTpl>,NoArg> visitor(jdata);
44  return boost::apply_visitor(visitor,jmodel);
45  }
46 
47  template<typename JointModelDerived, typename ArgsTmp>
48  static ReturnType run(const JointModelBase<JointModelDerived> & jmodel,
50  ArgsTmp args)
51  {
52  InternalVisitorModelAndData<JointModelDerived,ArgsTmp> visitor(jdata,args);
53  return visitor(jmodel.derived());
54  }
55 
56  template<typename JointModelDerived>
57  static ReturnType run(const JointModelBase<JointModelDerived> & jmodel,
59  {
60  InternalVisitorModelAndData<JointModelDerived,NoArg> visitor(jdata);
61  return visitor(jmodel.derived());
62  }
63 
64  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl, typename ArgsTmp>
65  static ReturnType run(const JointModelTpl<Scalar,Options,JointCollectionTpl> & jmodel,
66  ArgsTmp args)
67  {
68  InternalVisitorModel<ArgsTmp> visitor(args);
69  return boost::apply_visitor(visitor,jmodel);
70  }
71 
72  template<typename Scalar, int Options, template<typename,int> class JointCollectionTpl>
73  static ReturnType run(const JointModelTpl<Scalar,Options,JointCollectionTpl> & jmodel)
74  {
75  InternalVisitorModel<NoArg> visitor;
76  return boost::apply_visitor(visitor,jmodel);
77  }
78 
79  template<typename JointModelDerived, typename ArgsTmp>
80  static ReturnType run(const JointModelBase<JointModelDerived> & jmodel,
81  ArgsTmp args)
82  {
83  InternalVisitorModel<ArgsTmp> visitor(args);
84  return visitor(jmodel.derived());
85  }
86 
87  template<typename JointModelDerived>
88  static ReturnType run(const JointModelBase<JointModelDerived> & jmodel)
89  {
90  InternalVisitorModel<NoArg> visitor;
91  return visitor(jmodel.derived());
92  }
93 
94  private:
95 
96  template<typename JointModel, typename ArgType>
97  struct InternalVisitorModelAndData
98  : public boost::static_visitor<ReturnType>
99  {
100  typedef typename JointModel::JointDataDerived JointData;
101 
102  InternalVisitorModelAndData(JointData & jdata, ArgType args)
103  : jdata(jdata), args(args)
104  {}
105 
106  template<typename JointModelDerived>
107  ReturnType operator()(const JointModelBase<JointModelDerived> & jmodel) const
108  {
109  return bf::invoke(&JointVisitorDerived::template algo<JointModelDerived>,
110  bf::append(boost::ref(jmodel.derived()),
111  boost::ref(boost::get<typename JointModelBase<JointModelDerived>::JointDataDerived >(jdata)),
112  args));
113  }
114 
115  ReturnType operator()(const JointModelVoid) {return;}
116 
117  JointData & jdata;
118  ArgType args;
119  };
120 
121  template<typename JointModel>
122  struct InternalVisitorModelAndData<JointModel,NoArg>
123  : public boost::static_visitor<ReturnType>
124  {
125  typedef typename JointModel::JointDataDerived JointData;
126 
127  InternalVisitorModelAndData(JointData & jdata)
128  : jdata(jdata)
129  {}
130 
131  template<typename JointModelDerived>
132  ReturnType operator()(const JointModelBase<JointModelDerived> & jmodel) const
133  {
134  return bf::invoke(&JointVisitorDerived::template algo<JointModelDerived>,
135  bf::make_vector(boost::ref(jmodel.derived()),
136  boost::ref(boost::get<typename JointModelBase<JointModelDerived>::JointDataDerived >(jdata))));
137  }
138 
139  JointData & jdata;
140  };
141 
142  template<typename ArgType, typename Dummy = void>
143  struct InternalVisitorModel
144  : public boost::static_visitor<ReturnType>
145  {
146  InternalVisitorModel(ArgType args)
147  : args(args)
148  {}
149 
150  template<typename JointModelDerived>
151  ReturnType operator()(const JointModelBase<JointModelDerived> & jmodel) const
152  {
153  return bf::invoke(&JointVisitorDerived::template algo<JointModelDerived>,
154  bf::append(boost::ref(jmodel.derived()),
155  args));
156  }
157 
158  ReturnType operator()(const JointModelVoid) {return;}
159 
160  ArgType args;
161  };
162 
163  template<typename Dummy>
164  struct InternalVisitorModel<NoArg,Dummy>
165  : public boost::static_visitor<ReturnType>
166  {
167  InternalVisitorModel() {}
168 
169  template<typename JointModelDerived>
170  ReturnType operator()(const JointModelBase<JointModelDerived> & jmodel) const
171  {
172  return JointVisitorDerived::template algo<JointModelDerived>(jmodel.derived());
173  }
174  };
175  }; // struct JointUnaryVisitorBase
176 
180  template<typename JointVisitorDerived, typename ReturnType = void>
181  struct PINOCCHIO_DEPRECATED JointVisitorBase
182  : JointUnaryVisitorBase<JointVisitorDerived,ReturnType>
183  {
185  using Base::run;
186  };
187 
188  } // namespace fusion
189 } // namespace pinocchio
190 
191 #endif // ifndef __pinocchio_multibody_visitior_joint_unary_visitor_hpp__
Base structure for Unary visitation of a JointModel. This structure provides runners to call the righ...
This helper structure is now deprecated and has been replaced by JointUnaryVisitorBase.
Main pinocchio namespace.
Definition: treeview.dox:24