CARLA
 
载入中...
搜索中...
未找到
ObjectParser.cpp
浏览该文件的文档.
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
15namespace carla {
16namespace opendrive {
17namespace 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;
71 if (name.find("STATIC") != std::string::npos) {
72 speed_str = name.substr(13);
73 } else {
74 speed_str = name.substr(6);
75 }
76 double speed = std::stod(speed_str);
77 map_builder.AddSignal(road,
78 node_object.attribute("id").as_string(),
79 node_object.attribute("s").as_double(),
80 node_object.attribute("t").as_double(),
81 node_object.attribute("name").as_string(),
82 "no",
83 node_object.attribute("orientation").as_string(),
84 node_object.attribute("zOffset").as_double(),
85 "OpenDRIVE",
86 "274",
87 speed_str,
88 speed,
89 "mph",
90 node_object.attribute("height").as_double(),
91 node_object.attribute("width").as_double(),
92 speed_str,
93 node_object.attribute("hdg").as_double(),
94 node_object.attribute("pitch").as_double(),
95 node_object.attribute("roll").as_double());
96 } else if (name.find("Stencil_STOP") != std::string::npos) {
97 road::RoadId road_id = node_road.attribute("id").as_uint();
98 road::Road *road = map_builder.GetRoad(road_id);
99 map_builder.AddSignal(road,
100 node_object.attribute("id").as_string(),
101 node_object.attribute("s").as_double(),
102 node_object.attribute("t").as_double(),
103 node_object.attribute("name").as_string(),
104 "no",
105 node_object.attribute("orientation").as_string(),
106 node_object.attribute("zOffset").as_double(),
107 "OpenDRIVE",
108 "206",
109 "",
110 0,
111 "mph",
112 node_object.attribute("height").as_double(),
113 node_object.attribute("width").as_double(),
114 "",
115 node_object.attribute("hdg").as_double(),
116 node_object.attribute("pitch").as_double(),
117 node_object.attribute("roll").as_double());
118 }
119 }
120 }
121 }
122 }
123} // namespace parser
124} // namespace opendrive
125} // namespace carla
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
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)
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)
Road * GetRoad(const RoadId road_id)
const char_t * as_string(const char_t *def=PUGIXML_TEXT("")) const
Definition pugixml.cpp:5163
unsigned int as_uint(unsigned int def=0) const
Definition pugixml.cpp:5173
xml_node child(const char_t *name) const
Definition pugixml.cpp:5490
xml_object_range< xml_node_iterator > children() const
Definition pugixml.cpp:5425
xml_attribute attribute(const char_t *name) const
Definition pugixml.cpp:5500
uint32_t RoadId
Definition RoadTypes.h:15
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133