CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
road
element
LaneCrossingCalculator.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/road/element/LaneCrossingCalculator.h
"
8
#include "
carla/road/element/LaneMarking.h
"
9
10
#include "
carla/geom/Location.h
"
11
#include "
carla/road/Map.h
"
12
13
namespace
carla
{
14
namespace
road
{
15
namespace
element
{
16
17
/// @todo Temporary flags to search lanes where we can find road marks.
18
/// This needs to be expanded searching in shoulders too, but since
19
/// shouders have a small width, they can cause problems while finding
20
/// the nearest center of a lane given a location that are in a road,
21
/// but very close to a shoulder.
22
static
constexpr
uint32_t
FLAGS
=
23
static_cast<
uint32_t
>
(
Lane::LaneType::Driving
) |
24
static_cast<
uint32_t
>
(
Lane::LaneType::Bidirectional
) |
25
static_cast<
uint32_t
>
(
Lane::LaneType::Biking
) |
26
static_cast<
uint32_t
>
(
Lane::LaneType::Parking
);
27
28
/// Calculate the lane markings that need to be crossed from @a lane_id_origin
29
/// to @a lane_id_destination.
30
static
std::vector<LaneMarking>
CrossingAtSameSection
(
31
const
Map
&map,
32
const
Waypoint
*w0,
33
const
Waypoint
*w1,
34
const
bool
w0_is_offroad,
35
const
bool
dest_is_at_right) {
36
auto
w0_marks = map.
GetMarkRecord
(*w0);
37
auto
w1_marks = map.
GetMarkRecord
(*w1);
38
39
if
(dest_is_at_right) {
40
if
(w0_is_offroad) {
41
if
(w1_marks.second !=
nullptr
) {
42
return
{
LaneMarking
(*w1_marks.second) };
43
}
44
}
else
{
45
if
(w0_marks.first !=
nullptr
) {
46
return
{
LaneMarking
(*w0_marks.first) };
47
}
48
}
49
}
else
{
50
if
(w0_is_offroad) {
51
if
(w1_marks.first !=
nullptr
) {
52
return
{
LaneMarking
(*w1_marks.first) };
53
}
54
}
else
{
55
if
(w0_marks.second !=
nullptr
) {
56
return
{
LaneMarking
(*w0_marks.second) };
57
}
58
}
59
}
60
61
return
{};
62
}
63
64
static
bool
IsOffRoad
(
const
Map
&map,
const
geom::Location
&location) {
65
return
!map.
GetWaypoint
(location,
FLAGS
).has_value();
66
}
67
68
std::vector<LaneMarking>
LaneCrossingCalculator::Calculate
(
69
const
Map
&map,
70
const
geom::Location
&origin,
71
const
geom::Location
&destination) {
72
auto
w0 = map.
GetClosestWaypointOnRoad
(origin,
FLAGS
);
73
auto
w1 = map.
GetClosestWaypointOnRoad
(destination,
FLAGS
);
74
75
if
(!w0.has_value() || !w1.has_value()) {
76
return
{};
77
}
78
79
if
(w0->road_id != w1->road_id || w0->section_id != w1->section_id) {
80
/// @todo This case should also be handled.
81
return
{};
82
}
83
84
if
(map.
IsJunction
(w0->road_id) || map.
IsJunction
(w1->road_id)) {
85
return
{};
86
}
87
88
const
auto
w0_is_offroad =
IsOffRoad
(map, origin);
89
const
auto
w1_is_offroad =
IsOffRoad
(map, destination);
90
91
if
(w0_is_offroad && w1_is_offroad) {
92
// outside the road
93
return
{};
94
}
95
96
if
((w0->lane_id == w1->lane_id) && !w0_is_offroad && !w1_is_offroad) {
97
// both at the same lane and inside the road
98
return
{};
99
}
100
101
const
auto
transform = map.
ComputeTransform
(*w0);
102
geom::Vector3D
orig_vec = transform.GetForwardVector();
103
geom::Vector3D
dest_vec = (destination - origin).MakeUnitVector(2 * std::numeric_limits<float>::epsilon());
104
105
// cross product
106
const
auto
dest_is_at_right =
107
(-orig_vec.
x
* dest_vec.
y
+ orig_vec.
y
* dest_vec.
x
) < 0;
108
109
return
CrossingAtSameSection
(
110
map,
111
&*w0,
112
&*w1,
113
w0_is_offroad,
114
dest_is_at_right);
115
}
116
117
}
// namespace element
118
}
// namespace road
119
}
// namespace carla
LaneCrossingCalculator.h
LaneMarking.h
carla::road::Lane::LaneType::Driving
@ Driving
Definition
road/Lane.h:31
carla::road::Lane::LaneType::Biking
@ Biking
Definition
road/Lane.h:34
carla::road::Lane::LaneType::Bidirectional
@ Bidirectional
Definition
road/Lane.h:39
carla::road::Lane::LaneType::Parking
@ Parking
Definition
road/Lane.h:38
carla::road::Map
Definition
road/Map.h:29
carla::road::Map::IsJunction
bool IsJunction(RoadId road_id) const
Definition
road/Map.cpp:307
carla::road::Map::GetMarkRecord
std::pair< const element::RoadInfoMarkRecord *, const element::RoadInfoMarkRecord * > GetMarkRecord(Waypoint waypoint) const
Definition
road/Map.cpp:312
carla::road::Map::GetWaypoint
std::optional< element::Waypoint > GetWaypoint(const geom::Location &location, int32_t lane_type=static_cast< int32_t >(Lane::LaneType::Driving)) const
Definition
road/Map.cpp:217
carla::road::Map::GetClosestWaypointOnRoad
std::optional< element::Waypoint > GetClosestWaypointOnRoad(const geom::Location &location, int32_t lane_type=static_cast< int32_t >(Lane::LaneType::Driving)) const
========================================================================
Definition
road/Map.cpp:170
carla::road::Map::ComputeTransform
geom::Transform ComputeTransform(Waypoint waypoint) const
Definition
road/Map.cpp:278
carla::road::element::LaneCrossingCalculator::Calculate
static std::vector< LaneMarking > Calculate(const Map &map, const geom::Location &origin, const geom::Location &destination)
Definition
LaneCrossingCalculator.cpp:68
Location.h
carla::road::element
Definition
SignComponent.h:26
carla::road::element::FLAGS
static constexpr uint32_t FLAGS
Definition
LaneCrossingCalculator.cpp:22
carla::road::element::CrossingAtSameSection
static std::vector< LaneMarking > CrossingAtSameSection(const Map &map, const Waypoint *w0, const Waypoint *w1, const bool w0_is_offroad, const bool dest_is_at_right)
Calculate the lane markings that need to be crossed from lane_id_origin to lane_id_destination.
Definition
LaneCrossingCalculator.cpp:30
carla::road::element::IsOffRoad
static bool IsOffRoad(const Map &map, const geom::Location &location)
Definition
LaneCrossingCalculator.cpp:64
carla::road
Definition
SignComponent.h:23
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Map.h
carla::geom::Location
Definition
geom/Location.h:23
carla::geom::Vector3D
Definition
geom/Vector3D.h:17
carla::geom::Vector3D::y
float y
Definition
geom/Vector3D.h:27
carla::geom::Vector3D::x
float x
Definition
geom/Vector3D.h:25
carla::road::element::LaneMarking::LaneMarking
LaneMarking(const RoadInfoMarkRecord &info)
Definition
LaneMarking.cpp:76
carla::road::element::Waypoint
Definition
road/element/Waypoint.h:18
Generated by
1.18.0