CARLA
 
载入中...
搜索中...
未找到
LaneParser.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
10
11#include <pugixml/pugixml.hpp>
12
13namespace carla {
14namespace opendrive {
15namespace parser {
16
17 static void ParseLanes(
18 road::RoadId road_id,
19 double s,
20 const pugi::xml_node &parent_node,
21 carla::road::MapBuilder &map_builder) {
22 for (pugi::xml_node lane_node : parent_node.children("lane")) {
23
24 road::LaneId lane_id = lane_node.attribute("id").as_int();
25
26 road::Lane *lane = map_builder.GetLane(road_id, lane_id, s);
27
28 // Lane Width
29 int width_count = 0;
30 for (pugi::xml_node lane_width_node : lane_node.children("width")) {
31 const double s_offset = lane_width_node.attribute("sOffset").as_double();
32 const double a = lane_width_node.attribute("a").as_double();
33 const double b = lane_width_node.attribute("b").as_double();
34 const double c = lane_width_node.attribute("c").as_double();
35 const double d = lane_width_node.attribute("d").as_double();
36
37 // Call Map builder create Lane Width function
38 map_builder.CreateLaneWidth(lane, s_offset + s, a, b, c, d);
39 width_count++;
40 }
41 if (width_count == 0 && lane->GetId() != 0) {
42 map_builder.CreateLaneWidth(lane, s, 0.0, 0.0, 0.0, 0.0);
43 std::cout << "WARNING: In road " << lane->GetRoad()->GetId() << " lane " << lane->GetId() <<
44 " no \"<width>\" parameter found under \"<lane>\" tag. Using default values." << std::endl;
45 }
46
47 // Lane Border
48 for (pugi::xml_node lane_border_node : lane_node.children("border")) {
49 const double s_offset = lane_border_node.attribute("sOffset").as_double();
50 const double a = lane_border_node.attribute("a").as_double();
51 const double b = lane_border_node.attribute("b").as_double();
52 const double c = lane_border_node.attribute("c").as_double();
53 const double d = lane_border_node.attribute("d").as_double();
54
55 // Call Map builder create Lane Border function
56 map_builder.CreateLaneBorder(lane, s_offset + s, a, b, c, d);
57 }
58
59 // Lane Road Mark
60 int road_mark_id = 0;
61 for (pugi::xml_node lane_road_mark : lane_node.children("roadMark")) {
62 pugi::xml_node road_mark_type;
63 {
64 const double s_offset = lane_road_mark.attribute("sOffset").as_double();
65 const std::string type = lane_road_mark.attribute("type").value();
66 const std::string weight = lane_road_mark.attribute("weight").value();
67 const std::string color = lane_road_mark.attribute("color").value();
68 const std::string material = lane_road_mark.attribute("material").value();
69 const double width = lane_road_mark.attribute("width").as_double();
70 const std::string lane_change = lane_road_mark.attribute("laneChange").value();
71 const double height = lane_road_mark.attribute("height").as_double();
72
73 // Call map builder for LaneRoadMarkType
74
75 std::string type_name = "";
76 double type_width = 0.0;
77 road_mark_type = lane_road_mark.child("type");
78 if (road_mark_type) {
79 type_name = road_mark_type.attribute("name").value();
80 type_width = road_mark_type.attribute("width").as_double();
81 }
82
83 // Call map builder for LaneRoadMark
84 map_builder.CreateRoadMark(
85 lane,
86 road_mark_id,
87 s_offset + s,
88 type,
89 weight,
90 color,
91 material,
92 width,
93 lane_change,
94 height,
95 type_name,
96 type_width);
97 }
98
99 for (pugi::xml_node road_mark_type_line_node : road_mark_type.children("line")) {
100
101 const double length = road_mark_type_line_node.attribute("length").as_double();
102 const double space = road_mark_type_line_node.attribute("space").as_double();
103 const double t = road_mark_type_line_node.attribute("tOffset").as_double();
104 const double s_offset = road_mark_type_line_node.attribute("sOffset").as_double();
105 const std::string rule = road_mark_type_line_node.attribute("rule").value();
106 const double width = road_mark_type_line_node.attribute("width").as_double();
107
108 // Call map builder for LaneRoadMarkType LaneRoadMarkTypeLine
109 map_builder.CreateRoadMarkTypeLine(
110 lane,
111 road_mark_id,
112 length,
113 space,
114 t,
115 s_offset + s,
116 rule,
117 width);
118 }
119 ++road_mark_id;
120 }
121
122 // Lane Material
123 for (pugi::xml_node lane_material_node : lane_node.children("material")) {
124
125 const double s_offset = lane_material_node.attribute("sOffset").as_double();
126 const std::string surface = lane_material_node.attribute("surface").value();
127 const double friction = lane_material_node.attribute("friction").as_double();
128 const double roughness = lane_material_node.attribute("roughness").as_double();
129
130 // Create map builder for Lane Material
131 map_builder.CreateLaneMaterial(lane, s_offset + s, surface, friction, roughness);
132 }
133
134 // Lane Visibility
135 for (pugi::xml_node lane_visibility_node : lane_node.children("visibility")) {
136 const double s_offset = lane_visibility_node.attribute("sOffset").as_double();
137 const double forward = lane_visibility_node.attribute("forward").as_double();
138 const double back = lane_visibility_node.attribute("back").as_double();
139 const double left = lane_visibility_node.attribute("left").as_double();
140 const double right = lane_visibility_node.attribute("right").as_double();
141
142 // Create map builder for Lane Visibility
143 map_builder.CreateLaneVisibility(lane, s_offset + s, forward, back, left, right);
144 }
145
146 // Lane Speed
147 for (pugi::xml_node lane_speed_node : lane_node.children("speed")) {
148 const double s_offset = lane_speed_node.attribute("sOffset").as_double();
149 const double max = lane_speed_node.attribute("max").as_double();
150 std::string unit = lane_speed_node.attribute("unit").value();
151
152 // Create map builder for Lane Speed
153 map_builder.CreateLaneSpeed(lane, s_offset + s, max, unit);
154 }
155
156 // Lane Access
157 for (pugi::xml_node lane_access_node : lane_node.children("access")) {
158 const double s_offset = lane_access_node.attribute("sOffset").as_double();
159 const std::string restriction = lane_access_node.attribute("restriction").value();
160
161 // Create map builder for Lane Access
162 map_builder.CreateLaneAccess(lane, s_offset + s, restriction);
163 }
164
165 // Lane Height
166 for (pugi::xml_node lane_height_node : lane_node.children("height")) {
167 const double s_offset = lane_height_node.attribute("sOffset").as_double();
168 const double inner = lane_height_node.attribute("inner").as_double();
169 const double outer = lane_height_node.attribute("outer").as_double();
170
171 // Create map builder for Lane Height
172 map_builder.CreateLaneHeight(lane, s_offset + s, inner, outer);
173 }
174
175 // Lane Rule
176 for (pugi::xml_node lane_rule_node : lane_node.children("rule")) {
177 const double s_offset = lane_rule_node.attribute("sOffset").as_double();
178 const std::string value = lane_rule_node.attribute("value").value();
179
180 // Create map builder for Lane Height
181 map_builder.CreateLaneRule(lane, s_offset + s, value);
182 }
183
184 }
185 }
186
188 const pugi::xml_document &xml,
189 carla::road::MapBuilder &map_builder) {
190
191 pugi::xml_node open_drive_node = xml.child("OpenDRIVE");
192
193 // Lanes
194 for (pugi::xml_node road_node : open_drive_node.children("road")) {
195 road::RoadId road_id = road_node.attribute("id").as_uint();
196
197 for (pugi::xml_node lanes_node : road_node.children("lanes")) {
198
199 for (pugi::xml_node lane_section_node : lanes_node.children("laneSection")) {
200 double s = lane_section_node.attribute("s").as_double();
201 pugi::xml_node left_node = lane_section_node.child("left");
202 if (left_node) {
203 ParseLanes(road_id, s, left_node, map_builder);
204 }
205
206 pugi::xml_node center_node = lane_section_node.child("center");
207 if (center_node) {
208 ParseLanes(road_id, s, center_node, map_builder);
209 }
210
211 pugi::xml_node right_node = lane_section_node.child("right");
212 if (right_node) {
213 ParseLanes(road_id, s, right_node, map_builder);
214 }
215 }
216 }
217 }
218 }
219
220} // namespace parser
221} // namespace opendrive
222} // namespace carla
static void Parse(const pugi::xml_document &xml, carla::road::MapBuilder &map_builder)
Road * GetRoad() const
Definition Lane.cpp:29
LaneId GetId() const
Definition Lane.cpp:34
void CreateLaneAccess(Lane *lane, const double s, const std::string restriction)
void CreateLaneHeight(Lane *lane, const double s, const double inner, const double outer)
Lane * GetLane(const RoadId road_id, const LaneId lane_id, const double s)
void CreateLaneBorder(Lane *lane, const double s, const double a, const double b, const double c, const double d)
void CreateLaneRule(Lane *lane, const double s, const std::string value)
void CreateLaneSpeed(Lane *lane, const double s, const double max, const std::string unit)
void CreateRoadMarkTypeLine(Lane *lane, const int road_mark_id, const double length, const double space, const double tOffset, const double s, const std::string rule, const double width)
void CreateRoadMark(Lane *lane, const int road_mark_id, const double s, const std::string type, const std::string weight, const std::string color, const std::string material, const double width, const std::string lane_change, const double height, const std::string type_name, const double type_width)
void CreateLaneWidth(Lane *lane, const double s, const double a, const double b, const double c, const double d)
void CreateLaneVisibility(Lane *lane, const double s, const double forward, const double back, const double left, const double right)
void CreateLaneMaterial(Lane *lane, const double s, const std::string surface, const double friction, const double roughness)
double as_double(double def=0) const
Definition pugixml.cpp:5178
unsigned int as_uint(unsigned int def=0) const
Definition pugixml.cpp:5173
const char_t * value() const
Definition pugixml.cpp:5215
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
static void ParseLanes(road::RoadId road_id, double s, const pugi::xml_node &parent_node, carla::road::MapBuilder &map_builder)
int32_t LaneId
Definition RoadTypes.h:19
uint32_t RoadId
Definition RoadTypes.h:15
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133