ncore.geometry Package#
Package exposing NCore’s geometry utilities: pose interpolation and motion compensation, rigid transformations of points and bounding boxes, and time intervals
- class ncore.geometry.HalfClosedInterval(start: int, stop: int)#
Bases:
objectRepresents a half closed interval [start, stop) of integers
- cover_range(
- sorted_samples: ndarray,
Given a set of sorted samples (not validated), return the corresponding range for samples that are within the interval
- static from_start_end( ) HalfClosedInterval#
Creates a half-closed interval from start and end (inclusive)
- intersection(
- other: HalfClosedInterval,
Computes the intersection of two half-closed interval
- overlaps(
- other: HalfClosedInterval,
Checks if the interval has a non-zero overlap with an other closed interval
- class ncore.geometry.MotionCompensator(
- pose_graph: PoseGraphInterpolator,
- parameters: Parameters | None = None,
Bases:
objectPerforms motion compensation / decompensation of points measured relative to time-dependent frames
- class MotionCompensationResult(
- xyz_s_reftime: 'np.ndarray',
- xyz_e_reftime: 'np.ndarray',
- reference_frame_id: 'str',
- reference_timestamp_us: 'int',
- anchor_frame_id: 'str',
Bases:
object
- class Parameters( )#
Bases:
objectParameters of the motion compensation
- class Method(value)#
Bases:
IntEnumHow the per-point transformations are evaluated
- EXACT = 1#
interpolates the poses at each distinct point timestamp
- INTERPOLATED = 2#
interpolates the poses at the timestamps of a grid spanning the points’ timestamps, and linearly interpolates the transformations of the points in between (faster, see
interpolation_tolerance)
- interpolation_tolerance: float = 1e-05#
Maximum deviation of the points of the
INTERPOLATEDmethod from the exact transformations, in the units of the pose graph’s translations (e.g. meters), in addition to the float32 rounding of both methods. The grid is refined from an estimate of the deviation (see_InterpolationGrid.refined), which holds for motions that are smooth between the pose timestamps (as interpolated by the pose graph). Smaller tolerances refine the grid at practically no cost (the per-point work doesn’t depend on the grid size).
- static from_sensor_rig(
- sensor_id: str,
- T_sensor_rig: ndarray,
- T_rig_worlds: ndarray,
- T_rig_worlds_timestamps_us: ndarray,
- anchor_frame_id: str = 'world',
- rig_frame_id: str = 'rig',
- parameters: Parameters | None = None,
Constructs a motion-compensator from a sensor-rig transformations for a specific sensor only
- Parameters:
sensor_id (str) – id of the sensor node
T_sensor_rig (np.ndarray) – static sensor -> rig transform, [4, 4]
T_rig_worlds (np.ndarray) – time-dependent rig -> anchor transforms, [N, 4, 4]
T_rig_worlds_timestamps_us (np.ndarray) – timestamps for the rig -> anchor transforms, [N]
anchor_frame_id (str) – name of the common anchor frame node (defaults to “world”). Pass the same value as
anchor_frame_idto the (de)compensation methods.rig_frame_id (str) – name of the rig frame node (defaults to “rig”).
parameters (Optional[MotionCompensator.Parameters]) – parameters of the motion compensation
- motion_compensate_points(
- sensor_id: str,
- xyz_pointtime: np.ndarray,
- timestamp_us: np.ndarray,
- frame_start_timestamp_us: int,
- frame_end_timestamp_us: int,
- reference_timestamp_us: int | None = None,
- anchor_frame_id: str = 'world',
Perform motion compensation of points in time-dependent sensor frame at measurement time to a common reference sensor frame
By default the reference is the end of the frame (
frame_end_timestamp_us). Passreference_timestamp_usto compensate to a different reference frame (e.g. the start of the frame). The chosen reference must be inverted bymotion_decompensate_points()using the samereference_timestamp_usandanchor_frame_id.- Parameters:
sensor_id (str) – sensor the points are relative to. This is also the reference frame the compensated points are expressed in (
reference_frame_id).xyz_pointtime (np.ndarray) – points in time-dependent sensor frame (~before motion compensation), [N,3]
timestamp_us (np.ndarray) – timestamps of points, [N]
frame_start_timestamp_us (int) – frame start timestamp
frame_end_timestamp_us (int) – frame end timestamp
reference_timestamp_us (Optional[int]) – timestamp of the reference sensor frame to compensate to; defaults to
frame_end_timestamp_us. Must lie within[frame_start_timestamp_us, frame_end_timestamp_us].anchor_frame_id (str) – common anchor frame used to compose the transforms (defaults to “world”). Use a non-default anchor when the pose graph is anchored at a frame other than “world”.
- Returns:
result of the motion-compensation
- Return type:
- motion_decompensate_points(
- sensor_id: str,
- xyz_reftime: ndarray,
- timestamp_us: ndarray,
- frame_start_timestamp_us: int,
- frame_end_timestamp_us: int,
- reference_timestamp_us: int | None = None,
- anchor_frame_id: str = 'world',
Decompensate motion of motion-compensated points to bring points into time-dependent sensor-frame
The input points are assumed to be expressed in the sensor frame at a single reference timestamp (the timestamp the data was motion-compensated to). By default this reference is the end of the frame (
frame_end_timestamp_us), matchingmotion_compensate_points(). Datasets that compensate to a different reference (e.g. the start of the frame) can passreference_timestamp_usexplicitly.anchor_frame_idmust match the value passed tomotion_compensate_points().- Parameters:
sensor_id (str) – sensor the points are relative to
xyz_reftime (np.array) – motion-compensated points relative to the reference-time sensor frame to be decompensated, [N,3]
timestamp_us (np.ndarray) – timestamps of points, [N]
frame_start_timestamp_us (int) – frame start timestamp
frame_end_timestamp_us (int) – frame end timestamp
reference_timestamp_us (Optional[int]) – timestamp of the sensor frame the points are expressed in; defaults to
frame_end_timestamp_us. Must lie within[frame_start_timestamp_us, frame_end_timestamp_us].anchor_frame_id (str) – common anchor frame used to compose the transforms (defaults to “world”). Must match the anchor used for compensation.
- Returns:
points in time-dependent sensor frame after motion-decompensation [n,3]
- Return type:
xyz_pointtime(np.array)
- property parameters: Parameters#
The parameters of the motion compensation
- class ncore.geometry.PoseGraphInterpolator(edges: List[Edge])#
Bases:
objectInterpolates rigid poses between named nodes in a pose graph. Edges in the pose graph can be static or dynamic (time-dependent)
- class Edge(
- source_node: str,
- target_node: str,
- T_source_target: npt.NDArray[np.floating],
- timestamps_us: npt.NDArray[np.uint64] | None,
Bases:
objectRepresents an edge in the pose graph, either static or dynamic (time-dependent).
The computational data-type is given by the input arrays.
- get_T( ) npt.NDArray[np.floating]#
Returns the transformation from source to target node at the given timestamps
- Parameters:
- Returns:
- evaluated poses from source to target node at the given timestamps [batch-shape,4,4]
in the data-type of the edge
- Return type:
np.ndarray
- interpolator: PoseInterpolator | None#
- evaluate_poses( ) npt.NDArray[np.floating]#
Evaluates relative pose from source to target node frames at the given timestamps. Performs graph traversal and pose evaluation / composition (interpolation for time-dependent edges) as needed.
- Parameters:
- Returns:
evaluated poses from source to target node at the given timestamps [batch-shape,4,4]
- Return type:
np.ndarray
- get_edge( ) Edge | None#
Returns the edge between the given source and target node, or None if no such edge exists
- get_path_timestamps_us( ) List[npt.NDArray[np.uint64]]#
Returns the pose timestamps of the time-dependent edges on the path between two nodes (the timestamps at which the interpolated relative pose of the nodes may change its motion)
- class ncore.geometry.PoseInterpolator(poses, timestamps)#
Bases:
objectInterpolates the poses to the desired time stamps. The translation component is interpolated linearly, while spherical linear interpolation (SLERP) is used for the rotations. https://en.wikipedia.org/wiki/Slerp
- extrapolate_to_timestamps(
- ts_target: np.ndarray,
- max_extrapolation_time_us: int = 1000000,
- dtype: npt.DTypeLike = <class 'numpy.float32'>,
Extrapolates/interpolates poses to target timestamps, allowing extrapolation beyond the original range.
This requires the original timestamps to be in absolute microseconds (us / int type).
For timestamps within the original range, standard interpolation is used. For timestamps outside the range, linear extrapolation is used for translation and SLERP-based extrapolation (constant angular velocity) is used for rotation.
- Parameters:
ts_target – Target timestamps for which poses will be computed [m; us]
max_extrapolation_time_us – Maximum allowed extrapolation time in microseconds (default: 1 second). Raises ValueError if any timestamp exceeds this limit.
dtype – Data type for the output poses and the extrapolation computations
- Returns:
Extrapolated/interpolated poses in SE3 representation [m, 4, 4]
- Return type:
np.ndarray
- Raises:
ValueError – If any timestamp requires extrapolation beyond max_extrapolation_time_us
- in_range(ts) bool#
Returns true if all provided timestamps (scalar or array-like) are within the interpolation range
- interpolate_to_timestamps(
- ts_target,
- dtype: npt.DTypeLike = <class 'numpy.float32'>,
Interpolates poses to target timestamps. :param ts_target: Target timestamps for which poses will be computed in the same time-domain as the original timestamps [m] :param dtype: Data type for the output poses
- Returns:
Interpolated poses in SE3 representation [m, 4, 4]
- Return type:
np.ndarray
- Raises:
ValueError – If any timestamp is outside the interpolation range
- ncore.geometry.bbox_pose(bbox: ndarray) ndarray#
Converts an array-encoded bounding-box into a corresponding pose
- ncore.geometry.is_within_3d_bboxes( ) ndarray#
Checks whether points of a point cloud are in an array of 3d boxes
- Parameters:
pc – [N, 3] tensor. Inner dims are: [x, y, z].
bboxes – [M, 9] tensor. Inner dims are: [center_x, center_y, center_z, length, width, height, roll, pitch, yaw]. roll/pitch/yaw are in radians.
- Returns:
point_in_bboxes; [N,M] boolean array.
- ncore.geometry.se3_inverse(T: ndarray, unbatch: bool = True) ndarray#
Computes the inverse of multiple rigid transformations
- Parameters:
Ts (np.ndarray) – se3 transformation matrices to invert [N, 4, 4] or [4, 4]
unbatch (bool) – if the single matrix should be unbatched (first dimension removed) or not
- Returns:
Inverse transformations [N, 4, 4] or [4, 4]
- Return type:
(np array)
- ncore.geometry.so3_trans_2_se3(so3, trans) ndarray#
Create a 4x4 rigid transformation matrix given so3 rotation and translation.
- Parameters:
so3 – rotation matrix [n,3,3]
trans – x, y, z translation [n, 3]
- Returns:
the constructed transformation matrix [n,4,4]
- Return type:
np.ndarray
- ncore.geometry.time_bounds( ) tuple[int, int]#
Determine start and end timestamps given optional seek and duration times
- Parameters:
timestamps_us – list of all available timestamps (in microseconds)
seek_sec – Optional: if non-None, the time (in seconds) to skip starting from the first timestamp
duration_sec – Optional: if non-None, the total time (in seconds) between the start and end time bounds
- Returns:
first valid timestamp in restricted bounds (in microseconds) end_timestamp_us: last valid timestamp in restricted bounds (in microseconds)
- Return type:
start_timestamp_us
- ncore.geometry.transform_bbox( ) ndarray#
Applies a rigid-transformation to a bounding box :param bbox: bounding-box in source-frame parameterized by [x, y, z, length, width, height, eulerX, eulerY, eulerZ] :type bbox: np.ndarray :param T: se3 source->target transformation matrix to apply [4,4] :type T: np.array
- Out:
(np array): transformed bounding-box [num_pts, 3] or [bs, num_pts, 3]
- ncore.geometry.transform_point_cloud(pc: ndarray, T) ndarray#
- ncore.geometry.transform_point_cloud(pc: torch.Tensor, T) torch.Tensor
- Transform the point cloud with the provided transformation matrix,
support torch.Tensor and np.ndarry.
The returned type matches the type of
pc: a numpy array in, a numpy array out; a torch tensor in, a torch tensor out.- Parameters:
pc (np.array) – point cloud coordinates (x,y,z) [num_pts, 3] or [bs, num_pts, 3]
T (np.array) – se3 transformation matrix [4, 4] or [bs, 4, 4]
- Out:
(np array): transformed point cloud coordinated [num_pts, 3] or [bs, num_pts, 3]