| Directory: | ./ |
|---|---|
| File: | include/pinocchio/algorithm/check-model.hxx |
| Date: | 2025-04-30 16:14:33 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 16 | 17 | 94.1% |
| Branches: | 7 | 10 | 70.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_algorithm_check_model_hxx__ | ||
| 6 | #define __pinocchio_algorithm_check_model_hxx__ | ||
| 7 | |||
| 8 | #include "pinocchio/multibody/model.hpp" | ||
| 9 | |||
| 10 | #include <boost/fusion/algorithm.hpp> | ||
| 11 | |||
| 12 | namespace pinocchio | ||
| 13 | { | ||
| 14 | namespace internal | ||
| 15 | { | ||
| 16 | // Dedicated structure for the fusion::accumulate algorithm: validate the check-algorithm | ||
| 17 | // for all elements in a fusion list of AlgoCheckers. | ||
| 18 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 19 | struct AlgoFusionChecker | ||
| 20 | { | ||
| 21 | typedef bool result_type; | ||
| 22 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
| 23 | const Model & model; | ||
| 24 | |||
| 25 | 2 | AlgoFusionChecker(const Model & model) | |
| 26 | 2 | : model(model) | |
| 27 | { | ||
| 28 | 2 | } | |
| 29 | |||
| 30 | bool operator()(const bool & accumul, const boost::fusion::void_ &) const | ||
| 31 | { | ||
| 32 | return accumul; | ||
| 33 | } | ||
| 34 | |||
| 35 | template<typename T> | ||
| 36 | 12 | bool operator()(const bool & accumul, const AlgorithmCheckerBase<T> & t) const | |
| 37 | { | ||
| 38 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
12 | return accumul && t.checkModel(model); |
| 39 | } | ||
| 40 | }; | ||
| 41 | } // namespace internal | ||
| 42 | |||
| 43 | // Check the validity of the kinematic tree defined by parents. | ||
| 44 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 45 | inline bool | ||
| 46 | 2 | ParentChecker::checkModel_impl(const ModelTpl<Scalar, Options, JointCollectionTpl> & model) const | |
| 47 | { | ||
| 48 | typedef ModelTpl<Scalar, Options, JointCollectionTpl> Model; | ||
| 49 | typedef typename Model::JointIndex JointIndex; | ||
| 50 | |||
| 51 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 2 times.
|
56 | for (JointIndex j = 1; j < (JointIndex)model.njoints; ++j) |
| 52 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
|
54 | if (model.parents[j] >= j) |
| 53 | ✗ | return false; | |
| 54 | |||
| 55 | 2 | return true; | |
| 56 | } | ||
| 57 | |||
| 58 | // Check if there is a mimic joint in the kinematic tree | ||
| 59 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 60 | inline bool | ||
| 61 | 10992 | MimicChecker::checkModel_impl(const ModelTpl<Scalar, Options, JointCollectionTpl> & model) const | |
| 62 | { | ||
| 63 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 10985 times.
|
10992 | if (!model.mimicking_joints.empty()) |
| 64 | 2 | return false; | |
| 65 | |||
| 66 | 10990 | return true; | |
| 67 | } | ||
| 68 | |||
| 69 | template<class... T> | ||
| 70 | template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> | ||
| 71 | 2 | inline bool AlgorithmCheckerList<T...>::checkModel_impl( | |
| 72 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model) const | ||
| 73 | { | ||
| 74 | 2 | return boost::fusion::accumulate( | |
| 75 | 2 | checkerList, true, internal::AlgoFusionChecker<Scalar, Options, JointCollectionTpl>(model)); | |
| 76 | } | ||
| 77 | |||
| 78 | } // namespace pinocchio | ||
| 79 | |||
| 80 | #endif // __pinocchio_algorithm_check_model_hxx__ | ||
| 81 |