Skip to content

Commit 027be5b

Browse files
committed
feat: add support of rendering segmentation pointcloud
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent ffa2bc5 commit 027be5b

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

t4_devkit/helper/rendering.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from t4_devkit.common.geometry import view_points
1515
from t4_devkit.common.timestamp import microseconds2seconds, seconds2microseconds
16-
from t4_devkit.dataclass import LidarPointCloud, RadarPointCloud
16+
from t4_devkit.dataclass import LidarPointCloud, RadarPointCloud, SegmentationPointCloud
1717
from t4_devkit.schema import SensorModality
1818
from t4_devkit.viewer import (
1919
PointCloudColorMode,
@@ -56,6 +56,11 @@ def __init__(self, t4: Tier4) -> None:
5656
self._label2id: dict[str, int] = {
5757
category.name: idx for idx, category in enumerate(self._t4.category)
5858
}
59+
self._sample_data_to_lidarseg_filename: dict[str, str] | None = (
60+
{lidarseg.sample_data_token: lidarseg.filename for lidarseg in self._t4.lidarseg}
61+
if self._t4.lidarseg
62+
else None
63+
)
5964

6065
self._executor = concurrent.futures.ThreadPoolExecutor()
6166

@@ -122,7 +127,7 @@ def render_scene(
122127
app_id = f"scene@{self._t4.dataset_id}"
123128
viewer = self._init_viewer(app_id, render_ann=True, save_dir=save_dir)
124129

125-
self._render_map(viewer)
130+
# self._render_map(viewer)
126131

127132
scene: Scene = self._t4.scene[0]
128133
first_sample: Sample = self._t4.get("sample", scene.first_sample_token)
@@ -352,9 +357,21 @@ def _render_single_lidar(first_lidar_token: str) -> None:
352357
ego_pose: EgoPose = self._t4.get("ego_pose", sample_data.ego_pose_token)
353358
viewer.render_ego(ego_pose=ego_pose)
354359

355-
pointcloud = LidarPointCloud.from_file(
356-
osp.join(self._t4.data_root, sample_data.filename)
357-
)
360+
# render segmentation pointcloud if available, otherwise render raw pointcloud
361+
if (
362+
self._sample_data_to_lidarseg_filename
363+
and sample_data.token in self._sample_data_to_lidarseg_filename
364+
):
365+
label_filename = self._sample_data_to_lidarseg_filename[sample_data.token]
366+
pointcloud = SegmentationPointCloud.from_file(
367+
point_filepath=osp.join(self._t4.data_root, sample_data.filename),
368+
label_filepath=osp.join(self._t4.data_root, label_filename),
369+
)
370+
else:
371+
pointcloud = LidarPointCloud.from_file(
372+
osp.join(self._t4.data_root, sample_data.filename)
373+
)
374+
358375
viewer.render_pointcloud(
359376
seconds=microseconds2seconds(sample_data.timestamp),
360377
channel=sample_data.channel,

t4_devkit/viewer/viewer.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from t4_devkit.common.converter import to_quaternion
1111
from t4_devkit.common.timestamp import microseconds2seconds
12+
from t4_devkit.dataclass import SegmentationPointCloud
1213
from t4_devkit.lanelet import LaneletParser
1314
from t4_devkit.schema import SensorModality
1415

@@ -426,11 +427,17 @@ def render_pointcloud(
426427
# TODO(ktro2828): add support of rendering pointcloud on images
427428
rr.set_time_seconds(self.config.timeline, seconds)
428429

429-
colors = pointcloud_color(pointcloud, color_mode=color_mode)
430-
rr.log(
431-
format_entity(self.config.ego_entity, channel),
432-
rr.Points3D(pointcloud.points[:3].T, colors=colors),
433-
)
430+
if isinstance(pointcloud, SegmentationPointCloud):
431+
rr.log(
432+
format_entity(self.config.ego_entity, channel),
433+
rr.Points3D(pointcloud.points[:3].T, class_ids=pointcloud.labels),
434+
)
435+
else:
436+
colors = pointcloud_color(pointcloud, color_mode=color_mode)
437+
rr.log(
438+
format_entity(self.config.ego_entity, channel),
439+
rr.Points3D(pointcloud.points[:3].T, colors=colors),
440+
)
434441

435442
@_check_spatial2d
436443
def render_image(self, seconds: float, camera: str, image: str | NDArrayU8) -> None:

0 commit comments

Comments
 (0)