From 0d0191311a5eedc4a6566de5e0defb68c2de4567 Mon Sep 17 00:00:00 2001 From: Alan Race Date: Thu, 17 Nov 2022 14:56:35 +0100 Subject: [PATCH] Added ability to change the histogram scaling --- src/imc.rs | 30 +++++++++++++++++++++++- src/ui/mod.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/src/imc.rs b/src/imc.rs index 28592e0..d23fc94 100644 --- a/src/imc.rs +++ b/src/imc.rs @@ -84,6 +84,16 @@ pub enum IMCEvent { channels: Vec, output: ClassifierOutput, }, + + SetBackgroundColour { + entity: Entity, + colour: Colour, + }, + + SetHistogramScale { + entity: Entity, + scale: HistogramScale, + }, } /// Handle all `IMCEvent`s @@ -91,6 +101,7 @@ fn handle_imc_event( mut commands: Commands, mut events: EventReader, q_acquisitions: Query<(Entity, &Acquisition, &GlobalTransform)>, + mut q_imc: Query<&mut IMCDataset>, q_annotations: Query<(Entity, &Annotation)>, ) { let thread_pool = AsyncComputeTaskPool::get(); @@ -106,6 +117,16 @@ fn handle_imc_event( //load_imc(mcd, &mut commands, &mut textures, &thread_pool); } + IMCEvent::SetBackgroundColour { entity, colour } => { + if let Ok(mut imc) = q_imc.get_mut(*entity) { + imc.background_colour = colour.clone(); + } + } + IMCEvent::SetHistogramScale { entity, scale } => { + if let Ok(mut imc) = q_imc.get_mut(*entity) { + imc.histogram_scale = *scale; + } + } IMCEvent::GeneratePixelAnnotation { labels, target, @@ -1151,7 +1172,7 @@ pub struct ChannelImage(imc_rs::ChannelImage); // } // } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum HistogramScale { None, Log10, @@ -1178,6 +1199,13 @@ impl IMCDataset { .unwrap_or("Unknown name") } + pub fn background_colour(&self) -> &Colour { + &self.background_colour + } + pub fn histogram_scale(&self) -> &HistogramScale { + &self.histogram_scale + } + pub fn acquisition( &self, identifier: AcquisitionIdentifier, diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 2c22f33..f969fa9 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -20,7 +20,7 @@ use crate::{ }, data::{CellSegmentation, DataEvent}, image_plugin::{ImageControl, ImageEvent, Opacity}, - imc::{Acquisition, GenerateChannelImage, IMCDataset, LoadIMC}, + imc::{Acquisition, GenerateChannelImage, HistogramScale, IMCDataset, IMCEvent, LoadIMC}, Message, }; @@ -519,6 +519,57 @@ fn ui_imc_panel(world: &mut World, ui: &mut Ui) { .body(|ui| { // IMCGrid::new().ui(ui, imc, children, &mut ui_events); + // General IMC contols + egui::Grid::new(format!("{}_{:?}", "imc_controls", entity)) + .num_columns(2) + .spacing([40.0, 4.0]) + .show(ui, |ui| { + ui.label("Background colour"); + let mut colour = imc.background_colour().egui(); + + if ui.color_edit_button_srgba(&mut colour).changed() { + ui_events.push(UiEvent::Data(DataEvent::IMCEvent( + IMCEvent::SetBackgroundColour { + entity, + colour: colour.into(), + }, + ))); + } + + ui.end_row(); + + let mut histogram_scale = *imc.histogram_scale(); + ui.label("Histogram scaling"); + + egui::ComboBox::from_id_source(format!( + "{}_{:?}", + "histogram_scale", entity + )) + .selected_text(format!("{:?}", histogram_scale)) + .show_ui(ui, |ui| { + ui.selectable_value( + &mut histogram_scale, + HistogramScale::None, + "None", + ); + ui.selectable_value( + &mut histogram_scale, + HistogramScale::Log10, + "log10", + ); + ui.selectable_value(&mut histogram_scale, HistogramScale::Ln, "ln"); + }); + + if histogram_scale != *imc.histogram_scale() { + ui_events.push(UiEvent::Data(DataEvent::IMCEvent( + IMCEvent::SetHistogramScale { + entity, + scale: histogram_scale, + }, + ))); + } + }); + for child in children.iter() { let control = world.get::(*child); @@ -585,7 +636,17 @@ fn ui_imc_panel(world: &mut World, ui: &mut Ui) { Bar::new( (x as f32 * bin_size + control.intensity_range.0) as f64, - (control.histogram[x] as f64 + 1.0), //.log10() + match imc.histogram_scale() { + HistogramScale::None => { + control.histogram[x] as f64 + } + HistogramScale::Log10 => { + (control.histogram[x] as f64 + 1.0).log10() + } + HistogramScale::Ln => { + (control.histogram[x] as f64 + 1.0).ln() + } + }, ) .width(bin_size as f64) })