Skip to content

Commit

Permalink
feat: add Tier4Viewer
Browse files Browse the repository at this point in the history
Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 committed Oct 19, 2024
1 parent 0d7736e commit e4191db
Show file tree
Hide file tree
Showing 7 changed files with 477 additions and 4 deletions.
2 changes: 1 addition & 1 deletion t4_devkit/dataclass/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from t4_devkit.typing import NDArrayFloat, NDArrayU8

__all__ = ["LidarPointCloud", "RadarPointCloud", "SegmentationPointCloud"]
__all__ = ["PointCloud", "LidarPointCloud", "RadarPointCloud", "SegmentationPointCloud"]


@dataclass
Expand Down
6 changes: 3 additions & 3 deletions t4_devkit/tier4.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from PIL import Image
from pyquaternion import Quaternion

from t4_devkit.common.color import distance_color
from t4_devkit.common.geometry import is_box_in_image, view_points
from t4_devkit.common.timestamp import sec2us, us2sec
from t4_devkit.dataclass import (
Expand All @@ -25,6 +24,7 @@
convert_label,
)
from t4_devkit.schema import SchemaName, SensorModality, VisibilityLevel, build_schema
from t4_devkit.viewer import distance_color

if TYPE_CHECKING:
from rerun.blueprint.api import BlueprintLike, Container, SpaceView
Expand Down Expand Up @@ -1287,8 +1287,8 @@ def _render_sensor_calibration(self, sample_data_token: str) -> None:
f"world/ego_vehicle/{sensor_name}",
rr.Pinhole(
image_from_camera=calibrated_sensor.camera_intrinsic,
width=sample_data.width,
height=sample_data.height,
# width=sample_data.width,
# height=sample_data.height,
),
static=True,
)
Expand Down
2 changes: 2 additions & 0 deletions t4_devkit/viewer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .color import * # noqa
from .viewer import * # noqa
File renamed without changes.
107 changes: 107 additions & 0 deletions t4_devkit/viewer/rendering_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
import rerun as rr

if TYPE_CHECKING:
from t4_devkit.dataclass import Box2D, Box3D
from t4_devkit.typing import RoiType, SizeType, TranslationType, VelocityType


class BoxData3D:
"""A class to store 3D boxes data for rendering."""

def __init__(self) -> None:
self._centers: list[TranslationType] = []
self._rotations: list[rr.Quaternion] = []
self._sizes: list[SizeType] = []
self._class_ids: list[int] = []
self._uuids: list[int] = []
self._velocities: list[VelocityType] = []

def append(self, box: Box3D) -> None:
"""Append a 3D box data.
Args:
box (Box3D): `Box3D` object.
"""
self._centers.append(box.position)

rotation_xyzw = np.roll(box.rotation.q, shift=-1)
self._rotations.append(rr.Quaternion(xyzw=rotation_xyzw))

width, length, height = box.size
self._sizes.append((length, width, height))

self._class_ids.append(box.semantic_label.label.value)

if box.uuid is not None:
self._uuids.append(box.uuid[:6])

if box.velocity is not None:
self._velocities.append(box.velocity)

def as_boxes3d(self) -> rr.Boxes3D:
"""Return 3D boxes data as a `rr.Boxes3D`.
Returns:
`rr.Boxes3D` object.
"""
labels = None if len(self._uuids) == 0 else self._uuids
return rr.Boxes3D(
sizes=self._sizes,
centers=self._centers,
rotations=self._rotations,
labels=labels,
class_ids=self._class_ids,
)

def as_arrows3d(self) -> rr.Arrows3D:
"""Return velocities data as a `rr.Arrows3D`.
Returns:
`rr.Arrows3D` object.
"""
return rr.Arrows3D(
vectors=self._velocities,
origins=self._centers,
class_ids=self._class_ids,
)


class BoxData2D:
"""A class to store 2D boxes data for rendering."""

def __init__(self) -> None:
self._rois: list[RoiType] = []
self._uuids: list[str] = []
self._class_ids: list[int] = []

def append(self, box: Box2D) -> None:
"""Append a 2D box data.
Args:
box (Box2D): `Box2D` object.
"""
self._rois.append(box.roi.roi)

self._class_ids.append(box.semantic_label.label.value)

if box.uuid is not None:
self._uuids.append(box.uuid)

def as_boxes2d(self) -> rr.Boxes2D:
"""Return 2D boxes data as a `rr.Boxes2D`.
Returns:
`rr.Boxes2D` object.
"""
labels = None if len(self._uuids) == 0 else self._uuids
return rr.Boxes2D(
array=self._rois,
array_format=rr.Box2DFormat.XYXY,
labels=labels,
class_ids=self._class_ids,
)
Loading

0 comments on commit e4191db

Please sign in to comment.