| Directory: | ./ |
|---|---|
| File: | include/pinocchio/multibody/instance-filter.hpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 8 | 8 | 100.0% |
| Branches: | 8 | 12 | 66.7% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2022 INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_multibody_instance_filter_hpp__ | ||
| 6 | #define __pinocchio_multibody_instance_filter_hpp__ | ||
| 7 | |||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | namespace pinocchio | ||
| 11 | { | ||
| 12 | |||
| 13 | /// \brief Instance filter base class | ||
| 14 | template<typename T> | ||
| 15 | struct InstanceFilterBase | ||
| 16 | { | ||
| 17 | /// | ||
| 18 | /// \brief Returns true if the input obj matches the filter conditions | ||
| 19 | /// | ||
| 20 | /// \param[in] obj input geometry object to filter or not. | ||
| 21 | /// | ||
| 22 | /// \returns true if the obj matches the filter conditions | ||
| 23 | /// | ||
| 24 | virtual bool operator()(const T & obj) const = 0; | ||
| 25 | |||
| 26 | /// | ||
| 27 | /// \brief Apply the filter on the given vector of objects and returns the list of indexes of | ||
| 28 | /// the objects matching the filter conditions. | ||
| 29 | /// | ||
| 30 | /// \param[in] object_vector vector of objects. | ||
| 31 | /// | ||
| 32 | /// \returns the list of indexes of the objects matching the filter conditions. | ||
| 33 | /// | ||
| 34 | template<typename Allocator> | ||
| 35 | 70 | std::vector<size_t> apply(const std::vector<T, Allocator> & object_vector) const | |
| 36 | { | ||
| 37 | 70 | std::vector<size_t> res; | |
| 38 |
1/2✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
|
70 | res.reserve(object_vector.size()); |
| 39 | |||
| 40 |
2/2✓ Branch 1 taken 1342 times.
✓ Branch 2 taken 70 times.
|
1412 | for (size_t k = 0; k < object_vector.size(); ++k) |
| 41 | { | ||
| 42 |
3/4✓ Branch 2 taken 1342 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
✓ Branch 5 taken 1280 times.
|
1342 | if ((*this)(object_vector[k])) |
| 43 |
1/2✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
|
62 | res.push_back(k); |
| 44 | } | ||
| 45 | |||
| 46 |
1/2✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
|
70 | res.reserve(res.size()); |
| 47 | 70 | return res; | |
| 48 | } | ||
| 49 | }; | ||
| 50 | |||
| 51 | } // namespace pinocchio | ||
| 52 | |||
| 53 | #endif // #ifndef __pinocchio_multibody_instance_filter_hpp__ | ||
| 54 |