MCPcopy Create free account
hub / github.com/PJLab-ADG/OASim / plot_roadgraph

Function plot_roadgraph

limsim/utils/plotting.py:21–97  ·  view source on GitHub ↗
(roadgraph: RoadGraph)

Source from the content-addressed store, hash-verified

19
20
21def plot_roadgraph(roadgraph: RoadGraph) -> None:
22 edges = roadgraph.edges
23 lanes = roadgraph.lanes
24 fig, ax = plt.subplots()
25 for edge in edges.values():
26 for lane_index in range(edge.lane_num):
27 lane_id = edge.id + '_' + str(lane_index)
28 lane = lanes[lane_id]
29
30 lane.center_line, lane.left_bound, lane.right_bound = [], [], []
31 s = np.linspace(0, lane.course_spline.s[-1], num=50)
32 for si in s:
33 lane.center_line.append(lane.course_spline.calc_position(si))
34 lane.left_bound.append(
35 lane.course_spline.frenet_to_cartesian1D(
36 si, lane.width / 2)
37 )
38 lane.right_bound.append(
39 lane.course_spline.frenet_to_cartesian1D(
40 si, -lane.width / 2)
41 )
42 ax.plot(*zip(*lane.center_line), "w:", linewidth=1.5)
43 plt.arrow(
44 lane.center_line[0][0],
45 lane.center_line[0][1],
46 lane.center_line[2][0] - lane.center_line[0][0],
47 lane.center_line[2][1] - lane.center_line[0][1],
48 shape='full',
49 width=0.3,
50 length_includes_head=False,
51 zorder=2,
52 color="w",
53 )
54 if lane_index == edge.lane_num - 1:
55 ax.plot(*zip(*lane.left_bound), "k", linewidth=1.5)
56 else:
57 ax.plot(*zip(*lane.left_bound), "k--", linewidth=1)
58 if lane_index == 0:
59 ax.plot(*zip(*lane.right_bound), "k", linewidth=1.5)
60
61 if edge.from_junction == None:
62 ax.plot(
63 [lane.left_bound[0][0], lane.right_bound[0][0]],
64 [lane.left_bound[0][1], lane.right_bound[0][1]],
65 "r",
66 linewidth=2,
67 )
68 if edge.to_junction == None:
69 ax.plot(
70 [lane.left_bound[-1][0], lane.right_bound[-1][0]],
71 [lane.left_bound[-1][1], lane.right_bound[-1][1]],
72 "r",
73 linewidth=2,
74 )
75
76 for lane in lanes.values():
77 for junctionlane, dir in lane.next_lanes.values():
78 s = np.linspace(0, junctionlane.course_spline.s[-1], num=50)

Callers

nothing calls this directly

Calls 2

calc_positionMethod · 0.80
frenet_to_cartesian1DMethod · 0.80

Tested by

no test coverage detected