From fd4f3318db8df3e9f0542535fb7df6d621d07768 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 11 Mar 2023 19:57:18 +0100 Subject: first implementation of tile hunter mode This is a very basic idea, the downside is that you basically cannot "fix" the tilehunt overlay to a specific zoom level. It might be nice to get a second renderer that renders the tile hunt for a fixed zoom, and then adjusts the output tiles accordingly (then it also takes more space again though). --- src/main.rs | 7 ++++-- src/renderer/mod.rs | 1 + src/renderer/tile-marked.png | Bin 0 -> 116 bytes src/renderer/tilehunt.rs | 52 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/renderer/tile-marked.png create mode 100644 src/renderer/tilehunt.rs diff --git a/src/main.rs b/src/main.rs index 6c110e2..7f7c532 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use color_eyre::{ }; use hittekaart::{ gpx::{self, Compression}, - renderer::{self, heatmap, Renderer}, + renderer::{self, heatmap, tilehunt, Renderer}, storage::{Folder, Sqlite, Storage}, }; use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; @@ -71,7 +71,10 @@ fn main() -> Result<()> { .num_threads(args.threads) .build_global()?; - run::(args) + match args.mode { + Mode::Heatmap => run::(args), + Mode::Tilehunt => run::(args), + } } fn run(args: Args) -> Result<()> { diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 927c6ed..f109872 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -7,6 +7,7 @@ use crossbeam_channel::Sender; use super::gpx::Coordinates; pub mod heatmap; +pub mod tilehunt; const CHANNEL_SIZE: usize = 30; diff --git a/src/renderer/tile-marked.png b/src/renderer/tile-marked.png new file mode 100644 index 0000000..0b05ce2 Binary files /dev/null and b/src/renderer/tile-marked.png differ diff --git a/src/renderer/tilehunt.rs b/src/renderer/tilehunt.rs new file mode 100644 index 0000000..f44644b --- /dev/null +++ b/src/renderer/tilehunt.rs @@ -0,0 +1,52 @@ +//! Actual rendering functions for tile hunts. +use color_eyre::eyre::Result; +use crossbeam_channel::Sender; +use fnv::FnvHashSet; + +use super::{ + super::{ + gpx::Coordinates, + layer::{TILE_HEIGHT, TILE_WIDTH}, + }, + RenderedTile, +}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct Renderer; + +impl super::Renderer for Renderer { + type Prepared = FnvHashSet<(u64, u64)>; + + fn prepare(zoom: u32, tracks: &[Vec], tick: Sender<()>) -> Result { + let mut marked = FnvHashSet::default(); + + for track in tracks { + for point in track { + let merc = point.web_mercator(zoom); + let tile_x = merc.0 / TILE_WIDTH; + let tile_y = merc.1 / TILE_HEIGHT; + marked.insert((tile_x, tile_y)); + } + + tick.send(()).unwrap(); + } + + Ok(marked) + } + + fn colorize(layer: Self::Prepared, tx: Sender) -> Result<()> { + static IMAGE_DATA: &[u8] = include_bytes!("tile-marked.png"); + for (tile_x, tile_y) in layer { + tx.send(RenderedTile { + x: tile_x, + y: tile_y, + data: IMAGE_DATA.to_vec(), + })?; + } + Ok(()) + } + + fn tile_count(layer: &Self::Prepared) -> Result { + Ok(layer.len().try_into().unwrap()) + } +} -- cgit v1.2.3