Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bike elevation profiles #26

Draft
wants to merge 128 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
e3894ab
make bike faster
felixguendling Nov 26, 2024
2daa78c
Merge branch 'master' of github.com:motis-project/osr
felixguendling Nov 26, 2024
82171e5
WIP: Copy parser for BIL files from ppr
MichaelKutzner Nov 27, 2024
31caebe
Add example test query
MichaelKutzner Nov 27, 2024
cb0dfe6
Replace magic numbers
MichaelKutzner Nov 27, 2024
3c15f22
Prepare data structure for elevation data
MichaelKutzner Nov 27, 2024
478bed2
Merge branch 'master' of github.com:motis-project/osr
felixguendling Nov 28, 2024
f9fa329
Create test BIL data
MichaelKutzner Dec 2, 2024
329a44e
Fix error when loading BIL data
MichaelKutzner Dec 2, 2024
797230e
return lookup timing
felixguendling Dec 2, 2024
cb118f0
Fix test data
MichaelKutzner Dec 3, 2024
dc81f8b
Fix not loaded BIL data
MichaelKutzner Dec 3, 2024
9d42846
Accumulate elevation data
MichaelKutzner Dec 3, 2024
ff16508
Add elevation data to paths
MichaelKutzner Dec 3, 2024
7d81ecd
Cleanup some development code
MichaelKutzner Dec 3, 2024
e39e928
Make test elevation data more readable
MichaelKutzner Dec 3, 2024
29e4f1d
WIP: Add bike profile for elevations
MichaelKutzner Dec 4, 2024
9f01817
Simplify elevation cost calculation
MichaelKutzner Dec 4, 2024
c3a0169
Remove static member function
MichaelKutzner Dec 4, 2024
c683de3
Remove unused code
MichaelKutzner Dec 4, 2024
c983938
Enable elevation profile
MichaelKutzner Dec 4, 2024
9625dc5
Simplify elevation cost calculation
MichaelKutzner Dec 4, 2024
94e699f
Prepare progress bar updates
MichaelKutzner Dec 4, 2024
83edfdc
Parallelize way elevation calculation
MichaelKutzner Dec 4, 2024
9c17bb3
Move code for elevation calculation
MichaelKutzner Dec 5, 2024
597c769
Remove duplicated code for coordinates
MichaelKutzner Dec 5, 2024
a48239b
Store elevation data in memory mapped files
MichaelKutzner Dec 5, 2024
259f351
Remove no longer required members
MichaelKutzner Dec 5, 2024
35d17cf
Rename sum variable
MichaelKutzner Dec 5, 2024
7e5d715
Rename elevation struct
MichaelKutzner Dec 5, 2024
59ff8ba
Simplify check for existing files
MichaelKutzner Dec 5, 2024
a1a2e5d
Group filenames into namespace
MichaelKutzner Dec 5, 2024
8d68ecc
Merge remote-tracking branch 'origin/master' into altitude_profiles
MichaelKutzner Dec 5, 2024
43224b5
Cleanup code style
MichaelKutzner Dec 5, 2024
2bcba5f
Add bike profile with high elevation costs
MichaelKutzner Dec 5, 2024
2b94cb0
Copy value
MichaelKutzner Dec 5, 2024
736a5b7
Merge elevation costs into bike profile
MichaelKutzner Dec 6, 2024
ec185cf
Simplify segment elevation cost calculation
MichaelKutzner Dec 6, 2024
852c625
Use function composition to load elevations
MichaelKutzner Dec 6, 2024
b207dd3
WIP: Prepare way partitioning for way elevations
MichaelKutzner Dec 6, 2024
cabdf26
raw matches
felixguendling Dec 6, 2024
f2ceb19
Merge branch 'master' of github.com:motis-project/osr
felixguendling Dec 6, 2024
4ac20e1
Add step size to read intermediate elevation values
MichaelKutzner Dec 9, 2024
38259c8
Adjust elevation costs
MichaelKutzner Dec 9, 2024
cc52c51
Use more expressive return type
MichaelKutzner Dec 9, 2024
f12db6a
Update test data
MichaelKutzner Dec 9, 2024
faffac2
Delete dead code
MichaelKutzner Dec 9, 2024
fd29db3
Merge remote-tracking branch 'origin/master' into altitude_profiles
MichaelKutzner Dec 9, 2024
37b84f6
Fix code style
MichaelKutzner Dec 9, 2024
70df3dd
Rename variable
MichaelKutzner Dec 9, 2024
4cf8e7b
Improve code for elevation calculation
MichaelKutzner Dec 9, 2024
ba010d9
Fix possible out of bounds issue
MichaelKutzner Dec 9, 2024
8e03c10
Simplify `get_*()` methods
MichaelKutzner Dec 9, 2024
f45be4a
Fix formatting
MichaelKutzner Dec 9, 2024
033cb3e
Add missing header
MichaelKutzner Dec 9, 2024
1de3df2
Add missing file
MichaelKutzner Dec 9, 2024
f882250
Fix missing call argument
MichaelKutzner Dec 9, 2024
82a7853
Add missing header
MichaelKutzner Dec 9, 2024
fa15dc3
Add missing header
MichaelKutzner Dec 9, 2024
0b797b2
Update function signature
MichaelKutzner Dec 9, 2024
df7349c
WIP: Add support for SRTM HGT format
MichaelKutzner Dec 10, 2024
397cbec
Load data from SRTM HGT files
MichaelKutzner Dec 11, 2024
824cfde
Rename elevation provider
MichaelKutzner Dec 11, 2024
f668f94
WIP: Implement raster to improve import time
MichaelKutzner Dec 12, 2024
0fceb26
Add concept for raster drivers
MichaelKutzner Dec 12, 2024
bbcbb23
Use raster driver for STRM HGT data
MichaelKutzner Dec 12, 2024
97f0432
Remove used std::mutex
MichaelKutzner Dec 12, 2024
97c7339
Remove code for parallel elevation calculation
MichaelKutzner Dec 12, 2024
bd3a00d
Use R-Tree for SRTM HGT data files
MichaelKutzner Dec 13, 2024
5c99cf9
Fix compiler errors when using libc++
MichaelKutzner Dec 16, 2024
f3b21d5
Store elevation difference between two nodes
MichaelKutzner Dec 16, 2024
fb426a2
Store non flat elevations only
MichaelKutzner Dec 16, 2024
2d7190a
Remove useless assertion
MichaelKutzner Dec 17, 2024
1c527eb
Simpilfy code to calculate path elevation
MichaelKutzner Dec 17, 2024
aed7f0d
Remove passed progress tracker
MichaelKutzner Dec 17, 2024
5a0ecb3
WIP: Compress elevation data
MichaelKutzner Dec 17, 2024
2b03981
Fix elevation costs for segments
MichaelKutzner Dec 18, 2024
8eb811a
Update useabel sparse elevation values
MichaelKutzner Dec 18, 2024
42112a8
Rename structs and methods
MichaelKutzner Dec 18, 2024
a19965c
Fix MSVC compile errors
MichaelKutzner Dec 18, 2024
76139b1
Load elevation data for benchmark
MichaelKutzner Dec 18, 2024
d45b258
Make path to elevation data mandatory
MichaelKutzner Dec 18, 2024
4591676
Fix code style
MichaelKutzner Dec 18, 2024
6d844dc
Delete unused code for SRTM HGT driver
MichaelKutzner Dec 18, 2024
b6fcca2
Rename method to count drivers
MichaelKutzner Dec 18, 2024
016e419
Merge up and down elevations into one variable
MichaelKutzner Dec 18, 2024
e81d654
Fix maximum offset value
MichaelKutzner Dec 19, 2024
5985572
Simplify file checks
MichaelKutzner Dec 19, 2024
bc3cbb0
Rename variable
MichaelKutzner Dec 19, 2024
5fbb488
Improve calculation required for short ways
MichaelKutzner Dec 19, 2024
4a7be63
Fix header order
MichaelKutzner Dec 19, 2024
90df5c1
Remove incorrect std::move
MichaelKutzner Dec 19, 2024
2d9c290
Fix step size for mixed HGT tiles
MichaelKutzner Dec 19, 2024
7651a81
Remove unused headers
MichaelKutzner Dec 19, 2024
756bfdc
Remove variable used exactly once
MichaelKutzner Dec 19, 2024
e0150ad
Fix not matching header definition
MichaelKutzner Dec 19, 2024
e70ef4c
Revert unstable commits on 'origin/master'
MichaelKutzner Dec 19, 2024
353063a
Merge remote-tracking branch 'origin/master' into altitude_profiles
MichaelKutzner Dec 20, 2024
1615277
Fix header order
MichaelKutzner Dec 20, 2024
c10af84
Fix error for valid edge case
MichaelKutzner Dec 23, 2024
5395284
Revert "Use R-Tree for SRTM HGT data files"
MichaelKutzner Dec 24, 2024
8f6126b
Simplify offset calculation
MichaelKutzner Dec 24, 2024
c29766f
Fix offset calculation
MichaelKutzner Dec 27, 2024
17283b7
Fix value when no elevation data is available
MichaelKutzner Dec 27, 2024
0fe8c0b
Fix way approximation near longitude 180
MichaelKutzner Dec 27, 2024
64afd87
Reapply "Use R-Tree for SRTM HGT data files"
MichaelKutzner Jan 13, 2025
b685546
Simplify bounding box calculation for tiles
MichaelKutzner Jan 13, 2025
669f903
Fix tile offset calculation
MichaelKutzner Jan 13, 2025
afdb8b3
WIP: Fix route elevation
MichaelKutzner Jan 14, 2025
4feafe8
Cleanup code
MichaelKutzner Jan 14, 2025
e3ed4d2
Fix costs not matching direction
MichaelKutzner Jan 14, 2025
9dfc53b
WIP: Store elevation data to paged vector
MichaelKutzner Jan 14, 2025
d4bc92a
Parallelize way elevation calculation
MichaelKutzner Jan 15, 2025
45668ce
Unify elevation providers
MichaelKutzner Jan 15, 2025
ed14871
Fix variable name
MichaelKutzner Jan 15, 2025
94cef06
Group ways by elevation tiles
MichaelKutzner Jan 15, 2025
16c55a9
Fix compile errors
MichaelKutzner Jan 15, 2025
e1f63eb
Add check for empty ways
MichaelKutzner Jan 15, 2025
9d24a6c
Fix code style
MichaelKutzner Jan 16, 2025
a663ded
Rename hgt tile files
MichaelKutzner Jan 16, 2025
237e4e5
Use defined concepts for std::visit
MichaelKutzner Jan 16, 2025
012a811
Show route elevations for all bike profiles
MichaelKutzner Jan 16, 2025
d29e3de
Fix type for MSVC build
MichaelKutzner Jan 16, 2025
82a6a05
Fix type for MSVC build
MichaelKutzner Jan 16, 2025
a18cbe1
Remove std::mutex used for BIL files
MichaelKutzner Jan 16, 2025
5d83cce
Fix variable names in debug build
MichaelKutzner Jan 16, 2025
8e5de56
WIP: Group ways by tile
MichaelKutzner Jan 21, 2025
7779cb3
WIP: Delete not required code
MichaelKutzner Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ The current set of routing profiles can be found in the [`include/osr/routing/pr

- `resolve_start_node(ways::routing, way_idx_t, node_idx_t, level_t, direction, Fn&& f)`: resolves all nodes that belong to this particular (`way_idx_t`, `node_idx_t`, `level_t`, `direction`) combination. `Fn f` will be called with each `node`. It's the task of the profile to give the routing algorithm and entry point to its overlay graph.
- `resolve_all(ways::routing, node_ix_t, level_t, Fn&& f)`: Same as `resolve_start_node`, just without the condition that `way_idx_t` has to match.
- `adjacent<SearcHdir, WithBlocked, Fn>(ways::routing, node, bitvec<node_idx_t> blocked, Fn&& f)`: Calls `Fn f` with each adjacent neighbor of the given `node`. This is used in the shortest path algorithm to expand a node and visit all its neighbors. This takes a runtime provided bit vector `blocked` into account where bit `i` indicates if `i` can be visited or not. This allows us to dynamically block nodes depending on the routing query.
- `adjacent<SearcHdir, WithBlocked, Fn>(ways::routing, node, bitvec<node_idx_t>* blocked, sharing_data*, elevation_storage*, Fn&& f)`: Calls `Fn f` with each adjacent neighbor of the given `node`. This is used in the shortest path algorithm to expand a node and visit all its neighbors. This takes a runtime provided bit vector `blocked` into account where bit `i` indicates if `i` can be visited or not. This allows us to dynamically block nodes depending on the routing query.

As we can see, each profile can define its own overlay graph on top of the data model. This gives us the flexibility to define a routing for anything we want from pedestrians or wheelchair users over cars, trucks, trains to ships without any additional memory overhead. Even combined profiles (e.g. walking, taking a bike, walking) can be implemented. Commonly, routing engines have to have a graph for each profile which makes it quite expensive (in terms of memory) to add a new profile on a global routing server. With our approach, a new profile doesn't come with extra costs.

Expand Down
2 changes: 2 additions & 0 deletions exe/backend/include/osr/backend/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "boost/asio/io_context.hpp"

#include "osr/elevation_storage.h"
#include "osr/lookup.h"
#include "osr/platforms.h"
#include "osr/ways.h"
Expand All @@ -17,6 +18,7 @@ struct http_server {
ways const&,
lookup const&,
platforms const*,
elevation_storage const*,
std::string const& static_file_path);
~http_server();
http_server(http_server const&) = delete;
Expand Down
20 changes: 17 additions & 3 deletions exe/backend/src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ struct http_server::impl {
ways const& g,
lookup const& l,
platforms const* pl,
elevation_storage const* elevations,
std::string const& static_file_path)
: ioc_{ios},
thread_pool_{thread_pool},
w_{g},
l_{l},
pl_{pl},
elevations_{elevations},
server_{ioc_} {
try {
if (!static_file_path.empty() && fs::is_directory(static_file_path)) {
Expand Down Expand Up @@ -115,7 +117,8 @@ struct http_server::impl {
auto const max_it = q.find("max");
auto const max = static_cast<cost_t>(
max_it == q.end() ? 3600 : max_it->value().as_int64());
auto const p = route(w_, l_, profile, from, to, max, dir, 100);
auto const p = route(w_, l_, profile, from, to, max, dir, 100, nullptr,
nullptr, elevations_);
if (!p.has_value()) {
cb(json_response(req, "could not find a valid path",
http::status::not_found));
Expand Down Expand Up @@ -189,7 +192,15 @@ struct http_server::impl {
case search_profile::kWheelchair:
send_graph_response<foot<true, elevator_tracking>>(req, cb, gj);
break;
case search_profile::kBike: send_graph_response<bike>(req, cb, gj); break;
case search_profile::kBike:
send_graph_response<bike<kElevationNoCost>>(req, cb, gj);
break;
case search_profile::kBikeElevationLow:
send_graph_response<bike<kElevationLowCost>>(req, cb, gj);
break;
case search_profile::kBikeElevationHigh:
send_graph_response<bike<kElevationHighCost>>(req, cb, gj);
break;
case search_profile::kCar: send_graph_response<car>(req, cb, gj); break;
case search_profile::kCarParking:
send_graph_response<car_parking<false>>(req, cb, gj);
Expand Down Expand Up @@ -352,6 +363,7 @@ struct http_server::impl {
ways const& w_;
lookup const& l_;
platforms const* pl_;
elevation_storage const* elevations_;
web_server server_;
bool serve_static_files_{false};
std::string static_file_path_;
Expand All @@ -362,8 +374,10 @@ http_server::http_server(boost::asio::io_context& ioc,
ways const& w,
lookup const& l,
platforms const* pl,
elevation_storage const* elevation,
std::string const& static_file_path)
: impl_(new impl(ioc, thread_pool, w, l, pl, static_file_path)) {}
: impl_(new impl(ioc, thread_pool, w, l, pl, elevation, static_file_path)) {
}

http_server::~http_server() = default;

Expand Down
5 changes: 4 additions & 1 deletion exe/backend/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "net/stop_handler.h"

#include "osr/backend/http_server.h"
#include "osr/elevation_storage.h"
#include "osr/lookup.h"
#include "osr/platforms.h"
#include "osr/ways.h"
Expand Down Expand Up @@ -89,12 +90,14 @@ int main(int argc, char const* argv[]) {
if (pl != nullptr) {
pl->build_rtree(w);
}
auto const elevations = elevation_storage::try_open(opt.data_dir_);

auto const l = lookup{w, opt.data_dir_, cista::mmap::protection::READ};

auto ioc = boost::asio::io_context{};
auto pool = boost::asio::io_context{};
auto server = http_server{ioc, pool, w, l, pl.get(), opt.static_file_path_};
auto server = http_server{
ioc, pool, w, l, pl.get(), elevations.get(), opt.static_file_path_};

auto work_guard = boost::asio::make_work_guard(pool);
auto threads = std::vector<std::thread>(std::max(1U, opt.threads_));
Expand Down
11 changes: 8 additions & 3 deletions exe/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "utl/timer.h"

#include "osr/elevation_storage.h"
#include "osr/lookup.h"
#include "osr/routing/dijkstra.h"
#include "osr/routing/profile.h"
Expand Down Expand Up @@ -124,6 +125,7 @@ int main(int argc, char const* argv[]) {
}

auto const w = ways{opt.data_dir_, cista::mmap::protection::READ};
auto const elevations = elevation_storage::try_open(opt.data_dir_);

auto threads = std::vector<std::thread>(std::max(1U, opt.threads_));
auto results = std::vector<benchmark_result>{};
Expand All @@ -144,8 +146,8 @@ int main(int argc, char const* argv[]) {
node_idx_t{cista::hash_combine(h, ++n, i.load()) % w.n_nodes()};
d.reset(opt.max_dist_);
set_start<T>(d, w, start);
d.template run<direction::kForward, false>(w, *w.r_, opt.max_dist_,
nullptr, nullptr);
d.template run<direction::kForward, false>(
w, *w.r_, opt.max_dist_, nullptr, nullptr, elevations.get());
auto const end_time = std::chrono::steady_clock::now();
{
auto const guard = std::lock_guard{m};
Expand All @@ -168,5 +170,8 @@ int main(int argc, char const* argv[]) {
};

run_benchmark.template operator()<car>("car");
run_benchmark.template operator()<bike>("bike");
run_benchmark.template operator()<bike<kElevationNoCost>>(
"bike (no elevation costs)");
run_benchmark.template operator()<bike<kElevationHighCost>>(
"bike (high elevation costs)");
}
5 changes: 3 additions & 2 deletions exe/extract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ struct config : public conf::configuration {
: configuration{"Options"}, in_{std::move(in)}, out_{std::move(out)} {
param(in_, "in,i", "OpenStreetMap .osm.pbf input path");
param(out_, "out,o", "output directory");
param(elevation_data_, "elevation_data,e", "directory with elevation data");
param(with_platforms_, "with_platforms,p", "extract platform info");
}

std::filesystem::path in_, out_;
std::filesystem::path in_, out_, elevation_data_;
bool with_platforms_{false};
};

Expand All @@ -44,5 +45,5 @@ int main(int ac, char const** av) {
utl::activate_progress_tracker("osr");
auto const silencer = utl::global_progress_bars{false};

extract(c.with_platforms_, c.in_, c.out_);
extract(c.with_platforms_, c.in_, c.out_, c.elevation_data_);
}
51 changes: 51 additions & 0 deletions include/osr/elevation_storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include <cstdint>
#include <filesystem>
#include <memory>

#include "cista/mmap.h"

#include "osr/types.h"
#include "osr/ways.h"

namespace osr {

constexpr elevation_t NO_ELEVATION_DATA = -32767;

namespace preprocessing::elevation {
struct provider;
}

struct elevation_storage {
struct elevation {
elevation& operator+=(elevation const&);
elevation swap() const;
elevation_t up_;
elevation_t down_;
};
struct encoding {
using coding = std::uint8_t;
explicit encoding(elevation const&);
encoding() = default;
elevation decode() const;
explicit operator bool() const;
coding up_ : 4 {};
coding down_ : 4 {};
};
elevation_storage(std::filesystem::path const&,
cista::mmap::protection const mode);
static std::unique_ptr<elevation_storage> try_open(
std::filesystem::path const&);
void set_elevations(ways const&, preprocessing::elevation::provider const&);
elevation get_elevations(way_idx_t const way,
std::uint16_t const segment) const;

mm_paged_vecvec<way_idx_t, encoding> elevations_;
};

elevation_storage::elevation get_elevations(elevation_storage const*,
way_idx_t const way,
std::uint16_t const segment);

} // namespace osr
3 changes: 2 additions & 1 deletion include/osr/extract/extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace osr {

void extract(bool with_platforms,
std::filesystem::path const& in,
std::filesystem::path const& out);
std::filesystem::path const& out,
std::filesystem::path const& elevation_dir);

} // namespace osr
4 changes: 4 additions & 0 deletions include/osr/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ struct point {
return {l.x(), l.y()};
}

static point from_latlng(double lat, double lng) {
return from_location(osmium::Location(lng, lat));
}

osmium::Location as_location() const { return osmium::Location{lat_, lng_}; }

geo::latlng as_latlng() const {
Expand Down
28 changes: 28 additions & 0 deletions include/osr/preprocessing/elevation/dem_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <vector>

#include "cista/containers/rtree.h"

#include "osr/point.h"
#include "osr/preprocessing/elevation/dem_tile.h"
#include "osr/preprocessing/elevation/step_size.h"
#include "osr/types.h"

namespace fs = std::filesystem;

namespace osr::preprocessing::elevation {

struct dem_driver {
dem_driver() = default;
bool add_tile(fs::path const&);
::osr::elevation_t get(::osr::point const&) const;
step_size get_step_size() const;
elevation_tile_idx_t get_tile_idx(point const&) const;
std::size_t n_tiles() const;

cista::raw::rtree<std::size_t> rtree_{};
std::vector<dem_tile> tiles_{};
};

} // namespace osr::preprocessing::elevation
43 changes: 43 additions & 0 deletions include/osr/preprocessing/elevation/dem_tile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include <cstdint>
#include <filesystem>
#include <memory>

#include "osr/point.h"
#include "osr/preprocessing/elevation/shared.h"
#include "osr/preprocessing/elevation/step_size.h"
#include "osr/types.h"

namespace fs = std::filesystem;

namespace osr::preprocessing::elevation {

enum class pixel_type : std::uint8_t { int16, float32 };

union pixel_value {
std::int16_t int16_;
float float32_;
};

struct dem_tile {
explicit dem_tile(fs::path const& filename);
~dem_tile();
dem_tile(dem_tile&& grid) noexcept;
dem_tile(dem_tile const&) = delete;
dem_tile& operator=(dem_tile const&) = delete;
dem_tile& operator=(dem_tile&&) = delete;

::osr::elevation_t get(::osr::point const&) const;
coord_box get_coord_box() const;

pixel_value get_raw(::osr::point const&) const;
pixel_type get_pixel_type() const;
step_size get_step_size() const;

private:
struct impl;
std::unique_ptr<impl> impl_;
};

} // namespace osr::preprocessing::elevation
37 changes: 37 additions & 0 deletions include/osr/preprocessing/elevation/hgt_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <optional>
#include <variant>
#include <vector>

#include "cista/containers/rtree.h"

#include "osr/point.h"
#include "osr/preprocessing/elevation/hgt_tile.h"
#include "osr/preprocessing/elevation/shared.h"
#include "osr/preprocessing/elevation/step_size.h"
#include "osr/types.h"

namespace fs = std::filesystem;

namespace osr::preprocessing::elevation {

static_assert(IsTile<hgt_tile<3601>>);
static_assert(IsTile<hgt_tile<1201>>);

struct hgt_driver {
using hgt_tile_t = std::variant<hgt_tile<3601>, hgt_tile<1201>>;

hgt_driver() = default;
bool add_tile(fs::path const&);
::osr::elevation_t get(::osr::point const&) const;
step_size get_step_size() const;
elevation_tile_idx_t get_tile_idx(::osr::point const&) const;
std::size_t n_tiles() const;
static std::optional<hgt_tile_t> open(fs::path const&);

cista::raw::rtree<std::size_t> rtree_;
std::vector<hgt_tile_t> tiles_;
};

} // namespace osr::preprocessing::elevation
45 changes: 45 additions & 0 deletions include/osr/preprocessing/elevation/hgt_tile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <cstdint>
#include <memory>
#include <string>

#include "osr/point.h"
#include "osr/preprocessing/elevation/shared.h"
#include "osr/preprocessing/elevation/step_size.h"
#include "osr/types.h"

namespace osr::preprocessing::elevation {

template <std::size_t RasterSize>
struct hgt_tile {
constexpr static auto const kBytesPerPixel = std::size_t{2U};

explicit hgt_tile(std::string const& filename,
std::int8_t const lat,
std::int16_t const lng);
~hgt_tile();
hgt_tile(hgt_tile&& grid) noexcept;
hgt_tile(hgt_tile const&) = delete;
hgt_tile& operator=(hgt_tile const&) = delete;
hgt_tile& operator=(hgt_tile&&) = delete;

::osr::elevation_t get(::osr::point const&) const;

step_size get_step_size() const;

coord_box get_coord_box() const;

static constexpr std::size_t file_size() {
return RasterSize * RasterSize * kBytesPerPixel;
}

private:
struct impl;
std::unique_ptr<impl> impl_;
};

extern template struct hgt_tile<3601U>;
extern template struct hgt_tile<1201U>;

} // namespace osr::preprocessing::elevation
Loading
Loading