Skip to content

Commit 002451b

Browse files
committed
Ensure channels have a description
1 parent 40a7c71 commit 002451b

File tree

3 files changed

+68
-39
lines changed

3 files changed

+68
-39
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/imc.rs

+37-29
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub enum PixelAnnotationTarget {
216216

217217
#[derive(Component)]
218218
pub struct GenerateChannelImage {
219-
pub identifier: ChannelIdentifier,
219+
pub identifier: Option<ChannelIdentifier>,
220220
}
221221

222222
#[derive(Debug, Clone)]
@@ -1401,33 +1401,33 @@ fn image_control_changed(
14011401
* 255.0)
14021402
as u8;
14031403

1404-
if intensity > 0 {
1405-
match control.image_update_type {
1406-
ImageUpdateType::Red => {
1407-
image.data[index * 4] = intensity;
1408-
}
1409-
ImageUpdateType::Green => {
1410-
image.data[index * 4 + 1] = intensity;
1411-
}
1412-
ImageUpdateType::Blue => {
1413-
image.data[index * 4 + 2] = intensity;
1414-
}
1415-
ImageUpdateType::All => {
1416-
image.data[index * 4] = intensity;
1417-
image.data[index * 4 + 1] = intensity;
1418-
image.data[index * 4 + 2] = intensity;
1419-
}
1404+
match control.image_update_type {
1405+
ImageUpdateType::Red => {
1406+
image.data[index * 4] = intensity;
1407+
}
1408+
ImageUpdateType::Green => {
1409+
image.data[index * 4 + 1] = intensity;
1410+
}
1411+
ImageUpdateType::Blue => {
1412+
image.data[index * 4 + 2] = intensity;
1413+
}
1414+
ImageUpdateType::All => {
1415+
image.data[index * 4] = intensity;
1416+
image.data[index * 4 + 1] = intensity;
1417+
image.data[index * 4 + 2] = intensity;
14201418
}
1419+
}
14211420

1422-
// let intensity = image.data[index * 4 + 2]
1423-
// .max(image.data[index * 4 + 1])
1424-
// .max(image.data[index * 4]);
1425-
// let alpha = match intensity {
1426-
// 0..=25 => intensity * 10,
1427-
// _ => 255,
1428-
// };
1421+
// let intensity = image.data[index * 4 + 2]
1422+
// .max(image.data[index * 4 + 1])
1423+
// .max(image.data[index * 4]);
1424+
// let alpha = match intensity {
1425+
// 0..=25 => intensity * 10,
1426+
// _ => 255,
1427+
// };
14291428

1430-
// image.data[index * 4 + 3] = alpha;
1429+
// image.data[index * 4 + 3] = alpha;
1430+
if intensity > 0 {
14311431
image.data[index * 4 + 3] = 255;
14321432
}
14331433
}
@@ -1490,10 +1490,21 @@ fn generate_channel_image(
14901490
// Remove children from the image control (previously loaded data)
14911491
commands.entity(entity).despawn_descendants();
14921492

1493+
// We are generating the channel image, so we can remove this
1494+
commands.entity(entity).remove::<GenerateChannelImage>();
1495+
14931496
if let Ok(imc) = q_imc.get(parent.get()) {
14941497
let start = Instant::now();
14951498

1496-
match imc.channel_image(&generate.identifier) {
1499+
let Some(identifier) = &generate.identifier else {
1500+
image_control.histogram = vec![];
1501+
image_control.intensity_range = (0.0, f32::INFINITY);
1502+
image_control.colour_domain = (0.0, f32::INFINITY);
1503+
1504+
continue;
1505+
};
1506+
1507+
match imc.channel_image(identifier) {
14971508
Ok(mut channel_images) => {
14981509
let duration = start.elapsed();
14991510

@@ -1562,8 +1573,5 @@ fn generate_channel_image(
15621573
}
15631574
}
15641575
}
1565-
1566-
// We are finished with generating the channel image, so we can remove this
1567-
commands.entity(entity).remove::<GenerateChannelImage>();
15681576
}
15691577
}

src/ui/mod.rs

+29-8
Original file line numberDiff line numberDiff line change
@@ -594,16 +594,35 @@ fn ui_imc_panel(world: &mut World, ui: &mut Ui) {
594594
.spacing([40.0, 4.0])
595595
.show(ui, |ui| {
596596
ui.add(Label::new(&control.description));
597+
598+
let selected_text = if *selection == 0 {
599+
"None"
600+
} else if channels[*selection - 1].label().trim().is_empty() {
601+
channels[*selection - 1].name()
602+
} else {
603+
channels[*selection - 1].label()
604+
};
605+
597606
egui::ComboBox::from_id_source(control_entity)
598-
.selected_text(channels[*selection].label().to_string())
607+
.width(100.0)
608+
.selected_text(selected_text)
599609
.show_ui(ui, |ui| {
610+
if ui.selectable_value(selection, 0, "None").clicked() {
611+
generation_events.push((
612+
control_entity,
613+
GenerateChannelImage { identifier: None },
614+
));
615+
}
616+
600617
for (index, channel) in channels.iter().enumerate() {
618+
let name = if channel.label().trim().is_empty() {
619+
channel.name()
620+
} else {
621+
channel.label()
622+
};
623+
601624
if ui
602-
.selectable_value(
603-
selection,
604-
index,
605-
channel.label(),
606-
)
625+
.selectable_value(selection, index + 1, name)
607626
.clicked()
608627
{
609628
// TODO: Send out event that we should generate ion image
@@ -618,8 +637,10 @@ fn ui_imc_panel(world: &mut World, ui: &mut Ui) {
618637
generation_events.push((
619638
control_entity,
620639
GenerateChannelImage {
621-
identifier: ChannelIdentifier::Name(
622-
channel.name().into(),
640+
identifier: Some(
641+
ChannelIdentifier::Name(
642+
channel.name().into(),
643+
),
623644
),
624645
},
625646
));

0 commit comments

Comments
 (0)