From 25f7f41c4cee852bf79ca0c6eaf0a94b0ebb3972 Mon Sep 17 00:00:00 2001 From: ktro2828 Date: Tue, 10 Feb 2026 05:57:44 +0900 Subject: [PATCH 1/4] refactor: update lidarseg seraching logic Signed-off-by: ktro2828 --- t4_devkit/helper/rendering.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/t4_devkit/helper/rendering.py b/t4_devkit/helper/rendering.py index 85278c9a..49054729 100644 --- a/t4_devkit/helper/rendering.py +++ b/t4_devkit/helper/rendering.py @@ -56,16 +56,17 @@ def __init__(self, t4: Tier4) -> None: self._label2id: dict[str, int] = { category.name: category.index for category in self._t4.category } - self._sample_data_to_lidarseg_filename: dict[str, str] | None = ( - {lidarseg.sample_data_token: lidarseg.filename for lidarseg in self._t4.lidarseg} - if self._t4.lidarseg - else None - ) + self._sample_data_to_lidarseg_filename: dict[str, str] = { + lidarseg.sample_data_token: lidarseg.filename for lidarseg in self._t4.lidarseg + } self._executor = concurrent.futures.ThreadPoolExecutor() def _has_lidarseg(self) -> bool: - return self._sample_data_to_lidarseg_filename is not None + return len(self._sample_data_to_lidarseg_filename) > 0 + + def _find_lidarseg_file(self, sample_data_token: str) -> str | None: + return self._sample_data_to_lidarseg_filename.get(sample_data_token) def _init_viewer( self, @@ -380,13 +381,10 @@ def _render_single_lidar(first_lidar_token: str) -> None: # render segmentation pointcloud if available, otherwise render raw pointcloud if color_mode == PointCloudColorMode.SEGMENTATION: - if not ( - self._has_lidarseg() - and sample_data.token in self._sample_data_to_lidarseg_filename - ): + label_filename = self._find_lidarseg_file(sample_data.token) + if label_filename is None: continue - label_filename = self._sample_data_to_lidarseg_filename[sample_data.token] pointcloud = SegmentationPointCloud.from_file( point_filepath=osp.join(self._t4.data_root, sample_data.filename), label_filepath=osp.join(self._t4.data_root, label_filename), From 54b5a553b6f5f3b6a87642792e56ab89b7837bad Mon Sep 17 00:00:00 2001 From: ktro2828 Date: Tue, 10 Feb 2026 06:05:56 +0900 Subject: [PATCH 2/4] refactor: update rendering log logic Signed-off-by: ktro2828 --- t4_devkit/viewer/viewer.py | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/t4_devkit/viewer/viewer.py b/t4_devkit/viewer/viewer.py index 8cf2bf95..77a214bf 100644 --- a/t4_devkit/viewer/viewer.py +++ b/t4_devkit/viewer/viewer.py @@ -427,18 +427,17 @@ def render_pointcloud( # TODO(ktro2828): add support of rendering pointcloud on images rr.set_time_seconds(self.config.timeline, seconds) + entity_path = format_entity(self.config.ego_entity, channel) if color_mode == PointCloudColorMode.SEGMENTATION: - assert isinstance(pointcloud, SegmentationPointCloud) - rr.log( - format_entity(self.config.ego_entity, channel), - rr.Points3D(pointcloud.points[:3].T, class_ids=pointcloud.labels), - ) + assert isinstance( + pointcloud, SegmentationPointCloud + ), f"Expected SegmentationPointCloud instance, but got {type(pointcloud)}" + entity = rr.Points3D(pointcloud.points[:3].T, class_ids=pointcloud.labels) else: colors = pointcloud_color(pointcloud, color_mode=color_mode) - rr.log( - format_entity(self.config.ego_entity, channel), - rr.Points3D(pointcloud.points[:3].T, colors=colors), - ) + entity = rr.Points3D(pointcloud.points[:3].T, colors=colors) + + rr.log(entity_path, entity) @_check_spatial2d def render_image(self, seconds: float, camera: str, image: str | NDArrayU8) -> None: @@ -451,10 +450,10 @@ def render_image(self, seconds: float, camera: str, image: str | NDArrayU8) -> N """ rr.set_time_seconds(self.config.timeline, seconds) - if isinstance(image, str): - rr.log(format_entity(self.config.ego_entity, camera), rr.ImageEncoded(path=image)) - else: - rr.log(format_entity(self.config.ego_entity, camera), rr.Image(image)) + entity_path = format_entity(self.config.ego_entity, camera) + entity = rr.ImageEncoded(path=image) if isinstance(image, str) else rr.Image(image) + + rr.log(entity_path, entity) @overload def render_ego(self, ego_pose: EgoPose) -> None: @@ -519,18 +518,12 @@ def _render_ego_without_schema( ), ) + entity_path = self.config.geocoordinate_entity if geocoordinate is not None: - latitude, longitude, _ = geocoordinate - rr.log( - self.config.geocoordinate_entity, - rr.GeoPoints(lat_lon=(latitude, longitude)), - ) + rr.log(entity_path, rr.GeoPoints(lat_lon=geocoordinate[:2])) elif self.latlon is not None: latitude, longitude = calculate_geodetic_point(translation, self.latlon) - rr.log( - self.config.geocoordinate_entity, - rr.GeoPoints(lat_lon=(latitude, longitude)), - ) + rr.log(entity_path, rr.GeoPoints(lat_lon=(latitude, longitude))) @overload def render_calibration( From a860165c5294ff3ac6afe7c9bbf9cf5359686aa1 Mon Sep 17 00:00:00 2001 From: ktro2828 Date: Tue, 10 Feb 2026 06:15:17 +0900 Subject: [PATCH 3/4] refactor: replace assert into TypeError Signed-off-by: ktro2828 --- t4_devkit/viewer/viewer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/t4_devkit/viewer/viewer.py b/t4_devkit/viewer/viewer.py index 77a214bf..c450eeb7 100644 --- a/t4_devkit/viewer/viewer.py +++ b/t4_devkit/viewer/viewer.py @@ -429,9 +429,11 @@ def render_pointcloud( entity_path = format_entity(self.config.ego_entity, channel) if color_mode == PointCloudColorMode.SEGMENTATION: - assert isinstance( - pointcloud, SegmentationPointCloud - ), f"Expected SegmentationPointCloud instance, but got {type(pointcloud)}" + if not isinstance(pointcloud, SegmentationPointCloud): + raise TypeError( + f"Expected SegmentationPointCloud instance, but got {type(pointcloud)}" + ) + entity = rr.Points3D(pointcloud.points[:3].T, class_ids=pointcloud.labels) else: colors = pointcloud_color(pointcloud, color_mode=color_mode) From 10cd04fd2174da26e23cf7143ee6737f926c26f9 Mon Sep 17 00:00:00 2001 From: ktro2828 Date: Tue, 10 Feb 2026 06:16:35 +0900 Subject: [PATCH 4/4] refactor: use direct truthiness Signed-off-by: ktro2828 --- t4_devkit/helper/rendering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t4_devkit/helper/rendering.py b/t4_devkit/helper/rendering.py index 49054729..b3a5e472 100644 --- a/t4_devkit/helper/rendering.py +++ b/t4_devkit/helper/rendering.py @@ -63,7 +63,7 @@ def __init__(self, t4: Tier4) -> None: self._executor = concurrent.futures.ThreadPoolExecutor() def _has_lidarseg(self) -> bool: - return len(self._sample_data_to_lidarseg_filename) > 0 + return bool(self._sample_data_to_lidarseg_filename) def _find_lidarseg_file(self, sample_data_token: str) -> str | None: return self._sample_data_to_lidarseg_filename.get(sample_data_token)