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

Improve bounding boxes used by railviz #603

Merged
merged 27 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bb0ec38
Extend bounding boxes to contain trip shpaes
MichaelKutzner Oct 18, 2024
9efa879
WIP: Use precalculated bounding boxes per segment
MichaelKutzner Oct 18, 2024
03b26bb
WIP: Fix bounding boxes
MichaelKutzner Oct 21, 2024
aea7405
WIP: Store bounding boxes to disk
MichaelKutzner Oct 21, 2024
a298f9f
Merge branch 'main' into bounding_boxes
MichaelKutzner Oct 21, 2024
e9e8f1b
WIP: Remove not needed pointer
MichaelKutzner Oct 21, 2024
4fde2ff
Replace not merged function
MichaelKutzner Oct 21, 2024
c4e9649
Reduce storage usage for trivial bounding boxes
MichaelKutzner Oct 22, 2024
c9dc409
Update dependencies
MichaelKutzner Oct 22, 2024
73ba7df
Merge branch 'main' into bounding_boxes
MichaelKutzner Oct 22, 2024
7e75f79
Cleanup code
MichaelKutzner Oct 22, 2024
7f92a8d
Add comments for internal structure
MichaelKutzner Oct 22, 2024
c07735b
Remove fixed 'geo' dependency
MichaelKutzner Oct 23, 2024
a0d971e
Move implementation into 'nigiri'
MichaelKutzner Oct 23, 2024
1c476be
Use optionals to remove duplicated code
MichaelKutzner Oct 23, 2024
0a93712
Merge branch 'main' into bounding_boxes
MichaelKutzner Oct 31, 2024
4b9b8a1
Remove unused code
MichaelKutzner Nov 4, 2024
57cea1a
Merge branch 'main' into bounding_boxes
MichaelKutzner Nov 4, 2024
dae797c
Update nigiri dependency
MichaelKutzner Nov 5, 2024
195b7f6
Fix dangeling pointer
MichaelKutzner Nov 5, 2024
a156d88
Merge branch 'main' into bounding_boxes
MichaelKutzner Nov 5, 2024
05dbb21
Update nigiri dependency
MichaelKutzner Nov 12, 2024
26f935e
Merge branch 'main' into bounding_boxes
MichaelKutzner Nov 12, 2024
bd1f88b
Remove unused includes
MichaelKutzner Nov 12, 2024
14776b3
Simplify fallback for loading bounding boxes
MichaelKutzner Nov 12, 2024
fe9651a
Fix missing const
MichaelKutzner Nov 12, 2024
dc81e03
Update src/railviz.cc
felixguendling Nov 12, 2024
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 .pkg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[nigiri]
[email protected]:motis-project/nigiri.git
branch=master
commit=fe8663ead336cb0bb98b0d6a9a9ff7032985781b
commit=11b8d96f7c62b7f58c45b343ba8436e332d21a72
[cista]
[email protected]:felixguendling/cista.git
branch=master
Expand Down
4 changes: 2 additions & 2 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
4369112269552140948
7151612309715904295
cista 950f96f4ded53a6b5753824b280550b722933e55
zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3
boost 930f38eb0365ceb7853273e03da4d9e7787abfb9
Expand All @@ -24,7 +24,7 @@ opentelemetry-cpp 60770dc9dc63e3543fc87d605b2e88fd53d7a414
pugixml 60175e80e2f5e97e027ac78f7e14c5acc009ce50
unordered_dense b33b037377ca966bbdd9cccc3417e46e88f83bfb
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
nigiri fe8663ead336cb0bb98b0d6a9a9ff7032985781b
nigiri 11b8d96f7c62b7f58c45b343ba8436e332d21a72
conf f9bf4bd83bf55a2170725707e526cbacc45dcc66
expat 636c9861e8e7c119f3626d1e6c260603ab624516
libosmium 6e6d6b3081cc8bdf25dda89730e25c36eb995516
Expand Down
2 changes: 1 addition & 1 deletion include/motis/railviz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void data::load_shapes() {
}

void data::load_railviz() {
railviz_static_ = std::make_unique<railviz_static_index>(*tt_);
railviz_static_ = std::make_unique<railviz_static_index>(*tt_, shapes_.get());
rt_->railviz_rt_ = std::make_unique<railviz_rt_index>(*tt_, *rt_->rtt_);
}

Expand Down
47 changes: 35 additions & 12 deletions src/railviz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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<n::route_idx_t, float>& 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);
Expand Down Expand Up @@ -176,12 +187,13 @@ struct railviz_static_index::impl {
n::vector_map<n::route_idx_t, float> 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>()} {
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_};
}
}

Expand Down Expand Up @@ -234,6 +246,7 @@ void add_static_transports(n::timetable const& tt,
n::route_idx_t const r,
n::interval<n::unixtime_t> const time_interval,
geo::box const& area,
n::shapes_storage const* shapes_data,
std::vector<stop_pair>& runs) {
auto const is_active = [&](n::transport const t) -> bool {
return (rtt == nullptr
Expand All @@ -247,10 +260,20 @@ void add_static_transports(n::timetable const& tt,
n::interval{n::stop_idx_t{0U}, static_cast<n::stop_idx_t>(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;
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Loading