CARLA
Loading...
Searching...
No Matches
TrafficSign.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
10#include "carla/client/Map.h"
11
12#include <unordered_map>
13#include <unordered_set>
14
15namespace carla {
16namespace client {
17
19 return std::string(GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.sign_id);
20 }
21
22 std::vector<SharedPtr<Waypoint>> TrafficSign::GetAffectedLaneWaypoints() const {
23 std::vector<SharedPtr<Waypoint>> result;
24 SharedPtr<Map> carla_map = GetEpisode().Lock()->GetCurrentMap();
25 std::vector<SharedPtr<Landmark>> landmarks = carla_map->GetLandmarksFromId(GetSignId());
26 for (auto& landmark : landmarks) {
27 for (const road::LaneValidity& validity : landmark->GetValidities()) {
28 if (validity._from_lane < validity._to_lane) {
29 for (int lane_id = validity._from_lane; lane_id <= validity._to_lane; ++lane_id) {
30 if(lane_id == 0) continue;
31 result.emplace_back(
32 carla_map->GetWaypointXODR(
33 landmark->GetRoadId(), lane_id, static_cast<float>(landmark->GetS())));
34 }
35 } else {
36 for (int lane_id = validity._from_lane; lane_id >= validity._to_lane; --lane_id) {
37 if(lane_id == 0) continue;
38 result.emplace_back(
39 carla_map->GetWaypointXODR(
40 landmark->GetRoadId(), lane_id, static_cast<float>(landmark->GetS())));
41 }
42 }
43 }
44 }
45 return result;
46 }
47
48 std::vector<SharedPtr<Waypoint>> TrafficSign::GetStopWaypoints() const {
49 std::vector<SharedPtr<Waypoint>> result;
50 SharedPtr<Map> carla_map = GetEpisode().Lock()->GetCurrentMap();
52 geom::Transform transform = GetTransform();
53 geom::Location box_position = box.location;
54 transform.TransformPoint(box_position);
55 geom::Vector3D right_direction = transform.GetForwardVector();
56 float min_x = -0.9f*box.extent.x;
57 float max_x = 0.9f*box.extent.x;
58 float current_x = min_x;
59 std::unordered_map<road::RoadId, std::unordered_set<road::LaneId>> road_lanes_map;
60 while (current_x < max_x) {
61 geom::Location query_point = box_position + geom::Location(right_direction*current_x);
62 SharedPtr<Waypoint> waypoint = carla_map->GetWaypoint(query_point);
63 if (road_lanes_map[waypoint->GetRoadId()].count(waypoint->GetLaneId()) == 0) {
64 road_lanes_map[waypoint->GetRoadId()].insert(waypoint->GetLaneId());
65 result.emplace_back(waypoint);
66 }
67 current_x += 1.f;
68 }
69 return result;
70 }
71
72} // namespace client
73} // namespace carla
geom::Transform GetTransform() const
Return the current transform of the actor.
Definition Actor.cpp:19
const geom::BoundingBox & GetTriggerVolume() const
Definition TrafficSign.h:21
carla::road::SignId GetSignId() const
std::vector< SharedPtr< Waypoint > > GetAffectedLaneWaypoints() const
std::vector< SharedPtr< Waypoint > > GetStopWaypoints() const
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
Location location
Center of the BoundingBox in local space.
Vector3D extent
Half the size of the BoundingBox in local space.
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
void TransformPoint(Vector3D &in_point) const
Applies this transformation to in_point (first translation then rotation).
Vector3D GetForwardVector() const
std::string SignId
Definition RoadTypes.h:25
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15