MCPcopy Create free account
hub / github.com/OpenDriveLab/DriveAdapter / draw_topology

Method draw_topology

scenario_runner/no_rendering_mode.py:617–714  ·  view source on GitHub ↗
(carla_topology, index)

Source from the content-addressed store, hash-verified

615 return transform.location + shift * transform.get_forward_vector()
616
617 def draw_topology(carla_topology, index):
618 topology = [x[index] for x in carla_topology]
619 topology = sorted(topology, key=lambda w: w.transform.location.z)
620 for waypoint in topology:
621 # if waypoint.road_id == 150 or waypoint.road_id == 16:
622 waypoints = [waypoint]
623
624 nxt = waypoint.next(precision)
625 if len(nxt) > 0:
626 nxt = nxt[0]
627 while nxt.road_id == waypoint.road_id:
628 waypoints.append(nxt)
629 nxt = nxt.next(precision)
630 if len(nxt) > 0:
631 nxt = nxt[0]
632 else:
633 break
634
635 # Draw Road
636 road_left_side = [lateral_shift(w.transform, -w.lane_width * 0.5) for w in waypoints]
637 road_right_side = [lateral_shift(w.transform, w.lane_width * 0.5) for w in waypoints]
638
639 polygon = road_left_side + [x for x in reversed(road_right_side)]
640 polygon = [world_to_pixel(x) for x in polygon]
641
642 if len(polygon) > 2:
643 pygame.draw.polygon(map_surface, COLOR_ALUMINIUM_5, polygon, 5)
644 pygame.draw.polygon(map_surface, COLOR_ALUMINIUM_5, polygon)
645
646 # Draw Shoulders and Parkings
647 PARKING_COLOR = COLOR_ALUMINIUM_4_5
648 SHOULDER_COLOR = COLOR_ALUMINIUM_5
649
650 final_color = SHOULDER_COLOR
651
652 # Draw Right
653 shoulder = []
654 for w in waypoints:
655 r = w.get_right_lane()
656 if r is not None and (
657 r.lane_type == carla.LaneType.Shoulder or r.lane_type == carla.LaneType.Parking):
658 if r.lane_type == carla.LaneType.Parking:
659 final_color = PARKING_COLOR
660 shoulder.append(r)
661
662 shoulder_left_side = [lateral_shift(w.transform, -w.lane_width * 0.5) for w in shoulder]
663 shoulder_right_side = [lateral_shift(w.transform, w.lane_width * 0.5) for w in shoulder]
664
665 polygon = shoulder_left_side + [x for x in reversed(shoulder_right_side)]
666 polygon = [world_to_pixel(x) for x in polygon]
667
668 if len(polygon) > 2:
669 pygame.draw.polygon(map_surface, final_color, polygon, 5)
670 pygame.draw.polygon(map_surface, final_color, polygon)
671
672 draw_lane_marking(
673 map_surface,
674 shoulder,

Callers

nothing calls this directly

Calls 1

nextMethod · 0.80

Tested by

no test coverage detected