torchdrivesim.rendering.base ============================ .. py:module:: torchdrivesim.rendering.base .. autoapi-nested-parse:: Base class for renderers producing rasterized birdview images from given background meshes and agent positions. Attributes ---------- .. autoapisummary:: torchdrivesim.rendering.base.logger Classes ------- .. autoapisummary:: torchdrivesim.rendering.base.RendererConfig torchdrivesim.rendering.base.DummyRendererConfig torchdrivesim.rendering.base.Cameras torchdrivesim.rendering.base.BirdviewRenderer torchdrivesim.rendering.base.DummyRenderer Functions --------- .. autoapisummary:: torchdrivesim.rendering.base.get_default_rendering_levels torchdrivesim.rendering.base.get_default_color_map Module Contents --------------- .. py:data:: logger :value: None .. py:class:: RendererConfig Determines behavior of the renderer. Subclasses determine renderer class used. .. py:attribute:: backend :type: str :value: 'default' .. py:attribute:: render_agent_direction :type: bool :value: True .. py:attribute:: left_handed_coordinates :type: bool :value: False .. py:attribute:: highlight_ego_vehicle :type: bool :value: False .. py:attribute:: shift_mesh_by_camera_before_rendering :type: bool :value: True .. py:attribute:: device :type: Optional[str] :value: None .. py:class:: DummyRendererConfig Bases: :py:obj:`RendererConfig` For DummyRenderer. .. py:attribute:: backend :type: str :value: 'dummy' .. py:class:: Cameras(xy: torch.Tensor, sc: torch.Tensor, scale: float) Lightweight version of pytorch3d.renderer.FoVOrthographicCameras. Used to define an interface that works without pytorch3d. .. py:attribute:: xy .. py:attribute:: sc .. py:attribute:: scale .. py:attribute:: world_to_clip_transform .. py:method:: get_camera_center() -> torch.Tensor .. py:method:: get_world_to_view_transform() -> torch.Tensor .. py:method:: get_view_to_proj_transform() -> torch.Tensor .. py:method:: project_world_to_clip_space(points: torch.Tensor) -> torch.Tensor .. py:method:: transform_points_screen(points: torch.Tensor, res: torchdrivesim.utils.Resolution) -> torch.Tensor .. py:method:: reverse_transform_points_screen(points: torch.Tensor, res: torchdrivesim.utils.Resolution) -> torch.Tensor .. py:class:: BirdviewRenderer(cfg: RendererConfig, color_map: Optional[Dict[str, Tuple[int, int, int]]] = None, rendering_levels: Optional[Dict[str, float]] = None, res: torchdrivesim.utils.Resolution = Resolution(64, 64), fov: float = 35) Bases: :py:obj:`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. :param cfg: configuration object, usually subclassed :param color_map: a dictionary of RGB tuples in 0-255 range specifying colors of different rendered elements :param res: default resolution .. py:attribute:: cfg :type: RendererConfig .. py:attribute:: res .. py:attribute:: scale :value: 0.05714285714285714 .. py:attribute:: color_map :value: None .. py:attribute:: rendering_levels :value: None .. py:method:: copy() .. py:method:: get_color(element_type: str) -> Tuple[int, int, int] .. py:method:: render_frame(rgb_mesh: torchdrivesim.mesh.RGBMesh, camera_xy: torch.Tensor, camera_sc: torch.Tensor, res: Optional[torchdrivesim.utils.Resolution] = None, fov: Optional[float] = None) Renders a given rgb mesh according the camera position and rotation. :param rgb_mesh: the given rgb mesh to render which should be already expanded to match the number of cameras. :param camera_xy: BxNcx2 tensor of camera positions, by default one camera placed on each agent :param camera_sc: BxNcx2 tensor of camera orientations (sine and cosine), by default matching agent orientations :param res: resolution HxW of the resulting image, currently only square resolutions are supported :param fov: Field of view in meters :returns: tensor image of float RGB values in [0,255] range with shape shape (B*Nc)xCxHxW .. py:method:: render_rgb_mesh(mesh: torchdrivesim.mesh.RGBMesh, res: torchdrivesim.utils.Resolution, cameras: Cameras) -> torch.Tensor :abstractmethod: Renders a given mesh, producing BxHxWxC tensor image of float RGB values in [0,255] range. .. py:method:: construct_cameras(xy: torch.Tensor, sc: torch.Tensor, scale: Optional[float] = None) -> Cameras Create PyTorch3D cameras object for given positions and orientations. Input tensor dimensions should be Bx2. .. py:class:: DummyRenderer(cfg: RendererConfig, color_map: Optional[Dict[str, Tuple[int, int, int]]] = None, rendering_levels: Optional[Dict[str, float]] = None, res: torchdrivesim.utils.Resolution = Resolution(64, 64), fov: float = 35) Bases: :py:obj:`BirdviewRenderer` Produces a black image of the required size. Mostly used for debugging and benchmarking. .. py:method:: render_rgb_mesh(mesh: torchdrivesim.mesh.RGBMesh, res: torchdrivesim.utils.Resolution, cameras: Cameras) -> torch.Tensor Renders a given mesh, producing BxHxWxC tensor image of float RGB values in [0,255] range. .. py:function:: get_default_rendering_levels() -> Dict[str, float] 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. .. py:function:: get_default_color_map() -> Dict[str, Tuple[int, int, int]] Produces the default color map, mapping object categories to RGB 3-tuples in [0,255] range.