CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
road
RoadElementSet.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include "
carla/ListView.h
"
10
#include "
carla/NonCopyable.h
"
11
12
#include <iterator>
13
#include <memory>
14
#include <vector>
15
#include <algorithm>
16
#include <type_traits>
17
18
namespace
carla
{
19
namespace
road
{
20
21
/// A set of elements ordered by its position on the road.
22
template
<
typename
T>
23
class
RoadElementSet
:
private
MovableNonCopyable
{
24
public
:
25
26
using
mapped_type
= T;
27
28
using
key_type
= double;
29
30
RoadElementSet
() =
default
;
31
32
/// Explicit move constructor.
33
template
<
typename
InputTypeT>
34
RoadElementSet
(std::vector<InputTypeT> &&range)
35
:
_vec
([](auto &&input) {
36
static_assert
(!std::is_const<InputTypeT>::value,
"Input type cannot be const"
);
37
std::sort(std::begin(input), std::end(input),
LessComp
());
38
return
decltype
(
_vec
){
39
std::make_move_iterator(std::begin(input)),
40
std::make_move_iterator(std::end(input))};
41
}(std::move(range))) {}
42
43
/// Return all values from the set.
44
const
std::vector<mapped_type> &
GetAll
()
const
{
45
return
_vec
;
46
}
47
48
/// Return a reversed list of elements that have key
49
/// value GetDistance() <= s.
50
auto
GetReverseSubset
(
const
key_type
k)
const
{
51
return
MakeListView(
52
std::make_reverse_iterator(std::upper_bound(
_vec
.begin(),
_vec
.end(), k,
LessComp
())),
53
_vec
.rend());
54
}
55
56
/// Return a list of elements that have a key value in the range [min_k, max_k]
57
auto
GetSubsetInRange
(
const
key_type
min_k,
const
key_type
max_k)
const
{
58
auto
low_bound = (std::lower_bound(
_vec
.begin(),
_vec
.end(), min_k,
LessComp
()));
59
auto
up_bound = (std::upper_bound(
_vec
.begin(),
_vec
.end(), max_k,
LessComp
()));
60
return
MakeListView((low_bound), (up_bound));
61
}
62
63
auto
GetReverseSubsetInRange
(
const
key_type
min_k,
const
key_type
max_k)
const
{
64
auto
low_bound = (std::lower_bound(
_vec
.begin(),
_vec
.end(), min_k,
LessComp
()));
65
auto
up_bound = (std::upper_bound(low_bound,
_vec
.end(), max_k,
LessComp
()));
66
return
MakeListView(std::make_reverse_iterator(up_bound), std::make_reverse_iterator(low_bound));
67
}
68
69
bool
empty
()
const
{
70
return
_vec
.empty();
71
}
72
73
size_t
size
()
const
{
74
return
_vec
.size();
75
}
76
77
auto
begin
()
const
{
78
return
_vec
.begin();
79
}
80
81
auto
end
()
const
{
82
return
_vec
.end();
83
}
84
85
private
:
86
87
static
key_type
GetDistance
(
const
key_type
key) {
88
return
key;
89
}
90
91
template
<
typename
ValueT>
92
static
key_type
GetDistance
(
const
ValueT &value) {
93
return
value.GetDistance();
94
}
95
96
template
<
typename
ValueT>
97
static
key_type
GetDistance
(
const
ValueT *value) {
98
return
value->GetDistance();
99
}
100
101
template
<
typename
ValueT>
102
static
key_type
GetDistance
(
const
std::unique_ptr<ValueT> &value) {
103
return
value->GetDistance();
104
}
105
106
struct
LessComp
{
107
using
is_transparent
= void;
108
template
<
typename
LhsT,
typename
RhsT>
109
bool
operator()
(
110
const
LhsT &a,
111
const
RhsT &b)
const
{
112
return
GetDistance
(a) <
GetDistance
(b);
113
}
114
};
115
116
std::vector<mapped_type>
_vec
;
117
};
118
119
}
// road
120
}
// carla
ListView.h
NonCopyable.h
carla::MovableNonCopyable::MovableNonCopyable
MovableNonCopyable()=default
carla::road::RoadElementSet::key_type
double key_type
Definition
RoadElementSet.h:28
carla::road::RoadElementSet::RoadElementSet
RoadElementSet()=default
carla::road::RoadElementSet::GetAll
const std::vector< mapped_type > & GetAll() const
Return all values from the set.
Definition
RoadElementSet.h:44
carla::road::RoadElementSet::_vec
std::vector< mapped_type > _vec
Definition
RoadElementSet.h:116
carla::road::RoadElementSet::GetDistance
static key_type GetDistance(const ValueT &value)
Definition
RoadElementSet.h:92
carla::road::RoadElementSet::GetDistance
static key_type GetDistance(const ValueT *value)
Definition
RoadElementSet.h:97
carla::road::RoadElementSet::begin
auto begin() const
Definition
RoadElementSet.h:77
carla::road::RoadElementSet::GetDistance
static key_type GetDistance(const key_type key)
Definition
RoadElementSet.h:87
carla::road::RoadElementSet::end
auto end() const
Definition
RoadElementSet.h:81
carla::road::RoadElementSet::GetSubsetInRange
auto GetSubsetInRange(const key_type min_k, const key_type max_k) const
Return a list of elements that have a key value in the range [min_k, max_k].
Definition
RoadElementSet.h:57
carla::road::RoadElementSet::mapped_type
T mapped_type
Definition
RoadElementSet.h:26
carla::road::RoadElementSet::RoadElementSet
RoadElementSet(std::vector< InputTypeT > &&range)
Explicit move constructor.
Definition
RoadElementSet.h:34
carla::road::RoadElementSet::GetReverseSubsetInRange
auto GetReverseSubsetInRange(const key_type min_k, const key_type max_k) const
Definition
RoadElementSet.h:63
carla::road::RoadElementSet::size
size_t size() const
Definition
RoadElementSet.h:73
carla::road::RoadElementSet::GetDistance
static key_type GetDistance(const std::unique_ptr< ValueT > &value)
Definition
RoadElementSet.h:102
carla::road::RoadElementSet::GetReverseSubset
auto GetReverseSubset(const key_type k) const
Return a reversed list of elements that have key value GetDistance() <= s.
Definition
RoadElementSet.h:50
carla::road::RoadElementSet::empty
bool empty() const
Definition
RoadElementSet.h:69
carla::road
Definition
SignComponent.h:23
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::road::RoadElementSet::LessComp
Definition
RoadElementSet.h:106
carla::road::RoadElementSet::LessComp::is_transparent
void is_transparent
Definition
RoadElementSet.h:107
carla::road::RoadElementSet::LessComp::operator()
bool operator()(const LhsT &a, const RhsT &b) const
Definition
RoadElementSet.h:109
Generated by
1.18.0