room_util.h
Go to the documentation of this file.
1
2
/**
3
* This file is part of ArmarX.
4
*
5
* ArmarX is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation.
8
*
9
* ArmarX is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*
17
* @author Fabian Reister ( fabian dot reister at kit dot edu )
18
* @date 2025
19
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20
* GNU General Public License
21
*/
22
23
#pragma once
24
25
#include <vector>
26
27
#include <range/v3/range/conversion.hpp>
28
#include <range/v3/view/filter.hpp>
29
30
#include <
armarx/navigation/algorithms/Room.h
>
31
32
namespace
armarx::navigation::algorithms
33
{
34
/**
35
* @brief Filter a collection of objects by whether their projected position lies inside a room.
36
*
37
* This function applies a projection callable to each object in @p objects and retains those
38
* objects for which the room reports the projected value as inside (via Room::isInside).
39
* The relative order of the returned elements matches the order in @p objects.
40
*
41
* @tparam T Type of elements stored in @p objects. Must be CopyConstructible or MoveConstructible
42
* since selected elements are returned by value in a new std::vector<T>.
43
* @tparam Proj Callable type for the projection. Must be Invocable with an argument of type
44
* const T& (or T) and return a value accepted by
45
* armarx::navigation::algorithms::Room::isInside.
46
*
47
* @param room Reference to an armarx::navigation::algorithms::Room used for the inside-test.
48
* @param objects Constant reference to the input vector of objects to be filtered.
49
* @param proj Projection callable applied to each object to obtain the value checked by room.isInside.
50
*
51
* @returns A std::vector<T> containing copies of the objects for which
52
* room.isInside(proj(obj)) returns true. If no objects satisfy the predicate, an empty
53
* vector is returned.
54
*
55
* @complexity Linear in objects.size(): each element is projected and tested once.
56
*
57
* @exceptionsafety Any exceptions thrown by @p proj or Room::isInside propagate to the caller.
58
*
59
* @note This implementation relies on C++ ranges utilities (ranges::views::filter and ranges::to_vector).
60
*/
61
template
<
typename
T,
typename
Proj>
62
std::vector<T>
63
filterByRoom
(
const
armarx::navigation::algorithms::Room
& room,
64
const
std::vector<T>&
objects
,
65
Proj proj)
66
{
67
namespace
r = ::ranges;
68
namespace
rv = r::views;
69
70
return
objects
|
71
rv::filter([&room, &proj](
const
T
& obj) {
return
room.
isInside
(proj(obj)); }) |
72
r::to_vector;
73
}
74
75
}
// namespace armarx::navigation::algorithms
Room.h
T
float T
Definition
UnscentedKalmanFilterTest.cpp:38
armarx::navigation::algorithms
This file is part of ArmarX.
Definition
aron_conversions.cpp:29
armarx::navigation::algorithms::filterByRoom
std::vector< T > filterByRoom(const armarx::navigation::algorithms::Room &room, const std::vector< T > &objects, Proj proj)
Filter a collection of objects by whether their projected position lies inside a room.
Definition
room_util.h:63
armarx::objects
Definition
forward_declarations.h:32
armarx::navigation::algorithms::Room
Definition
Room.h:34
armarx::navigation::algorithms::Room::isInside
bool isInside(const Eigen::Vector3f &point, bool restrictTo2dCheck=false) const
Definition
Room.cpp:17
armarx
navigation
algorithms
room_util.h
Generated by
1.13.2