use crate::KeyPointWorldMatch;
use derive_more::{AsMut, AsRef, Constructor, Deref, DerefMut, From, Into};
use nalgebra::{Isometry3};
use sample_consensus::Model;
#[derive(Debug, Clone, Copy, PartialEq, AsMut, AsRef, Constructor, Deref, DerefMut, From, Into)]
pub struct WorldPose(pub Isometry3<f32>);
impl Model<KeyPointWorldMatch> for WorldPose {
fn residual(&self, data: &KeyPointWorldMatch) -> f32 {
let WorldPose(iso) = *self;
let KeyPointWorldMatch(camera, world) = *data;
let new_bearing = (iso * world.coords).normalize();
let bearing_vector = camera.to_homogeneous().normalize();
1.0 - bearing_vector.dot(&new_bearing)
}
}
impl From<CameraPose> for WorldPose {
fn from(camera: CameraPose) -> Self {
Self(camera.inverse())
}
}
#[derive(Debug, Clone, Copy, PartialEq, AsMut, AsRef, Constructor, Deref, DerefMut, From, Into)]
pub struct CameraPose(pub Isometry3<f32>);
impl From<WorldPose> for CameraPose {
fn from(world: WorldPose) -> Self {
Self(world.inverse())
}
}