CARLA
JunctionParser.cpp
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 
8 
10 
11 #include <pugixml/pugixml.hpp>
12 
13 namespace carla {
14 namespace opendrive {
15 namespace parser {
16 
18  const pugi::xml_document &xml,
19  carla::road::MapBuilder &map_builder) {
20 
21  struct LaneLink {
22  road::LaneId from;
23  road::LaneId to;
24  };
25 
26  struct Connection {
27  road::ConId id;
28  road::RoadId incoming_road;
29  road::RoadId connecting_road;
30  std::vector<LaneLink> lane_links;
31  };
32 
33  struct Junction {
34  road::JuncId id;
35  std::string name;
36  std::vector<Connection> connections;
37  std::set<road::ContId> controllers;
38  };
39 
40  pugi::xml_node open_drive_node = xml.child("OpenDRIVE");
41 
42  // Junctions
43  std::vector<Junction> junctions;
44  for (pugi::xml_node junction_node : open_drive_node.children("junction")) {
45  Junction junction;
46  junction.id = junction_node.attribute("id").as_int();
47  junction.name = junction_node.attribute("name").value();
48 
49  // Connections
50  for (pugi::xml_node connection_node : junction_node.children("connection")) {
51 
52  Connection connection;
53  connection.id = connection_node.attribute("id").as_uint();
54  connection.incoming_road = connection_node.attribute("incomingRoad").as_uint();
55  connection.connecting_road = connection_node.attribute("connectingRoad").as_uint();
56 
57  // Lane Links
58  for (pugi::xml_node lane_link_node : connection_node.children("laneLink")) {
59 
60  LaneLink lane_link;
61  lane_link.from = lane_link_node.attribute("from").as_int();
62  lane_link.to = lane_link_node.attribute("to").as_int();
63 
64  connection.lane_links.push_back(lane_link);
65  }
66 
67  junction.connections.push_back(connection);
68  }
69 
70  // Controller
71  for (pugi::xml_node controller_node : junction_node.children("controller")) {
72  const road::ContId controller_id = controller_node.attribute("id").value();
73  // const std::string controller_name = controller_node.attribute("name").value();
74  // const uint32_t controller_sequence = controller_node.attribute("sequence").as_uint();
75  junction.controllers.insert(controller_id);
76  }
77 
78  junctions.push_back(junction);
79  }
80 
81  // Fill Map Builder
82  for (auto &junction : junctions) {
83  map_builder.AddJunction(junction.id, junction.name);
84  for (auto &connection : junction.connections) {
85  map_builder.AddConnection(
86  junction.id,
87  connection.id,
88  connection.incoming_road,
89  connection.connecting_road);
90  for (auto &lane_link : connection.lane_links) {
91  map_builder.AddLaneLink(junction.id,
92  connection.id,
93  lane_link.from,
94  lane_link.to);
95  }
96  }
97  map_builder.AddJunctionController(junction.id, std::move(junction.controllers));
98  }
99  }
100 } // namespace parser
101 } // namespace opendrive
102 } // namespace carla
uint32_t RoadId
Definition: RoadTypes.h:15
void AddJunctionController(const JuncId junction_id, std::set< ContId > &&controllers)
Definition: MapBuilder.cpp:589
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
int32_t JuncId
Definition: RoadTypes.h:17
xml_node child(const char_t *name) const
Definition: pugixml.cpp:5490
int32_t LaneId
Definition: RoadTypes.h:19
void AddLaneLink(const JuncId junction_id, const ConId connection_id, const LaneId from, const LaneId to)
Definition: MapBuilder.cpp:580
void AddJunction(const JuncId id, const std::string name)
Definition: MapBuilder.cpp:566
void AddConnection(const JuncId junction_id, const ConId connection_id, const RoadId incoming_road, const RoadId connecting_road)
Definition: MapBuilder.cpp:570
uint32_t ConId
Definition: RoadTypes.h:27
std::string ContId
Definition: RoadTypes.h:29
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
xml_object_range< xml_node_iterator > children() const
Definition: pugixml.cpp:5425
carla::SharedPtr< carla::client::Junction > Junction