Skip to content

Commit e1f01c9

Browse files
ktro2828Copilot
andauthored
style(viewer): add docstrings (#267)
* style: add docstrings Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp> * Update t4_devkit/viewer/config.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update t4_devkit/viewer/builder.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update t4_devkit/viewer/builder.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update t4_devkit/viewer/config.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d5907a9 commit e1f01c9

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

t4_devkit/helper/rendering.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242

4343
class RenderingMode(Enum):
44+
"""Rendering mode enumerations."""
45+
4446
SCENE = "scene"
4547
INSTANCE = "instance"
4648
POINTCLOUD = "pointcloud"
@@ -66,9 +68,11 @@ def __init__(self, t4: Tier4) -> None:
6668
self._executor = concurrent.futures.ThreadPoolExecutor()
6769

6870
def _has_lidarseg(self) -> bool:
71+
"""Return `True` if the dataset includes lidarseg."""
6972
return bool(self._sample_data_to_lidarseg_filename)
7073

7174
def _find_lidarseg_file(self, sample_data_token: str) -> str | None:
75+
"""Try to find lidarseg filename from the sample data token."""
7276
return self._sample_data_to_lidarseg_filename.get(sample_data_token)
7377

7478
def _init_viewer(

t4_devkit/viewer/builder.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,24 @@ def __init__(self) -> None:
3333
self._config = ViewerConfig()
3434

3535
def with_spatial3d(self) -> Self:
36+
"""Update the viewer configuration to include 3D view space.
37+
38+
Returns:
39+
Self: Updated `ViewerBuilder` instance itself.
40+
"""
3641
self._config.spatial3ds.append(rrb.Spatial3DView(name="3D", origin=EntityPath.MAP))
3742
return self
3843

3944
def with_spatial2d(self, cameras: Sequence[str], contents: list[str] | None = None) -> Self:
45+
"""Update the viewer configuration to include 2D view spaces for each camera.
46+
47+
Args:
48+
cameras (Sequence[str]): Camera names.
49+
contents (list[str] | None): List of 3D view contents to project onto 2D view spaces.
50+
51+
Returns:
52+
Self: Updated `ViewerBuilder` instance itself.
53+
"""
4054
# Preserve the original contents arguments so each camera gets its own view_contents.
4155
base_contents = contents
4256
for name in cameras:
@@ -53,14 +67,39 @@ def with_spatial2d(self, cameras: Sequence[str], contents: list[str] | None = No
5367
return self
5468

5569
def with_labels(self, label2id: dict[str, int]) -> Self:
70+
"""Update the viewer configuration to include label to id mapping.
71+
72+
Args:
73+
label2id (dict[str, int]): Key-value mapping to convert label name to its ID.
74+
75+
Returns:
76+
Self: Updated `ViewerBuilder` instance itself.
77+
"""
5678
self._config.label2id = label2id
5779
return self
5880

5981
def with_streetmap(self, latlon: Vector2Like | None = None) -> Self:
82+
"""Update the viewer configuration to include the streetmap view space.
83+
84+
Args:
85+
latlon (Vector2Like | None): Starting point in (latitude, longitude).
86+
87+
Returns:
88+
Self: Updated `ViewerBuilder` instance itself.
89+
"""
6090
self._config.spatial3ds.append(rrb.MapView(name="Map", origin=EntityPath.GEOCOORDINATE))
6191
if latlon is not None:
6292
self._config.latlon = latlon
6393
return self
6494

6595
def build(self, app_id: str, save_dir: str | None = None) -> RerunViewer:
96+
"""Build `RerunViewer` from the configuration.
97+
98+
Args:
99+
app_id (str): Viewer application ID.
100+
save_dir (str | None): Directory path to save the rendering record.
101+
102+
Returns:
103+
RerunViewer: Viewer instance.
104+
"""
66105
return RerunViewer(app_id=app_id, config=self._config, save_dir=save_dir)

t4_devkit/viewer/color.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def pointcloud_color(
3232
Args:
3333
pointcloud (PointCloudLike): Any inheritance of `PointCloud` class.
3434
color_mode (PointCloudColorMode, optional): Color mode for pointcloud.
35+
36+
Returns:
37+
NDArrayF64: RGB color array in the shape of (N, 3).
3538
"""
3639
match color_mode:
3740
case PointCloudColorMode.DISTANCE:

t4_devkit/viewer/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ class EntityPath(str, Enum):
3030

3131
@define
3232
class ViewerConfig:
33+
"""Viewer configuration.
34+
35+
Attributes:
36+
spatial3ds (list[rrb.Spatial3DView | rrb.MapView]): List of 3D spatial views.
37+
spatial2ds (list[rrb.Spatial2DView]): List of 2D spatial views.
38+
label2id (dict[str, int]): Key-value mapping to convert label name to its ID.
39+
latlon (Vector2Like | None): Starting point in (latitude, longitude).
40+
"""
41+
3342
spatial3ds: list[rrb.Spatial3DView | rrb.MapView] = field(factory=list)
3443
spatial2ds: list[rrb.Spatial2DView] = field(factory=list)
3544
label2id: dict[str, int] = field(factory=dict)

0 commit comments

Comments
 (0)