Apollo 10.0
自动驾驶开放平台
apollo::routing::GraphCreator类 参考

#include <graph_creator.h>

apollo::routing::GraphCreator 的协作图:

Public 成员函数

 GraphCreator (const std::string &base_map_file_path, const std::string &dump_topo_file_path, const RoutingConfig &routing_conf)
 
 ~GraphCreator ()=default
 
bool Create ()
 

详细描述

在文件 graph_creator.h30 行定义.

构造及析构函数说明

◆ GraphCreator()

apollo::routing::GraphCreator::GraphCreator ( const std::string &  base_map_file_path,
const std::string &  dump_topo_file_path,
const RoutingConfig routing_conf 
)

在文件 graph_creator.cc56 行定义.

59 : base_map_file_path_(base_map_file_path),
60 dump_topo_file_path_(dump_topo_file_path),
61 routing_conf_(routing_conf) {}

◆ ~GraphCreator()

apollo::routing::GraphCreator::~GraphCreator ( )
default

成员函数说明

◆ Create()

bool apollo::routing::GraphCreator::Create ( )

在文件 graph_creator.cc63 行定义.

63 {
64 if (absl::EndsWith(base_map_file_path_, ".xml")) {
65 if (!hdmap::adapter::OpendriveAdapter::LoadData(base_map_file_path_,
66 &pbmap_)) {
67 AERROR << "Failed to load base map file from " << base_map_file_path_;
68 return false;
69 }
70 } else {
71 if (!cyber::common::GetProtoFromFile(base_map_file_path_, &pbmap_)) {
72 AERROR << "Failed to load base map file from " << base_map_file_path_;
73 return false;
74 }
75 }
76
77 AINFO << "Number of lanes: " << pbmap_.lane_size();
78
79 graph_.set_hdmap_version(pbmap_.header().version());
80 graph_.set_hdmap_district(pbmap_.header().district());
81
82 node_index_map_.clear();
83 road_id_map_.clear();
84 showed_edge_id_set_.clear();
85
86 for (const auto& road : pbmap_.road()) {
87 for (const auto& section : road.section()) {
88 for (const auto& lane_id : section.lane_id()) {
89 road_id_map_[lane_id.id()] = road.id().id();
90 }
91 }
92 }
93
94 InitForbiddenLanes();
95 const double min_turn_radius =
97
98 for (const auto& lane : pbmap_.lane()) {
99 const auto& lane_id = lane.id().id();
100 if (forbidden_lane_id_set_.find(lane_id) != forbidden_lane_id_set_.end()) {
101 ADEBUG << "Ignored lane id: " << lane_id
102 << " because its type is NOT CITY_DRIVING.";
103 continue;
104 }
105 if (lane.turn() == hdmap::Lane::U_TURN &&
106 !IsValidUTurn(lane, min_turn_radius)) {
107 ADEBUG << "The u-turn lane radius is too small for the vehicle to turn";
108 continue;
109 }
110 AINFO << "Current lane id: " << lane_id;
111 node_index_map_[lane_id] = graph_.node_size();
112 const auto iter = road_id_map_.find(lane_id);
113 if (iter != road_id_map_.end()) {
114 node_creator::GetPbNode(lane, iter->second, routing_conf_,
115 graph_.add_node());
116 } else {
117 AWARN << "Failed to find road id of lane " << lane_id;
118 node_creator::GetPbNode(lane, "", routing_conf_, graph_.add_node());
119 }
120 }
121
122 for (const auto& lane : pbmap_.lane()) {
123 const auto& lane_id = lane.id().id();
124 if (forbidden_lane_id_set_.find(lane_id) != forbidden_lane_id_set_.end()) {
125 ADEBUG << "Ignored lane id: " << lane_id
126 << " because its type is NOT CITY_DRIVING.";
127 continue;
128 }
129 const auto& from_node = graph_.node(node_index_map_[lane_id]);
130
131 AddEdge(from_node, lane.successor_id(), Edge::FORWARD);
132 if (lane.length() < FLAGS_min_length_for_lane_change) {
133 continue;
134 }
135 if (lane.has_left_boundary() && IsAllowedToCross(lane.left_boundary())) {
136 AddEdge(from_node, lane.left_neighbor_forward_lane_id(), Edge::LEFT);
137 }
138
139 if (lane.has_right_boundary() && IsAllowedToCross(lane.right_boundary())) {
140 AddEdge(from_node, lane.right_neighbor_forward_lane_id(), Edge::RIGHT);
141 }
142 }
143
144 if (!absl::EndsWith(dump_topo_file_path_, ".bin") &&
145 !absl::EndsWith(dump_topo_file_path_, ".txt")) {
146 AERROR << "Failed to dump topo data into file, incorrect file type "
147 << dump_topo_file_path_;
148 return false;
149 }
150 auto type_pos = dump_topo_file_path_.find_last_of(".") + 1;
151 std::string bin_file = dump_topo_file_path_.replace(type_pos, 3, "bin");
152 std::string txt_file = dump_topo_file_path_.replace(type_pos, 3, "txt");
153 if (!cyber::common::SetProtoToASCIIFile(graph_, txt_file)) {
154 AERROR << "Failed to dump topo data into file " << txt_file;
155 return false;
156 }
157 AINFO << "Txt file is dumped successfully. Path: " << txt_file;
158 if (!cyber::common::SetProtoToBinaryFile(graph_, bin_file)) {
159 AERROR << "Failed to dump topo data into file " << bin_file;
160 return false;
161 }
162 AINFO << "Bin file is dumped successfully. Path: " << bin_file;
163 return true;
164}
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
static bool LoadData(const std::string &filename, apollo::hdmap::Map *pb_map)
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
bool SetProtoToBinaryFile(const google::protobuf::Message &message, const std::string &file_name)
Sets the content of the file specified by the file_name to be the binary representation of the input ...
Definition file.cc:111
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
Definition file.cc:43
void GetPbNode(const hdmap::Lane &lane, const std::string &road_id, const RoutingConfig &routingconfig, Node *const node)
optional VehicleParam vehicle_param
optional bytes version
Definition map.proto:30
optional bytes district
Definition map.proto:33
optional Header header
Definition map.proto:45

该类的文档由以下文件生成: