Skip to content

Commit

Permalink
deleted: assets/cut_example.gif
Browse files Browse the repository at this point in the history
	deleted:    assets/hist1d_fitting.gif
	deleted:    assets/projection_example.gif
	modified:   src/histoer/histo2d/histogram2d.rs
	modified:   src/histoer/histogrammer.rs
	modified:   src/histogram_scripter/histogram_script.rs
	renamed:    src/histogram_scripter/manual_histogram_script.rs -> src/histogram_scripter/manual_histogram_scripts.rs
	modified:   src/histogram_scripter/mod.rs
	modified:   src/ui/app.rs
	modified:   src/util/processer.rs
  • Loading branch information
alconley committed Nov 7, 2024
1 parent f724814 commit 0ee3781
Show file tree
Hide file tree
Showing 10 changed files with 943 additions and 359 deletions.
Binary file removed assets/cut_example.gif
Binary file not shown.
Binary file removed assets/hist1d_fitting.gif
Binary file not shown.
Binary file removed assets/projection_example.gif
Binary file not shown.
51 changes: 27 additions & 24 deletions src/histoer/histo2d/histogram2d.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fnv::FnvHashMap;
use rayon::prelude::*;

use crate::egui_plot_stuff::egui_image::EguiImage;

Expand Down Expand Up @@ -107,35 +108,37 @@ impl Histogram2D {
Some(bin_index)
}

// Convert histogram data to a ColorImage
// Convert histogram data to a ColorImage in parallel using Rayon
fn data_2_image(&self) -> egui::ColorImage {
let width = ((self.range.x.max - self.range.x.min) / self.bins.x_width) as usize; // number of pixels in x direction
let height = ((self.range.y.max - self.range.y.min) / self.bins.y_width) as usize; // number of pixels in y direction

// The pixels, row by row, from top to bottom. Each pixel is a Color32.
let mut pixels = Vec::with_capacity(width * height);
let width = ((self.range.x.max - self.range.x.min) / self.bins.x_width) as usize;
let height = ((self.range.y.max - self.range.y.min) / self.bins.y_width) as usize;

let colormap_options = self.plot_settings.colormap_options;

for y in 0..height {
for x in 0..width {
let count = self
.bins
.counts
.get(&(x, height - y - 1))
.cloned()
.unwrap_or(0);
let color = self.plot_settings.colormap.color(
count,
self.bins.min_count,
self.bins.max_count,
colormap_options,
);
pixels.push(color);
}
}
// Parallelize over rows, and for each row, compute pixel colors for all columns
let pixels: Vec<_> = (0..height)
.into_par_iter()
.map(|y| {
(0..width)
.map(|x| {
let count = self
.bins
.counts
.get(&(x, height - y - 1))
.cloned()
.unwrap_or(0);
self.plot_settings.colormap.color(
count,
self.bins.min_count,
self.bins.max_count,
colormap_options,
)
})
.collect::<Vec<_>>() // Collect each row as a `Vec<Color32>`
})
.flatten() // Flatten the rows into a single Vec<Color32> for pixels
.collect();

// Create the ColorImage with the specified width and height and pixel data
egui::ColorImage {
size: [width, height],
pixels,
Expand Down
Loading

0 comments on commit 0ee3781

Please sign in to comment.