From e291ab480abdecc5246c5adbbbdcb3ebbdb06006 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Wed, 2 Jul 2025 12:32:33 +0200 Subject: [PATCH] Clean and add world grid for mapping (WIP, fix glitch on pillow distortion) --- src/bin/render_lines_gui.rs | 51 +-------------------------------- src/trap/laser.rs | 56 ++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/bin/render_lines_gui.rs b/src/bin/render_lines_gui.rs index a06f703..0fafa28 100644 --- a/src/bin/render_lines_gui.rs +++ b/src/bin/render_lines_gui.rs @@ -177,16 +177,6 @@ fn zmq_receive(model: &mut GuiModel) { } -// #[derive(Serialize, Deserialize)] -// #[serde(remote = "DacId")] -// pub enum DacIdSerializable { -// EtherDream { mac_address: [u8; 6] }, -// Helios { id: u32 }, -// } - -// DEPRECATED - - type DacConfigMap = HashMap; @@ -641,12 +631,7 @@ fn update(_app: &App, model: &mut GuiModel, update: Update) { let source = &mut stream_config.config.source; - // for source_option in STREAM_SOURCES { - // if ui.radio_value(source, source_option.clone(), format!("{:?}", &source_option)).changed() { - // println!("Clicked!") - // }; - - // } + egui::ComboBox::from_label("Source") .selected_text(format!("{source:?}")) .show_ui(ui, |ui| { @@ -659,43 +644,9 @@ fn update(_app: &App, model: &mut GuiModel, update: Update) { }; } - // ui.selectable_value(source, StreamSource::CurrentLines, "Zmq Stream"); - // ui.selectable_value(source, StreamSource::Rectangle, "Rectangle"); - // ui.selectable_value(source, StreamSource::Grid, "Grid"); }); - // ui.radio_value(source, StreamSource::Rectangle, "Rectangle"); - // ui.radio_value(source, StreamSource::Grid, "Grid"); - - // if ui.add(DropDownBox::from_iter( - // vec!(StreamSource::CurrentLines, StreamSource::Rectangle, StreamSource::Grid(5)), - // "test_dropbox", - // &mut stream_config.config.source, - // |ui, text| ui.selectable_label(false, text) - // )).changed() { - // println!("Changed source! {:?}", stream_config.config.source); - // let source = stream_config.config.source; - // stream_config.stream.send(move |laser_model: &mut LaserModel| { - // laser_model.config.source = source; - // }).unwrap(); - // } - // if ui.add( - // egui::ComboBox::from_label("Source") - // .selected_text(format!("{source:?}")) - // // .show_ui(ui, |ui| { - // // ui.selectable_value(source, StreamSource::CurrentLines, "Zmq Stream"); - // // ui.selectable_value(source, StreamSource::Rectangle, "Rectangle"); - // // ui.selectable_value(source, StreamSource::Grid(5), "Grid"); - // // }) - // ).changed() - // { - // let source = stream_config.config.source; - // stream_config.stream.send(move |laser_model: &mut LaserModel| { - // laser_model.config.source = source; - // }).unwrap(); - // } - if ui .add(egui::Slider::new(&mut stream_config.config.filters.dim.intensity, 0.0..=1.).text("Dimming")) .changed() diff --git a/src/trap/laser.rs b/src/trap/laser.rs index 33197d5..5af2263 100644 --- a/src/trap/laser.rs +++ b/src/trap/laser.rs @@ -97,12 +97,20 @@ pub enum StreamSource { CurrentLines, Rectangle, Grid, // lines - Circle, // segments - Spiral, + WorldGrid, // grid in world space + // Circle, // segments + // Spiral, } // usefull to create pull downs with an iterator -pub const STREAM_SOURCES: [StreamSource; 5] = [StreamSource::CurrentLines, StreamSource::Rectangle, StreamSource::Grid, StreamSource::Circle, StreamSource::Spiral]; +pub const STREAM_SOURCES: [StreamSource; 4] = [ + StreamSource::CurrentLines, + StreamSource::Rectangle, + StreamSource::Grid, + StreamSource::WorldGrid, + // StreamSource::Circle, + // StreamSource::Spiral + ]; const LASER_H: Mat3 = python_cv_h_into_mat3(TMP_PYTHON_LASER_H); @@ -193,7 +201,47 @@ impl StreamSource{ LaserPoints { points, space: CoordinateSpace::Laser } }, - _ => LaserPoints::default(), + Self::WorldGrid => { + // a grid in world space. Usefull for calibrating + let mut points = Vec::new(); + for i in (-20..=50).step_by(5) { + let color = if i % 10 == 0 { [1.,0.,0.]} else {[1.,1.,1.]}; + points.push(laser::Point{ + position:[i as f32, 0.], + color: [0., 0., 0.], + weight: 0, + }); + for j in (-20..=50).step_by(2) { + points.push(laser::Point{ + position:[i as f32, j as f32], + color, + weight: 0, + }); + } + points.push(points[points.len()-1].blanked()); + } + + for i in (-20..=50).step_by(5) { + let color = if i % 10 == 0 { [0.,0.,1.]} else {[1.,1.,1.]}; + points.push(laser::Point{ + position:[0., i as f32], + color: [0., 0., 0.], + weight: 0, + }); + for j in (-20..=50).step_by(2) { + points.push(laser::Point{ + position:[j as f32, i as f32], + color, + weight: 0, + }); + } + points.push(points[points.len()-1].blanked()); + } + + + LaserPoints { points, space: CoordinateSpace::World } + }, + _ => LaserPoints::default(), // empty set } } } \ No newline at end of file