1616from t4_devkit .common .timestamp import sec2us , us2sec
1717from t4_devkit .dataclass import LidarPointCloud , RadarPointCloud
1818from t4_devkit .schema import SensorModality
19- from t4_devkit .viewer import RerunViewer , distance_color , format_entity
19+ from t4_devkit .viewer import PointCloudColorMode , RerunViewer , format_entity , normalize_color
2020
2121if TYPE_CHECKING :
2222 from t4_devkit import Tier4
@@ -468,7 +468,7 @@ def _render_points_on_single_camera(camera: str) -> None:
468468 if max_timestamp_us < sample .timestamp :
469469 break
470470
471- points_on_image , depths , image = self ._project_pointcloud (
471+ points_on_image , colors , image = self ._project_pointcloud (
472472 point_sample_data_token = current_point_sample_data_token ,
473473 camera_sample_data_token = camera_sample_data_token ,
474474 min_dist = min_dist ,
@@ -480,7 +480,7 @@ def _render_points_on_single_camera(camera: str) -> None:
480480 rr .log (format_entity (RerunViewer .ego_entity , camera ), rr .Image (image ))
481481 rr .log (
482482 format_entity (RerunViewer .ego_entity , camera , "pointcloud" ),
483- rr .Points2D (positions = points_on_image .T , colors = distance_color ( depths ) ),
483+ rr .Points2D (positions = points_on_image .T , colors = colors ),
484484 )
485485
486486 current_point_sample_data_token = sample_data .next
@@ -498,6 +498,7 @@ def _project_pointcloud(
498498 min_dist : float = 1.0 ,
499499 * ,
500500 ignore_distortion : bool = True ,
501+ color_mode : PointCloudColorMode = PointCloudColorMode .INTENSITY ,
501502 ) -> tuple [NDArrayF64 , NDArrayF64 , NDArrayU8 ]:
502503 """Project pointcloud on image plane.
503504
@@ -506,9 +507,10 @@ def _project_pointcloud(
506507 camera_sample_data_token (str): Sample data token of camera.
507508 min_dist (float, optional): Distance from the camera below which points are discarded.
508509 ignore_distortion (bool, optional): Whether to ignore distortion parameters.
510+ color_mode (PointCloudColorMode, optional): Color mode for pointcloud.
509511
510512 Returns:
511- Projected points [2, n], their normalized depths [n] and an image.
513+ Projected points [2, n], their normalized features [n] and an image.
512514 """
513515 point_sample_data : SampleData = self ._t4 .get ("sample_data" , point_sample_data_token )
514516 pc_filepath = osp .join (self ._t4 .data_root , point_sample_data .filename )
@@ -549,8 +551,6 @@ def _project_pointcloud(
549551 pointcloud .translate (- camera_cs_record .translation )
550552 pointcloud .rotate (camera_cs_record .rotation .rotation_matrix .T )
551553
552- depths = pointcloud .points [2 , :]
553-
554554 distortion = None if ignore_distortion else camera_cs_record .camera_distortion
555555
556556 points_on_img = view_points (
@@ -560,16 +560,24 @@ def _project_pointcloud(
560560 normalize = True ,
561561 )[:2 ]
562562
563- mask = np .ones (depths .shape [0 ], dtype = bool )
564- mask = np .logical_and (mask , depths > min_dist )
563+ match color_mode :
564+ case PointCloudColorMode .DISTANCE :
565+ colors = normalize_color (pointcloud .points [2 , :])
566+ case _:
567+ colors = normalize_color (pointcloud .points [3 , :])
568+ depths = pointcloud .points [2 , :]
569+
570+ mask = np .ones (colors .shape [0 ], dtype = bool )
571+ mask = np .logical_and (mask , depths > min_dist ) # mask by depths
572+ # mask by size of points on image
565573 mask = np .logical_and (mask , 1 < points_on_img [0 ])
566574 mask = np .logical_and (mask , points_on_img [0 ] < img .size [0 ] - 1 )
567575 mask = np .logical_and (mask , 1 < points_on_img [1 ])
568576 mask = np .logical_and (mask , points_on_img [1 ] < img .size [1 ] - 1 )
569577 points_on_img = points_on_img [:, mask ]
570- depths = depths [mask ]
578+ colors = colors [mask ]
571579
572- return points_on_img , depths , np .array (img , dtype = np .uint8 )
580+ return points_on_img , colors , np .array (img , dtype = np .uint8 )
573581
574582 def _render_annotation3ds (
575583 self ,
0 commit comments