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

pass flags into process_segment #6658

Merged
merged 6 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions features/options/extract/lua.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 5 additions & 2 deletions include/extractor/extraction_segment.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef OSRM_EXTRACTION_SEGMENT_HPP
#define OSRM_EXTRACTION_SEGMENT_HPP

#include <extractor/node_based_edge.hpp>
#include <util/coordinate.hpp>

namespace osrm::extractor
Expand All @@ -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_)
{
}

Expand All @@ -23,6 +25,7 @@ struct ExtractionSegment
const double distance;
double weight;
double duration;
const NodeBasedEdgeClassification flags;
};
} // namespace osrm::extractor

Expand Down
7 changes: 6 additions & 1 deletion src/extractor/extraction_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 33 additions & 1 deletion src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
"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>("ExtractionSegment",
"source",
&ExtractionSegment::source,
Expand All @@ -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"
Expand Down
Loading