torchdrivesim.rendering.base

Base class for renderers producing rasterized birdview images from given background meshes and agent positions.

Attributes

Classes

RendererConfig

Determines behavior of the renderer.

DummyRendererConfig

For DummyRenderer.

Cameras

Lightweight version of pytorch3d.renderer.FoVOrthographicCameras.

BirdviewRenderer

A renderer producing simple 2D birdview images based on static background meshes and rectangular agents.

DummyRenderer

Produces a black image of the required size. Mostly used for debugging and benchmarking.

Functions

get_default_rendering_levels(→ Dict[str, float])

Produces the default rendering levels, mapping object categories

get_default_color_map(→ Dict[str, Tuple[int, int, int]])

Produces the default color map, mapping object categories

Module Contents

torchdrivesim.rendering.base.logger = None[source]
class torchdrivesim.rendering.base.RendererConfig[source]

Determines behavior of the renderer. Subclasses determine renderer class used.

backend: str = 'default'[source]
render_agent_direction: bool = True[source]
left_handed_coordinates: bool = False[source]
highlight_ego_vehicle: bool = False[source]
shift_mesh_by_camera_before_rendering: bool = True[source]
device: str | None = None[source]
class torchdrivesim.rendering.base.DummyRendererConfig[source]

Bases: RendererConfig

For DummyRenderer.

backend: str = 'dummy'[source]
class torchdrivesim.rendering.base.Cameras(xy: torch.Tensor, sc: torch.Tensor, scale: float)[source]

Lightweight version of pytorch3d.renderer.FoVOrthographicCameras. Used to define an interface that works without pytorch3d.

xy[source]
sc[source]
scale[source]
world_to_clip_transform[source]
get_camera_center() torch.Tensor[source]
get_world_to_view_transform() torch.Tensor[source]
get_view_to_proj_transform() torch.Tensor[source]
project_world_to_clip_space(points: torch.Tensor) torch.Tensor[source]
transform_points_screen(points: torch.Tensor, res: torchdrivesim.utils.Resolution) torch.Tensor[source]
reverse_transform_points_screen(points: torch.Tensor, res: torchdrivesim.utils.Resolution) torch.Tensor[source]
class torchdrivesim.rendering.base.BirdviewRenderer(cfg: RendererConfig, color_map: Dict[str, Tuple[int, int, int]] | None = None, rendering_levels: Dict[str, float] | None = None, res: torchdrivesim.utils.Resolution = Resolution(64, 64), fov: float = 35)[source]

Bases: abc.ABC

A renderer producing simple 2D birdview images based on static background meshes and rectangular agents. Currently only square resolutions are supported. The renderer always operates in batch mode, with a single batch dimension on the left.

Parameters:
  • cfg – configuration object, usually subclassed

  • color_map – a dictionary of RGB tuples in 0-255 range specifying colors of different rendered elements

  • res – default resolution

cfg: RendererConfig[source]
res[source]
scale = 0.05714285714285714[source]
color_map = None[source]
rendering_levels = None[source]
copy()[source]
get_color(element_type: str) Tuple[int, int, int][source]
render_frame(rgb_mesh: torchdrivesim.mesh.RGBMesh, camera_xy: torch.Tensor, camera_sc: torch.Tensor, res: torchdrivesim.utils.Resolution | None = None, fov: float | None = None)[source]

Renders a given rgb mesh according the camera position and rotation.

Parameters:
  • rgb_mesh – the given rgb mesh to render which should be already expanded to match the number of cameras.

  • camera_xy – BxNcx2 tensor of camera positions, by default one camera placed on each agent

  • camera_sc – BxNcx2 tensor of camera orientations (sine and cosine), by default matching agent orientations

  • res – resolution HxW of the resulting image, currently only square resolutions are supported

  • fov – Field of view in meters

Returns:

tensor image of float RGB values in [0,255] range with shape shape (B*Nc)xCxHxW

abstract render_rgb_mesh(mesh: torchdrivesim.mesh.RGBMesh, res: torchdrivesim.utils.Resolution, cameras: Cameras) torch.Tensor[source]

Renders a given mesh, producing BxHxWxC tensor image of float RGB values in [0,255] range.

construct_cameras(xy: torch.Tensor, sc: torch.Tensor, scale: float | None = None) Cameras[source]

Create PyTorch3D cameras object for given positions and orientations. Input tensor dimensions should be Bx2.

class torchdrivesim.rendering.base.DummyRenderer(cfg: RendererConfig, color_map: Dict[str, Tuple[int, int, int]] | None = None, rendering_levels: Dict[str, float] | None = None, res: torchdrivesim.utils.Resolution = Resolution(64, 64), fov: float = 35)[source]

Bases: BirdviewRenderer

Produces a black image of the required size. Mostly used for debugging and benchmarking.

render_rgb_mesh(mesh: torchdrivesim.mesh.RGBMesh, res: torchdrivesim.utils.Resolution, cameras: Cameras) torch.Tensor[source]

Renders a given mesh, producing BxHxWxC tensor image of float RGB values in [0,255] range.

torchdrivesim.rendering.base.get_default_rendering_levels() Dict[str, float][source]

Produces the default rendering levels, mapping object categories to their rendering level. Lower level renders on top, but levels lower than 0 don’t render at all.

torchdrivesim.rendering.base.get_default_color_map() Dict[str, Tuple[int, int, int]][source]

Produces the default color map, mapping object categories to RGB 3-tuples in [0,255] range.