CARLA
TrackTraffic.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "carla/road/RoadTypes.h"
5 #include "carla/rpc/ActorId.h"
6 
8 
9 namespace carla {
10 namespace traffic_manager {
11 
12 using ActorId = carla::ActorId;
13 using ActorIdSet = std::unordered_set<ActorId>;
14 using SimpleWaypointPtr = std::shared_ptr<SimpleWaypoint>;
15 using Buffer = std::deque<SimpleWaypointPtr>;
17 
18 // This class is used to track the waypoint occupancy of all the actors.
19 class TrackTraffic {
20 
21 private:
22  /// Structure to keep track of overlapping waypoints between vehicles.
23  using WaypointOverlap = std::unordered_map<uint64_t, ActorIdSet>;
25 
26  /// Structure to keep track of waypoints occupied by vehicles;
27  using WaypointIdSet = std::unordered_set<uint64_t>;
28  using WaypointOccupancyMap = std::unordered_map<ActorId, WaypointIdSet>;
30 
31  /// Geodesic grids occupied by actors's paths.
32  std::unordered_map<ActorId, std::unordered_set<GeoGridId>> actor_to_grids;
33  /// Actors currently passing through grids.
34  std::unordered_map<GeoGridId, ActorIdSet> grid_to_actors;
35 
36 public:
37  TrackTraffic();
38 
39  /// Methods to update, remove and retrieve vehicles passing through a waypoint.
40  void UpdatePassingVehicle(uint64_t waypoint_id, ActorId actor_id);
41  void RemovePassingVehicle(uint64_t waypoint_id, ActorId actor_id);
42  ActorIdSet GetPassingVehicles(uint64_t waypoint_id) const;
43 
44  void UpdateGridPosition(const ActorId actor_id, const Buffer &buffer);
45  void UpdateUnregisteredGridPosition(const ActorId actor_id,
46  const std::vector<SimpleWaypointPtr> waypoints);
47 
49  /// Method to delete actor data from tracking.
50  void DeleteActor(ActorId actor_id);
51 
52  void Clear();
53 };
54 
55 } // namespace traffic_manager
56 } // namespace carla
std::unordered_map< uint64_t, ActorIdSet > WaypointOverlap
Structure to keep track of overlapping waypoints between vehicles.
Definition: TrackTraffic.h:23
std::unordered_set< uint64_t > WaypointIdSet
Structure to keep track of waypoints occupied by vehicles;.
Definition: TrackTraffic.h:27
rpc::ActorId ActorId
Definition: ActorId.h:18
void UpdatePassingVehicle(uint64_t waypoint_id, ActorId actor_id)
Methods to update, remove and retrieve vehicles passing through a waypoint.
void UpdateGridPosition(const ActorId actor_id, const Buffer &buffer)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
std::unordered_set< ActorId > ActorIdSet
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
int32_t JuncId
Definition: RoadTypes.h:17
void RemovePassingVehicle(uint64_t waypoint_id, ActorId actor_id)
std::unordered_map< GeoGridId, ActorIdSet > grid_to_actors
Actors currently passing through grids.
Definition: TrackTraffic.h:34
void UpdateUnregisteredGridPosition(const ActorId actor_id, const std::vector< SimpleWaypointPtr > waypoints)
carla::ActorId ActorId
ActorIdSet GetOverlappingVehicles(ActorId actor_id) const
crd::JuncId GeoGridId
Definition: InMemoryMap.h:38
void DeleteActor(ActorId actor_id)
Method to delete actor data from tracking.
WaypointOccupancyMap waypoint_occupied
Definition: TrackTraffic.h:29
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
ActorIdSet GetPassingVehicles(uint64_t waypoint_id) const
std::unordered_map< ActorId, std::unordered_set< GeoGridId > > actor_to_grids
Geodesic grids occupied by actors&#39;s paths.
Definition: TrackTraffic.h:32
std::unordered_map< ActorId, WaypointIdSet > WaypointOccupancyMap
Definition: TrackTraffic.h:28