use crate::mapping::map::{ImuFactor, Keyframe, Map, MapPoint};
use kornia_3d::pose::Pose3d;
use kornia_algebra::Vec3F64;
use kornia_sensors::imu::{ImuBias, PreintegratedImu};
#[derive(Debug, Clone)]
pub struct BaSnapshot {
pub(super) keyframes: Vec<Keyframe>,
pub(super) map_points: Vec<MapPoint>,
pub(super) imu_factors: Vec<ImuFactor>,
pub(super) world_epoch: u64,
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct KeyframeBaState {
pub pose_world_to_cam: Pose3d,
pub velocity_world: Vec3F64,
pub imu_bias: ImuBias,
}
#[derive(Debug)]
pub struct BaUpdate {
pub(crate) keyframes: Vec<KeyframeBaState>,
pub(crate) map_points: Vec<Vec3F64>,
pub(crate) imu_preintegrations: Vec<PreintegratedImu>,
pub(crate) snapshot: BaSnapshot,
}
impl BaSnapshot {
pub fn keyframes(&self) -> &[Keyframe] {
&self.keyframes
}
pub fn map_points(&self) -> &[MapPoint] {
&self.map_points
}
pub fn imu_factors(&self) -> &[ImuFactor] {
&self.imu_factors
}
pub(crate) fn into_update(self) -> BaUpdate {
BaUpdate {
keyframes: self
.keyframes
.iter()
.map(|kf| KeyframeBaState {
pose_world_to_cam: kf.frame.pose_world_to_cam,
velocity_world: kf.velocity_world,
imu_bias: kf.imu_bias,
})
.collect(),
map_points: self.map_points.iter().map(|mp| mp.position).collect(),
imu_preintegrations: self
.imu_factors
.iter()
.map(|factor| factor.preintegrated.clone())
.collect(),
snapshot: self,
}
}
}
impl Map {
pub fn ba_snapshot(&self) -> BaSnapshot {
BaSnapshot {
keyframes: self.keyframes.clone(),
map_points: self.map_points.clone(),
imu_factors: self.imu_factors.clone(),
world_epoch: self.world_epoch,
}
}
}