MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / __init__

Method __init__

PythonAPI/examples/no_rendering_mode.py:433–501  ·  view source on GitHub ↗

Renders the map image generated based on the world, its map and additional flags that provide extra information about the road network

(self, carla_world, carla_map, pixels_per_meter, show_triggers, show_connections, show_spawn_points)

Source from the content-addressed store, hash-verified

431 of a Carla town has not changed, it will read and use the stored image if it was rendered in a previous execution"""
432
433 def __init__(self, carla_world, carla_map, pixels_per_meter, show_triggers, show_connections, show_spawn_points):
434 """ Renders the map image generated based on the world, its map and additional flags that provide extra information about the road network"""
435 self._pixels_per_meter = pixels_per_meter
436 self.scale = 1.0
437 self.show_triggers = show_triggers
438 self.show_connections = show_connections
439 self.show_spawn_points = show_spawn_points
440
441 waypoints = carla_map.generate_waypoints(2)
442 margin = 50
443 max_x = max(waypoints, key=lambda x: x.transform.location.x).transform.location.x + margin
444 max_y = max(waypoints, key=lambda x: x.transform.location.y).transform.location.y + margin
445 min_x = min(waypoints, key=lambda x: x.transform.location.x).transform.location.x - margin
446 min_y = min(waypoints, key=lambda x: x.transform.location.y).transform.location.y - margin
447
448 self.width = max(max_x - min_x, max_y - min_y)
449 self._world_offset = (min_x, min_y)
450
451 # Maximum size of a Pygame surface
452 width_in_pixels = (1 << 14) - 1
453
454 # Adapt Pixels per meter to make world fit in surface
455 surface_pixel_per_meter = int(width_in_pixels / self.width)
456 if surface_pixel_per_meter > PIXELS_PER_METER:
457 surface_pixel_per_meter = PIXELS_PER_METER
458
459 self._pixels_per_meter = surface_pixel_per_meter
460 width_in_pixels = int(self._pixels_per_meter * self.width)
461
462 self.big_map_surface = pygame.Surface((width_in_pixels, width_in_pixels)).convert()
463
464 # Load OpenDrive content
465 opendrive_content = carla_map.to_opendrive()
466
467 # Get hash based on content
468 hash_func = hashlib.sha1()
469 hash_func.update(opendrive_content.encode("UTF-8"))
470 opendrive_hash = str(hash_func.hexdigest())
471
472 # Build path for saving or loading the cached rendered map
473 filename = carla_map.name + "_" + opendrive_hash + ".tga"
474 dirname = os.path.join("cache", "no_rendering_mode")
475 full_path = str(os.path.join(dirname, filename))
476
477 if os.path.isfile(full_path):
478 # Load Image
479 self.big_map_surface = pygame.image.load(full_path)
480 else:
481 # Render map
482 self.draw_road_map(
483 self.big_map_surface,
484 carla_world,
485 carla_map,
486 self.world_to_pixel,
487 self.world_to_pixel_width)
488
489 # If folders path does not exist, create it
490 if not os.path.exists(dirname):

Callers

nothing calls this directly

Calls 4

draw_road_mapMethod · 0.95
updateMethod · 0.80
saveMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected