constraint-model-visitor.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2023 INRIA
3 //
4 
5 #ifndef __pinocchio_algorithm_constraints_constraint_model_visitor_hpp__
6 #define __pinocchio_algorithm_constraints_constraint_model_visitor_hpp__
7 
9 // #include "pinocchio/algorithm/constraints/constraint-model-generic.hpp"
10 // #include "pinocchio/algorithm/constraints/constraint-data-generic.hpp"
12 
13 namespace pinocchio
14 {
15 
16  namespace fusion
17  {
18 
24  template<typename ConstraintModelVisitorDerived, typename ReturnType = void>
26  {
27 
28  template<
29  typename Scalar,
30  int Options,
31  template<typename, int> class ConstraintCollectionTpl,
32  typename ArgsTmp>
33  static ReturnType run(
36  ArgsTmp args)
37  {
39  InternalVisitorModelAndData<Scalar, Options, ConstraintCollectionTpl, ArgsTmp> visitor(
40  cdata, args);
41  return boost::apply_visitor(visitor, cmodel);
42  }
43 
44  template<
45  typename Scalar,
46  int Options,
47  template<typename, int> class ConstraintCollectionTpl,
48  typename ArgsTmp>
49  static ReturnType
51  {
53  InternalVisitorModel<Scalar, Options, ConstraintCollectionTpl, ArgsTmp> visitor(args);
54  return boost::apply_visitor(visitor, cdata);
55  }
56 
57  private:
58  template<
59  typename Scalar,
60  int Options,
61  template<typename, int> class ConstraintCollectionTpl,
62  typename ArgsTmp>
63  struct InternalVisitorModel : public boost::static_visitor<ReturnType>
64  {
67 
69  : args(args)
70  {
71  }
72 
73  template<typename ConstraintModelDerived>
75  {
76  return bf::invoke(
77  &ConstraintModelVisitorDerived::template algo<ConstraintModelDerived>,
78  bf::append(boost::ref(cmodel.derived()), args));
79  }
80 
81  template<typename ConstraintDataDerived>
82  ReturnType operator()(const ConstraintDataBase<ConstraintDataDerived> & cdata) const
83  {
84  return bf::invoke(
85  &ConstraintModelVisitorDerived::template algo<ConstraintDataDerived>,
86  bf::append(boost::ref(cdata.derived()), args));
87  }
88 
89  ArgsTmp args;
90  };
91 
92  template<
93  typename Scalar,
94  int Options,
95  template<typename, int> class ConstraintCollectionTpl,
96  typename ArgsTmp>
97  struct InternalVisitorModelAndData : public boost::static_visitor<ReturnType>
98  {
101 
103  : cdata(cdata)
104  , args(args)
105  {
106  }
107 
108  template<typename ConstraintModelDerived>
110  {
111  return bf::invoke(
112  &ConstraintModelVisitorDerived::template algo<ConstraintModelDerived>,
113  bf::append(
114  boost::ref(cmodel.derived()),
115  boost::ref(
117  cdata)),
118  args));
119  }
120 
122  ArgsTmp args;
123  };
124  };
125  } // namespace fusion
126 
130  template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
133  ConstraintModelCalcVisitor<Scalar, Options, JointCollectionTpl>>
134  {
137  typedef boost::fusion::vector<const Model &, const Data &> ArgsType;
138 
139  template<typename ConstraintModel>
140  static void algo(
142  typename ConstraintModel::ConstraintData & cdata,
143  const Model & model,
144  const Data & data)
145  {
146  cmodel.calc(model, data, cdata.derived());
147  }
148  };
149 
150  template<
151  typename Scalar,
152  int Options,
153  template<typename S, int O> class JointCollectionTpl,
154  template<typename S, int O> class ConstraintCollectionTpl>
155  void calc(
160  {
162  Algo::run(cmodel, cdata, typename Algo::ArgsType(model, data));
163  }
164 
168  template<
169  typename Scalar,
170  int Options,
171  template<typename, int> class JointCollectionTpl,
172  typename JacobianMatrix>
175  ConstraintModelJacobianVisitor<Scalar, Options, JointCollectionTpl, JacobianMatrix>>
176  {
179  typedef boost::fusion::vector<const Model &, const Data &, JacobianMatrix &> ArgsType;
180 
181  template<typename ConstraintModel>
182  static void algo(
184  typename ConstraintModel::ConstraintData & cdata,
185  const Model & model,
186  const Data & data,
187  const Eigen::MatrixBase<JacobianMatrix> & jacobian_matrix)
188  {
189  cmodel.jacobian(model, data, cdata.derived(), jacobian_matrix.const_cast_derived());
190  }
191  };
192 
193  template<
194  typename Scalar,
195  int Options,
196  template<typename S, int O> class JointCollectionTpl,
197  template<typename S, int O> class ConstraintCollectionTpl,
198  typename JacobianMatrix>
199  void jacobian(
204  const Eigen::MatrixBase<JacobianMatrix> & jacobian_matrix)
205  {
207  Algo;
208  Algo::run(
209  cmodel, cdata, typename Algo::ArgsType(model, data, jacobian_matrix.const_cast_derived()));
210  }
211 
215  template<typename Scalar, int Options, template<typename S, int O> class ConstraintCollectionTpl>
217  : boost::static_visitor<typename ConstraintCollectionTpl<Scalar, Options>::ConstraintDataVariant>
218  {
223 
224  template<typename ConstraintModel>
227  {
228  return cmodel.createData();
229  }
230 
232  {
233  return boost::apply_visitor(ConstraintModelCreateDataVisitor(), cmodel);
234  }
235  };
236 
237  template<typename Scalar, int Options, template<typename S, int O> class ConstraintCollectionTpl>
238  ConstraintDataTpl<Scalar, Options, ConstraintCollectionTpl>
240  {
242  }
243 
244  template<
245  typename Scalar,
246  int Options,
247  template<typename S, int O> class ConstraintCollectionTpl,
248  typename ConstraintDataDerived>
251  ConstraintDataComparisonOperatorVisitor<
252  Scalar,
253  Options,
254  ConstraintCollectionTpl,
255  ConstraintDataDerived>,
256  bool>
257  {
258  typedef boost::fusion::vector<const ConstraintDataDerived &> ArgsType;
259 
260  template<typename ConstraintData>
261  static bool algo(
262  const ConstraintDataBase<ConstraintData> & cdata_lhs, const ConstraintDataDerived & cdata_rhs)
263  {
264  return cdata_lhs.derived() == cdata_rhs;
265  }
266  };
267 
268  template<
269  typename Scalar,
270  int Options,
271  template<typename S, int O> class ConstraintCollectionTpl,
272  typename ConstraintDataDerived>
273  bool isEqual(
276  {
278  Scalar, Options, ConstraintCollectionTpl, ConstraintDataDerived>
279  Algo;
280  return Algo::run(cdata_generic, typename Algo::ArgsType(boost::ref(cdata.derived())));
281  }
282 
283 } // namespace pinocchio
284 
285 #endif // ifdef __pinocchio_algorithm_constraints_constraint_model_visitor_hpp__
pinocchio::ConstraintCollectionTpl
Definition: algorithm/constraints/fwd.hpp:19
pinocchio::ConstraintModelJacobianVisitor::Data
DataTpl< Scalar, Options, JointCollectionTpl > Data
Definition: constraint-model-visitor.hpp:178
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModel::operator()
ReturnType operator()(const ConstraintModelBase< ConstraintModelDerived > &cmodel) const
Definition: constraint-model-visitor.hpp:74
pinocchio::DataTpl
Definition: context/generic.hpp:25
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModelAndData::args
ArgsTmp args
Definition: constraint-model-visitor.hpp:122
omniidl_be_python_with_docstring.run
def run(tree, args)
Definition: cmake/hpp/idl/omniidl_be_python_with_docstring.py:140
pinocchio::ConstraintCollectionTpl::ConstraintDataVariant
boost::variant< RigidConstraintData > ConstraintDataVariant
Definition: algorithm/constraints/fwd.hpp:31
pinocchio::ConstraintModelCreateDataVisitor::ArgsType
fusion::NoArg ArgsType
Definition: constraint-model-visitor.hpp:219
pinocchio::ConstraintModelCalcVisitor::ArgsType
boost::fusion::vector< const Model &, const Data & > ArgsType
Definition: constraint-model-visitor.hpp:137
pinocchio::fusion::ConstraintUnaryVisitorBase::run
static ReturnType run(const ConstraintModelTpl< Scalar, Options, ConstraintCollectionTpl > &cmodel, ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > &cdata, ArgsTmp args)
Definition: constraint-model-visitor.hpp:33
pinocchio::Options
Options
Definition: joint-configuration.hpp:1082
pinocchio::ConstraintModelCreateDataVisitor::run
static ConstraintDataVariant run(const ConstraintModelVariant &cmodel)
Definition: constraint-model-visitor.hpp:231
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::python::Scalar
context::Scalar Scalar
Definition: admm-solver.cpp:29
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModel::ConstraintData
ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > ConstraintData
Definition: constraint-model-visitor.hpp:66
contact-cholesky.cmodel
cmodel
Definition: contact-cholesky.py:25
pinocchio::ConstraintModelCreateDataVisitor::ConstraintModelVariant
ConstraintCollection::ConstraintModelVariant ConstraintModelVariant
Definition: constraint-model-visitor.hpp:221
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModelAndData::cdata
ConstraintData & cdata
Definition: constraint-model-visitor.hpp:121
pinocchio::fusion::ConstraintUnaryVisitorBase::run
static ReturnType run(const ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > &cdata, ArgsTmp args)
Definition: constraint-model-visitor.hpp:50
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModel::args
ArgsTmp args
Definition: constraint-model-visitor.hpp:89
args
args
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModel::ConstraintModel
ConstraintModelTpl< Scalar, Options, ConstraintCollectionTpl > ConstraintModel
Definition: constraint-model-visitor.hpp:65
pinocchio::ConstraintModelCreateDataVisitor
ConstraintModelCreateDataVisitor fusion visitor.
Definition: constraint-model-visitor.hpp:216
pinocchio::fusion::ConstraintUnaryVisitorBase
Base structure for Unary visitation of a ConstraintModel. This structure provides runners to call the...
Definition: constraint-model-visitor.hpp:25
pinocchio::ConstraintDataTpl
Definition: constraint-data-generic.hpp:34
pinocchio::ConstraintModelJacobianVisitor::ArgsType
boost::fusion::vector< const Model &, const Data &, JacobianMatrix & > ArgsType
Definition: constraint-model-visitor.hpp:179
pinocchio::createData
ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > createData(const ConstraintModelTpl< Scalar, Options, ConstraintCollectionTpl > &cmodel)
Definition: constraint-model-visitor.hpp:239
pinocchio::ConstraintDataComparisonOperatorVisitor
Definition: constraint-model-visitor.hpp:249
pinocchio::ConstraintModelCalcVisitor::Data
DataTpl< Scalar, Options, JointCollectionTpl > Data
Definition: constraint-model-visitor.hpp:136
pinocchio::calc
void calc(const ConstraintModelTpl< Scalar, Options, ConstraintCollectionTpl > &cmodel, ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > &cdata, const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data)
Definition: constraint-model-visitor.hpp:155
pinocchio::ConstraintModelCreateDataVisitor::ConstraintCollection
ConstraintCollectionTpl< Scalar, Options > ConstraintCollection
Definition: constraint-model-visitor.hpp:220
pinocchio::ConstraintModelCreateDataVisitor::ConstraintDataVariant
ConstraintCollection::ConstraintDataVariant ConstraintDataVariant
Definition: constraint-model-visitor.hpp:222
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModel
Definition: constraint-model-visitor.hpp:63
pinocchio::ConstraintDataBase::derived
Derived & derived()
Definition: constraint-data-base.hpp:19
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModelAndData::InternalVisitorModelAndData
InternalVisitorModelAndData(ConstraintData &cdata, ArgsTmp args)
Definition: constraint-model-visitor.hpp:102
pinocchio::jacobian
void jacobian(const ConstraintModelTpl< Scalar, Options, ConstraintCollectionTpl > &cmodel, ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > &cdata, const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< JacobianMatrix > &jacobian_matrix)
Definition: constraint-model-visitor.hpp:199
fusion.hpp
pinocchio::ConstraintModelBase
Definition: constraint-model-base.hpp:15
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModelAndData::ConstraintData
ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > ConstraintData
Definition: constraint-model-visitor.hpp:100
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModel::InternalVisitorModel
InternalVisitorModel(ArgsTmp args)
Definition: constraint-model-visitor.hpp:68
pinocchio::ConstraintModelCreateDataVisitor::operator()
ConstraintDataVariant operator()(const pinocchio::ConstraintModelBase< ConstraintModel > &cmodel) const
Definition: constraint-model-visitor.hpp:226
pinocchio::ConstraintModelTpl
Definition: constraint-model-generic.hpp:34
pinocchio::isEqual
bool isEqual(const ConstraintDataTpl< Scalar, Options, ConstraintCollectionTpl > &cdata_generic, const ConstraintDataBase< ConstraintDataDerived > &cdata)
Definition: constraint-model-visitor.hpp:273
pinocchio::ConstraintModelCalcVisitor
ConstraintModelCalcVisitor fusion visitor.
Definition: constraint-model-visitor.hpp:131
pinocchio::ConstraintModelJacobianVisitor::algo
static void algo(const pinocchio::ConstraintModelBase< ConstraintModel > &cmodel, typename ConstraintModel::ConstraintData &cdata, const Model &model, const Data &data, const Eigen::MatrixBase< JacobianMatrix > &jacobian_matrix)
Definition: constraint-model-visitor.hpp:182
pinocchio::ConstraintDataComparisonOperatorVisitor::ArgsType
boost::fusion::vector< const ConstraintDataDerived & > ArgsType
Definition: constraint-model-visitor.hpp:258
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModelAndData::operator()
ReturnType operator()(const ConstraintModelBase< ConstraintModelDerived > &cmodel) const
Definition: constraint-model-visitor.hpp:109
fwd.hpp
pinocchio::ConstraintCollectionTpl::ConstraintModelVariant
boost::variant< RigidConstraintModel > ConstraintModelVariant
Definition: algorithm/constraints/fwd.hpp:30
pinocchio::ConstraintModel
ConstraintModelTpl< context::Scalar, context::Options, ConstraintCollectionTpl > ConstraintModel
Definition: algorithm/constraints/fwd.hpp:37
boost::fusion::append
result_of::push_front< V const, T >::type append(T const &t, V const &v)
Append the element T at the front of boost fusion vector V.
Definition: fusion.hpp:32
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModelAndData
Definition: constraint-model-visitor.hpp:97
pinocchio::ConstraintDataComparisonOperatorVisitor::algo
static bool algo(const ConstraintDataBase< ConstraintData > &cdata_lhs, const ConstraintDataDerived &cdata_rhs)
Definition: constraint-model-visitor.hpp:261
pinocchio::fusion::NoArg
boost::blank NoArg
Definition: fusion.hpp:20
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModelAndData::ConstraintModel
ConstraintModelTpl< Scalar, Options, ConstraintCollectionTpl > ConstraintModel
Definition: constraint-model-visitor.hpp:99
pinocchio::ConstraintModelJacobianVisitor::Model
ModelTpl< Scalar, Options, JointCollectionTpl > Model
Definition: constraint-model-visitor.hpp:177
pinocchio::ConstraintModelCalcVisitor::algo
static void algo(const pinocchio::ConstraintModelBase< ConstraintModel > &cmodel, typename ConstraintModel::ConstraintData &cdata, const Model &model, const Data &data)
Definition: constraint-model-visitor.hpp:140
pinocchio::fusion::ConstraintUnaryVisitorBase::InternalVisitorModel::operator()
ReturnType operator()(const ConstraintDataBase< ConstraintDataDerived > &cdata) const
Definition: constraint-model-visitor.hpp:82
pinocchio::ModelTpl
Definition: context/generic.hpp:20
pinocchio::ConstraintModelBase::ConstraintData
traits< Derived >::ConstraintData ConstraintData
Definition: constraint-model-base.hpp:22
pinocchio::ConstraintDataBase
Definition: constraint-data-base.hpp:14
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1082
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
pinocchio::ConstraintModelCalcVisitor::Model
ModelTpl< Scalar, Options, JointCollectionTpl > Model
Definition: constraint-model-visitor.hpp:135
pinocchio::ConstraintModelJacobianVisitor
ConstraintModelJacobianVisitor fusion visitor.
Definition: constraint-model-visitor.hpp:173


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:08