aboutsummaryrefslogtreecommitdiff
path: root/src/renderer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer.rs')
-rw-r--r--src/renderer.rs28
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
}