From 1bcb2e023acade7dd5eb8275027bc0b1264e4d90 Mon Sep 17 00:00:00 2001 From: ktro2828 Date: Tue, 2 Jun 2026 14:27:01 +0900 Subject: [PATCH] feat: add an option whether to render map Signed-off-by: ktro2828 --- t4_devkit/cli/visualize.py | 35 ++++++++++++++++++++++++++++++++--- t4_devkit/helper/rendering.py | 16 ++++++++++++---- t4_devkit/tier4.py | 9 +++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/t4_devkit/cli/visualize.py b/t4_devkit/cli/visualize.py index fa92752a..a7c285df 100644 --- a/t4_devkit/cli/visualize.py +++ b/t4_devkit/cli/visualize.py @@ -44,11 +44,20 @@ def scene( help="Output directory to save recorded .rrd file.", ), ] = None, + show_map: Annotated[ + bool, + typer.Option( + ..., + "-m", + "--map", + help="Whether to render the map.", + ), + ] = False, ) -> None: _create_dir(output) t4 = T4Devkit(data_root, revision=revision, verbose=False) - t4.render_scene(future_seconds=future, save_dir=output) + t4.render_scene(future_seconds=future, save_dir=output, show_map=show_map) @cli.command("instance", help="Visualize a particular instance in the corresponding scene.") @@ -79,11 +88,22 @@ def instance( help="Output directory to save recorded .rrd file.", ), ] = None, + show_map: Annotated[ + bool, + typer.Option( + ..., + "-m", + "--map", + help="Whether to render the map.", + ), + ] = False, ) -> None: _create_dir(output) t4 = T4Devkit(data_root, revision=revision, verbose=False) - t4.render_instance(instance_token=instance, future_seconds=future, save_dir=output) + t4.render_instance( + instance_token=instance, future_seconds=future, save_dir=output, show_map=show_map + ) @cli.command("pointcloud", help="Visualize pointcloud in the corresponding scene.") @@ -104,11 +124,20 @@ def pointcloud( help="Output directory to save recorded .rrd file.", ), ] = None, + show_map: Annotated[ + bool, + typer.Option( + ..., + "-m", + "--map", + help="Whether to render the map.", + ), + ] = False, ) -> None: _create_dir(output) t4 = T4Devkit(data_root, revision=revision, verbose=False) - t4.render_pointcloud(save_dir=output) + t4.render_pointcloud(save_dir=output, show_map=show_map) def _create_dir(dir_path: str | None) -> None: diff --git a/t4_devkit/helper/rendering.py b/t4_devkit/helper/rendering.py index 84863372..ec3147d0 100644 --- a/t4_devkit/helper/rendering.py +++ b/t4_devkit/helper/rendering.py @@ -149,6 +149,7 @@ def render_scene( max_time_seconds: float = np.inf, future_seconds: float = 0.0, save_dir: str | None = None, + show_map: bool = False, ) -> None: """Render specified scene. @@ -157,6 +158,7 @@ def render_scene( future_seconds (float, optional): Future time in [s]. save_dir (str | None, optional): Directory path to save the recording. Viewer will be spawned if it is None, otherwise not. + show_map (bool, optional): Whether to render the map. """ # search first sample data tokens first_lidar_tokens: list[str] = [ @@ -179,7 +181,8 @@ def render_scene( contents = self._load_contents(RenderingMode.SCENE) viewer = self._init_viewer(app_id, contents=contents, render_ann=True, save_dir=save_dir) - self._try_render_map(viewer) + if show_map: + self._try_render_map(viewer) scene: Scene = self._t4.scene[0] first_sample: Sample = self._t4.get("sample", scene.first_sample_token) @@ -233,6 +236,7 @@ def render_instance( *, future_seconds: float = 0.0, save_dir: str | None = None, + show_map: bool = False, ) -> None: """Render particular instance. @@ -241,7 +245,7 @@ def render_instance( future_seconds (float, optional): Future time in [s]. save_dir (str | None, optional): Directory path to save the recording. Viewer will be spawned if it is None, otherwise not. - + show_map (bool, optional): Whether to render the map. """ instance_tokens = [instance_token] if isinstance(instance_token, str) else instance_token @@ -293,7 +297,8 @@ def render_instance( contents = self._load_contents(RenderingMode.INSTANCE) viewer = self._init_viewer(app_id, contents=contents, render_ann=True, save_dir=save_dir) - self._try_render_map(viewer) + if show_map: + self._try_render_map(viewer) pointcloud_color_mode = ( PointCloudColorMode.SEGMENTATION @@ -344,6 +349,7 @@ def render_pointcloud( *, max_time_seconds: float = np.inf, save_dir: str | None = None, + show_map: bool = False, ) -> None: """Render pointcloud on 3D and 2D view. @@ -351,6 +357,7 @@ def render_pointcloud( max_time_seconds (float, optional): Max time length to be rendered [s]. save_dir (str | None, optional): Directory path to save the recording. Viewer will be spawned if it is None, otherwise not. + show_map (bool, optional): Whether to render the map. TODO: Add an option of rendering radar channels. @@ -379,7 +386,8 @@ def render_pointcloud( ) viewer = self._init_viewer(app_id, contents=contents, render_ann=False, save_dir=save_dir) - self._try_render_map(viewer) + if show_map: + self._try_render_map(viewer) # TODO: support rendering segmentation pointcloud on camera futures = self._render_lidar_and_ego( diff --git a/t4_devkit/tier4.py b/t4_devkit/tier4.py index 884f19f6..df439cfc 100644 --- a/t4_devkit/tier4.py +++ b/t4_devkit/tier4.py @@ -747,6 +747,7 @@ def render_scene( max_time_seconds: float = np.inf, future_seconds: float = 0.0, save_dir: str | None = None, + show_map: bool = False, ) -> None: """Render specified scene. @@ -754,11 +755,13 @@ def render_scene( max_time_seconds (float, optional): Max time length to be rendered [s]. future_seconds (float, optional): Future time in [s]. save_dir (str | None, optional): Directory path to save the recording. + show_map (bool, optional): Whether to render the map. """ self._rendering_helper.render_scene( max_time_seconds=max_time_seconds, future_seconds=future_seconds, save_dir=save_dir, + show_map=show_map, ) def render_instance( @@ -767,6 +770,7 @@ def render_instance( *, future_seconds: float = 0.0, save_dir: str | None = None, + show_map: bool = False, ) -> None: """Render particular instance. @@ -774,11 +778,13 @@ def render_instance( instance_token (str | Sequence[str]): Instance token(s). future_seconds (float, optional): Future time in [s]. save_dir (str | None, optional): Directory path to save the recording. + show_map (bool, optional): Whether to render the map. """ self._rendering_helper.render_instance( instance_token=instance_token, future_seconds=future_seconds, save_dir=save_dir, + show_map=show_map, ) def render_pointcloud( @@ -786,12 +792,14 @@ def render_pointcloud( *, max_time_seconds: float = np.inf, save_dir: str | None = None, + show_map: bool = False, ) -> None: """Render pointcloud on 3D and 2D view. Args: max_time_seconds (float, optional): Max time length to be rendered [s]. save_dir (str | None, optional): Directory path to save the recording. + show_map (bool, optional): Whether to render the map. TODO: Add an option of rendering radar channels. @@ -799,6 +807,7 @@ def render_pointcloud( self._rendering_helper.render_pointcloud( max_time_seconds=max_time_seconds, save_dir=save_dir, + show_map=show_map, )