CARLA
ObjectParser.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 
11 #include "carla/road/Road.h"
12 
13 #include <pugixml/pugixml.hpp>
14 
15 namespace carla {
16 namespace opendrive {
17 namespace parser {
18 
20  const pugi::xml_document &xml,
21  carla::road::MapBuilder &map_builder) {
22 
23  std::vector<road::element::CrosswalkPoint> points;
24 
25  for (pugi::xml_node node_road : xml.child("OpenDRIVE").children("road")) {
26 
27  // parse all objects
28  pugi::xml_node node_objects = node_road.child("objects");
29  if (node_objects) {
30 
31  for (pugi::xml_node node_object : node_objects.children("object")) {
32 
33  // type Crosswalk
34  std::string type = node_object.attribute("type").as_string();
35  std::string name = node_object.attribute("name").as_string();
36  if (type == "crosswalk") {
37 
38  // read all points
39  pugi::xml_node node_outline = node_object.child("outline");
40  if (node_outline) {
41  points.clear();
42  for (pugi::xml_node node_corner : node_outline.children("cornerLocal")) {
43  points.emplace_back(node_corner.attribute("u").as_double(),
44  node_corner.attribute("v").as_double(),
45  node_corner.attribute("z").as_double());
46  }
47  }
48  // get road id
49  road::RoadId road_id = node_road.attribute("id").as_uint();
50  road::Road *road = map_builder.GetRoad(road_id);
51 
52  // create the object
53  map_builder.AddRoadObjectCrosswalk(road,
54  node_object.attribute("name").as_string(),
55  node_object.attribute("s").as_double(),
56  node_object.attribute("t").as_double(),
57  node_object.attribute("zOffset").as_double(),
58  node_object.attribute("hdg").as_double(),
59  node_object.attribute("pitch").as_double(),
60  node_object.attribute("roll").as_double(),
61  node_object.attribute("orientation").as_string(),
62  node_object.attribute("width").as_double(),
63  node_object.attribute("length").as_double(),
64  points);
65 
66  } else if (name.substr(0, 6) == "Speed_" || name.substr(0, 6) == "speed_") {
67  road::RoadId road_id = node_road.attribute("id").as_uint();
68  road::Road *road = map_builder.GetRoad(road_id);
69  // speed signal by roadrunner
70  std::string speed_str = name.substr(6);
71  double speed = std::stod(speed_str);
72  map_builder.AddSignal(road,
73  node_object.attribute("id").as_string(),
74  node_object.attribute("s").as_double(),
75  node_object.attribute("t").as_double(),
76  node_object.attribute("name").as_string(),
77  "no",
78  node_object.attribute("orientation").as_string(),
79  node_object.attribute("zOffset").as_double(),
80  "OpenDRIVE",
81  "274",
82  speed_str,
83  speed,
84  "mph",
85  node_object.attribute("height").as_double(),
86  node_object.attribute("width").as_double(),
87  speed_str,
88  node_object.attribute("hdg").as_double(),
89  node_object.attribute("pitch").as_double(),
90  node_object.attribute("roll").as_double());
91  } else if (name.find("Stencil_STOP") != std::string::npos) {
92  road::RoadId road_id = node_road.attribute("id").as_uint();
93  road::Road *road = map_builder.GetRoad(road_id);
94  map_builder.AddSignal(road,
95  node_object.attribute("id").as_string(),
96  node_object.attribute("s").as_double(),
97  node_object.attribute("t").as_double(),
98  node_object.attribute("name").as_string(),
99  "no",
100  node_object.attribute("orientation").as_string(),
101  node_object.attribute("zOffset").as_double(),
102  "OpenDRIVE",
103  "206",
104  "",
105  0,
106  "mph",
107  node_object.attribute("height").as_double(),
108  node_object.attribute("width").as_double(),
109  "",
110  node_object.attribute("hdg").as_double(),
111  node_object.attribute("pitch").as_double(),
112  node_object.attribute("roll").as_double());
113  }
114  }
115  }
116  }
117  }
118 } // namespace parser
119 } // namespace opendrive
120 } // namespace carla
void AddRoadObjectCrosswalk(Road *road, const std::string name, const double s, const double t, const double zOffset, const double hdg, const double pitch, const double roll, const std::string orientation, const double width, const double length, const std::vector< road::element::CrosswalkPoint > points)
Definition: MapBuilder.cpp:86
Road * GetRoad(const RoadId road_id)
Definition: MapBuilder.cpp:603
uint32_t RoadId
Definition: RoadTypes.h:15
unsigned int as_uint(unsigned int def=0) const
Definition: pugixml.cpp:5173
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 Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
const char_t * as_string(const char_t *def=PUGIXML_TEXT("")) const
Definition: pugixml.cpp:5163
xml_node child(const char_t *name) const
Definition: pugixml.cpp:5490
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
xml_object_range< xml_node_iterator > children() const
Definition: pugixml.cpp:5425