Skip to content

Commit

Permalink
refactor: rename Tier4Viewer to RerunViewer (#58)
Browse files Browse the repository at this point in the history
Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 authored Dec 2, 2024
1 parent 1725518 commit 9b18d78
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 45 deletions.
8 changes: 4 additions & 4 deletions docs/tutorials/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ If you don't want to spawn the viewer, please specify `show=False` as below:
>>> t4.render_scene(scene_token, save_dir=<DIR_TO_SAVE>, show=False)
```

## Rendering with `Tier4Viewer`
## Rendering with `RerunViewer`

If you want to visualize your components, such as boxes that your ML-model estimated, `Tier4Viewer` allows you to visualize these components.
If you want to visualize your components, such as boxes that your ML-model estimated, `RerunViewer` allows you to visualize these components.
For details, please refer to the API references.

```python
>>> from t4_devkit.viewer import Tier4Viewer
>>> from t4_devkit.viewer import RerunViewer
# You need to specify `cameras` if you want to 2D spaces
>>> viewer = Tier4Viewer(app_id, cameras=<CAMERA_NAMES:[str;N]>)
>>> viewer = RerunViewer(app_id, cameras=<CAMERA_NAMES:[str;N]>)
# Rendering 3D boxes
>>> viewer.render_box3ds(seconds, box3ds)
# Rendering 2D boxes
Expand Down
36 changes: 18 additions & 18 deletions t4_devkit/tier4.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ShapeType,
)
from t4_devkit.schema import SchemaName, SensorModality, VisibilityLevel, build_schema
from t4_devkit.viewer import Tier4Viewer, distance_color, format_entity
from t4_devkit.viewer import RerunViewer, distance_color, format_entity

if TYPE_CHECKING:
from t4_devkit.typing import CamIntrinsicType, NDArrayF64, NDArrayU8, VelocityType
Expand Down Expand Up @@ -882,7 +882,7 @@ def _init_viewer(
render_2d: bool = True,
render_annotation: bool = True,
spawn: bool = False,
) -> Tier4Viewer:
) -> RerunViewer:
"""Initialize rendering viewer.
Args:
Expand All @@ -904,7 +904,7 @@ def _init_viewer(
else None
)

viewer = Tier4Viewer(application_id, cameras=cameras, with_3d=render_3d, spawn=spawn)
viewer = RerunViewer(application_id, cameras=cameras, with_3d=render_3d, spawn=spawn)

if render_annotation:
viewer = viewer.with_labels(self._label2id)
Expand All @@ -915,7 +915,7 @@ def _init_viewer(

def _render_lidar_and_ego(
self,
viewer: Tier4Viewer,
viewer: RerunViewer,
first_lidar_token: str,
max_timestamp_us: float,
*,
Expand All @@ -925,7 +925,7 @@ def _render_lidar_and_ego(
"""Render lidar pointcloud and ego transform.
Args:
viewer (Tier4Viewer): Viewer object.
viewer (RerunViewer): Viewer object.
first_lidar_token (str): First sample data token corresponding to the lidar.
max_timestamp_us (float): Max time length in [us].
project_points (bool, optional): Whether to project 3d points on 2d images.
Expand Down Expand Up @@ -961,14 +961,14 @@ def _render_lidar_and_ego(

def _render_radars(
self,
viewer: Tier4Viewer,
viewer: RerunViewer,
first_radar_tokens: list[str],
max_timestamp_us: float,
) -> None:
"""Render radar pointcloud.
Args:
viewer (Tier4Viewer): Viewer object.
viewer (RerunViewer): Viewer object.
first_radar_tokens (list[str]): List of first sample data tokens corresponding to radars.
max_timestamp_us (float): Max time length in [us].
"""
Expand All @@ -993,12 +993,12 @@ def _render_radars(
current_radar_token = sample_data.next

def _render_cameras(
self, viewer: Tier4Viewer, first_camera_tokens: list[str], max_timestamp_us: float
self, viewer: RerunViewer, first_camera_tokens: list[str], max_timestamp_us: float
) -> None:
"""Render camera images.
Args:
viewer (Tier4Viewer): Viewer object.
viewer (RerunViewer): Viewer object.
first_camera_tokens (list[str]): List of first sample data tokens corresponding to cameras.
max_timestamp_us (float): Max time length in [us].
"""
Expand Down Expand Up @@ -1038,7 +1038,7 @@ def _render_points_on_cameras(
ignore_distortion (bool, optional): Whether to ignore distortion parameters.
TODO:
Replace operation by `Tier4Viewer`.
Replace operation by `RerunViewer`.
"""
point_sample_data: SampleData = self.get("sample_data", point_sample_data_token)
sample: Sample = self.get("sample", point_sample_data.sample_token)
Expand All @@ -1060,10 +1060,10 @@ def _render_points_on_cameras(

sensor_name = channel
rr.set_time_seconds("timestamp", us2sec(camera_sample_data.timestamp))
rr.log(format_entity(Tier4Viewer.ego_entity, sensor_name), rr.Image(img))
rr.log(format_entity(RerunViewer.ego_entity, sensor_name), rr.Image(img))

rr.log(
format_entity(Tier4Viewer.ego_entity, sensor_name, "pointcloud"),
format_entity(RerunViewer.ego_entity, sensor_name, "pointcloud"),
rr.Points2D(
positions=points_on_img.T,
colors=distance_color(depths),
Expand All @@ -1072,15 +1072,15 @@ def _render_points_on_cameras(

def _render_annotation_3ds(
self,
viewer: Tier4Viewer,
viewer: RerunViewer,
first_sample_token: str,
max_timestamp_us: float,
instance_token: str | None = None,
) -> None:
"""Render annotated 3D boxes.
Args:
viewer (Tier4Viewer): Viewer object.
viewer (RerunViewer): Viewer object.
first_sample_token (str): First sample token.
max_timestamp_us (float): Max time length in [us].
instance_token (str | None, optional): Specify if you want to render only particular instance.
Expand All @@ -1107,15 +1107,15 @@ def _render_annotation_3ds(

def _render_annotation_2ds(
self,
viewer: Tier4Viewer,
viewer: RerunViewer,
first_sample_token: str,
max_timestamp_us: float,
instance_token: str | None = None,
) -> None:
"""Render annotated 2D boxes.
Args:
viewer (Tier4Viewer): Viewer object.
viewer (RerunViewer): Viewer object.
first_sample_token (str): First sample token.
max_timestamp_us (float): Max time length in [us].
instance_token (str | None, optional): Specify if you want to render only particular instance.
Expand Down Expand Up @@ -1175,11 +1175,11 @@ def _render_annotation_2ds(
# TODO: add support of rendering keypoints
current_sample_token = sample.next

def _render_sensor_calibration(self, viewer: Tier4Viewer, sample_data_token: str) -> None:
def _render_sensor_calibration(self, viewer: RerunViewer, sample_data_token: str) -> None:
"""Render a fixed calibrated sensor transform.
Args:
viewer (Tier4Viewer): Viewer object.
viewer (RerunViewer): Viewer object.
sample_data_token (str): First sample data token corresponding to the sensor.
"""
sample_data: SampleData = self.get("sample_data", sample_data_token)
Expand Down
14 changes: 7 additions & 7 deletions t4_devkit/viewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
VelocityType,
)

__all__ = ["Tier4Viewer", "format_entity"]
__all__ = ["RerunViewer", "format_entity"]


def format_entity(root: str, *entities) -> str:
Expand Down Expand Up @@ -61,7 +61,7 @@ def format_entity(root: str, *entities) -> str:
return osp.join(root, "/".join(entities))


class Tier4Viewer:
class RerunViewer:
"""A viewer class that renders some components powered by rerun."""

# entity paths
Expand All @@ -88,13 +88,13 @@ def __init__(
spawn (bool, optional): Whether to spawn the viewer.
Examples:
>>> from t4_devkit.viewer import Tier4Viewer
>>> from t4_devkit.viewer import RerunViewer
# Rendering both 3D/2D spaces
>>> viewer = Tier4Viewer("myapp", cameras=["camera0", "camera1"])
>>> viewer = RerunViewer("myapp", cameras=["camera0", "camera1"])
# Rendering 3D space only
>>> viewer = Tier4Viewer("myapp")
>>> viewer = RerunViewer("myapp")
# Rendering 2D space only
>>> viewer = Tier4Viewer("myapp", cameras=["camera0", "camera1"], with_3d=False)
>>> viewer = RerunViewer("myapp", cameras=["camera0", "camera1"], with_3d=False)
"""
self.app_id = app_id
self.cameras = cameras
Expand Down Expand Up @@ -148,7 +148,7 @@ def with_labels(self, label2id: dict[str, int]) -> Self:
Examples:
>>> label2id = {"car": 0, "pedestrian": 1}
>>> viewer = Tier4Viewer("myapp").with_labels(label2id)
>>> viewer = RerunViewer("myapp").with_labels(label2id)
"""
self.label2id = label2id

Expand Down
14 changes: 8 additions & 6 deletions tests/viewer/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import pytest

from t4_devkit.viewer import Tier4Viewer
from t4_devkit.viewer import RerunViewer


@pytest.fixture(scope="module")
def dummy_viewer(label2id) -> Tier4Viewer:
def dummy_viewer(label2id) -> RerunViewer:
"""Return a dummy viewer.
Returns:
`Tier4Viewer` without spawning.
`RerunViewer` without spawning.
"""
return Tier4Viewer("test_viewer", cameras=["camera"], spawn=False).with_labels(
label2id=label2id
)
return RerunViewer(
"test_viewer",
cameras=["camera"],
spawn=False,
).with_labels(label2id=label2id)
20 changes: 10 additions & 10 deletions tests/viewer/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def test_format_entity() -> None:


def test_render_box3ds(dummy_viewer, dummy_box3ds) -> None:
"""Test rendering 3D boxes with `Tier4Viewer`.
"""Test rendering 3D boxes with `RerunViewer`.
Args:
dummy_viewer (Tier4Viewer): Viewer object.
dummy_viewer (RerunViewer): Viewer object.
dummy_box3ds (list[Box3D]): List of 3D boxes.
"""
seconds = 1.0 # [sec]
Expand All @@ -46,10 +46,10 @@ def test_render_box3ds(dummy_viewer, dummy_box3ds) -> None:


def test_render_box2ds(dummy_viewer, dummy_box2ds) -> None:
"""Test rendering 2D boxes with `Tier4Viewer`.
"""Test rendering 2D boxes with `RerunViewer`.
Args:
dummy_viewer (Tier4Viewer): Viewer object.
dummy_viewer (RerunViewer): Viewer object.
dummy_box2ds (list[Box2D): List of 2D boxes.
"""
seconds = 1.0 # [sec]
Expand All @@ -65,10 +65,10 @@ def test_render_box2ds(dummy_viewer, dummy_box2ds) -> None:


def test_render_pointcloud(dummy_viewer) -> None:
"""Test rendering pointcloud with `Tier4Viewer`.
"""Test rendering pointcloud with `RerunViewer`.
Args:
dummy_viewer (Tier4Viewer): Viewer object.
dummy_viewer (RerunViewer): Viewer object.
"""
seconds = 1.0 # [sec]

Expand All @@ -77,10 +77,10 @@ def test_render_pointcloud(dummy_viewer) -> None:


def test_render_ego(dummy_viewer) -> None:
"""Test rendering ego pose with `Tier4Viewer`.
"""Test rendering ego pose with `RerunViewer`.
Args:
dummy_viewer (Tier4Viewer): Viewer object.
dummy_viewer (RerunViewer): Viewer object.
"""
seconds = 1.0 # [sec]

Expand All @@ -100,10 +100,10 @@ def test_render_ego(dummy_viewer) -> None:


def test_render_calibration(dummy_viewer) -> None:
"""Test rendering sensor calibration with `Tier4Viewer`.
"""Test rendering sensor calibration with `RerunViewer`.
Args:
dummy_viewer (Tier4Viewer): Viewer object.
dummy_viewer (RerunViewer): Viewer object.
"""
# without `Sensor` and `CalibratedSensor`
channel = "camera"
Expand Down

0 comments on commit 9b18d78

Please sign in to comment.