CARLA
road/Junction.h
Go to the documentation of this file.
1 // Copyright (c) 2017 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 
10 #include "carla/NonCopyable.h"
11 #include "carla/road/RoadTypes.h"
12 
13 #include <unordered_map>
14 #include <unordered_set>
15 #include <vector>
16 #include <string>
17 
18 namespace carla {
19 namespace road {
20 
21  class MapBuilder;
22 
23  class Junction : private MovableNonCopyable {
24  public:
25 
26  struct LaneLink {
29  };
30 
31  struct Connection {
35  std::vector<LaneLink> lane_links;
36 
38  lane_links.push_back(LaneLink{from, to});
39  }
40 
41  Connection(ConId id, RoadId incoming_road, RoadId connecting_road)
42  : id(id),
43  incoming_road(incoming_road),
44  connecting_road(connecting_road),
45  lane_links() {}
46  };
47 
48  Junction(const JuncId id, const std::string name)
49  : _id(id),
50  _name(name),
51  _connections() {}
52 
53  JuncId GetId() const {
54  return _id;
55  }
56 
58  const auto search = _connections.find(id);
59  if (search != _connections.end()) {
60  return &search->second;
61  }
62  return nullptr;
63  }
64 
65  std::unordered_map<ConId, Connection> &GetConnections() {
66  return _connections;
67  }
68 
69  std::unordered_map<ConId, Connection> GetConnections() const {
70  return _connections;
71  }
72 
74  return _bounding_box;
75  }
76 
77  bool RoadHasConflicts(RoadId road_id) const {
78  return _road_conflicts.count(road_id) > 0;
79  }
80 
81  const std::unordered_set<RoadId> & GetConflictsOfRoad(RoadId road_id) const {
82  return _road_conflicts.at(road_id);
83  }
84 
85  const std::set<ContId>& GetControllers() const {
86  return _controllers;
87  }
88 
89  private:
90 
91  friend MapBuilder;
92 
94 
95  std::string _name;
96 
97  std::unordered_map<ConId, Connection> _connections;
98 
99  std::set<ContId> _controllers;
100 
101  std::unordered_map<RoadId, std::unordered_set<RoadId>>
103 
105  };
106 
107 } // road
108 } // carla
uint32_t RoadId
Definition: RoadTypes.h:15
carla::geom::BoundingBox GetBoundingBox() const
Definition: road/Junction.h:73
void AddLaneLink(LaneId from, LaneId to)
Definition: road/Junction.h:37
std::vector< LaneLink > lane_links
Definition: road/Junction.h:35
const std::set< ContId > & GetControllers() const
Definition: road/Junction.h:85
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
JuncId GetId() const
Definition: road/Junction.h:53
std::unordered_map< RoadId, std::unordered_set< RoadId > > _road_conflicts
int32_t JuncId
Definition: RoadTypes.h:17
Inherit (privately) to suppress copy construction and assignment.
Connection(ConId id, RoadId incoming_road, RoadId connecting_road)
Definition: road/Junction.h:41
int32_t LaneId
Definition: RoadTypes.h:19
std::unordered_map< ConId, Connection > GetConnections() const
Definition: road/Junction.h:69
bool RoadHasConflicts(RoadId road_id) const
Definition: road/Junction.h:77
std::unordered_map< ConId, Connection > _connections
Definition: road/Junction.h:97
const std::unordered_set< RoadId > & GetConflictsOfRoad(RoadId road_id) const
Definition: road/Junction.h:81
uint32_t ConId
Definition: RoadTypes.h:27
Junction(const JuncId id, const std::string name)
Definition: road/Junction.h:48
std::unordered_map< ConId, Connection > & GetConnections()
Definition: road/Junction.h:65
std::set< ContId > _controllers
Definition: road/Junction.h:99
Connection * GetConnection(ConId id)
Definition: road/Junction.h:57
carla::geom::BoundingBox _bounding_box