CARLA
Loading...
Searching...
No Matches
client/Lane.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 <vector>
16
17namespace carla {
18namespace client {
19
20 class Map;
21 class Road;
22 class LaneSection;
23 class Waypoint;
24
25 /// A single OpenDRIVE lane, identified by (road id, lane section id, lane id).
26 ///
27 /// A lane lives inside exactly one lane section, which is why its identity
28 /// carries the section: the same lane id on the same road is a different lane
29 /// in a different section. Following GetNextLanes() can therefore cross into
30 /// another section, or return nothing where the lane simply ends.
31 ///
32 /// Like carla::client::Junction, this holds the parent map alive and resolves
33 /// its ids on each call rather than caching a road::Lane pointer, which would
34 /// dangle once the map is released.
35 class Lane
36 : public EnableSharedFromThis<Lane>,
37 private NonCopyable {
38 public:
39
41 return _lane_id;
42 }
43
45 return _road_id;
46 }
47
49 return _section_id;
50 }
51
52 /// Unique id of this lane within its map, for use as a dictionary key.
53 uint64_t GetUniqueId() const;
54
56
58
60
61 /// Length of the lane, in metres.
62 double GetLength() const;
63
64 /// The s coordinate, along the road, at which this lane's section begins.
65 double GetDistance() const;
66
67 bool GetLevel() const;
68
69 bool IsStraight() const;
70
71 /// Whether the lane runs along increasing s (a right-hand lane, id < 0).
72 bool IsPositiveDirection() const;
73
74 /// Lane width at the given s, in metres. @a s is a road coordinate, not an
75 /// offset from the start of the lane.
76 double GetWidth(double s) const;
77
78 geom::Transform GetTransform(double s) const;
79
80 /// The lane to the right, or nullptr at the edge of the road. Crossing the
81 /// centre line flips the sign of the lane id, so the neighbour returned may
82 /// run in the opposite direction; this matches Waypoint::GetRight().
84
85 /// The lane to the left, or nullptr. See GetRightLane() on direction.
87
88 /// Lanes this one leads into. Empty where the lane ends.
89 std::vector<SharedPtr<Lane>> GetNextLanes() const;
90
91 /// Lanes leading into this one.
92 std::vector<SharedPtr<Lane>> GetPreviousLanes() const;
93
94 /// The waypoint on this lane at road coordinate @a s, or nullptr when @a s
95 /// falls outside the lane.
96 SharedPtr<Waypoint> GetWaypoint(double s) const;
97
98 /// Waypoints along this lane, every @a distance metres.
99 std::vector<SharedPtr<Waypoint>> GetWaypoints(double distance) const;
100
101 bool operator==(const Lane &rhs) const {
102 return (_road_id == rhs._road_id) &&
103 (_section_id == rhs._section_id) &&
104 (_lane_id == rhs._lane_id);
105 }
106
107 bool operator!=(const Lane &rhs) const {
108 return !(*this == rhs);
109 }
110
111 private:
112
113 friend class Map;
114 friend class Road;
115 friend class LaneSection;
116 friend class Junction;
117 friend class Waypoint;
118
122 road::SectionId section_id,
123 road::LaneId lane_id)
124 : _parent(std::move(parent)),
126 _section_id(section_id),
127 _lane_id(lane_id) {}
128
129 /// The underlying OpenDRIVE lane. Valid only while _parent is alive.
130 const road::Lane &GetLane() const;
131
133
135
137
139 };
140
141} // namespace client
142} // 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
SharedPtr< Lane > GetRightLane() const
The lane to the right, or nullptr at the edge of the road.
road::LaneId _lane_id
road::Lane::LaneType GetType() const
double GetDistance() const
The s coordinate, along the road, at which this lane's section begins.
std::vector< SharedPtr< Waypoint > > GetWaypoints(double distance) const
Waypoints along this lane, every distance metres.
SharedPtr< const Map > _parent
road::SectionId _section_id
double GetLength() const
Length of the lane, in metres.
bool IsStraight() const
bool GetLevel() const
SharedPtr< Road > GetRoad() const
road::RoadId _road_id
SharedPtr< LaneSection > GetSection() const
road::LaneId GetId() const
Definition client/Lane.h:40
std::vector< SharedPtr< Lane > > GetPreviousLanes() const
Lanes leading into this one.
SharedPtr< Lane > GetLeftLane() const
The lane to the left, or nullptr. See GetRightLane() on direction.
road::SectionId GetSectionId() const
Definition client/Lane.h:48
bool operator!=(const Lane &rhs) const
std::vector< SharedPtr< Lane > > GetNextLanes() const
Lanes this one leads into. Empty where the lane ends.
double GetWidth(double s) const
Lane width at the given s, in metres.
uint64_t GetUniqueId() const
Unique id of this lane within its map, for use as a dictionary key.
bool IsPositiveDirection() const
Whether the lane runs along increasing s (a right-hand lane, id < 0).
SharedPtr< Waypoint > GetWaypoint(double s) const
The waypoint on this lane at road coordinate s, or nullptr when s falls outside the lane.
geom::Transform GetTransform(double s) const
const road::Lane & GetLane() const
The underlying OpenDRIVE lane. Valid only while _parent is alive.
Lane(SharedPtr< const Map > parent, road::RoadId road_id, road::SectionId section_id, road::LaneId lane_id)
bool operator==(const Lane &rhs) const
road::RoadId GetRoadId() const
Definition client/Lane.h:44
An OpenDRIVE road: a run of carriageway divided along s into lane sections, each holding the lanes.
Definition client/Road.h:36
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
uint32_t RoadId
Definition RoadTypes.h:15
int32_t LaneId
Definition RoadTypes.h:19
uint32_t SectionId
Definition RoadTypes.h:21
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15