Implementation:CARLA simulator Carla SceneLayout
| Knowledge Sources | |
|---|---|
| Domains | Scene Description, Map Data |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
A Python module that extracts the full scene layout (road network and dynamic objects) from a CARLA world for use as a structured scene description.
Description
This module provides two main functions. get_scene_layout(carla_map) extracts the complete road network as a waypoint graph. It iterates over the map topology, traces each lane by following waypoints at fine precision (0.05m), computes left and right lane markings using lateral shifts, and builds a dictionary indexed by waypoint ID containing road_id, lane_id, geolocation position, orientation, left/right margin positions, next waypoint IDs, and left/right lane waypoint IDs. get_dynamic_objects(carla_world, carla_map) captures the current state of all dynamic actors in the scene. It splits actors into vehicles, traffic_lights, speed_limits, walkers, stops, and static_obstacles. Each actor category is processed into dictionaries with geolocation positions, bounding boxes (computed by transforming corner locations), trigger volumes (for traffic lights and stops), orientations, and states. The hero vehicle is identified by its role_name attribute. All positions are converted to geolocation coordinates (latitude, longitude, altitude).
Usage
This module is used to generate a complete machine-readable description of the simulation scene, useful for external planners, visualization tools, or benchmark evaluation systems that need a snapshot of the full road and actor layout.
Code Reference
Source Location
- Repository: CARLA
- File: PythonAPI/carla/scene_layout.py
Signature
def get_scene_layout(carla_map):
"""Returns a waypoint graph dictionary describing the full road network."""
def get_dynamic_objects(carla_world, carla_map):
"""Returns a dictionary of all dynamic objects in the scene."""
Import
from scene_layout import get_scene_layout, get_dynamic_objects
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| carla_map | carla.Map | Yes | Map instance for road network extraction |
| carla_world | carla.World | Yes (get_dynamic_objects) | World instance for actor queries |
Outputs
| Name | Type | Description |
|---|---|---|
| waypoints_graph | dict | Waypoint ID to dict with road_id, lane_id, position, orientation, margins, neighbors |
| dynamic_objects | dict | Keys: vehicles, hero_vehicle, walkers, traffic_lights, stop_signs, speed_limits, static_obstacles |
Usage Examples
import carla
from scene_layout import get_scene_layout, get_dynamic_objects
client = carla.Client('localhost', 2000)
world = client.get_world()
carla_map = world.get_map()
# Get static road layout
layout = get_scene_layout(carla_map)
for wp_id, wp_data in layout.items():
print(f"Waypoint {wp_id}: Road {wp_data['road_id']}, Lane {wp_data['lane_id']}")
# Get dynamic objects
objects = get_dynamic_objects(world, carla_map)
print(f"Vehicles: {len(objects['vehicles'])}")
print(f"Traffic lights: {len(objects['traffic_lights'])}")
if objects['hero_vehicle']:
print(f"Hero position: {objects['hero_vehicle']['position']}")