aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock157
-rw-r--r--Cargo.toml3
-rw-r--r--src/main.rs73
3 files changed, 217 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d705490..337cfc7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -152,12 +152,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5"
dependencies = [
"bitflags",
- "clap_lex",
+ "clap_lex 0.2.4",
"indexmap",
"textwrap",
]
[[package]]
+name = "clap"
+version = "4.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa91278560fc226a5d9d736cc21e485ff9aad47d26b8ffe1f54cba868b684b9f"
+dependencies = [
+ "bitflags",
+ "clap_derive",
+ "clap_lex 0.3.1",
+ "is-terminal",
+ "once_cell",
+ "strsim",
+ "termcolor",
+]
+
+[[package]]
+name = "clap_derive"
+version = "4.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "clap_lex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -167,6 +195,15 @@ dependencies = [
]
[[package]]
+name = "clap_lex"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade"
+dependencies = [
+ "os_str_bytes",
+]
+
+[[package]]
name = "color-eyre"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -249,7 +286,7 @@ dependencies = [
"atty",
"cast",
"ciborium",
- "clap",
+ "clap 3.2.23",
"criterion-plot",
"itertools",
"lazy_static",
@@ -352,6 +389,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
+name = "errno"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
+dependencies = [
+ "errno-dragonfly",
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "errno-dragonfly"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
+dependencies = [
+ "cc",
+ "libc",
+]
+
+[[package]]
name = "exr"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -479,6 +537,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
+name = "heck"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
+
+[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -500,6 +564,7 @@ dependencies = [
name = "hittekaart"
version = "0.1.0"
dependencies = [
+ "clap 4.1.0",
"color-eyre",
"colorgrad",
"criterion",
@@ -507,6 +572,7 @@ dependencies = [
"image",
"imageproc",
"indicatif",
+ "is-terminal",
"nalgebra 0.31.4",
"num-traits",
"rayon",
@@ -579,6 +645,28 @@ dependencies = [
]
[[package]]
+name = "io-lifetimes"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e"
+dependencies = [
+ "libc",
+ "windows-sys",
+]
+
+[[package]]
+name = "is-terminal"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189"
+dependencies = [
+ "hermit-abi 0.2.6",
+ "io-lifetimes",
+ "rustix",
+ "windows-sys",
+]
+
+[[package]]
name = "itertools"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -630,6 +718,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
+name = "linux-raw-sys"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
+
+[[package]]
name = "lock_api"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -993,6 +1087,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
+[[package]]
name = "proc-macro2"
version = "1.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1134,6 +1252,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
+name = "rustix"
+version = "0.36.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549"
+dependencies = [
+ "bitflags",
+ "errno",
+ "io-lifetimes",
+ "libc",
+ "linux-raw-sys",
+ "windows-sys",
+]
+
+[[package]]
name = "rusttype"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1254,6 +1386,12 @@ dependencies = [
]
[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
+[[package]]
name = "syn"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1265,6 +1403,15 @@ dependencies = [
]
[[package]]
+name = "termcolor"
+version = "1.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
name = "textwrap"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1382,6 +1529,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
+name = "version_check"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
+
+[[package]]
name = "walkdir"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 468fafc..cf67d91 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,6 +2,7 @@
name = "hittekaart"
version = "0.1.0"
edition = "2021"
+description = "Generates OSM heatmap tiles from GPX tracks"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -10,12 +11,14 @@ name = "hittebench"
harness = false
[dependencies]
+clap = { version = "4.1.0", features = ["derive"] }
color-eyre = "0.6.2"
colorgrad = "0.6.2"
fnv = "1.0.7"
image = "0.24.5"
imageproc = "0.23.0"
indicatif = "0.17.2"
+is-terminal = "0.4.2"
nalgebra = "0.31.4"
num-traits = "0.2.15"
rayon = "1.6.1"
diff --git a/src/main.rs b/src/main.rs
index 269d95c..77af69f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,47 +1,92 @@
-use std::{env, fs, path::PathBuf};
+use std::{fs, io, path::PathBuf};
-use color_eyre::eyre::Result;
-use indicatif::{ProgressBar, ProgressStyle};
+use clap::Parser;
+use color_eyre::eyre::{bail, Result};
+use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
+use is_terminal::IsTerminal;
mod gpx;
mod layer;
mod renderer;
+#[derive(Parser, Debug, Clone)]
+#[command(author, version, about)]
+struct Args {
+ /// The GPX files to parse.
+ #[arg(required = true)]
+ files: Vec<PathBuf>,
+
+ #[arg(long, default_value_t = 0)]
+ min_zoom: u32,
+
+ #[arg(long, default_value_t = 19)]
+ max_zoom: u32,
+}
+
fn main() -> Result<()> {
color_eyre::install()?;
+ let args = Args::parse();
+
+ if args.max_zoom < args.min_zoom {
+ bail!("Max zoom cannot be smaller than min zoom!");
+ }
+
let progress_style =
ProgressStyle::with_template("[{elapsed}] {prefix:.cyan} {wide_bar} {pos:.green}/{len}")?;
+ let zoom_style =
+ ProgressStyle::with_template("[{elapsed}] {prefix:.yellow} {wide_bar} {pos:.green}/{len}")?;
+
+ let use_progress_bars = io::stdout().is_terminal();
+ let make_bar = |len| {
+ if use_progress_bars {
+ ProgressBar::new(len)
+ } else {
+ ProgressBar::hidden()
+ }
+ };
- let gpx_folder = env::args().nth(1).unwrap();
- println!("Reading from {gpx_folder}");
+ let bar = make_bar(args.files.len().try_into().unwrap()).with_style(progress_style.clone());
+ bar.set_prefix("Reading GPX files");
let mut tracks = Vec::new();
- for file in fs::read_dir(gpx_folder).unwrap() {
- let file = file.unwrap();
- let data = gpx::extract_from_file(file.path(), gpx::Compression::None).unwrap();
+ for file in &args.files {
+ let data = gpx::extract_from_file(file, gpx::Compression::None).unwrap();
tracks.push(data);
+ bar.inc(1);
}
+ bar.finish();
- for zoom in 0..=19 {
- println!("Doing level {zoom}");
+ let multibar = MultiProgress::new();
+ if !use_progress_bars {
+ multibar.set_draw_target(ProgressDrawTarget::hidden())
+ }
+ let zoom_bar = make_bar((args.max_zoom - args.min_zoom + 1).into()).with_style(zoom_style);
+ multibar.add(zoom_bar.clone());
+ zoom_bar.set_prefix("Zoom levels");
- let bar =
- ProgressBar::new(tracks.len().try_into().unwrap()).with_style(progress_style.clone());
+ for zoom in args.min_zoom..=args.max_zoom {
+ let bar = make_bar(tracks.len().try_into().unwrap()).with_style(progress_style.clone());
+ multibar.insert_from_back(1, bar.clone());
bar.set_prefix("Rendering heat zones");
let counter =
renderer::render_heatcounter(zoom, &tracks, |x| bar.inc(x.try_into().unwrap()));
bar.finish();
+ multibar.remove(&bar);
let target = ["tiles", &zoom.to_string()].iter().collect::<PathBuf>();
fs::create_dir(&target)?;
- let bar = ProgressBar::new(counter.tile_count().try_into().unwrap())
- .with_style(progress_style.clone());
+ let bar =
+ make_bar(counter.tile_count().try_into().unwrap()).with_style(progress_style.clone());
+ multibar.insert_from_back(1, bar.clone());
bar.set_prefix("Saving heat tiles");
renderer::lazy_colorization(counter, &target, |x| bar.inc(x.try_into().unwrap()))?;
bar.finish();
+ multibar.remove(&bar);
+ zoom_bar.inc(1);
}
+ zoom_bar.finish();
Ok(())
}