Skip to content

Commit

Permalink
Ensure channels have a description
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRace committed Nov 17, 2022
1 parent 40a7c71 commit 002451b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 37 additions & 29 deletions src/imc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub enum PixelAnnotationTarget {

#[derive(Component)]
pub struct GenerateChannelImage {
pub identifier: ChannelIdentifier,
pub identifier: Option<ChannelIdentifier>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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::<GenerateChannelImage>();

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();

Expand Down Expand Up @@ -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::<GenerateChannelImage>();
}
}
37 changes: 29 additions & 8 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
),
),
},
));
Expand Down

0 comments on commit 002451b

Please sign in to comment.