Apollo 10.0
自动驾驶开放平台
opendrive_adapter.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
17#include <vector>
18
19#include "cyber/common/log.h"
30
31namespace apollo {
32namespace hdmap {
33namespace adapter {
34
35bool OpendriveAdapter::LoadData(const std::string& filename,
36 apollo::hdmap::Map* pb_map) {
37 CHECK_NOTNULL(pb_map);
38
39 tinyxml2::XMLDocument document;
40 if (document.LoadFile(filename.c_str()) != tinyxml2::XML_SUCCESS) {
41 AERROR << "fail to load file " << filename;
42 return false;
43 }
44
45 // root node
46 const tinyxml2::XMLElement* root_node = document.RootElement();
47 ACHECK(root_node != nullptr);
48 // header
49 PbHeader* map_header = pb_map->mutable_header();
50 Status status = HeaderXmlParser::Parse(*root_node, map_header);
51 if (!status.ok()) {
52 AERROR << "fail to parse opendrive header, " << status.error_message();
53 return false;
54 }
55
56 // road
57 std::vector<RoadInternal> roads;
58 status = RoadsXmlParser::Parse(*root_node, &roads);
59 if (!status.ok()) {
60 AERROR << "fail to parse opendrive road, " << status.error_message();
61 return false;
62 }
63
64 // junction
65 std::vector<JunctionInternal> junctions;
66 status = JunctionsXmlParser::Parse(*root_node, &junctions);
67 if (!status.ok()) {
68 AERROR << "fail to parse opendrive junction, " << status.error_message();
69 return false;
70 }
71
72 // objects
73 ObjectInternal objects;
74 status = ObjectsXmlParser::ParseObjects(*root_node, &objects);
75 if (!status.ok()) {
76 AERROR << "fail to parse opendrive objects, " << status.error_message();
77 return false;
78 }
79
80 ProtoOrganizer proto_organizer;
81 proto_organizer.GetRoadElements(&roads);
82 proto_organizer.GetJunctionElements(junctions);
83 proto_organizer.GetObjectElements(objects);
84 proto_organizer.GetOverlapElements(roads, junctions);
85 proto_organizer.OutputData(pb_map);
86
87 return true;
88}
89
90} // namespace adapter
91} // namespace hdmap
92} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
bool ok() const
check whether the return status is OK.
Definition status.h:67
const std::string & error_message() const
returns the error message of the status, empty if the status is OK.
Definition status.h:91
static Status Parse(const tinyxml2::XMLElement &xml_node, PbHeader *header)
static Status Parse(const tinyxml2::XMLElement &xml_node, std::vector< JunctionInternal > *junctions)
static Status ParseObjects(const tinyxml2::XMLElement &xml_node, ObjectInternal *objects)
static bool LoadData(const std::string &filename, apollo::hdmap::Map *pb_map)
void GetObjectElements(const ObjectInternal &objects)
void OutputData(apollo::hdmap::Map *pb_map)
void GetJunctionElements(const std::vector< JunctionInternal > &junctions)
void GetOverlapElements(const std::vector< RoadInternal > &roads, const std::vector< JunctionInternal > &junctions)
void GetRoadElements(std::vector< RoadInternal > *roads)
static Status Parse(const tinyxml2::XMLElement &xml_node, std::vector< RoadInternal > *roads)
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37