-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mlhoutel/develop
- Loading branch information
Showing
19 changed files
with
272 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::collections::HashMap; | ||
|
||
const COLOR_MIN: u8 = 0; | ||
const COLOR_MAX: u8 = 255; | ||
const SCALE: f64 = 0.02; | ||
|
||
pub fn show(ui: &mut egui::Ui, spectrum: &[HashMap<u8, usize>]) { | ||
egui::plot::Plot::new("Image spectrum") | ||
.legend(egui::plot::Legend::default()) | ||
.data_aspect(1.0) | ||
.show(ui, |plot_ui| { | ||
for (index, c_map) in spectrum.iter().enumerate() { | ||
let (color, name) = match index { | ||
0 => (egui::Color32::RED, "Red spectrum"), | ||
1 => (egui::Color32::GREEN, "Green spectrum"), | ||
_ => (egui::Color32::BLUE, "Blue spectrum"), | ||
}; | ||
|
||
let chart = egui::plot::BarChart::new( | ||
(COLOR_MIN..COLOR_MAX) | ||
.map(|intensity| { | ||
if let Some(&count) = c_map.get(&intensity) { | ||
(intensity, count as f64) | ||
} else { | ||
(intensity, 0.0_f64) | ||
} | ||
}) | ||
// The 10 factor here is purely for a nice 1:1 aspect ratio | ||
.map(|(x, f)| egui::plot::Bar::new(x as f64, f * SCALE).width(1.0)) | ||
.collect(), | ||
) | ||
.color(color) | ||
.name(name); | ||
|
||
plot_ui.bar_chart(chart) | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod image_frame; | ||
pub mod image_spectrum; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod display; | ||
pub mod graph; | ||
pub mod input; | ||
pub mod output; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod central_pannel; | ||
pub mod output_pannel; | ||
pub mod side_pannel; | ||
pub mod top_bar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use egui_extras::RetainedImage; | ||
use std::collections::HashMap; | ||
|
||
use crate::app::components::display; | ||
use crate::app::components::graph::node::{self, *}; | ||
use crate::app::math::image::slice_to_image; | ||
use crate::app::state; | ||
|
||
pub fn show(state: &mut state::AppState, ui: &mut egui::Ui) { | ||
egui::ScrollArea::vertical().show(ui, |ui| { | ||
if let Some(selected_id) = state.selected_node.node_id { | ||
let selected_node = state | ||
.graph | ||
.graph | ||
.nodes | ||
.iter() | ||
.find(|&(node_id, _node)| node_id == selected_id); | ||
|
||
// Check if the node exist in the graph | ||
if let Some((_, node)) = selected_node { | ||
let outputs = node.output_ids(); | ||
|
||
// Try to find a node output that correspond to an image | ||
let find_image = outputs | ||
.into_iter() | ||
.find(|id| state.graph.user_state.outputs_images.contains_key(id)); | ||
|
||
// If the image was found, we update the value | ||
if let Some(output_id) = find_image { | ||
show_selected(state, ui, output_id); | ||
} | ||
} | ||
} else { | ||
show_not_selected(ui); | ||
} | ||
}); | ||
} | ||
|
||
fn show_not_selected(ui: &mut egui::Ui) { | ||
ui.allocate_ui_with_layout( | ||
ui.available_size(), | ||
egui::Layout::centered_and_justified(egui::Direction::TopDown), | ||
|ui| ui.label("Select a node to preview it"), | ||
); | ||
} | ||
|
||
fn show_selected(state: &mut state::AppState, ui: &mut egui::Ui, output_id: OutputId) { | ||
// Extract the color image from the results | ||
if state.selected_node.color_image.is_none() { | ||
state.selected_node.color_image = match state.graph.user_state.outputs_cache.get(&output_id) | ||
{ | ||
Some(node::ValueType::Image { value }) => Some(value.clone()), | ||
Some(node::ValueType::Slice { value }) => Some(slice_to_image(value)), | ||
_ => None, | ||
}; | ||
|
||
// If the color image was just initialized | ||
if let Some(color_image) = &state.selected_node.color_image { | ||
// We compute and store the image spectrum | ||
for px in &color_image.pixels { | ||
for i in 0..3 { | ||
let intensity = px[i]; | ||
|
||
if intensity == 0 { | ||
continue; // dont take into account the intensity 0 | ||
} | ||
|
||
if let Some(&count) = &mut state.selected_node.spectrum[i].get(&intensity) { | ||
state.selected_node.spectrum[i].insert(intensity, count + 1); | ||
} else { | ||
state.selected_node.spectrum[i].insert(intensity, 1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Compute a new retained image | ||
if state.selected_node.retained_image.is_none() { | ||
if let Some(color_image) = &state.selected_node.color_image { | ||
state.selected_node.retained_image = Some(RetainedImage::from_color_image( | ||
"selected node retained image", | ||
(*color_image).clone(), | ||
)) | ||
} | ||
} | ||
|
||
if let Some(retained_image) = &state.selected_node.retained_image { | ||
if let Some(_color_image) = &state.selected_node.color_image { | ||
ui.horizontal(|ui| { | ||
ui.selectable_value( | ||
&mut state.o_pannel, | ||
state::OutputPanel::Image, | ||
"Image display", | ||
); | ||
ui.selectable_value( | ||
&mut state.o_pannel, | ||
state::OutputPanel::Spectrum, | ||
"Spectrum graph", | ||
); | ||
}); | ||
|
||
ui.separator(); | ||
|
||
match state.o_pannel { | ||
state::OutputPanel::Image => show_image_display(ui, retained_image), | ||
state::OutputPanel::Spectrum => { | ||
show_image_spectrum(ui, &state.selected_node.spectrum) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn show_image_display(ui: &mut egui::Ui, image: &RetainedImage) { | ||
display::image_frame::show(ui, image); | ||
} | ||
|
||
fn show_image_spectrum(ui: &mut egui::Ui, spectrum: &[HashMap<u8, usize>]) { | ||
display::image_spectrum::show(ui, spectrum); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.