Apollo  6.0
Open source self driving car software
topo_node.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #pragma once
18 
19 #include <string>
20 #include <unordered_map>
21 #include <unordered_set>
22 #include <vector>
23 
25 #include "modules/routing/proto/topo_graph.pb.h"
26 
27 namespace apollo {
28 namespace routing {
29 
30 class TopoEdge;
31 
32 class TopoNode {
33  public:
34  static bool IsOutRangeEnough(const std::vector<NodeSRange>& range_vec,
35  double start_s, double end_s);
36 
37  public:
38  explicit TopoNode(const Node& node);
39  TopoNode(const TopoNode* topo_node, const NodeSRange& range);
40 
41  ~TopoNode();
42 
43  const Node& PbNode() const;
44  double Length() const;
45  double Cost() const;
46  bool IsVirtual() const;
47 
48  const std::string& LaneId() const;
49  const std::string& RoadId() const;
50  const hdmap::Curve& CentralCurve() const;
51  const common::PointENU& AnchorPoint() const;
52  const std::vector<NodeSRange>& LeftOutRange() const;
53  const std::vector<NodeSRange>& RightOutRange() const;
54 
55  const std::unordered_set<const TopoEdge*>& InFromAllEdge() const;
56  const std::unordered_set<const TopoEdge*>& InFromLeftEdge() const;
57  const std::unordered_set<const TopoEdge*>& InFromRightEdge() const;
58  const std::unordered_set<const TopoEdge*>& InFromLeftOrRightEdge() const;
59  const std::unordered_set<const TopoEdge*>& InFromPreEdge() const;
60  const std::unordered_set<const TopoEdge*>& OutToAllEdge() const;
61  const std::unordered_set<const TopoEdge*>& OutToLeftEdge() const;
62  const std::unordered_set<const TopoEdge*>& OutToRightEdge() const;
63  const std::unordered_set<const TopoEdge*>& OutToLeftOrRightEdge() const;
64  const std::unordered_set<const TopoEdge*>& OutToSucEdge() const;
65 
66  const TopoEdge* GetInEdgeFrom(const TopoNode* from_node) const;
67  const TopoEdge* GetOutEdgeTo(const TopoNode* to_node) const;
68 
69  const TopoNode* OriginNode() const;
70  double StartS() const;
71  double EndS() const;
72  bool IsSubNode() const;
73  bool IsInFromPreEdgeValid() const;
74  bool IsOutToSucEdgeValid() const;
75  bool IsOverlapEnough(const TopoNode* sub_node,
76  const TopoEdge* edge_for_type) const;
77  void AddInEdge(const TopoEdge* edge);
78  void AddOutEdge(const TopoEdge* edge);
79 
80  private:
81  void Init();
82  bool FindAnchorPoint();
83  void SetAnchorPoint(const common::PointENU& anchor_point);
84 
85  Node pb_node_;
86  common::PointENU anchor_point_;
87 
88  double start_s_;
89  double end_s_;
90  bool is_left_range_enough_;
91  int left_prefer_range_index_;
92  bool is_right_range_enough_;
93  int right_prefer_range_index_;
94 
95  std::vector<NodeSRange> left_out_sorted_range_;
96  std::vector<NodeSRange> right_out_sorted_range_;
97 
98  std::unordered_set<const TopoEdge*> in_from_all_edge_set_;
99  std::unordered_set<const TopoEdge*> in_from_left_edge_set_;
100  std::unordered_set<const TopoEdge*> in_from_right_edge_set_;
101  std::unordered_set<const TopoEdge*> in_from_left_or_right_edge_set_;
102  std::unordered_set<const TopoEdge*> in_from_pre_edge_set_;
103  std::unordered_set<const TopoEdge*> out_to_all_edge_set_;
104  std::unordered_set<const TopoEdge*> out_to_left_edge_set_;
105  std::unordered_set<const TopoEdge*> out_to_right_edge_set_;
106  std::unordered_set<const TopoEdge*> out_to_left_or_right_edge_set_;
107  std::unordered_set<const TopoEdge*> out_to_suc_edge_set_;
108 
109  std::unordered_map<const TopoNode*, const TopoEdge*> out_edge_map_;
110  std::unordered_map<const TopoNode*, const TopoEdge*> in_edge_map_;
111 
112  const TopoNode* origin_node_;
113 };
114 
119 };
120 
121 class TopoEdge {
122  public:
123  TopoEdge(const Edge& edge, const TopoNode* from_node,
124  const TopoNode* to_node);
125 
126  ~TopoEdge();
127 
128  const Edge& PbEdge() const;
129  double Cost() const;
130  const std::string& FromLaneId() const;
131  const std::string& ToLaneId() const;
132  TopoEdgeType Type() const;
133 
134  const TopoNode* FromNode() const;
135  const TopoNode* ToNode() const;
136 
137  private:
138  Edge pb_edge_;
139  const TopoNode* from_node_ = nullptr;
140  const TopoNode* to_node_ = nullptr;
141 };
142 
143 } // namespace routing
144 } // namespace apollo
const std::vector< NodeSRange > & RightOutRange() const
const std::unordered_set< const TopoEdge * > & OutToLeftEdge() const
bool IsOverlapEnough(const TopoNode *sub_node, const TopoEdge *edge_for_type) const
Definition: node.h:31
const std::vector< NodeSRange > & LeftOutRange() const
Definition: topo_node.h:32
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: topo_node.h:118
Definition: topo_node.h:117
void AddOutEdge(const TopoEdge *edge)
bool IsOutToSucEdgeValid() const
const std::unordered_set< const TopoEdge * > & OutToLeftOrRightEdge() const
const TopoEdge * GetOutEdgeTo(const TopoNode *to_node) const
const common::PointENU & AnchorPoint() const
bool IsInFromPreEdgeValid() const
const TopoNode * OriginNode() const
const std::string & LaneId() const
const std::unordered_set< const TopoEdge * > & OutToSucEdge() const
TopoEdgeType
Definition: topo_node.h:115
const TopoEdge * GetInEdgeFrom(const TopoNode *from_node) const
const std::unordered_set< const TopoEdge * > & InFromAllEdge() const
const std::unordered_set< const TopoEdge * > & InFromLeftOrRightEdge() const
const std::unordered_set< const TopoEdge * > & InFromPreEdge() const
const std::unordered_set< const TopoEdge * > & OutToRightEdge() const
const std::unordered_set< const TopoEdge * > & OutToAllEdge() const
void AddInEdge(const TopoEdge *edge)
Definition: topo_node.h:116
const std::unordered_set< const TopoEdge * > & InFromLeftEdge() const
Definition: topo_node.h:121
const Node & PbNode() const
static bool IsOutRangeEnough(const std::vector< NodeSRange > &range_vec, double start_s, double end_s)
const std::string & RoadId() const
const hdmap::Curve & CentralCurve() const
const std::unordered_set< const TopoEdge * > & InFromRightEdge() const
Definition: topo_range.h:22
TopoNode(const Node &node)