diff --git a/.pkg b/.pkg index 661ebab7a..b30a4b6a0 100644 --- a/.pkg +++ b/.pkg @@ -1,7 +1,7 @@ [nigiri] url=git@github.com:motis-project/nigiri.git branch=master - commit=fe8663ead336cb0bb98b0d6a9a9ff7032985781b + commit=11b8d96f7c62b7f58c45b343ba8436e332d21a72 [cista] url=git@github.com:felixguendling/cista.git branch=master diff --git a/.pkg.lock b/.pkg.lock index 7f6725710..c503d28d0 100644 --- a/.pkg.lock +++ b/.pkg.lock @@ -1,4 +1,4 @@ -4369112269552140948 +7151612309715904295 cista 950f96f4ded53a6b5753824b280550b722933e55 zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3 boost 930f38eb0365ceb7853273e03da4d9e7787abfb9 @@ -24,7 +24,7 @@ opentelemetry-cpp 60770dc9dc63e3543fc87d605b2e88fd53d7a414 pugixml 60175e80e2f5e97e027ac78f7e14c5acc009ce50 unordered_dense b33b037377ca966bbdd9cccc3417e46e88f83bfb wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99 -nigiri fe8663ead336cb0bb98b0d6a9a9ff7032985781b +nigiri 11b8d96f7c62b7f58c45b343ba8436e332d21a72 conf f9bf4bd83bf55a2170725707e526cbacc45dcc66 expat 636c9861e8e7c119f3626d1e6c260603ab624516 libosmium 6e6d6b3081cc8bdf25dda89730e25c36eb995516 diff --git a/include/motis/railviz.h b/include/motis/railviz.h index d4110813b..245c8ecc2 100644 --- a/include/motis/railviz.h +++ b/include/motis/railviz.h @@ -9,7 +9,7 @@ namespace motis { struct railviz_static_index { - railviz_static_index(nigiri::timetable const&); + railviz_static_index(nigiri::timetable const&, nigiri::shapes_storage const*); ~railviz_static_index(); struct impl; diff --git a/src/data.cc b/src/data.cc index 3945c8456..e3d21da81 100644 --- a/src/data.cc +++ b/src/data.cc @@ -197,7 +197,7 @@ void data::load_shapes() { } void data::load_railviz() { - railviz_static_ = std::make_unique(*tt_); + railviz_static_ = std::make_unique(*tt_, shapes_.get()); rt_->railviz_rt_ = std::make_unique(*tt_, *rt_->rtt_); } diff --git a/src/railviz.cc b/src/railviz.cc index 7d7f535cd..c8bff7fb6 100644 --- a/src/railviz.cc +++ b/src/railviz.cc @@ -6,8 +6,11 @@ #include "utl/enumerate.h" #include "utl/get_or_create.h" +#include "utl/pairwise.h" #include "utl/to_vec.h" +#include "utl/verify.h" +#include "geo/box.h" #include "geo/detail/register_box.h" #include "geo/latlng.h" #include "geo/polyline_format.h" @@ -18,6 +21,7 @@ #include "nigiri/rt/frun.h" #include "nigiri/rt/rt_timetable.h" #include "nigiri/rt/run.h" +#include "nigiri/shapes_storage.h" #include "nigiri/timetable.h" #include "nigiri/types.h" @@ -93,19 +97,26 @@ struct route_geo_index { route_geo_index() = default; route_geo_index(n::timetable const& tt, + n::shapes_storage const* shapes_data, n::clasz const clasz, n::vector_map& distances) { + // Fallback, if no route bounding box can be loaded + auto const get_box = [&](n::route_idx_t const route_idx) { + auto bounding_box = geo::box{}; + for (auto const l : tt.route_location_seq_[route_idx]) { + bounding_box.extend( + tt.locations_.coordinates_.at(n::stop{l}.location_idx())); + } + return bounding_box; + }; for (auto const [i, claszes] : utl::enumerate(tt.route_section_clasz_)) { auto const r = n::route_idx_t{i}; if (claszes.at(0) != clasz) { continue; } - - auto bounding_box = geo::box{}; - for (auto const l : tt.route_location_seq_[r]) { - bounding_box.extend( - tt.locations_.coordinates_.at(n::stop{l}.location_idx())); - } + auto const bounding_box = (shapes_data == nullptr) + ? get_box(r) + : shapes_data->get_bounding_box(r); rtree_.insert(bounding_box.min_.lnglat_float(), bounding_box.max_.lnglat_float(), r); @@ -176,12 +187,13 @@ struct railviz_static_index::impl { n::vector_map static_distances_{}; }; -railviz_static_index::railviz_static_index(n::timetable const& tt) +railviz_static_index::railviz_static_index(n::timetable const& tt, + n::shapes_storage const* shapes_data) : impl_{std::make_unique()} { impl_->static_distances_.resize(tt.route_location_seq_.size()); for (auto c = int_clasz{0U}; c != n::kNumClasses; ++c) { impl_->static_geo_indices_[c] = - route_geo_index{tt, n::clasz{c}, impl_->static_distances_}; + route_geo_index{tt, shapes_data, n::clasz{c}, impl_->static_distances_}; } } @@ -234,6 +246,7 @@ void add_static_transports(n::timetable const& tt, n::route_idx_t const r, n::interval const time_interval, geo::box const& area, + n::shapes_storage const* shapes_data, std::vector& runs) { auto const is_active = [&](n::transport const t) -> bool { return (rtt == nullptr @@ -247,10 +260,20 @@ void add_static_transports(n::timetable const& tt, n::interval{n::stop_idx_t{0U}, static_cast(seq.size())}; auto const [start_day, _] = tt.day_idx_mam(time_interval.from_); auto const [end_day, _1] = tt.day_idx_mam(time_interval.to_); + auto const get_box = [&](std::size_t segment) { + if (shapes_data != nullptr) { + auto const box = shapes_data->get_bounding_box(r, segment); + if (box.has_value()) { + return *box; + } + } + // Fallback, if no segment bounding box can be loaded + return geo::make_box( + {tt.locations_.coordinates_[n::stop{seq[segment]}.location_idx()], + tt.locations_.coordinates_[n::stop{seq[segment + 1]}.location_idx()]}); + }; for (auto const [from, to] : utl::pairwise(stop_indices)) { - auto const box = geo::make_box( - {tt.locations_.coordinates_[n::stop{seq[from]}.location_idx()], - tt.locations_.coordinates_[n::stop{seq[to]}.location_idx()]}); + auto const box = get_box(from); if (!box.overlaps(area)) { continue; } @@ -323,7 +346,7 @@ api::trips_response get_trains(tag_lookup const& tags, for (auto const& r : static_index.static_geo_indices_[c].get_routes(area)) { if (should_display(cl, zoom_level, static_index.static_distances_[r])) { - add_static_transports(tt, rtt, r, time_interval, area, runs); + add_static_transports(tt, rtt, r, time_interval, area, shapes, runs); } } }