fix(lab): seal RAV004 spatial replay transport
This commit is contained in:
@@ -75,7 +75,13 @@ def _session_times(batch: Any) -> Any | None:
|
||||
return batch.column("session_time")
|
||||
|
||||
|
||||
def _point_rows(chunks: list[Any], entity: str, component: str, *, nested: bool = False) -> _TimedPoints:
|
||||
def _point_rows(
|
||||
chunks: list[Any],
|
||||
entity: str,
|
||||
component: str,
|
||||
*,
|
||||
nested: bool = False,
|
||||
) -> _TimedPoints:
|
||||
rows: list[tuple[int, np.ndarray]] = []
|
||||
for chunk in chunks:
|
||||
if chunk.entity_path != entity:
|
||||
@@ -436,6 +442,8 @@ def _bounded_local_slam(
|
||||
def _canonical_lab_spatial_frame_from_index(
|
||||
index: _CanonicalSpatialIndex,
|
||||
target_time_ns: int,
|
||||
*,
|
||||
include_local_slam: bool = True,
|
||||
) -> dict[str, object]:
|
||||
point_index = _latest_index(index.points.times_ns, target_time_ns)
|
||||
pose_index = _latest_index(index.poses.times_ns, index.points.times_ns[point_index])
|
||||
@@ -462,12 +470,17 @@ def _canonical_lab_spatial_frame_from_index(
|
||||
ground_origin,
|
||||
basis_map_from_body,
|
||||
)
|
||||
local_slam, local_slam_source_frames, local_slam_source_points = _bounded_local_slam(
|
||||
index.points,
|
||||
index.points.times_ns[point_index],
|
||||
ground_origin,
|
||||
basis_map_from_body,
|
||||
)
|
||||
if include_local_slam:
|
||||
local_slam, local_slam_source_frames, local_slam_source_points = _bounded_local_slam(
|
||||
index.points,
|
||||
index.points.times_ns[point_index],
|
||||
ground_origin,
|
||||
basis_map_from_body,
|
||||
)
|
||||
else:
|
||||
local_slam = np.empty((0, 3), dtype=np.float32)
|
||||
local_slam_source_frames = 0
|
||||
local_slam_source_points = 0
|
||||
return {
|
||||
"schema_version": "missioncore.canonical-recorded-lab-spatial-frame/v3",
|
||||
"target_time_ns": target_time_ns,
|
||||
@@ -531,6 +544,8 @@ def canonical_lab_spatial_timeline_samples(
|
||||
frame_times_ns: tuple[int, ...],
|
||||
start_sequence: int,
|
||||
frame_count: int,
|
||||
*,
|
||||
include_local_slam: bool = True,
|
||||
) -> tuple[dict[str, object] | None, ...]:
|
||||
"""Project only new source increments onto a denser camera timeline.
|
||||
|
||||
@@ -545,7 +560,10 @@ def canonical_lab_spatial_timeline_samples(
|
||||
start_sequence < 0
|
||||
or frame_count < 1
|
||||
or start_sequence >= len(frame_times_ns)
|
||||
or any(current <= previous for previous, current in zip(frame_times_ns, frame_times_ns[1:]))
|
||||
or any(
|
||||
current <= previous
|
||||
for previous, current in zip(frame_times_ns, frame_times_ns[1:], strict=False)
|
||||
)
|
||||
):
|
||||
raise ValueError("Recorded LAB timeline sample request is invalid")
|
||||
stat = recording_path.stat()
|
||||
@@ -566,8 +584,75 @@ def canonical_lab_spatial_timeline_samples(
|
||||
else _latest_index(index.points.times_ns, frame_times_ns[sequence - 1])
|
||||
)
|
||||
samples.append(
|
||||
_canonical_lab_spatial_frame_from_index(index, target_time_ns)
|
||||
_canonical_lab_spatial_frame_from_index(
|
||||
index,
|
||||
target_time_ns,
|
||||
include_local_slam=include_local_slam,
|
||||
)
|
||||
if point_index != previous_point_index
|
||||
else None
|
||||
)
|
||||
return tuple(samples)
|
||||
|
||||
|
||||
@lru_cache(maxsize=2)
|
||||
def _canonical_lab_spatial_playback_points_cached(
|
||||
recording_path_text: str,
|
||||
recording_size: int,
|
||||
recording_mtime_ns: int,
|
||||
generation_sha256: str,
|
||||
frame_times_ns: tuple[int, ...],
|
||||
) -> tuple[np.ndarray, tuple[int, ...]]:
|
||||
del recording_size, recording_mtime_ns
|
||||
recording_path = Path(recording_path_text)
|
||||
stat = recording_path.stat()
|
||||
index = _load_index(
|
||||
str(recording_path),
|
||||
stat.st_size,
|
||||
stat.st_mtime_ns,
|
||||
generation_sha256,
|
||||
)
|
||||
increments: list[np.ndarray] = []
|
||||
offsets = [0]
|
||||
point_count = 0
|
||||
previous_point_index = -1
|
||||
for target_time_ns in frame_times_ns:
|
||||
point_index = _latest_index(index.points.times_ns, target_time_ns)
|
||||
if point_index != previous_point_index:
|
||||
increment = np.ascontiguousarray(index.points.values[point_index], dtype="<f4")
|
||||
increments.append(increment)
|
||||
point_count += int(increment.shape[0])
|
||||
offsets.append(point_count)
|
||||
previous_point_index = point_index
|
||||
points = (
|
||||
np.ascontiguousarray(np.concatenate(increments, axis=0), dtype="<f4")
|
||||
if increments
|
||||
else np.empty((0, 3), dtype="<f4")
|
||||
)
|
||||
points.setflags(write=False)
|
||||
return points, tuple(offsets)
|
||||
|
||||
|
||||
def canonical_lab_spatial_playback_points(
|
||||
recording_path: Path,
|
||||
generation_sha256: str,
|
||||
frame_times_ns: tuple[int, ...],
|
||||
) -> tuple[np.ndarray, tuple[int, ...]]:
|
||||
"""Return one retained map-coordinate point track for a camera timeline."""
|
||||
|
||||
if (
|
||||
not frame_times_ns
|
||||
or any(
|
||||
current <= previous
|
||||
for previous, current in zip(frame_times_ns, frame_times_ns[1:], strict=False)
|
||||
)
|
||||
):
|
||||
raise ValueError("Recorded LAB playback timeline is invalid")
|
||||
stat = recording_path.stat()
|
||||
return _canonical_lab_spatial_playback_points_cached(
|
||||
str(recording_path),
|
||||
stat.st_size,
|
||||
stat.st_mtime_ns,
|
||||
generation_sha256,
|
||||
frame_times_ns,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user