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

Class MapImage

scenario_runner/no_rendering_mode.py:434–775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432
433
434class MapImage(object):
435 def __init__(self, carla_world, carla_map, pixels_per_meter, show_triggers, show_connections, show_spawn_points):
436 self._pixels_per_meter = pixels_per_meter
437 self.scale = 1.0
438 self.show_triggers = show_triggers
439 self.show_connections = show_connections
440 self.show_spawn_points = show_spawn_points
441
442 waypoints = carla_map.generate_waypoints(2)
443 margin = 50
444 max_x = max(waypoints, key=lambda x: x.transform.location.x).transform.location.x + margin
445 max_y = max(waypoints, key=lambda x: x.transform.location.y).transform.location.y + margin
446 min_x = min(waypoints, key=lambda x: x.transform.location.x).transform.location.x - margin
447 min_y = min(waypoints, key=lambda x: x.transform.location.y).transform.location.y - margin
448
449 self.width = max(max_x - min_x, max_y - min_y)
450 self._world_offset = (min_x, min_y)
451
452 width_in_pixels = int(self._pixels_per_meter * self.width)
453
454 self.big_map_surface = pygame.Surface((width_in_pixels, width_in_pixels)).convert()
455 self.draw_road_map(self.big_map_surface, carla_world, carla_map, self.world_to_pixel, self.world_to_pixel_width)
456 self.surface = self.big_map_surface
457
458 def draw_road_map(self, map_surface, carla_world, carla_map, world_to_pixel, world_to_pixel_width):
459 map_surface.fill(COLOR_ALUMINIUM_4)
460 precision = 0.05
461
462 def lane_marking_color_to_tango(lane_marking_color):
463 tango_color = COLOR_BLACK
464
465 if lane_marking_color == carla.LaneMarkingColor.White:
466 tango_color = COLOR_ALUMINIUM_2
467
468 elif lane_marking_color == carla.LaneMarkingColor.Blue:
469 tango_color = COLOR_SKY_BLUE_0
470
471 elif lane_marking_color == carla.LaneMarkingColor.Green:
472 tango_color = COLOR_CHAMELEON_0
473
474 elif lane_marking_color == carla.LaneMarkingColor.Red:
475 tango_color = COLOR_SCARLET_RED_0
476
477 elif lane_marking_color == carla.LaneMarkingColor.Yellow:
478 tango_color = COLOR_ORANGE_0
479
480 return tango_color
481
482 def draw_solid_line(surface, color, closed, points, width):
483 if len(points) >= 2:
484 pygame.draw.lines(surface, color, closed, points, width)
485
486 def draw_broken_line(surface, color, closed, points, width):
487 broken_lines = [x for n, x in enumerate(zip(*(iter(points),) * 20)) if n % 3 == 0]
488 for line in broken_lines:
489 pygame.draw.lines(surface, color, closed, line, width)
490
491 def get_lane_markings(lane_marking_type, lane_marking_color, waypoints, sign):

Callers 1

startMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected