diff --git a/Cargo.lock b/Cargo.lock index bb55602..2db49f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2070,9 +2070,9 @@ dependencies = [ [[package]] name = "imc-rs" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0598848515ada2541fb4d9588534f8777a43ad4acddc3fc8229bf9b9d7215cc1" +checksum = "b8024a3256f6644df790e90c176bd09c76a099067d5fe07eb6cd045e32ce5c4d" dependencies = [ "byteorder", "csv", diff --git a/src/imc.rs b/src/imc.rs index 77a5c96..c01c2f0 100644 --- a/src/imc.rs +++ b/src/imc.rs @@ -216,7 +216,7 @@ pub enum PixelAnnotationTarget { #[derive(Component)] pub struct GenerateChannelImage { - pub identifier: ChannelIdentifier, + pub identifier: Option, } #[derive(Debug, Clone)] @@ -1401,33 +1401,33 @@ fn image_control_changed( * 255.0) as u8; - if intensity > 0 { - match control.image_update_type { - ImageUpdateType::Red => { - image.data[index * 4] = intensity; - } - ImageUpdateType::Green => { - image.data[index * 4 + 1] = intensity; - } - ImageUpdateType::Blue => { - image.data[index * 4 + 2] = intensity; - } - ImageUpdateType::All => { - image.data[index * 4] = intensity; - image.data[index * 4 + 1] = intensity; - image.data[index * 4 + 2] = intensity; - } + match control.image_update_type { + ImageUpdateType::Red => { + image.data[index * 4] = intensity; + } + ImageUpdateType::Green => { + image.data[index * 4 + 1] = intensity; + } + ImageUpdateType::Blue => { + image.data[index * 4 + 2] = intensity; + } + ImageUpdateType::All => { + image.data[index * 4] = intensity; + image.data[index * 4 + 1] = intensity; + image.data[index * 4 + 2] = intensity; } + } - // let intensity = image.data[index * 4 + 2] - // .max(image.data[index * 4 + 1]) - // .max(image.data[index * 4]); - // let alpha = match intensity { - // 0..=25 => intensity * 10, - // _ => 255, - // }; + // let intensity = image.data[index * 4 + 2] + // .max(image.data[index * 4 + 1]) + // .max(image.data[index * 4]); + // let alpha = match intensity { + // 0..=25 => intensity * 10, + // _ => 255, + // }; - // image.data[index * 4 + 3] = alpha; + // image.data[index * 4 + 3] = alpha; + if intensity > 0 { image.data[index * 4 + 3] = 255; } } @@ -1490,10 +1490,21 @@ fn generate_channel_image( // Remove children from the image control (previously loaded data) commands.entity(entity).despawn_descendants(); + // We are generating the channel image, so we can remove this + commands.entity(entity).remove::(); + if let Ok(imc) = q_imc.get(parent.get()) { let start = Instant::now(); - match imc.channel_image(&generate.identifier) { + let Some(identifier) = &generate.identifier else { + image_control.histogram = vec![]; + image_control.intensity_range = (0.0, f32::INFINITY); + image_control.colour_domain = (0.0, f32::INFINITY); + + continue; + }; + + match imc.channel_image(identifier) { Ok(mut channel_images) => { let duration = start.elapsed(); @@ -1562,8 +1573,5 @@ fn generate_channel_image( } } } - - // We are finished with generating the channel image, so we can remove this - commands.entity(entity).remove::(); } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index b9fbff0..3cf4687 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -594,16 +594,35 @@ fn ui_imc_panel(world: &mut World, ui: &mut Ui) { .spacing([40.0, 4.0]) .show(ui, |ui| { ui.add(Label::new(&control.description)); + + let selected_text = if *selection == 0 { + "None" + } else if channels[*selection - 1].label().trim().is_empty() { + channels[*selection - 1].name() + } else { + channels[*selection - 1].label() + }; + egui::ComboBox::from_id_source(control_entity) - .selected_text(channels[*selection].label().to_string()) + .width(100.0) + .selected_text(selected_text) .show_ui(ui, |ui| { + if ui.selectable_value(selection, 0, "None").clicked() { + generation_events.push(( + control_entity, + GenerateChannelImage { identifier: None }, + )); + } + for (index, channel) in channels.iter().enumerate() { + let name = if channel.label().trim().is_empty() { + channel.name() + } else { + channel.label() + }; + if ui - .selectable_value( - selection, - index, - channel.label(), - ) + .selectable_value(selection, index + 1, name) .clicked() { // TODO: Send out event that we should generate ion image @@ -618,8 +637,10 @@ fn ui_imc_panel(world: &mut World, ui: &mut Ui) { generation_events.push(( control_entity, GenerateChannelImage { - identifier: ChannelIdentifier::Name( - channel.name().into(), + identifier: Some( + ChannelIdentifier::Name( + channel.name().into(), + ), ), }, ));