CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
client
client/LaneSection.cpp
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
#include "
carla/client/LaneSection.h
"
8
9
#include "
carla/client/Lane.h
"
10
#include "
carla/client/Map.h
"
11
#include "
carla/client/Road.h
"
12
#include "
carla/road/LaneSection.h
"
13
#include "
carla/road/Road.h
"
14
15
#include <algorithm>
16
#include <vector>
17
18
namespace
carla
{
19
namespace
client
{
20
21
// Sections ordered by their s coordinate, so "next" and "previous" mean
22
// along the road rather than by id.
23
static
std::vector<const road::LaneSection *>
SectionsByDistance
(
const
road::Road
&
road
) {
24
std::vector<const road::LaneSection *> sections;
25
for
(
const
road::LaneSection
§ion :
road
.GetLaneSections()) {
26
sections.emplace_back(§ion);
27
}
28
std::sort(sections.begin(), sections.end(),
29
[](
const
road::LaneSection
*lhs,
const
road::LaneSection
*rhs) {
30
return lhs->GetDistance() < rhs->GetDistance();
31
});
32
return
sections;
33
}
34
35
uint64_t
LaneSection::GetUniqueId
()
const
{
36
return
(
static_cast<
uint64_t
>
(
_road_id
) << 32) ^
static_cast<
uint64_t
>
(
_section_id
);
37
}
38
39
SharedPtr<Road>
LaneSection::GetRoad
()
const
{
40
return
_parent
->GetRoad(
_road_id
);
41
}
42
43
double
LaneSection::GetDistance
()
const
{
44
return
_parent
->GetMap().GetData().GetRoad(
_road_id
)
45
.GetLaneSectionById(
_section_id
).GetDistance();
46
}
47
48
double
LaneSection::GetLength
()
const
{
49
return
_parent
->GetMap().GetData().GetRoad(
_road_id
)
50
.GetLaneSectionById(
_section_id
).GetLength();
51
}
52
53
std::vector<SharedPtr<Lane>>
LaneSection::GetLanes
(
road::Lane::LaneType
type)
const
{
54
std::vector<SharedPtr<Lane>> result;
55
const
road::LaneSection
§ion =
56
_parent
->GetMap().GetData().GetRoad(
_road_id
).GetLaneSectionById(
_section_id
);
57
for
(
const
auto
&pair : section.
GetLanes
()) {
58
const
road::Lane
&lane = pair.second;
59
// The centre lane has no width and cannot be driven or walked on.
60
if
(lane.
GetId
() == 0) {
61
continue
;
62
}
63
if
((
static_cast<
int32_t
>
(lane.
GetType
()) &
static_cast<
int32_t
>
(type)) == 0) {
64
continue
;
65
}
66
result.emplace_back(
_parent
->GetLane(
_road_id
,
_section_id
, lane.
GetId
()));
67
}
68
return
result;
69
}
70
71
SharedPtr<Lane>
LaneSection::GetLane
(
road::LaneId
lane_id)
const
{
72
return
_parent
->GetLane(
_road_id
,
_section_id
, lane_id);
73
}
74
75
bool
LaneSection::ContainsLane
(
road::LaneId
lane_id)
const
{
76
return
_parent
->GetMap().GetData().GetRoad(
_road_id
)
77
.GetLaneSectionById(
_section_id
).ContainsLane(lane_id);
78
}
79
80
SharedPtr<LaneSection>
LaneSection::GetNextSection
()
const
{
81
const
road::Road
&
road
=
_parent
->GetMap().GetData().GetRoad(
_road_id
);
82
const
auto
sections =
SectionsByDistance
(
road
);
83
for
(
size_t
i = 0u; i < sections.size(); ++i) {
84
if
(sections[i]->
GetId
() ==
_section_id
) {
85
if
(i + 1u < sections.size()) {
86
return
_parent
->GetLaneSection(
_road_id
, sections[i + 1u]->
GetId
());
87
}
88
break
;
89
}
90
}
91
return
nullptr
;
92
}
93
94
SharedPtr<LaneSection>
LaneSection::GetPreviousSection
()
const
{
95
const
road::Road
&
road
=
_parent
->GetMap().GetData().GetRoad(
_road_id
);
96
const
auto
sections =
SectionsByDistance
(
road
);
97
for
(
size_t
i = 0u; i < sections.size(); ++i) {
98
if
(sections[i]->
GetId
() ==
_section_id
) {
99
if
(i > 0u) {
100
return
_parent
->GetLaneSection(
_road_id
, sections[i - 1u]->
GetId
());
101
}
102
break
;
103
}
104
}
105
return
nullptr
;
106
}
107
108
}
// namespace client
109
}
// namespace carla
carla::client::LaneSection::GetDistance
double GetDistance() const
The s coordinate, along the road, at which this section begins.
Definition
client/LaneSection.cpp:43
carla::client::LaneSection::ContainsLane
bool ContainsLane(road::LaneId lane_id) const
Definition
client/LaneSection.cpp:75
carla::client::LaneSection::GetRoad
SharedPtr< Road > GetRoad() const
Definition
client/LaneSection.cpp:39
carla::client::LaneSection::_section_id
road::SectionId _section_id
Definition
client/LaneSection.h:92
carla::client::LaneSection::_road_id
road::RoadId _road_id
Definition
client/LaneSection.h:90
carla::client::LaneSection::GetId
road::SectionId GetId() const
Definition
client/LaneSection.h:34
carla::client::LaneSection::GetNextSection
SharedPtr< LaneSection > GetNextSection() const
The next section along the road, or nullptr at the end.
Definition
client/LaneSection.cpp:80
carla::client::LaneSection::GetLanes
std::vector< SharedPtr< Lane > > GetLanes(road::Lane::LaneType type=road::Lane::LaneType::Driving) const
Every lane in this section of the given type.
Definition
client/LaneSection.cpp:53
carla::client::LaneSection::_parent
SharedPtr< const Map > _parent
Definition
client/LaneSection.h:88
carla::client::LaneSection::GetLane
SharedPtr< Lane > GetLane(road::LaneId lane_id) const
The lane with this id, or nullptr when the section has no such lane.
Definition
client/LaneSection.cpp:71
carla::client::LaneSection::GetPreviousSection
SharedPtr< LaneSection > GetPreviousSection() const
The previous section along the road, or nullptr at the start.
Definition
client/LaneSection.cpp:94
carla::client::LaneSection::GetUniqueId
uint64_t GetUniqueId() const
Unique id of this section within its map, for use as a dictionary key.
Definition
client/LaneSection.cpp:35
carla::client::LaneSection::GetLength
double GetLength() const
Length of the section, in metres.
Definition
client/LaneSection.cpp:48
carla::road::LaneSection
Definition
road/LaneSection.h:24
carla::road::LaneSection::GetLanes
std::map< LaneId, Lane > & GetLanes()
Definition
road/LaneSection.cpp:47
carla::road::Lane
Definition
road/Lane.h:25
carla::road::Lane::GetType
LaneType GetType() const
Definition
road/Lane.cpp:38
carla::road::Lane::LaneType
LaneType
Can be used as flags.
Definition
road/Lane.h:29
carla::road::Lane::GetId
LaneId GetId() const
Definition
road/Lane.cpp:34
carla::road::Road
Definition
road/Road.h:32
LaneSection.h
Lane.h
Map.h
Road.h
carla::client
Definition
BasicAgent.h:24
carla::client::SectionsByDistance
static std::vector< const road::LaneSection * > SectionsByDistance(const road::Road &road)
Definition
client/LaneSection.cpp:23
carla::road
Definition
SignComponent.h:23
carla::road::LaneId
int32_t LaneId
Definition
RoadTypes.h:19
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::SharedPtr
std::shared_ptr< T > SharedPtr
Definition
Memory.h:15
LaneSection.h
Road.h
Generated by
1.18.0