diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-01-11 23:37:46 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-01-11 23:37:46 +0100 |
commit | 3826d00f339e87698f95dc24c33739e2880aac65 (patch) | |
tree | cc713233330efda0240299a5c72ef2d292b83272 /src/renderer.rs | |
parent | 42cd7c82745e19234a6350e326064baf2454c717 (diff) | |
download | hittekaart-3826d00f339e87698f95dc24c33739e2880aac65.tar.gz hittekaart-3826d00f339e87698f95dc24c33739e2880aac65.tar.bz2 hittekaart-3826d00f339e87698f95dc24c33739e2880aac65.zip |
add some first benchmarks
Diffstat (limited to 'src/renderer.rs')
-rw-r--r-- | src/renderer.rs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index 1346ed1..6e17304 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -2,7 +2,6 @@ use std::{fs, mem, path::Path}; use color_eyre::eyre::{bail, Result}; use image::{ImageBuffer, Luma, Pixel, Rgba, RgbaImage}; -use indicatif::ProgressBar; use nalgebra::{vector, Vector2}; use num_traits::identities::Zero; @@ -21,7 +20,10 @@ fn render_circle<P: Pixel>(layer: &mut TileLayer<P>, center: (u64, u64), radius: let mut circle = ImageBuffer::<P, Vec<P::Subpixel>>::new(rad_32 * 2 + 1, rad_32 * 2 + 1); imageproc::drawing::draw_filled_circle_mut( &mut circle, - (i32::try_from(radius).unwrap(), i32::try_from(radius).unwrap()), + ( + i32::try_from(radius).unwrap(), + i32::try_from(radius).unwrap(), + ), radius.try_into().unwrap(), pixel, ); @@ -145,15 +147,17 @@ pub fn colorize_heatcounter(layer: &HeatCounter) -> HeatMap { /// rendering the next one. /// /// This has a way lower memory usage than [`colorize_heatcounter`]. -pub fn lazy_colorization<P: AsRef<Path>>(layer: &HeatCounter, base_dir: P) -> Result<()> { +pub fn lazy_colorization<P: AsRef<Path>, F: FnMut(usize)>( + layer: &HeatCounter, + base_dir: P, + mut progress_callback: F, +) -> Result<()> { let base_dir = base_dir.as_ref(); let max = layer.pixels().map(|l| l.0[0]).max().unwrap_or_default(); if max == 0 { return Ok(()); } - let bar = ProgressBar::new(layer.tile_count().try_into().unwrap()); - for (tile_x, tile_y, tile) in layer.enumerate_tiles() { let colorized = colorize_tile(&tile, max.into()); let folder = base_dir.join(&tile_x.to_string()); @@ -165,18 +169,19 @@ pub fn lazy_colorization<P: AsRef<Path>>(layer: &HeatCounter, base_dir: P) -> Re } let file = folder.join(&format!("{tile_y}.png")); layer::compress_png(&colorized, file)?; - bar.inc(1); + progress_callback(1); } - bar.finish(); Ok(()) } /// Renders the heat counter for the given zoom level and track points. -pub fn render_heatcounter(zoom: u32, tracks: &[Vec<Coordinates>]) -> HeatCounter { +pub fn render_heatcounter<F: FnMut(usize)>( + zoom: u32, + tracks: &[Vec<Coordinates>], + mut progress_callback: F, +) -> HeatCounter { let size = 256 * 2u64.pow(zoom); - let bar = ProgressBar::new(tracks.len().try_into().unwrap()); - let mut heatcounter = TileLayer::from_pixel(size, size, [0].into()); for track in tracks { @@ -196,8 +201,7 @@ pub fn render_heatcounter(zoom: u32, tracks: &[Vec<Coordinates>]) -> HeatCounter } merge_heat_counter(&mut heatcounter, &layer); - bar.inc(1); + progress_callback(1); } - bar.finish(); heatcounter } |