CARLA
Loading...
Searching...
No Matches
SimpleWaypoint.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/geom/Math.h"
8
10
11namespace carla {
12namespace traffic_manager {
13
14 using SimpleWaypointPtr = std::shared_ptr<SimpleWaypoint>;
15
17 waypoint = _waypoint;
18 next_left_waypoint = nullptr;
19 next_right_waypoint = nullptr;
20 }
22
24 next_waypoints.clear();
25 previous_waypoints.clear();
26 next_left_waypoint.reset();
27 next_right_waypoint.reset();
28 }
29
30 std::vector<SimpleWaypointPtr> SimpleWaypoint::GetNextWaypoint() const {
31 return next_waypoints;
32 }
33
34 std::vector<SimpleWaypointPtr> SimpleWaypoint::GetPreviousWaypoint() const {
35 return previous_waypoints;
36 }
37
41
42 uint64_t SimpleWaypoint::GetId() const {
43 return waypoint->GetId();
44 }
45
49
53
55 return waypoint->GetTransform().location;
56 }
57
59 return waypoint->GetTransform().rotation.GetForwardVector();
60 }
61
62 uint64_t SimpleWaypoint::SetNextWaypoint(const std::vector<SimpleWaypointPtr> &waypoints) {
63 for (auto &simple_waypoint: waypoints) {
64 next_waypoints.push_back(simple_waypoint);
65 }
66 return static_cast<uint64_t>(waypoints.size());
67 }
68
69 uint64_t SimpleWaypoint::SetPreviousWaypoint(const std::vector<SimpleWaypointPtr> &waypoints) {
70 for (auto &simple_waypoint: waypoints) {
71 previous_waypoints.push_back(simple_waypoint);
72 }
73 return static_cast<uint64_t>(waypoints.size());
74 }
75
77
78 const cg::Vector3D heading_vector = waypoint->GetTransform().GetForwardVector();
79 const cg::Vector3D relative_vector = GetLocation() - _waypoint->GetLocation();
80 if ((heading_vector.x * relative_vector.y - heading_vector.y * relative_vector.x) > 0.0f) {
81 next_left_waypoint = _waypoint;
82 }
83 }
84
86
87 const cg::Vector3D heading_vector = waypoint->GetTransform().GetForwardVector();
88 const cg::Vector3D relative_vector = GetLocation() - _waypoint->GetLocation();
89 if ((heading_vector.x * relative_vector.y - heading_vector.y * relative_vector.x) < 0.0f) {
90 next_right_waypoint = _waypoint;
91 }
92 }
93
94 float SimpleWaypoint::Distance(const cg::Location &location) const {
95 return GetLocation().Distance(location);
96 }
97
98 float SimpleWaypoint::Distance(const SimpleWaypointPtr &other) const {
99 return GetLocation().Distance(other->GetLocation());
100 }
101
102 float SimpleWaypoint::DistanceSquared(const cg::Location &location) const {
103 return cg::Math::DistanceSquared(GetLocation(), location);
104 }
105
107 return cg::Math::DistanceSquared(GetLocation(), other->GetLocation());
108 }
109
111 return _is_junction;
112 }
113
115 _is_junction = value;
116 }
117
119 return (next_waypoints.size() > 1);
120 }
121
123 geodesic_grid_id = _geodesic_grid_id;
124 }
125
127 GeoGridId grid_id;
128 if (waypoint->IsJunction()) {
129 grid_id = waypoint->GetJunctionId();
130 } else {
131 grid_id = geodesic_grid_id;
132 }
133 return grid_id;
134 }
135
137 return waypoint->GetJunctionId();
138 }
139
141 return waypoint->GetTransform();
142 }
143
145 road_option = _road_option;
146 }
147
151
152} // namespace traffic_manager
153} // namespace carla
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
std::vector< SimpleWaypointPtr > previous_waypoints
List of pointers to previous connecting waypoints.
bool CheckIntersection() const
Returns true if the object's waypoint belongs to an intersection (Doesn't use OpenDrive).
uint64_t SetNextWaypoint(const std::vector< SimpleWaypointPtr > &next_waypoints)
This method is used to set the next waypoints.
GeoGridId GetJunctionId() const
Method to retreive junction id of the waypoint.
void SetLeftWaypoint(SimpleWaypointPtr &waypoint)
This method is used to set the closest left waypoint for a lane change.
std::vector< SimpleWaypointPtr > GetNextWaypoint() const
Returns the list of next waypoints.
void SetRightWaypoint(SimpleWaypointPtr &waypoint)
This method is used to set the closest right waypoint for a lane change.
SimpleWaypointPtr next_left_waypoint
Pointer to left lane change waypoint.
WaypointPtr waypoint
Pointer to Carla's waypoint object around which this class wraps around.
bool CheckJunction() const
Returns true if the object's waypoint belongs to an intersection.
float DistanceSquared(const cg::Location &location) const
Calculates the square of the distance to given location.
GeoGridId geodesic_grid_id
Integer placing the waypoint into a geodesic grid.
cg::Vector3D GetForwardVector() const
Returns the vector along the waypoint's direction.
void SetRoadOption(RoadOption _road_option)
std::vector< SimpleWaypointPtr > next_waypoints
List of pointers to next connecting waypoints.
std::vector< SimpleWaypointPtr > GetPreviousWaypoint() const
Returns the list of previous waypoints.
uint64_t GetId() const
Returns the unique id for the waypoint.
WaypointPtr GetWaypoint() const
Returns a carla::shared_ptr to carla::waypoint.
SimpleWaypointPtr next_right_waypoint
Pointer to right lane change waypoint.
void ClearLinks()
Drops the links to the neighbouring waypoints (next, previous, left and right).
void SetIsJunction(bool value)
This method is used to set whether the waypoint belongs to a junction.
uint64_t SetPreviousWaypoint(const std::vector< SimpleWaypointPtr > &next_waypoints)
This method is used to set the previous waypoints.
cg::Transform GetTransform() const
Return transform object for the current waypoint.
SimpleWaypointPtr GetLeftWaypoint()
This method is used to get the closest left waypoint for a lane change.
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
float Distance(const cg::Location &location) const
Calculates the distance from the object's waypoint to the passed location.
void SetGeodesicGridId(GeoGridId _geodesic_grid_id)
Accessor methods for geodesic grid id.
cg::Location GetLocation() const
Returns the location object for this waypoint.
SimpleWaypointPtr GetRightWaypoint()
This method is used to get the closest right waypoint for a lane change.
RoadOption road_option
RoadOption for the actual waypoint.
carla::SharedPtr< cc::Waypoint > WaypointPtr
Definition InMemoryMap.h:45
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
This file contains definitions of common data structures used in traffic manager.
auto Distance(Location loc) const