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 | |
parent | 97894620cd648648bdeba62e9b35c84dcf0e1962 (diff) | |
download | hittekaart-4b30bda722668bef4ba362b3e578f02dede0099b.tar.gz hittekaart-4b30bda722668bef4ba362b3e578f02dede0099b.tar.bz2 hittekaart-4b30bda722668bef4ba362b3e578f02dede0099b.zip |
add a progress bar
-rw-r--r-- | Cargo.lock | 107 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/layer.rs | 4 | ||||
-rw-r--r-- | src/renderer.rs | 21 |
4 files changed, 129 insertions, 4 deletions
@@ -138,6 +138,19 @@ dependencies = [ ] [[package]] +name = "console" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9b6515d269224923b26b5febea2ed42b2d5f2ce37284a4dd670fedd6cb8347a" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys", +] + +[[package]] name = "conv" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -226,6 +239,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] name = "exr" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -259,6 +278,7 @@ dependencies = [ "fnv", "image", "imageproc", + "indicatif", "nalgebra 0.31.4", "num-traits", "roxmltree", @@ -407,6 +427,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] +name = "indicatif" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4295cbb7573c16d310e99e713cf9e75101eb190ab31fccd35f2d2691b4352b19" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "unicode-width", +] + +[[package]] name = "itertools" version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -641,6 +673,12 @@ dependencies = [ ] [[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] name = "object" version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -757,6 +795,12 @@ dependencies = [ ] [[package]] +name = "portable-atomic" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26f6a7b87c2e435a3241addceeeff740ff8b7e76b74c13bf9acb17fa454ea00b" + +[[package]] name = "ppv-lite86" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1063,6 +1107,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1151,6 +1201,63 @@ dependencies = [ ] [[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + +[[package]] name = "xmlparser" version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -11,6 +11,7 @@ colorgrad = "0.6.2" fnv = "1.0.7" image = "0.24.5" imageproc = "0.23.0" +indicatif = "0.17.2" nalgebra = "0.31.4" num-traits = "0.2.15" roxmltree = "0.17.0" diff --git a/src/layer.rs b/src/layer.rs index 465953d..1c14df3 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -121,6 +121,10 @@ impl<P: Pixel> TileLayer<P> { pub fn pixels_mut(&mut self) -> impl Iterator<Item = &mut P> { self.enumerate_pixels_mut().map(|x| x.2) } + + pub fn tile_count(&self) -> usize { + self.tiles.len() + } } impl TileLayer<Rgba<u8>> { 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 } |