Skip to content

Commit

Permalink
Merge branch 'master' into platform
Browse files Browse the repository at this point in the history
# Conflicts:
#	exe/backend/src/http_server.cc
#	include/osr/routing/route.h
#	include/osr/ways.h
#	src/extract.cc
#	web/index.html
  • Loading branch information
felixguendling committed Jul 19, 2024
2 parents 058a79c + d4d147c commit 670fcd6
Show file tree
Hide file tree
Showing 16 changed files with 1,146 additions and 397 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- name: Format files
run: |
find base libs modules test \
find exe include src test \
-type f -a \( -name "*.cc" -o -name "*.h" -o -name ".cuh" -o -name ".cu" \) \
-print0 | xargs -0 clang-format-17 -i
Expand Down
29 changes: 29 additions & 0 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
16761676331022936617
cista bcabd041ddf07baf1b544bbe46ef195c2b6d22bd
zlib d1c943390ba4f97aa2f50bedc629b6d29027fa0e
boost 60cae66449fa3c9599b2b7d3d5d44c65301ed3a3
conf f9bf4bd83bf55a2170725707e526cbacc45dcc66
expat 636c9861e8e7c119f3626d1e6c260603ab624516
fmt edb385ac526c24bc917ec4a41bb0edb28f0ca59e
doctest 70e8f76437b76dd5e9c0a2eb9b907df190ab71a0
geo 10fde5b467825c059881c93aeea00412338a9b06
googletest 34a46558609e05865c197f0260ab36daa7cbbb6e
libosmium 6e6d6b3081cc8bdf25dda89730e25c36eb995516
mimalloc 0087f000848de31b0090cb6f282348bd2fd3a9b8
libressl 390253a44ceef00eb620c38606588414326e9f23
net 44674d2f3917e20b7019a0f7254d332522c36fb7
protozero 8c9f3fa97c2cfdceef86d0b61818ae98e9328f29
rapidjson e7a1ac95c7840c6f4351abead02b1f7a02874197
LuaJIT babeae2c3311bed245ee86f3e35a1f244e3da60b
clipper 904f0e6644c7f01c176443613be8f7788d59c658
concurrentqueue 54fdce755d3e52c785d6d9d7d91c94615495868c
lmdb 39d8127e5697b1323a67e61c3ad8f087384c7429
miniz 1edbdece9d71dc65c6ff405572ee37cbdcef7af4
res 7d97784ba785ce8a2677ea77164040fde484fb04
pbf-sdf-fonts 91b369e4eb8a618e0a83b0c04b1b08632ea872c4
sol2 fdb0f8a60e48aa737f0a8d73edede48627f0c984
utl 80df7a6f1e2de4d290c48e9218d48eb9792b7289
variant 5aa73631dc969087c77433a5cdef246303051f69
tiles 64f297ea0f782d04c89e82c6d478a1dd453e5f70
unordered_dense c11595a7743d20622637584bddf77243d72ae152
rtree.c 6ed73a7dc4f1184f2b5b2acd8ac1c2b28a273057
2 changes: 1 addition & 1 deletion exe/backend/include/osr/backend/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ struct http_server {
http_server(boost::asio::io_context& ioc,
boost::asio::io_context& thread_pool,
ways const&,
platforms const*,
lookup const&,
platforms const*,
std::string const& static_file_path);
~http_server();
http_server(http_server const&) = delete;
Expand Down
151 changes: 80 additions & 71 deletions exe/backend/src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "boost/json.hpp"
#include "boost/thread/tss.hpp"

#include "rapidjson/error/en.h"

#include "fmt/core.h"

#include "utl/enumerate.h"
Expand All @@ -22,6 +24,7 @@
#include "osr/lookup.h"
#include "osr/routing/profiles/bike.h"
#include "osr/routing/profiles/car.h"
#include "osr/routing/profiles/car_parking.h"
#include "osr/routing/profiles/foot.h"
#include "osr/routing/route.h"

Expand Down Expand Up @@ -73,14 +76,14 @@ struct http_server::impl {
impl(boost::asio::io_context& ios,
boost::asio::io_context& thread_pool,
ways const& g,
platforms const* pl,
lookup const& l,
platforms const* pl,
std::string const& static_file_path)
: ioc_{ios},
thread_pool_{thread_pool},
w_{g},
pl_{pl},
l_{l},
pl_{pl},
server_{ioc_} {
try {
if (!static_file_path.empty() && fs::is_directory(static_file_path)) {
Expand All @@ -101,14 +104,18 @@ struct http_server::impl {
return *s.get();
}

static search_profile get_search_profile_from_request(
boost::json::object const& q) {
auto const profile_it = q.find("profile");
return profile_it == q.end() || !profile_it->value().is_string()
? search_profile::kFoot
: to_profile(profile_it->value().as_string());
}

void handle_route(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb) {
auto const q = boost::json::parse(req.body()).as_object();
auto const profile_it = q.find("profile");
auto const profile =
to_profile(profile_it == q.end() || !profile_it->value().is_string()
? to_str(search_profile::kFoot)
: profile_it->value().as_string());
auto const profile = get_search_profile_from_request(q);
auto const direction_it = q.find("direction");
auto const dir = to_direction(direction_it == q.end() ||
!direction_it->value().is_string()
Expand All @@ -120,29 +127,35 @@ struct http_server::impl {
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 response = json::serialize(
p.has_value()
? boost::json::
value{{"type", "FeatureCollection"},
{"metadata",
{{"duration", p->cost_}, {"distance", p->dist_}}},
{"features",
utl::all(p->segments_) //
|
utl::transform([&](auto&& s) {
return json::value{
if (!p.has_value()) {
cb(json_response(req, "could not find a valid path",
http::status::not_found));
return;
}
cb(json_response(
req,
json::serialize(json::object{
{"type", "FeatureCollection"},
{"metadata", {{"duration", p->cost_}, {"distance", p->dist_}}},
{"features", utl::all(p->segments_) |
utl::transform([&](const path::segment& s) {
return json::object{
{"type", "Feature"},
{"properties",
{{"level", to_float(s.from_level_)},
{"way",
s.way_ == way_idx_t::invalid()
? 0U
: to_idx(w_.way_osm_idx_[s.way_])}}},
{
"properties",
{{"level", to_float(s.from_level_)},
{"osm_way_id",
s.way_ == way_idx_t::invalid()
? 0U
: to_idx(w_.way_osm_idx_[s.way_])},
{"cost", s.cost_},
{"distance", s.dist_},
{"from_node", s.from_node_properties_},
{"to_node", s.to_node_properties_}},
},
{"geometry", to_line_string(s.polyline_)}};
}) //
| utl::emplace_back_to<json::array>()}}
: json::value{{"error", "no path found"}});
return cb(json_response(req, response));
}) |
utl::emplace_back_to<json::array>()}})));
}

void handle_levels(web_server::http_req_t const& req,
Expand Down Expand Up @@ -172,47 +185,51 @@ struct http_server::impl {
void handle_graph(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb) {
auto const query = boost::json::parse(req.body()).as_object();
auto const level = query.contains("level")
? to_level(query.at("level").to_number<float>())
: level_t::invalid();
auto const waypoints = query.at("waypoints").as_array();
auto const profile = get_search_profile_from_request(query);
auto const min = point::from_latlng(
{waypoints[1].as_double(), waypoints[0].as_double()});
auto const max = point::from_latlng(
{waypoints[3].as_double(), waypoints[2].as_double()});

auto gj = geojson_writer{.w_ = w_, .platforms_ = pl_};
l_.find(min, max, [&](way_idx_t const w) {
if (level == level_t::invalid()) {
gj.write_way(w);
return;
}

auto const way_prop = w_.r_->way_properties_[w];
if (way_prop.is_elevator()) {
auto const n = w_.r_->way_nodes_[w][0];
auto const np = w_.r_->node_properties_[n];
if (np.is_multi_level()) {
auto has_level = false;
for_each_set_bit(
foot<true>::get_elevator_multi_levels(*w_.r_, n),
[&](auto&& bit) { has_level |= (level == level_t{bit}); });
if (has_level) {
gj.write_way(w);
return;
}
}
}
auto gj = geojson_writer{.w_ = w_};
l_.find(min, max, [&](way_idx_t const w) { gj.write_way(w); });

switch (profile) {
case search_profile::kFoot:
send_graph_response<foot<false>>(req, cb, gj);
break;
case search_profile::kWheelchair:
send_graph_response<foot<true>>(req, cb, gj);
break;
case search_profile::kBike: send_graph_response<bike>(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);
break;
case search_profile::kCarParkingWheelchair:
send_graph_response<car_parking<true>>(req, cb, gj);
break;
default: throw utl::fail("not implemented");
}
}

if (way_prop.from_level() == level || way_prop.to_level() == level) {
gj.write_way(w);
return;
}
});
gj.finish(&get_dijkstra<foot<true>>());
template <typename Profile>
void send_graph_response(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb,
geojson_writer& gj) {
gj.finish(&get_dijkstra<Profile>());
cb(json_response(req, gj.string()));
}

void handle_static(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb) {
if (!serve_static_files_ ||
!net::serve_static_file(static_file_path_, req, cb)) {
return cb(net::not_found_response(req));
}
}

void handle_platforms(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb) {
utl::verify(pl_ != nullptr, "no platforms");
Expand All @@ -237,14 +254,6 @@ struct http_server::impl {
cb(json_response(req, gj.string()));
}

void handle_static(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb) {
if (!serve_static_files_ ||
!net::serve_static_file(static_file_path_, req, cb)) {
return cb(net::not_found_response(req));
}
}

void handle_request(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb) {
std::cout << "[" << req.method_string() << "] " << req.target() << '\n';
Expand Down Expand Up @@ -348,8 +357,8 @@ struct http_server::impl {
boost::asio::io_context& ioc_;
boost::asio::io_context& thread_pool_;
ways const& w_;
platforms const* pl_;
lookup const& l_;
platforms const* pl_;
web_server server_;
bool serve_static_files_{false};
std::string static_file_path_;
Expand All @@ -358,10 +367,10 @@ struct http_server::impl {
http_server::http_server(boost::asio::io_context& ioc,
boost::asio::io_context& thread_pool,
ways const& w,
platforms const* p,
lookup const& l,
platforms const* pl,
std::string const& static_file_path)
: impl_(new impl(ioc, thread_pool, w, p, l, static_file_path)) {}
: impl_(new impl(ioc, thread_pool, w, l, pl, static_file_path)) {}

http_server::~http_server() = default;

Expand All @@ -371,4 +380,4 @@ void http_server::listen(std::string const& host, std::string const& port) {

void http_server::stop() { impl_->stop(); }

} // namespace osr::backend
} // namespace osr::backend
30 changes: 22 additions & 8 deletions include/osr/extract/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ struct tags {
for (auto const& t : o.tags()) {
switch (cista::hash(std::string_view{t.key()})) {
using namespace std::string_view_literals;
case cista::hash("building"): [[fallthrough]];
case cista::hash("parking"): is_parking_ = true; break;
case cista::hash("amenity"):
is_parking_ |=
(t.value() == "parking"sv || t.value() == "parking_entrance"sv);
break;
case cista::hash("building"):
is_parking_ |= t.value() == "parking"sv;
landuse_ = true;
break;
case cista::hash("landuse"): landuse_ = true; break;
case cista::hash("railway"):
landuse_ |= t.value() == "station_area"sv;
Expand All @@ -31,7 +39,7 @@ struct tags {
break;
case cista::hash("motor_vehicle"):
motor_vehicle_ = t.value();
is_destination_ |= motor_vehicle_ == "destination";
is_destination_ |= motor_vehicle_ == "destination"sv;
break;
case cista::hash("foot"): foot_ = t.value(); break;
case cista::hash("bicycle"): bicycle_ = t.value(); break;
Expand Down Expand Up @@ -166,6 +174,9 @@ struct tags {
// https://wiki.openstreetmap.org/wiki/Key:entrance
bool is_entrance_{false};

// https://wiki.openstreetmap.org/wiki/Tag:amenity%3Dparking
bool is_parking_{false};

// https://wiki.openstreetmap.org/wiki/Key:level
bool has_level_{false};
level_bits_t level_bits_{0U};
Expand Down Expand Up @@ -196,7 +207,7 @@ struct foot_profile {
case cista::hash("designated"): return override::kWhitelist;
}

if (t.is_platform_) {
if (t.is_platform_ || t.is_parking_) {
return override::kWhitelist;
}

Expand All @@ -209,7 +220,7 @@ struct foot_profile {

static bool default_access(tags const& t, osm_obj_type const type) {
if (type == osm_obj_type::kWay) {
if (t.is_elevator_) {
if (t.is_elevator_ || t.is_parking_) {
return true;
}
switch (cista::hash(t.highway_)) {
Expand Down Expand Up @@ -328,18 +339,21 @@ struct car_profile {
case cista::hash("designated"):
case cista::hash("permissive"): [[fallthrough]];
case cista::hash("yes"): return override::kWhitelist;

default: return override::kNone;
}
};

if (auto mv = get_override(t.motor_vehicle_); mv != override::kNone) {
return mv;
} else if (auto mc = get_override(t.motorcar_); mv != override::kNone) {
} else if (auto mc = get_override(t.motorcar_); mc != override::kNone) {
return mc;
} else {
return t.vehicle_;
}

if (t.is_parking_) {
return override::kWhitelist;
}

return t.vehicle_;
}

static bool default_access(tags const& t, osm_obj_type const type) {
Expand Down
Loading

0 comments on commit 670fcd6

Please sign in to comment.