| Directory: | ./ |
|---|---|
| File: | include/pinocchio/multibody/visitor/joint-unary-visitor.hpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 49 | 50 | 98.0% |
| Branches: | 22 | 44 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2015-2023 CNRS INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_multibody_visitor_joint_unary_visitor_hpp__ | ||
| 6 | #define __pinocchio_multibody_visitor_joint_unary_visitor_hpp__ | ||
| 7 | |||
| 8 | #include <boost/variant/apply_visitor.hpp> | ||
| 9 | #include <boost/variant/get.hpp> | ||
| 10 | |||
| 11 | #include "pinocchio/multibody/visitor/fusion.hpp" | ||
| 12 | #include "pinocchio/multibody/joint/joint-base.hpp" | ||
| 13 | |||
| 14 | namespace pinocchio | ||
| 15 | { | ||
| 16 | namespace fusion | ||
| 17 | { | ||
| 18 | |||
| 19 | /// | ||
| 20 | /// \brief Base structure for \b Unary visitation of a JointModel. | ||
| 21 | /// This structure provides runners to call the right visitor according to the number of | ||
| 22 | /// arguments. This should be used when deriving new rigid body algorithms. | ||
| 23 | /// | ||
| 24 | template<typename JointVisitorDerived, typename ReturnType = void> | ||
| 25 | struct JointUnaryVisitorBase | ||
| 26 | { | ||
| 27 | |||
| 28 | template< | ||
| 29 | typename Scalar, | ||
| 30 | int Options, | ||
| 31 | template<typename, int> class JointCollectionTpl, | ||
| 32 | typename ArgsTmp> | ||
| 33 | 1392913 | static ReturnType run( | |
| 34 | const JointModelTpl<Scalar, Options, JointCollectionTpl> & jmodel, | ||
| 35 | JointDataTpl<Scalar, Options, JointCollectionTpl> & jdata, | ||
| 36 | ArgsTmp args) | ||
| 37 | { | ||
| 38 | InternalVisitorModelAndData<JointModelTpl<Scalar, Options, JointCollectionTpl>, ArgsTmp> | ||
| 39 |
2/4✓ Branch 1 taken 700654 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 700654 times.
✗ Branch 5 not taken.
|
1392913 | visitor(jdata, args); |
| 40 |
1/2✓ Branch 1 taken 700654 times.
✗ Branch 2 not taken.
|
2785826 | return boost::apply_visitor(visitor, jmodel); |
| 41 | } | ||
| 42 | |||
| 43 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 44 | 26 | static ReturnType run( | |
| 45 | const JointModelTpl<Scalar, Options, JointCollectionTpl> & jmodel, | ||
| 46 | JointDataTpl<Scalar, Options, JointCollectionTpl> & jdata) | ||
| 47 | { | ||
| 48 | InternalVisitorModelAndData<JointModelTpl<Scalar, Options, JointCollectionTpl>, NoArg> | ||
| 49 | 26 | visitor(jdata); | |
| 50 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
52 | return boost::apply_visitor(visitor, jmodel); |
| 51 | } | ||
| 52 | |||
| 53 | template<typename JointModelDerived, typename ArgsTmp> | ||
| 54 | static ReturnType run( | ||
| 55 | const JointModelBase<JointModelDerived> & jmodel, | ||
| 56 | typename JointModelBase<JointModelDerived>::JointDataDerived & jdata, | ||
| 57 | ArgsTmp args) | ||
| 58 | { | ||
| 59 | InternalVisitorModelAndData<JointModelDerived, ArgsTmp> visitor(jdata, args); | ||
| 60 | return visitor(jmodel.derived()); | ||
| 61 | } | ||
| 62 | |||
| 63 | template<typename JointModelDerived> | ||
| 64 | static ReturnType run( | ||
| 65 | const JointModelBase<JointModelDerived> & jmodel, | ||
| 66 | typename JointModelBase<JointModelDerived>::JointDataDerived & jdata) | ||
| 67 | { | ||
| 68 | InternalVisitorModelAndData<JointModelDerived, NoArg> visitor(jdata); | ||
| 69 | return visitor(jmodel.derived()); | ||
| 70 | } | ||
| 71 | |||
| 72 | template< | ||
| 73 | typename Scalar, | ||
| 74 | int Options, | ||
| 75 | template<typename, int> class JointCollectionTpl, | ||
| 76 | typename ArgsTmp> | ||
| 77 | static ReturnType | ||
| 78 | 373719 | run(const JointModelTpl<Scalar, Options, JointCollectionTpl> & jmodel, ArgsTmp args) | |
| 79 | { | ||
| 80 |
2/4✓ Branch 1 taken 211662 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 211662 times.
✗ Branch 5 not taken.
|
373719 | InternalVisitorModel<ArgsTmp> visitor(args); |
| 81 |
1/2✓ Branch 1 taken 211662 times.
✗ Branch 2 not taken.
|
747438 | return boost::apply_visitor(visitor, jmodel); |
| 82 | } | ||
| 83 | |||
| 84 | template< | ||
| 85 | typename Scalar, | ||
| 86 | int Options, | ||
| 87 | template<typename, int> class JointCollectionTpl, | ||
| 88 | typename ArgsTmp> | ||
| 89 | static ReturnType | ||
| 90 | 100 | run(const JointDataTpl<Scalar, Options, JointCollectionTpl> & jdata, ArgsTmp args) | |
| 91 | { | ||
| 92 |
2/4✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
|
100 | InternalVisitorModel<ArgsTmp> visitor(args); |
| 93 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
200 | return boost::apply_visitor(visitor, jdata); |
| 94 | } | ||
| 95 | |||
| 96 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 97 | 998 | static ReturnType run(const JointModelTpl<Scalar, Options, JointCollectionTpl> & jmodel) | |
| 98 | { | ||
| 99 | 998 | InternalVisitorModel<NoArg> visitor; | |
| 100 |
1/2✓ Branch 1 taken 670 times.
✗ Branch 2 not taken.
|
1996 | return boost::apply_visitor(visitor, jmodel); |
| 101 | } | ||
| 102 | |||
| 103 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 104 | static ReturnType run(const JointDataTpl<Scalar, Options, JointCollectionTpl> & jdata) | ||
| 105 | { | ||
| 106 | InternalVisitorModel<NoArg> visitor; | ||
| 107 | return boost::apply_visitor(visitor, jdata); | ||
| 108 | } | ||
| 109 | |||
| 110 | template<typename JointModelDerived, typename ArgsTmp> | ||
| 111 | 46 | static ReturnType run(const JointModelBase<JointModelDerived> & jmodel, ArgsTmp args) | |
| 112 | { | ||
| 113 |
2/4✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
|
46 | InternalVisitorModel<ArgsTmp> visitor(args); |
| 114 |
1/2✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
|
92 | return visitor(jmodel.derived()); |
| 115 | } | ||
| 116 | |||
| 117 | template<typename JointDataDerived, typename ArgsTmp> | ||
| 118 | static ReturnType run(const JointDataBase<JointDataDerived> & jdata, ArgsTmp args) | ||
| 119 | { | ||
| 120 | InternalVisitorModel<ArgsTmp> visitor(args); | ||
| 121 | return visitor(jdata.derived()); | ||
| 122 | } | ||
| 123 | |||
| 124 | template<typename JointModelDerived> | ||
| 125 | static ReturnType run(const JointModelBase<JointModelDerived> & jmodel) | ||
| 126 | { | ||
| 127 | InternalVisitorModel<NoArg> visitor; | ||
| 128 | return visitor(jmodel.derived()); | ||
| 129 | } | ||
| 130 | |||
| 131 | template<typename JointDataDerived> | ||
| 132 | static ReturnType run(const JointDataBase<JointDataDerived> & jdata) | ||
| 133 | { | ||
| 134 | InternalVisitorModel<NoArg> visitor; | ||
| 135 | return visitor(jdata.derived()); | ||
| 136 | } | ||
| 137 | |||
| 138 | private: | ||
| 139 | template<typename JointModel, typename ArgType> | ||
| 140 | struct InternalVisitorModelAndData : public boost::static_visitor<ReturnType> | ||
| 141 | { | ||
| 142 | typedef typename JointModel::JointDataDerived JointData; | ||
| 143 | |||
| 144 | 1392913 | InternalVisitorModelAndData(JointData & jdata, ArgType args) | |
| 145 | 1392913 | : jdata(jdata) | |
| 146 | 1392913 | , args(args) | |
| 147 | { | ||
| 148 | 1392913 | } | |
| 149 | |||
| 150 | template<typename JointModelDerived> | ||
| 151 | 789269 | ReturnType operator()(const JointModelBase<JointModelDerived> & jmodel) const | |
| 152 | { | ||
| 153 |
1/2✓ Branch 1 taken 88615 times.
✗ Branch 2 not taken.
|
789269 | return bf::invoke( |
| 154 | &JointVisitorDerived::template algo<JointModelDerived>, | ||
| 155 | ✗ | bf::append( | |
| 156 |
1/2✓ Branch 1 taken 88615 times.
✗ Branch 2 not taken.
|
789269 | boost::ref(jmodel.derived()), |
| 157 | 789269 | boost::ref( | |
| 158 | 789269 | boost::get<typename JointModelBase<JointModelDerived>::JointDataDerived>(jdata)), | |
| 159 | 1578538 | args)); | |
| 160 | } | ||
| 161 | |||
| 162 | ReturnType operator()(const JointModelVoid) | ||
| 163 | { | ||
| 164 | return; | ||
| 165 | } | ||
| 166 | |||
| 167 | JointData & jdata; | ||
| 168 | ArgType args; | ||
| 169 | }; | ||
| 170 | |||
| 171 | template<typename JointModel> | ||
| 172 | struct InternalVisitorModelAndData<JointModel, NoArg> | ||
| 173 | : public boost::static_visitor<ReturnType> | ||
| 174 | { | ||
| 175 | typedef typename JointModel::JointDataDerived JointData; | ||
| 176 | |||
| 177 | 26 | InternalVisitorModelAndData(JointData & jdata) | |
| 178 | 26 | : jdata(jdata) | |
| 179 | { | ||
| 180 | 26 | } | |
| 181 | |||
| 182 | template<typename JointModelDerived> | ||
| 183 | 52 | ReturnType operator()(const JointModelBase<JointModelDerived> & jmodel) const | |
| 184 | { | ||
| 185 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
52 | return bf::invoke( |
| 186 | &JointVisitorDerived::template algo<JointModelDerived>, | ||
| 187 | bf::make_vector( | ||
| 188 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
52 | boost::ref(jmodel.derived()), |
| 189 | 52 | boost::ref( | |
| 190 | 104 | boost::get<typename JointModelBase<JointModelDerived>::JointDataDerived>(jdata)))); | |
| 191 | } | ||
| 192 | |||
| 193 | JointData & jdata; | ||
| 194 | }; | ||
| 195 | |||
| 196 | template<typename ArgType, typename Dummy = void> | ||
| 197 | struct InternalVisitorModel : public boost::static_visitor<ReturnType> | ||
| 198 | { | ||
| 199 | 373868 | InternalVisitorModel(ArgType args) | |
| 200 | 373868 | : args(args) | |
| 201 | { | ||
| 202 | 373868 | } | |
| 203 | |||
| 204 | template<typename JointModelDerived> | ||
| 205 | 213795 | ReturnType operator()(const JointModelBase<JointModelDerived> & jmodel) const | |
| 206 | { | ||
| 207 |
1/2✓ Branch 1 taken 2110 times.
✗ Branch 2 not taken.
|
213795 | return bf::invoke( |
| 208 | &JointVisitorDerived::template algo<JointModelDerived>, | ||
| 209 |
1/2✓ Branch 2 taken 2110 times.
✗ Branch 3 not taken.
|
641385 | bf::append(boost::ref(jmodel.derived()), args)); |
| 210 | } | ||
| 211 | |||
| 212 | template<typename JointDataDerived> | ||
| 213 | 100 | ReturnType operator()(const JointDataBase<JointDataDerived> & jdata) const | |
| 214 | { | ||
| 215 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
100 | return bf::invoke( |
| 216 | &JointVisitorDerived::template algo<JointDataDerived>, | ||
| 217 |
1/2✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
|
300 | bf::append(boost::ref(jdata.derived()), args)); |
| 218 | } | ||
| 219 | |||
| 220 | ReturnType operator()(const JointModelVoid) | ||
| 221 | { | ||
| 222 | return; | ||
| 223 | } | ||
| 224 | |||
| 225 | ArgType args; | ||
| 226 | }; | ||
| 227 | |||
| 228 | template<typename Dummy> | ||
| 229 | struct InternalVisitorModel<NoArg, Dummy> : public boost::static_visitor<ReturnType> | ||
| 230 | { | ||
| 231 | 998 | InternalVisitorModel() | |
| 232 | { | ||
| 233 | 998 | } | |
| 234 | |||
| 235 | template<typename JointModelDerived> | ||
| 236 | 670 | ReturnType operator()(const JointModelBase<JointModelDerived> & jmodel) const | |
| 237 | { | ||
| 238 | 670 | return JointVisitorDerived::template algo<JointModelDerived>(jmodel.derived()); | |
| 239 | } | ||
| 240 | |||
| 241 | template<typename JointDataDerived> | ||
| 242 | ReturnType operator()(const JointDataBase<JointDataDerived> & jdata) const | ||
| 243 | { | ||
| 244 | return JointVisitorDerived::template algo<JointDataDerived>(jdata.derived()); | ||
| 245 | } | ||
| 246 | }; | ||
| 247 | }; // struct JointUnaryVisitorBase | ||
| 248 | |||
| 249 | } // namespace fusion | ||
| 250 | } // namespace pinocchio | ||
| 251 | |||
| 252 | #endif // ifndef __pinocchio_multibody_visitor_joint_unary_visitor_hpp__ | ||
| 253 |