CARLA
Loading...
Searching...
No Matches
client/Road.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/Memory.h"
10#include "carla/NonCopyable.h"
12#include "carla/road/Lane.h"
14
15#include <string>
16#include <vector>
17
18namespace carla {
19namespace client {
20
21 class Map;
22 class Lane;
23 class LaneSection;
24 class Junction;
25 class Waypoint;
26
27 /// An OpenDRIVE road: a run of carriageway divided along s into lane
28 /// sections, each holding the lanes.
29 ///
30 /// Roads connect end to end through GetNextRoads() / GetPreviousRoads(), or
31 /// through a junction. There is deliberately no left/right here: OpenDRIVE
32 /// gives roads no lateral relation, since a road already contains the lanes
33 /// on both sides of its centre line. Lateral neighbours live on Lane.
34 class Road
35 : public EnableSharedFromThis<Road>,
36 private NonCopyable {
37 public:
38
40 return _road_id;
41 }
42
43 std::string GetName() const;
44
45 /// Length of the road, in metres.
46 double GetLength() const;
47
48 bool IsJunction() const;
49
50 /// Id of the junction this road belongs to, or -1 when it is not part of
51 /// one.
53
54 /// Whether traffic on this road drives on the right.
55 bool IsRHT() const;
56
57 /// Id of the road that follows this one, as recorded in OpenDRIVE.
59
60 /// Id of the road that precedes this one, as recorded in OpenDRIVE.
62
63 /// Roads reachable by continuing forward.
64 std::vector<SharedPtr<Road>> GetNextRoads() const;
65
66 /// Roads that lead into this one.
67 std::vector<SharedPtr<Road>> GetPreviousRoads() const;
68
69 /// Every lane of the given type present at road coordinate @a s, across
70 /// every lane section covering it.
71 std::vector<SharedPtr<Lane>> GetLanes(
72 double s,
74
75 SharedPtr<Lane> GetLane(road::SectionId section_id, road::LaneId lane_id) const;
76
77 /// The lane with this id in whichever section covers @a s.
78 SharedPtr<Lane> GetLaneAt(double s, road::LaneId lane_id) const;
79
80 std::vector<SharedPtr<LaneSection>> GetSections() const;
81
83
84 /// The lane section covering road coordinate @a s, or nullptr.
86
87 /// The junction this road belongs to, or nullptr when it is not part of
88 /// one.
90
91 /// Transform at the centre of the road at road coordinate @a s.
92 geom::Transform GetTransformAt(double s) const;
93
94 /// A cross-section: one waypoint per lane of the given type at @a s.
95 std::vector<SharedPtr<Waypoint>> GetWaypointsAt(
96 double s,
98
99 /// Waypoints sampled *along* the road every @a distance metres, on every
100 /// lane of the given type. Not to be confused with GetWaypointsAt(), which
101 /// cuts across the road at a single s.
102 std::vector<SharedPtr<Waypoint>> GetWaypoints(
103 double distance,
105
106 bool operator==(const Road &rhs) const {
107 return _road_id == rhs._road_id;
108 }
109
110 bool operator!=(const Road &rhs) const {
111 return !(*this == rhs);
112 }
113
114 private:
115
116 friend class Map;
117 friend class Lane;
118 friend class LaneSection;
119 friend class Junction;
120 friend class Waypoint;
121
123 : _parent(std::move(parent)),
124 _road_id(road_id) {}
125
127
129 };
130
131} // namespace client
132} // namespace carla
float distance
std::string road_id
Definition LaneGraph.cpp:39
Inherit (privately) to suppress copy/move construction and assignment.
A stretch of road over which the lane layout does not change.
A single OpenDRIVE lane, identified by (road id, lane section id, lane id).
Definition client/Lane.h:37
An OpenDRIVE road: a run of carriageway divided along s into lane sections, each holding the lanes.
Definition client/Road.h:36
road::RoadId GetId() const
Definition client/Road.h:39
bool operator!=(const Road &rhs) const
std::vector< SharedPtr< LaneSection > > GetSections() const
std::vector< SharedPtr< Waypoint > > GetWaypointsAt(double s, road::Lane::LaneType type=road::Lane::LaneType::Driving) const
A cross-section: one waypoint per lane of the given type at s.
road::JuncId GetJunctionId() const
Id of the junction this road belongs to, or -1 when it is not part of one.
std::vector< SharedPtr< Waypoint > > GetWaypoints(double distance, road::Lane::LaneType type=road::Lane::LaneType::Driving) const
Waypoints sampled along the road every distance metres, on every lane of the given type.
SharedPtr< const Map > _parent
SharedPtr< Junction > GetJunction() const
The junction this road belongs to, or nullptr when it is not part of one.
geom::Transform GetTransformAt(double s) const
Transform at the centre of the road at road coordinate s.
bool IsJunction() const
std::vector< SharedPtr< Lane > > GetLanes(double s, road::Lane::LaneType type=road::Lane::LaneType::Driving) const
Every lane of the given type present at road coordinate s, across every lane section covering it.
bool IsRHT() const
Whether traffic on this road drives on the right.
std::vector< SharedPtr< Road > > GetPreviousRoads() const
Roads that lead into this one.
road::RoadId GetSuccessorId() const
Id of the road that follows this one, as recorded in OpenDRIVE.
road::RoadId _road_id
Road(SharedPtr< const Map > parent, road::RoadId road_id)
bool operator==(const Road &rhs) const
SharedPtr< LaneSection > GetSectionAt(double s) const
The lane section covering road coordinate s, or nullptr.
SharedPtr< Lane > GetLane(road::SectionId section_id, road::LaneId lane_id) const
double GetLength() const
Length of the road, in metres.
SharedPtr< LaneSection > GetSection(road::SectionId section_id) const
SharedPtr< Lane > GetLaneAt(double s, road::LaneId lane_id) const
The lane with this id in whichever section covers s.
std::string GetName() const
std::vector< SharedPtr< Road > > GetNextRoads() const
Roads reachable by continuing forward.
road::RoadId GetPredecessorId() const
Id of the road that precedes this one, as recorded in OpenDRIVE.
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
LaneType
Can be used as flags.
Definition road/Lane.h:29
int32_t JuncId
Definition RoadTypes.h:17
uint32_t RoadId
Definition RoadTypes.h:15
int32_t LaneId
Definition RoadTypes.h:19
uint32_t SectionId
Definition RoadTypes.h:21
carla::SharedPtr< carla::client::Junction > Junction
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15