diff --git a/t4_devkit/helper/rendering.py b/t4_devkit/helper/rendering.py index 1c748078..938269a4 100644 --- a/t4_devkit/helper/rendering.py +++ b/t4_devkit/helper/rendering.py @@ -41,6 +41,8 @@ class RenderingMode(Enum): + """Rendering mode enumerations.""" + SCENE = "scene" INSTANCE = "instance" POINTCLOUD = "pointcloud" @@ -66,9 +68,11 @@ def __init__(self, t4: Tier4) -> None: self._executor = concurrent.futures.ThreadPoolExecutor() def _has_lidarseg(self) -> bool: + """Return `True` if the dataset includes lidarseg.""" return bool(self._sample_data_to_lidarseg_filename) def _find_lidarseg_file(self, sample_data_token: str) -> str | None: + """Try to find lidarseg filename from the sample data token.""" return self._sample_data_to_lidarseg_filename.get(sample_data_token) def _init_viewer( diff --git a/t4_devkit/viewer/builder.py b/t4_devkit/viewer/builder.py index bb27eec8..e33b6ddd 100644 --- a/t4_devkit/viewer/builder.py +++ b/t4_devkit/viewer/builder.py @@ -33,10 +33,24 @@ def __init__(self) -> None: self._config = ViewerConfig() def with_spatial3d(self) -> Self: + """Update the viewer configuration to include 3D view space. + + Returns: + Self: Updated `ViewerBuilder` instance itself. + """ self._config.spatial3ds.append(rrb.Spatial3DView(name="3D", origin=EntityPath.MAP)) return self def with_spatial2d(self, cameras: Sequence[str], contents: list[str] | None = None) -> Self: + """Update the viewer configuration to include 2D view spaces for each camera. + + Args: + cameras (Sequence[str]): Camera names. + contents (list[str] | None): List of 3D view contents to project onto 2D view spaces. + + Returns: + Self: Updated `ViewerBuilder` instance itself. + """ # Preserve the original contents arguments so each camera gets its own view_contents. base_contents = contents for name in cameras: @@ -53,14 +67,39 @@ def with_spatial2d(self, cameras: Sequence[str], contents: list[str] | None = No return self def with_labels(self, label2id: dict[str, int]) -> Self: + """Update the viewer configuration to include label to id mapping. + + Args: + label2id (dict[str, int]): Key-value mapping to convert label name to its ID. + + Returns: + Self: Updated `ViewerBuilder` instance itself. + """ self._config.label2id = label2id return self def with_streetmap(self, latlon: Vector2Like | None = None) -> Self: + """Update the viewer configuration to include the streetmap view space. + + Args: + latlon (Vector2Like | None): Starting point in (latitude, longitude). + + Returns: + Self: Updated `ViewerBuilder` instance itself. + """ self._config.spatial3ds.append(rrb.MapView(name="Map", origin=EntityPath.GEOCOORDINATE)) if latlon is not None: self._config.latlon = latlon return self def build(self, app_id: str, save_dir: str | None = None) -> RerunViewer: + """Build `RerunViewer` from the configuration. + + Args: + app_id (str): Viewer application ID. + save_dir (str | None): Directory path to save the rendering record. + + Returns: + RerunViewer: Viewer instance. + """ return RerunViewer(app_id=app_id, config=self._config, save_dir=save_dir) diff --git a/t4_devkit/viewer/color.py b/t4_devkit/viewer/color.py index 435abc38..fb465f8f 100644 --- a/t4_devkit/viewer/color.py +++ b/t4_devkit/viewer/color.py @@ -32,6 +32,9 @@ def pointcloud_color( Args: pointcloud (PointCloudLike): Any inheritance of `PointCloud` class. color_mode (PointCloudColorMode, optional): Color mode for pointcloud. + + Returns: + NDArrayF64: RGB color array in the shape of (N, 3). """ match color_mode: case PointCloudColorMode.DISTANCE: diff --git a/t4_devkit/viewer/config.py b/t4_devkit/viewer/config.py index 5c15d344..1c894b20 100644 --- a/t4_devkit/viewer/config.py +++ b/t4_devkit/viewer/config.py @@ -30,6 +30,15 @@ class EntityPath(str, Enum): @define class ViewerConfig: + """Viewer configuration. + + Attributes: + spatial3ds (list[rrb.Spatial3DView | rrb.MapView]): List of 3D spatial views. + spatial2ds (list[rrb.Spatial2DView]): List of 2D spatial views. + label2id (dict[str, int]): Key-value mapping to convert label name to its ID. + latlon (Vector2Like | None): Starting point in (latitude, longitude). + """ + spatial3ds: list[rrb.Spatial3DView | rrb.MapView] = field(factory=list) spatial2ds: list[rrb.Spatial2DView] = field(factory=list) label2id: dict[str, int] = field(factory=dict)