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 |
|
✗ |
std::vector<size_t> apply(const std::vector<T, Allocator> & object_vector) const |
36 |
|
|
{ |
37 |
|
✗ |
std::vector<size_t> res; |
38 |
|
✗ |
res.reserve(object_vector.size()); |
39 |
|
|
|
40 |
|
✗ |
for (size_t k = 0; k < object_vector.size(); ++k) |
41 |
|
|
{ |
42 |
|
✗ |
if ((*this)(object_vector[k])) |
43 |
|
✗ |
res.push_back(k); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
✗ |
res.reserve(res.size()); |
47 |
|
✗ |
return res; |
48 |
|
|
} |
49 |
|
|
}; |
50 |
|
|
|
51 |
|
|
} // namespace pinocchio |
52 |
|
|
|
53 |
|
|
#endif // #ifndef __pinocchio_multibody_instance_filter_hpp__ |
54 |
|
|
|