add homography transformer

This commit is contained in:
Marc Planard 2023-07-01 16:01:11 +02:00
parent ddf44460ae
commit ee9e3f1da0
3 changed files with 43 additions and 3 deletions

View file

@ -0,0 +1,36 @@
use crate::transformer::Transformers;
use crate::point::Point;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize};
use log::info;
use nalgebra::Matrix3;
/// Homography
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
pub struct Homography {}
impl Transformers for Homography {
fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec<Point> {
let m = ws.edh.matrix;
point_list.iter()
.map(| point | {
// THIS IS CERTAINLY ALL WRONG! NEEDS DEBUGING!!!
let p = Matrix3::new(point.x, point.y, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, 1.0);
let dot = p.tr_dot(&m);
let new_p = Point { x: point.x / dot, y: point.y / dot,
..*point
};
info!("{:?} => {:?}", point, new_p);
new_p
})
.collect()
}
}