diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-01-08 19:36:31 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-01-08 19:36:31 +0100 |
commit | 4b30bda722668bef4ba362b3e578f02dede0099b (patch) | |
tree | 1d61601adbcc4795e624694951337bdd39bf8532 /src/renderer.rs | |
parent | 97894620cd648648bdeba62e9b35c84dcf0e1962 (diff) | |
download | hittekaart-4b30bda722668bef4ba362b3e578f02dede0099b.tar.gz hittekaart-4b30bda722668bef4ba362b3e578f02dede0099b.tar.bz2 hittekaart-4b30bda722668bef4ba362b3e578f02dede0099b.zip |
add a progress bar
Diffstat (limited to 'src/renderer.rs')
-rw-r--r-- | src/renderer.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index c523268..757019c 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,6 +1,7 @@ use std::{fs, mem, path::Path}; use color_eyre::eyre::{bail, Result}; +use indicatif::ProgressBar; use image::{ImageBuffer, Luma, Pixel, Rgba, RgbaImage}; use nalgebra::{vector, Vector2}; use num_traits::identities::Zero; @@ -87,6 +88,9 @@ fn render_line<P: Pixel>( let displacement = normal * thickness as f64; let displacement = displacement.map(|x| x as i32); + if displacement == vector![0, 0] { + return; + } let polygon = [ unsigned_add(start, displacement), unsigned_add(end, displacement), @@ -123,12 +127,12 @@ fn merge_heat_counter(base: &mut HeatCounter, overlay: &HeatCounter) { } fn colorize_tile(tile: &ImageBuffer<Luma<u32>, Vec<u32>>, max: u32) -> RgbaImage { - let gradient = colorgrad::turbo(); + let gradient = colorgrad::yl_or_rd(); let mut result = ImageBuffer::from_pixel(tile.width(), tile.height(), [0, 0, 0, 0].into()); for (x, y, pixel) in tile.enumerate_pixels() { if pixel[0] > 0 { let alpha = pixel[0] as f64 / max as f64; - let color = gradient.at(alpha); + let color = gradient.at(1.0 - alpha); let target = result.get_pixel_mut(x, y); *target = color.to_rgba8().into(); } @@ -159,6 +163,9 @@ pub fn lazy_colorization<P: AsRef<Path>>(layer: &HeatCounter, base_dir: P) -> Re 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); let folder = base_dir.join(&tile_x.to_string()); @@ -170,7 +177,9 @@ 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); } + bar.finish(); Ok(()) } @@ -178,6 +187,8 @@ pub fn lazy_colorization<P: AsRef<Path>>(layer: &HeatCounter, base_dir: P) -> Re pub fn render_heatcounter(zoom: u32, tracks: &[Vec<Coordinates>]) -> 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 { @@ -189,14 +200,16 @@ pub fn render_heatcounter(zoom: u32, tracks: &[Vec<Coordinates>]) -> HeatCounter .collect::<Vec<_>>(); for point in points.iter() { - render_circle(&mut layer, *point, 10, [1].into()); + render_circle(&mut layer, *point, (zoom as u64 / 4).max(1), [1].into()); } for (a, b) in points.iter().zip(points.iter().skip(1)) { - render_line(&mut layer, *a, *b, 10, [1].into()); + render_line(&mut layer, *a, *b, (zoom as u64 / 4).max(1), [1].into()); } merge_heat_counter(&mut heatcounter, &layer); + bar.inc(1); } + bar.finish(); heatcounter } |