CARLA
SignalParser.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 
17  static void AddValidity(
18  road::element::RoadInfoSignal* signal_reference,
19  pugi::xml_node parent_node,
20  const std::string &node_name,
21  road::MapBuilder &map_builder) {
22  for (pugi::xml_node validity_node = parent_node.child(node_name.c_str());
23  validity_node;
24  validity_node = validity_node.next_sibling("validity")) {
25  const auto from_lane = validity_node.attribute("fromLane").as_int();
26  const auto to_lane = validity_node.attribute("toLane").as_int();
27  map_builder.AddValidityToSignalReference(signal_reference, from_lane, to_lane);
28  }
29  }
30 
32  const pugi::xml_document &xml,
33  carla::road::MapBuilder &map_builder) {
34 
35  // Extracting the OpenDRIVE
36  const pugi::xml_node opendrive_node = xml.child("OpenDRIVE");
37  const std::string validity = "validity";
38  for (pugi::xml_node road_node = opendrive_node.child("road");
39  road_node;
40  road_node = road_node.next_sibling("road")) {
41 
42  road::RoadId road_id = road_node.attribute("id").as_uint();
43 
44  const pugi::xml_node signals_node = road_node.child("signals");
45  if(signals_node){
46  for (pugi::xml_node signal_node : signals_node.children("signal")) {
47  const double s_position = signal_node.attribute("s").as_double();
48  const double t_position = signal_node.attribute("t").as_double();
49  const road::SignId signal_id = signal_node.attribute("id").value();
50  const std::string name = signal_node.attribute("name").value();
51  const std::string dynamic = signal_node.attribute("dynamic").value();
52  const std::string orientation = signal_node.attribute("orientation").value();
53  const double zOffset = signal_node.attribute("zOffSet").as_double();
54  const std::string country = signal_node.attribute("country").value();
55  const std::string type = signal_node.attribute("type").value();
56  const std::string subtype = signal_node.attribute("subtype").value();
57  const double value = signal_node.attribute("value").as_double();
58  const std::string unit = signal_node.attribute("unit").value();
59  const double height = signal_node.attribute("height").as_double();
60  const double width = signal_node.attribute("width").as_double();
61  const std::string text = signal_node.attribute("text").value();
62  const double hOffset = signal_node.attribute("hOffset").as_double();
63  const double pitch = signal_node.attribute("pitch").as_double();
64  const double roll = signal_node.attribute("roll").as_double();
65  log_debug("Road: ",
66  road_id,
67  "Adding Signal: ",
68  s_position,
69  t_position,
70  signal_id,
71  name,
72  dynamic,
73  orientation,
74  zOffset,
75  country,
76  type,
77  subtype,
78  value,
79  unit,
80  height,
81  width,
82  text,
83  hOffset,
84  pitch,
85  roll);
86 
87  carla::road::Road *road = map_builder.GetRoad(road_id);
88  auto signal_reference = map_builder.AddSignal(road,
89  signal_id,
90  s_position,
91  t_position,
92  name,
93  dynamic,
94  orientation,
95  zOffset,
96  country,
97  type,
98  subtype,
99  value,
100  unit,
101  height,
102  width,
103  text,
104  hOffset,
105  pitch,
106  roll);
107  AddValidity(signal_reference, signal_node, "validity", map_builder);
108 
109  for (pugi::xml_node dependency_node : signal_node.children("dependency")) {
110  const std::string dependency_id = dependency_node.attribute("id").value();
111  const std::string dependency_type = dependency_node.attribute("type").value();
112  log_debug("Added dependency to signal ", signal_id, ":", dependency_id, dependency_type);
113  map_builder.AddDependencyToSignal(signal_id, dependency_id, dependency_type);
114  }
115  for (pugi::xml_node position_node : signal_node.children("positionInertial")) {
116  const double x = position_node.attribute("x").as_double();
117  const double y = position_node.attribute("y").as_double();
118  const double z = position_node.attribute("z").as_double();
119  const double hdg = position_node.attribute("hdg").as_double();
120  const double inertial_pitch = position_node.attribute("pitch").as_double();
121  const double inertial_roll = position_node.attribute("roll").as_double();
122  map_builder.AddSignalPositionInertial(
123  signal_id,
124  x, y, z,
125  hdg, inertial_pitch, inertial_roll);
126  }
127  }
128  for (pugi::xml_node signal_reference_node : signals_node.children("signalReference")) {
129  const double s_position = signal_reference_node.attribute("s").as_double();
130  const double t_position = signal_reference_node.attribute("t").as_double();
131  const road::SignId signal_id = signal_reference_node.attribute("id").value();
132  const std::string signal_reference_orientation =
133  signal_reference_node.attribute("orientation").value();
134  log_debug("Road: ",
135  road_id,
136  "Added SignalReference ",
137  s_position,
138  t_position,
139  signal_reference_orientation);
140  carla::road::Road *road = map_builder.GetRoad(road_id);
141  auto signal_reference = map_builder.AddSignalReference(
142  road,
143  signal_id,
144  s_position,
145  t_position,
146  signal_reference_orientation);
147  AddValidity(signal_reference, signal_reference_node, "validity", map_builder);
148  }
149  }
150  }
151  }
152 } // namespace parser
153 } // namespace opendrive
154 } // namespace carla
void AddSignalPositionInertial(const SignId signal_id, const double x, const double y, const double z, const double hdg, const double pitch, const double roll)
Definition: MapBuilder.cpp:282
double as_double(double def=0) const
Definition: pugixml.cpp:5178
std::string SignId
Definition: RoadTypes.h:25
Road * GetRoad(const RoadId road_id)
Definition: MapBuilder.cpp:603
uint32_t RoadId
Definition: RoadTypes.h:15
element::RoadInfoSignal * AddSignalReference(Road *road, const SignId signal_id, const double s_position, const double t_position, const std::string signal_reference_orientation)
Definition: MapBuilder.cpp:318
unsigned int as_uint(unsigned int def=0) const
Definition: pugixml.cpp:5173
xml_node next_sibling() const
Definition: pugixml.cpp:5521
void AddDependencyToSignal(const SignId signal_id, const std::string dependency_id, const std::string dependency_type)
Definition: MapBuilder.cpp:344
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
xml_attribute attribute(const char_t *name) const
Definition: pugixml.cpp:5500
static void log_debug(Args &&...)
Definition: Logging.h:75
void AddValidityToSignalReference(element::RoadInfoSignal *signal_reference, const LaneId from_lane, const LaneId to_lane)
Definition: MapBuilder.cpp:337
xml_node child(const char_t *name) const
Definition: pugixml.cpp:5490
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
element::RoadInfoSignal * AddSignal(Road *road, const SignId signal_id, const double s, const double t, const std::string name, const std::string dynamic, const std::string orientation, const double zOffset, const std::string country, const std::string type, const std::string subtype, const double value, const std::string unit, const double height, const double width, const std::string text, const double hOffset, const double pitch, const double roll)
Definition: MapBuilder.cpp:238
static void AddValidity(road::element::RoadInfoSignal *signal_reference, pugi::xml_node parent_node, const std::string &node_name, road::MapBuilder &map_builder)
xml_object_range< xml_node_iterator > children() const
Definition: pugixml.cpp:5425