From 7ebd21f39e32640e0d40b893d228350f218085ad Mon Sep 17 00:00:00 2001 From: Matthew Wigginton Bhagat-Conway Date: Sat, 6 Apr 2024 04:27:42 -0400 Subject: [PATCH] pass flags into process_segment (#6658) * pass flags into process_segment --------- Co-authored-by: Michael Bell --- CHANGELOG.md | 1 + features/options/extract/lua.feature | 24 +++++++++++++++ include/extractor/extraction_segment.hpp | 7 +++-- src/extractor/extraction_containers.cpp | 7 ++++- src/extractor/scripting_environment_lua.cpp | 34 ++++++++++++++++++++- 5 files changed, 69 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51ea16359..df6171707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - ADDED: Add support for a default_radius flag. [#6575](https://github.com/Project-OSRM/osrm-backend/pull/6575) - ADDED: Add support for disabling feature datasets. [#6666](https://github.com/Project-OSRM/osrm-backend/pull/6666) - ADDED: Add support for opposite approach request parameter. [#6842](https://github.com/Project-OSRM/osrm-backend/pull/6842) + - ADDED: Add support for accessing edge flags in `process_segment` [#6658](https://github.com/Project-OSRM/osrm-backend/pull/6658) - Build: - ADDED: Add CI job which builds OSRM with gcc 12. [#6455](https://github.com/Project-OSRM/osrm-backend/pull/6455) - CHANGED: Upgrade to clang-tidy 15. [#6439](https://github.com/Project-OSRM/osrm-backend/pull/6439) diff --git a/features/options/extract/lua.feature b/features/options/extract/lua.feature index c238cde61..e886d7102 100644 --- a/features/options/extract/lua.feature +++ b/features/options/extract/lua.feature @@ -154,3 +154,27 @@ Feature: osrm-extract lua ways:get_nodes() Then it should exit successfully And stdout should contain "node 42" And stdout should contain "way 42" + + Scenario: osrm-extract flags accessible in process_segment function + Given the profile file + """ + functions = require('testbot') + + functions.process_segment = function (profile, segment) + print('segment forward ' .. tostring(segment.flags.forward) .. ' backward ' .. tostring(segment.flags.backward)) + end + + return functions + """ + + And the node map + """ + a b + """ + And the ways + | nodes | oneway | + | ab | yes | + And the data has been saved to disk + When I run "osrm-extract --profile {profile_file} {osm_file}" + Then it should exit successfully + And stdout should contain "segment forward true backward false" diff --git a/include/extractor/extraction_segment.hpp b/include/extractor/extraction_segment.hpp index f6bda5e48..ce646685e 100644 --- a/include/extractor/extraction_segment.hpp +++ b/include/extractor/extraction_segment.hpp @@ -1,6 +1,7 @@ #ifndef OSRM_EXTRACTION_SEGMENT_HPP #define OSRM_EXTRACTION_SEGMENT_HPP +#include #include namespace osrm::extractor @@ -12,9 +13,10 @@ struct ExtractionSegment const osrm::util::Coordinate target_, double distance_, double weight_, - double duration_) + double duration_, + const NodeBasedEdgeClassification flags_) : source(source_), target(target_), distance(distance_), weight(weight_), - duration(duration_) + duration(duration_), flags(flags_) { } @@ -23,6 +25,7 @@ struct ExtractionSegment const double distance; double weight; double duration; + const NodeBasedEdgeClassification flags; }; } // namespace osrm::extractor diff --git a/src/extractor/extraction_containers.cpp b/src/extractor/extraction_containers.cpp index d75122d48..ab8e74ad3 100644 --- a/src/extractor/extraction_containers.cpp +++ b/src/extractor/extraction_containers.cpp @@ -706,7 +706,12 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm const auto accurate_distance = util::coordinate_calculation::greatCircleDistance(source_coord, target_coord); - ExtractionSegment segment(source_coord, target_coord, distance, weight, duration); + ExtractionSegment segment(source_coord, + target_coord, + distance, + weight, + duration, + edge_iterator->result.flags); scripting_environment.ProcessSegment(segment); auto &edge = edge_iterator->result; diff --git a/src/extractor/scripting_environment_lua.cpp b/src/extractor/scripting_environment_lua.cpp index 9576cc18b..0521ce15f 100644 --- a/src/extractor/scripting_environment_lua.cpp +++ b/src/extractor/scripting_environment_lua.cpp @@ -471,6 +471,36 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) [](ExtractionRelationContainer &cont, const ExtractionRelation::OsmIDTyped &rel_id) -> const ExtractionRelation & { return cont.GetRelationData(rel_id); }); + context.state.new_usertype( + "NodeBasedEdgeClassification", + "forward", + // can't just do &NodeBasedEdgeClassification::forward with bitfields + sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.forward; }), + "backward", + sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.backward; }), + "is_split", + sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.is_split; }), + "roundabout", + sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.roundabout; }), + "circular", + sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.circular; }), + "startpoint", + sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.startpoint; }), + "restricted", + sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.restricted; }), + "road_classification", + sol::property([](NodeBasedEdgeClassification &c) -> RoadClassification { + return c.road_classification; + }), + "highway_turn_classification", + sol::property([](NodeBasedEdgeClassification &c) -> uint8_t { + return c.highway_turn_classification; + }), + "access_turn_classification", + sol::property([](NodeBasedEdgeClassification &c) -> uint8_t { + return c.access_turn_classification; + })); + context.state.new_usertype("ExtractionSegment", "source", &ExtractionSegment::source, @@ -481,7 +511,9 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "weight", &ExtractionSegment::weight, "duration", - &ExtractionSegment::duration); + &ExtractionSegment::duration, + "flags", + &ExtractionSegment::flags); // Keep in mind .location is available only if .pbf is preprocessed to set the location with the // ref using osmium command "osmium add-locations-to-ways"