Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions t4_devkit/helper/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@


class RenderingMode(Enum):
"""Rendering mode enumerations."""

SCENE = "scene"
INSTANCE = "instance"
POINTCLOUD = "pointcloud"
Expand All @@ -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(
Expand Down
39 changes: 39 additions & 0 deletions t4_devkit/viewer/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
3 changes: 3 additions & 0 deletions t4_devkit/viewer/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions t4_devkit/viewer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading