Apollo 10.0
自动驾驶开放平台
signals_xml_parser.cc
浏览该文件的文档.
1/* Copyright 2017 The Apollo Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14=========================================================================*/
16
18
19namespace apollo {
20namespace hdmap {
21namespace adapter {
22
24 const tinyxml2::XMLElement& xml_node,
25 std::vector<TrafficLightInternal>* traffic_lights) {
26 CHECK_NOTNULL(traffic_lights);
27 auto signal_node = xml_node.FirstChildElement("signal");
28 while (signal_node) {
29 std::string object_type;
30 std::string object_id;
31 int checker =
32 UtilXmlParser::QueryStringAttribute(*signal_node, "type", &object_type);
33 checker +=
34 UtilXmlParser::QueryStringAttribute(*signal_node, "id", &object_id);
35 if (checker != tinyxml2::XML_SUCCESS) {
36 std::string err_msg = "Error parse signal type.";
38 }
39
40 if (object_type == "trafficLight") {
41 PbSignal traffic_light;
42 traffic_light.mutable_id()->set_id(object_id);
43 std::string layout_type;
45 *signal_node, "layoutType", &layout_type);
46 if (checker != tinyxml2::XML_SUCCESS) {
47 std::string err_msg = "Error parse signal layout type.";
49 }
50 PbSignalType signal_layout_type;
51 ToPbSignalType(layout_type, &signal_layout_type);
52 traffic_light.set_type(signal_layout_type);
53
54 auto sign_infos_node = signal_node->FirstChildElement("signInfos");
55 if (sign_infos_node != nullptr) {
56 auto sign_info_node = sign_infos_node->FirstChildElement("signInfo");
57 while (sign_info_node != nullptr) {
58 std::string sign_info_type;
59 checker = UtilXmlParser::QueryStringAttribute(*sign_info_node, "type",
60 &sign_info_type);
61 if (checker != tinyxml2::XML_SUCCESS) {
62 std::string err_msg = "Error parse sign info type.";
64 }
65
66 auto sign_info = traffic_light.add_sign_info();
67 PbSignInfoType pb_sign_info_type;
68 to_pb_sign_info_type(sign_info_type, &pb_sign_info_type);
69 sign_info->set_type(pb_sign_info_type);
70
71 sign_info_node = sign_info_node->NextSiblingElement("signInfo");
72 }
73 }
74
75 PbPolygon* polygon = traffic_light.mutable_boundary();
76 auto outline_node = signal_node->FirstChildElement("outline");
77 if (outline_node == nullptr) {
78 std::string err_msg = "Error parse signal outline";
80 }
81 RETURN_IF_ERROR(UtilXmlParser::ParseOutline(*outline_node, polygon));
82 auto sub_node = signal_node->FirstChildElement("subSignal");
83 if (sub_node == nullptr) {
84 std::string err_msg = "Error parse sub signal.";
86 }
87
88 while (sub_node) {
89 std::string sub_signal_id;
90 std::string sub_signal_xml_type;
91 checker = UtilXmlParser::QueryStringAttribute(*sub_node, "type",
92 &sub_signal_xml_type);
93 checker += UtilXmlParser::QueryStringAttribute(*sub_node, "id",
94 &sub_signal_id);
95 if (checker != tinyxml2::XML_SUCCESS) {
96 std::string err_msg = "Error parse sub signal layout type.";
98 }
99
100 PbSubSignal* sub_signal = traffic_light.add_subsignal();
101 PbSubSignalType sub_signal_type;
102 ToPbSubSignalType(sub_signal_xml_type, &sub_signal_type);
103 sub_signal->mutable_id()->set_id(sub_signal_id);
104 sub_signal->set_type(sub_signal_type);
105 PbPoint3D* pt = sub_signal->mutable_location();
107
108 sub_node = sub_node->NextSiblingElement("subSignal");
109 }
110
111 TrafficLightInternal trafficlight_internal;
112 trafficlight_internal.id = object_id;
113 trafficlight_internal.traffic_light = traffic_light;
114
115 sub_node = signal_node->FirstChildElement("stopline");
116 if (sub_node) {
117 sub_node = sub_node->FirstChildElement("objectReference");
118 while (sub_node) {
119 std::string stop_line_id;
120 int checker = UtilXmlParser::QueryStringAttribute(*sub_node, "id",
121 &stop_line_id);
122 ACHECK(checker == tinyxml2::XML_SUCCESS);
123 trafficlight_internal.stop_line_ids.insert(stop_line_id);
124 sub_node = sub_node->NextSiblingElement("objectReference");
125 }
126 }
127 traffic_lights->emplace_back(trafficlight_internal);
128 }
129 signal_node = signal_node->NextSiblingElement("signal");
130 }
131 return Status::OK();
132}
133
134Status SignalsXmlParser::ToPbSignalType(const std::string& xml_type,
135 PbSignalType* signal_type) {
136 CHECK_NOTNULL(signal_type);
137
138 std::string upper_str = UtilXmlParser::ToUpper(xml_type);
139
140 if (upper_str == "UNKNOWN") {
141 *signal_type = hdmap::Signal::UNKNOWN;
142 } else if (upper_str == "MIX2HORIZONTAL") {
143 *signal_type = hdmap::Signal::MIX_2_HORIZONTAL;
144 } else if (upper_str == "MIX2VERTICAL") {
145 *signal_type = hdmap::Signal::MIX_2_VERTICAL;
146 } else if (upper_str == "MIX3HORIZONTAL") {
147 *signal_type = hdmap::Signal::MIX_3_HORIZONTAL;
148 } else if (upper_str == "MIX3VERTICAL") {
149 *signal_type = hdmap::Signal::MIX_3_VERTICAL;
150 } else if (upper_str == "SINGLE") {
151 *signal_type = hdmap::Signal::SINGLE;
152 } else {
153 std::string err_msg = "Error or unsupport signal layout type";
155 }
156
157 return Status::OK();
158}
159
160Status SignalsXmlParser::ToPbSubSignalType(const std::string& xml_type,
161 PbSubSignalType* sub_signal_type) {
162 CHECK_NOTNULL(sub_signal_type);
163
164 std::string upper_str = UtilXmlParser::ToUpper(xml_type);
165
166 if (upper_str == "UNKNOWN") {
167 *sub_signal_type = hdmap::Subsignal::UNKNOWN;
168 } else if (upper_str == "CIRCLE") {
169 *sub_signal_type = hdmap::Subsignal::CIRCLE;
170 } else if (upper_str == "ARROWLEFT") {
171 *sub_signal_type = hdmap::Subsignal::ARROW_LEFT;
172 } else if (upper_str == "ARROWFORWARD") {
173 *sub_signal_type = hdmap::Subsignal::ARROW_FORWARD;
174 } else if (upper_str == "ARROWRIGHT") {
175 *sub_signal_type = hdmap::Subsignal::ARROW_RIGHT;
176 } else if (upper_str == "ARROWLEFTANDFORWARD") {
178 } else if (upper_str == "ARROWRIGHTANDFORWARD") {
180 } else if (upper_str == "ARROWUTURN") {
181 *sub_signal_type = hdmap::Subsignal::ARROW_U_TURN;
182 } else {
183 std::string err_msg = "Error or unsupport sub signal type";
185 }
186 return Status::OK();
187}
188
189Status SignalsXmlParser::to_pb_sign_info_type(const std::string& xml_type,
190 PbSignInfoType* sign_info_type) {
191 CHECK_NOTNULL(sign_info_type);
192
193 std::string upper_str = UtilXmlParser::ToUpper(xml_type);
194
195 if (upper_str == "NORIGHTTURNONRED") {
197 } else {
198 std::string err_msg = "Error or unsupport stop sign type";
200 }
201 return Status::OK();
202}
203
204Status SignalsXmlParser::ToPbStopSignType(const std::string& xml_type,
205 PbStopSignType* stop_type) {
206 CHECK_NOTNULL(stop_type);
207
208 std::string upper_str = UtilXmlParser::ToUpper(xml_type);
209
210 if (upper_str == "UNKNOWN") {
211 *stop_type = hdmap::StopSign::UNKNOWN;
212 } else if (upper_str == "ONEWAY") {
213 *stop_type = hdmap::StopSign::ONE_WAY;
214 } else if (upper_str == "TWOWAY") {
215 *stop_type = hdmap::StopSign::TWO_WAY;
216 } else if (upper_str == "THREEWAY") {
217 *stop_type = hdmap::StopSign::THREE_WAY;
218 } else if (upper_str == "FOURWAY") {
219 *stop_type = hdmap::StopSign::FOUR_WAY;
220 } else if (upper_str == "ALLWAY") {
221 *stop_type = hdmap::StopSign::ALL_WAY;
222 } else {
223 std::string err_msg = "Error or unsupport stop sign type";
225 }
226 return Status::OK();
227}
228
230 const tinyxml2::XMLElement& xml_node,
231 std::vector<StopSignInternal>* stop_signs) {
232 CHECK_NOTNULL(stop_signs);
233
234 auto signal_node = xml_node.FirstChildElement("signal");
235 while (signal_node) {
236 std::string object_type;
237 std::string object_id;
238 int checker =
239 UtilXmlParser::QueryStringAttribute(*signal_node, "type", &object_type);
240 checker +=
241 UtilXmlParser::QueryStringAttribute(*signal_node, "id", &object_id);
242 if (checker != tinyxml2::XML_SUCCESS) {
243 std::string err_msg = "Error parse signal type.";
245 }
246
247 if (object_type == "stopSign") {
248 PbStopSign stop_sign;
249 stop_sign.mutable_id()->set_id(object_id);
250
251 StopSignInternal stop_sign_internal;
252 stop_sign_internal.stop_sign = stop_sign;
253
254 auto sub_node = signal_node->FirstChildElement("stopline");
255 if (sub_node) {
256 sub_node = sub_node->FirstChildElement("objectReference");
257 while (sub_node) {
258 std::string stop_line_id;
259 int checker = UtilXmlParser::QueryStringAttribute(*sub_node, "id",
260 &stop_line_id);
261 ACHECK(checker == tinyxml2::XML_SUCCESS);
262 stop_sign_internal.stop_line_ids.insert(stop_line_id);
263
264 sub_node = sub_node->NextSiblingElement("objectReference");
265 }
266 }
267
268 sub_node = signal_node->FirstChildElement("attribute");
269 if (sub_node) {
270 std::string stop_type;
271 int checker = UtilXmlParser::QueryStringAttribute(*sub_node, "stopType",
272 &stop_type);
273 if (checker != tinyxml2::XML_SUCCESS) {
274 std::string err_msg = "Error parse stop type.";
276 }
277
278 PbStopSignType pb_stop_type;
279 ToPbStopSignType(stop_type, &pb_stop_type);
280 stop_sign_internal.stop_sign.set_type(pb_stop_type);
281 }
282
283 stop_signs->emplace_back(stop_sign_internal);
284 }
285
286 signal_node = signal_node->NextSiblingElement("signal");
287 }
288 return Status::OK();
289}
290
292 const tinyxml2::XMLElement& xml_node,
293 std::vector<YieldSignInternal>* yield_signs) {
294 CHECK_NOTNULL(yield_signs);
295
296 auto signal_node = xml_node.FirstChildElement("signal");
297 while (signal_node) {
298 std::string object_type;
299 std::string object_id;
300 int checker =
301 UtilXmlParser::QueryStringAttribute(*signal_node, "type", &object_type);
302 checker +=
303 UtilXmlParser::QueryStringAttribute(*signal_node, "id", &object_id);
304 if (checker != tinyxml2::XML_SUCCESS) {
305 std::string err_msg = "Error parse signal type.";
307 }
308
309 if (object_type == "yieldSign") {
310 PbYieldSign yield_sign;
311 yield_sign.mutable_id()->set_id(object_id);
312 YieldSignInternal yield_sign_internal;
313 yield_sign_internal.id = object_id;
314 yield_sign_internal.yield_sign = yield_sign;
315 auto sub_node = signal_node->FirstChildElement("stopline");
316 if (sub_node) {
317 sub_node = sub_node->FirstChildElement("objectReference");
318 while (sub_node) {
319 std::string stop_line_id;
320 int checker = UtilXmlParser::QueryStringAttribute(*sub_node, "id",
321 &stop_line_id);
322 ACHECK(checker == tinyxml2::XML_SUCCESS);
323 yield_sign_internal.stop_line_ids.insert(stop_line_id);
324
325 sub_node = sub_node->NextSiblingElement("objectReference");
326 }
327 }
328 yield_signs->emplace_back(yield_sign_internal);
329 }
330
331 signal_node = signal_node->NextSiblingElement("signal");
332 }
333 return Status::OK();
334}
335
336} // namespace adapter
337} // namespace hdmap
338} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
static Status ParseStopSigns(const tinyxml2::XMLElement &xml_node, std::vector< StopSignInternal > *stop_signs)
static Status ParseYieldSigns(const tinyxml2::XMLElement &xml_node, std::vector< YieldSignInternal > *yield_signs)
static Status ParseTrafficLights(const tinyxml2::XMLElement &xml_node, std::vector< TrafficLightInternal > *traffic_lights)
static std::string ToUpper(const std::string &s)
static tinyxml2::XMLError QueryStringAttribute(const tinyxml2::XMLElement &xml_node, const std::string &name, std::string *value)
static Status ParseOutline(const tinyxml2::XMLElement &xml_node, PbPolygon *polygon)
static Status ParsePoint(const tinyxml2::XMLElement &xml_node, PbPoint3D *pt)
#define ACHECK(cond)
Definition log.h:80
#define RETURN_IF_ERROR(expr)
Definition status.h:25
apollo::hdmap::Subsignal_Type PbSubSignalType
apollo::hdmap::SignInfo::Type PbSignInfoType
apollo::hdmap::StopSign_StopType PbStopSignType
apollo::hdmap::Signal_Type PbSignalType
class register implement
Definition arena_queue.h:37
std::unordered_set< std::string > stop_line_ids
std::unordered_set< std::string > stop_line_ids
std::unordered_set< std::string > stop_line_ids