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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [{ name = "Kotaro Uetake", email = "kotaro.uetake@tier4.jp" }]
readme = "README.md"
requires-python = ">=3.10,<3.13"
dependencies = [
"rerun-sdk>=0.20.0,<0.28.0",
"rerun-sdk>=0.20.0",
"pyquaternion>=0.9.9",
"matplotlib>=3.9.2",
"shapely<2.0.0; python_version=='3.10'",
Expand Down
25 changes: 17 additions & 8 deletions t4_devkit/viewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

__all__ = ["RerunViewer"]

RERUN_SDK_VERSION = tuple(int(part) for part in rr.__version__.split(".")[:2])


def _check_spatial3d(function: Callable) -> Callable:
"""Check if the viewer has the 3D view space.
Expand Down Expand Up @@ -90,6 +92,13 @@ def checker(viewer: RerunViewer, filepath: str):
return checker


def _set_time_seconds(timeline: EntityPath, seconds: float) -> None:
if RERUN_SDK_VERSION < (0, 27):
rr.set_time_seconds(timeline, seconds)
else:
rr.set_time(timeline, timestamp=seconds)


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

Expand Down Expand Up @@ -215,7 +224,7 @@ def render_box3ds(self, *args, **kwargs) -> None:
self._render_box3ds_with_elements(*args, **kwargs)

def _render_box3ds_with_boxes(self, seconds: float, boxes: Sequence[Box3D]) -> None:
rr.set_time_seconds(EntityPath.TIMELINE, seconds)
_set_time_seconds(EntityPath.TIMELINE, seconds)

batches: dict[str, BatchBox3D] = {}
for box in boxes:
Expand Down Expand Up @@ -288,7 +297,7 @@ def _render_box3ds_with_elements(
future=future,
)

rr.set_time_seconds(EntityPath.TIMELINE, seconds)
_set_time_seconds(EntityPath.TIMELINE, seconds)

rr.log(format_entity(EntityPath.MAP, frame_id, EntityPath.BOX), batch.as_boxes3d())

Expand Down Expand Up @@ -344,7 +353,7 @@ def render_box2ds(self, *args, **kwargs) -> None:
self._render_box2ds_with_elements(*args, **kwargs)

def _render_box2ds_with_boxes(self, seconds: float, boxes: Sequence[Box2D]) -> None:
rr.set_time_seconds(EntityPath.TIMELINE, seconds)
_set_time_seconds(EntityPath.TIMELINE, seconds)

batches: dict[str, BatchBox2D] = {}
for box in boxes:
Expand Down Expand Up @@ -373,7 +382,7 @@ def _render_box2ds_with_elements(
for roi, class_id, uuid in zip(rois, class_ids, uuids, strict=True):
batch.append(roi=roi, class_id=class_id, uuid=uuid)

rr.set_time_seconds(EntityPath.TIMELINE, seconds)
_set_time_seconds(EntityPath.TIMELINE, seconds)
rr.log(format_entity(EntityPath.BASE_LINK, camera, EntityPath.BOX), batch.as_boxes2d())

@_check_spatial2d
Expand All @@ -395,7 +404,7 @@ def render_segmentation2d(
class_ids (Sequence[int]): Sequence of label ids.
uuids (Sequence[str | None] | None, optional): Sequence of each instance ID.
"""
rr.set_time_seconds(EntityPath.TIMELINE, seconds)
_set_time_seconds(EntityPath.TIMELINE, seconds)

batch = BatchSegmentation2D()
if uuids is None:
Expand Down Expand Up @@ -425,7 +434,7 @@ def render_pointcloud(
color_mode (PointCloudColorMode, optional): Color mode for pointcloud.
"""
# TODO(ktro2828): add support of rendering pointcloud on images
rr.set_time_seconds(EntityPath.TIMELINE, seconds)
_set_time_seconds(EntityPath.TIMELINE, seconds)

entity_path = format_entity(EntityPath.BASE_LINK, channel)
if color_mode == PointCloudColorMode.SEGMENTATION:
Expand All @@ -450,7 +459,7 @@ def render_image(self, seconds: float, camera: str, image: str | NDArrayU8) -> N
camera (str): Name of the camera channel.
image (str | NDArrayU8): Image tensor or path of the image file.
"""
rr.set_time_seconds(EntityPath.TIMELINE, seconds)
_set_time_seconds(EntityPath.TIMELINE, seconds)

entity_path = format_entity(EntityPath.BASE_LINK, camera)
entity = rr.ImageEncoded(path=image) if isinstance(image, str) else rr.Image(image)
Expand Down Expand Up @@ -509,7 +518,7 @@ def _render_ego_without_schema(
rotation: RotationLike,
geocoordinate: Vector3Like | None = None,
) -> None:
rr.set_time_seconds(EntityPath.TIMELINE, seconds)
_set_time_seconds(EntityPath.TIMELINE, seconds)

rr.log(
EntityPath.BASE_LINK,
Expand Down
Loading