24void TopoGraph::Clear() {
27 node_index_map_.clear();
30bool TopoGraph::LoadNodes(
const Graph& graph) {
31 if (graph.node().empty()) {
32 AERROR <<
"No nodes found in topology graph.";
35 for (
const auto& node : graph.node()) {
36 node_index_map_[node.lane_id()] =
static_cast<int>(topo_nodes_.size());
39 road_node_map_[node.road_id()].insert(
topo_node.get());
40 topo_nodes_.push_back(std::move(
topo_node));
46bool TopoGraph::LoadEdges(
const Graph& graph) {
47 if (graph.edge().empty()) {
48 AINFO <<
"0 edges found in topology graph, but it's fine";
51 for (
const auto& edge : graph.edge()) {
52 const std::string& from_lane_id = edge.from_lane_id();
53 const std::string& to_lane_id = edge.to_lane_id();
54 if (node_index_map_.count(from_lane_id) != 1 ||
55 node_index_map_.count(to_lane_id) != 1) {
58 std::shared_ptr<TopoEdge> topo_edge;
59 TopoNode* from_node = topo_nodes_[node_index_map_[from_lane_id]].get();
60 TopoNode* to_node = topo_nodes_[node_index_map_[to_lane_id]].get();
61 topo_edge.reset(
new TopoEdge(edge, from_node, to_node));
62 from_node->AddOutEdge(topo_edge.get());
63 to_node->AddInEdge(topo_edge.get());
64 topo_edges_.push_back(std::move(topo_edge));
75 if (!LoadNodes(graph)) {
76 AERROR <<
"Failed to load nodes from topology graph.";
79 if (!LoadEdges(graph)) {
80 AERROR <<
"Failed to load edges from topology graph.";
83 AINFO <<
"Load Topo data successful.";
92 const auto& iter = node_index_map_.find(
id);
93 if (iter == node_index_map_.end()) {
96 return topo_nodes_[iter->second].get();
100 const std::string& road_id,
101 std::unordered_set<const TopoNode*>*
const node_in_road)
const {
102 const auto& iter = road_node_map_.find(road_id);
103 if (iter != road_node_map_.end()) {
104 node_in_road->insert(iter->second.begin(), iter->second.end());
const TopoNode * topo_node
const std::string & MapVersion() const
void GetNodesByRoadId(const std::string &road_id, std::unordered_set< const TopoNode * > *const node_in_road) const
const std::string & MapDistrict() const
bool LoadGraph(const Graph &filename)
const TopoNode * GetNode(const std::string &id) const
optional string hdmap_district
optional string hdmap_version