99import rerun .blueprint as rrb
1010from typing_extensions import Self
1111
12+ from t4_devkit .common .converter import to_quaternion
1213from t4_devkit .common .timestamp import us2sec
1314from t4_devkit .lanelet import LaneletParser
1415from t4_devkit .schema import SensorModality
15- from t4_devkit .typing import Quaternion , Roi , Vector3
1616
1717from .color import distance_color
1818from .geography import calculate_geodetic_point
2727if TYPE_CHECKING :
2828 from t4_devkit .dataclass import Box2D , Box3D , Future , PointCloudLike
2929 from t4_devkit .schema import CalibratedSensor , EgoPose , Sensor
30- from t4_devkit .typing import CamIntrinsicLike , NDArrayU8
30+ from t4_devkit .typing import CamIntrinsicLike , NDArrayU8 , RoiLike , RotationLike , Vector3Like
3131
3232__all__ = ["RerunViewer" , "format_entity" ]
3333
@@ -214,23 +214,23 @@ def render_box3ds(self, seconds: float, boxes: Sequence[Box3D]) -> None:
214214 def render_box3ds (
215215 self ,
216216 seconds : float ,
217- centers : Sequence [Vector3 ],
218- rotations : Sequence [Quaternion ],
219- sizes : Sequence [Vector3 ],
217+ centers : Sequence [Vector3Like ],
218+ rotations : Sequence [RotationLike ],
219+ sizes : Sequence [Vector3Like ],
220220 class_ids : Sequence [int ],
221- velocities : Sequence [Vector3 ] | None = None ,
221+ velocities : Sequence [Vector3Like ] | None = None ,
222222 uuids : Sequence [str ] | None = None ,
223223 futures : Sequence [Future ] | None = None ,
224224 ) -> None :
225225 """Render 3D boxes with its elements.
226226
227227 Args:
228228 seconds (float): Timestamp in [sec].
229- centers (Sequence[Vector3 ]): Sequence of 3D positions in the order of (x, y, z).
230- rotations (Sequence[Quaternion ]): Sequence of quaternions .
231- sizes (Sequence[Vector3 ]): Sequence of box sizes in the order of (width, length, height).
229+ centers (Sequence[Vector3Like ]): Sequence of 3D positions in the order of (x, y, z).
230+ rotations (Sequence[RotationLike ]): Sequence of rotations .
231+ sizes (Sequence[Vector3Like ]): Sequence of box sizes in the order of (width, length, height).
232232 class_ids (Sequence[int]): Sequence of class IDs.
233- velocities (Sequence[Vector3 ] | None, optional): Sequence of velocities.
233+ velocities (Sequence[Vector3Like ] | None, optional): Sequence of velocities.
234234 uuids (Sequence[str] | None, optional): Sequence of unique identifiers.
235235 futures (Sequence[Future] | None, optional): Sequence future trajectories.
236236 """
@@ -276,11 +276,11 @@ def _render_box3ds_with_boxes(self, seconds: float, boxes: Sequence[Box3D]) -> N
276276 def _render_box3ds_with_elements (
277277 self ,
278278 seconds : float ,
279- centers : Sequence [Vector3 ],
280- rotations : Sequence [Quaternion ],
281- sizes : Sequence [Vector3 ],
279+ centers : Sequence [Vector3Like ],
280+ rotations : Sequence [RotationLike ],
281+ sizes : Sequence [Vector3Like ],
282282 class_ids : Sequence [int ],
283- velocities : Sequence [Vector3 ] | None = None ,
283+ velocities : Sequence [Vector3Like ] | None = None ,
284284 uuids : Sequence [str ] | None | None = None ,
285285 futures : Sequence [Future ] | None = None ,
286286 ) -> None :
@@ -346,7 +346,7 @@ def render_box2ds(
346346 self ,
347347 seconds : float ,
348348 camera : str ,
349- rois : Sequence [Roi ],
349+ rois : Sequence [RoiLike ],
350350 class_ids : Sequence [int ],
351351 uuids : Sequence [str ] | None = None ,
352352 ) -> None :
@@ -355,7 +355,7 @@ def render_box2ds(
355355 Args:
356356 seconds (float): Timestamp in [sec].
357357 camera (str): Camera name.
358- rois (Sequence[Roi ]): Sequence of ROIs in the order of (xmin, ymin, xmax, ymax).
358+ rois (Sequence[RoiLike ]): Sequence of ROIs in the order of (xmin, ymin, xmax, ymax).
359359 class_ids (Sequence[int]): Sequence of class IDs.
360360 uuids (Sequence[str] | None, optional): Sequence of unique identifiers.
361361 """
@@ -391,7 +391,7 @@ def _render_box2ds_with_elements(
391391 self ,
392392 seconds : float ,
393393 camera : str ,
394- rois : Sequence [Roi ],
394+ rois : Sequence [RoiLike ],
395395 class_ids : Sequence [int ],
396396 uuids : Sequence [str ] | None = None ,
397397 ) -> None :
@@ -496,18 +496,18 @@ def render_ego(self, ego_pose: EgoPose) -> None:
496496 def render_ego (
497497 self ,
498498 seconds : float ,
499- translation : Vector3 ,
500- rotation : Quaternion ,
501- geocoordinate : Vector3 | None = None ,
499+ translation : Vector3Like ,
500+ rotation : RotationLike ,
501+ geocoordinate : Vector3Like | None = None ,
502502 ) -> None :
503503 """Render an ego pose.
504504
505505 Args:
506506 seconds (float): Timestamp in [sec].
507- translation (Vector3 ): 3D position in the map coordinate system
507+ translation (Vector3Like ): 3D position in the map coordinate system
508508 , in the order of (x, y, z) in [m].
509- rotation (Quaternion ): Rotation in the map coordinate system.
510- geocoordinate (Vector3 | None, optional): Coordinates in the WGS 84
509+ rotation (RotationLike ): Rotation in the map coordinate system.
510+ geocoordinate (Vector3Like | None, optional): Coordinates in the WGS 84
511511 reference ellipsoid (latitude, longitude, altitude) in degrees and meters.
512512 """
513513 pass
@@ -530,18 +530,17 @@ def _render_ego_with_schema(self, ego_pose: EgoPose) -> None:
530530 def _render_ego_without_schema (
531531 self ,
532532 seconds : float ,
533- translation : Vector3 ,
534- rotation : Quaternion ,
535- geocoordinate : Vector3 | None = None ,
533+ translation : Vector3Like ,
534+ rotation : RotationLike ,
535+ geocoordinate : Vector3Like | None = None ,
536536 ) -> None :
537537 rr .set_time_seconds (self .timeline , seconds )
538538
539- rotation_xyzw = np .roll (rotation .q , shift = - 1 )
540539 rr .log (
541540 self .ego_entity ,
542541 rr .Transform3D (
543542 translation = translation ,
544- rotation = rr . Quaternion ( xyzw = rotation_xyzw ),
543+ rotation = _to_rerun_quaternion ( rotation ),
545544 relation = rr .TransformRelation .ParentFromChild ,
546545 ),
547546 )
@@ -578,17 +577,17 @@ def render_calibration(
578577 self ,
579578 channel : str ,
580579 modality : str | SensorModality ,
581- translation : Vector3 ,
582- rotation : Quaternion ,
580+ translation : Vector3Like ,
581+ rotation : RotationLike ,
583582 camera_intrinsic : CamIntrinsicLike | None = None ,
584583 ) -> None :
585584 """Render a sensor calibration.
586585
587586 Args:
588587 channel (str): Name of the sensor channel.
589588 modality (str | SensorModality): Sensor modality.
590- translation (Vector3 ): Sensor translation in ego centric coords.
591- rotation (Quaternion ): Sensor rotation in ego centric coords.
589+ translation (Vector3Like ): Sensor translation in ego centric coords.
590+ rotation (RotationLike ): Sensor rotation in ego centric coords.
592591 camera_intrinsic (CamIntrinsicLike | None, optional): Camera intrinsic matrix.
593592 Defaults to None.
594593 """
@@ -618,25 +617,23 @@ def _render_calibration_without_schema(
618617 self ,
619618 channel : str ,
620619 modality : str | SensorModality ,
621- translation : Vector3 ,
622- rotation : Quaternion ,
620+ translation : Vector3Like ,
621+ rotation : RotationLike ,
623622 camera_intrinsic : CamIntrinsicLike | None = None ,
624623 ) -> None :
625624 """Render a sensor calibration.
626625
627626 Args:
628627 channel (str): Name of the sensor channel.
629628 modality (str | SensorModality): Sensor modality.
630- translation (Vector3 ): Sensor translation in ego centric coords.
631- rotation (Quaternion ): Sensor rotation in ego centric coords.
629+ translation (Vector3Like ): Sensor translation in ego centric coords.
630+ rotation (RotationLike ): Sensor rotation in ego centric coords.
632631 camera_intrinsic (CamIntrinsicLike | None, optional): Camera intrinsic matrix.
633632 Defaults to None.
634633 """
635- rotation_xyzw = np .roll (rotation .q , shift = - 1 )
636-
637634 rr .log (
638635 format_entity (self .ego_entity , channel ),
639- rr .Transform3D (translation = translation , rotation = rr . Quaternion ( xyzw = rotation_xyzw )),
636+ rr .Transform3D (translation = translation , rotation = _to_rerun_quaternion ( rotation )),
640637 static = True ,
641638 )
642639
@@ -661,3 +658,8 @@ def render_map(self, filepath: str) -> None:
661658 render_ways (parser , root_entity )
662659
663660 render_geographic_borders (parser , f"{ self .geocoordinate_entity } /vector_map" )
661+
662+
663+ def _to_rerun_quaternion (rotation : RotationLike ) -> rr .Quaternion :
664+ rotation_xyzw = np .roll (to_quaternion (rotation ).q , shift = - 1 )
665+ return rr .Quaternion (xyzw = rotation_xyzw )
0 commit comments