Skip to content

Commit

Permalink
Added ability to change the histogram scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRace committed Nov 17, 2022
1 parent 8c04118 commit 0d01913
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
30 changes: 29 additions & 1 deletion src/imc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,24 @@ pub enum IMCEvent {
channels: Vec<ChannelIdentifier>,
output: ClassifierOutput,
},

SetBackgroundColour {
entity: Entity,
colour: Colour,
},

SetHistogramScale {
entity: Entity,
scale: HistogramScale,
},
}

/// Handle all `IMCEvent`s
fn handle_imc_event(
mut commands: Commands,
mut events: EventReader<IMCEvent>,
q_acquisitions: Query<(Entity, &Acquisition, &GlobalTransform)>,
mut q_imc: Query<&mut IMCDataset>,
q_annotations: Query<(Entity, &Annotation)>,
) {
let thread_pool = AsyncComputeTaskPool::get();
Expand All @@ -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,
Expand Down Expand Up @@ -1151,7 +1172,7 @@ pub struct ChannelImage(imc_rs::ChannelImage);
// }
// }

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HistogramScale {
None,
Log10,
Expand All @@ -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,
Expand Down
65 changes: 63 additions & 2 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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::<ImageControl>(*child);

Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 0d01913

Please sign in to comment.