Skip to content

Commit 7ebd21f

Browse files
mattwigwaymjjbell
andauthored
pass flags into process_segment (#6658)
* pass flags into process_segment --------- Co-authored-by: Michael Bell <michael@mjjbell.com>
1 parent 8ef366e commit 7ebd21f

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- ADDED: Add support for a default_radius flag. [#6575](https://github.com/Project-OSRM/osrm-backend/pull/6575)
66
- ADDED: Add support for disabling feature datasets. [#6666](https://github.com/Project-OSRM/osrm-backend/pull/6666)
77
- ADDED: Add support for opposite approach request parameter. [#6842](https://github.com/Project-OSRM/osrm-backend/pull/6842)
8+
- ADDED: Add support for accessing edge flags in `process_segment` [#6658](https://github.com/Project-OSRM/osrm-backend/pull/6658)
89
- Build:
910
- ADDED: Add CI job which builds OSRM with gcc 12. [#6455](https://github.com/Project-OSRM/osrm-backend/pull/6455)
1011
- CHANGED: Upgrade to clang-tidy 15. [#6439](https://github.com/Project-OSRM/osrm-backend/pull/6439)

features/options/extract/lua.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,27 @@ Feature: osrm-extract lua ways:get_nodes()
154154
Then it should exit successfully
155155
And stdout should contain "node 42"
156156
And stdout should contain "way 42"
157+
158+
Scenario: osrm-extract flags accessible in process_segment function
159+
Given the profile file
160+
"""
161+
functions = require('testbot')
162+
163+
functions.process_segment = function (profile, segment)
164+
print('segment forward ' .. tostring(segment.flags.forward) .. ' backward ' .. tostring(segment.flags.backward))
165+
end
166+
167+
return functions
168+
"""
169+
170+
And the node map
171+
"""
172+
a b
173+
"""
174+
And the ways
175+
| nodes | oneway |
176+
| ab | yes |
177+
And the data has been saved to disk
178+
When I run "osrm-extract --profile {profile_file} {osm_file}"
179+
Then it should exit successfully
180+
And stdout should contain "segment forward true backward false"

include/extractor/extraction_segment.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef OSRM_EXTRACTION_SEGMENT_HPP
22
#define OSRM_EXTRACTION_SEGMENT_HPP
33

4+
#include <extractor/node_based_edge.hpp>
45
#include <util/coordinate.hpp>
56

67
namespace osrm::extractor
@@ -12,9 +13,10 @@ struct ExtractionSegment
1213
const osrm::util::Coordinate target_,
1314
double distance_,
1415
double weight_,
15-
double duration_)
16+
double duration_,
17+
const NodeBasedEdgeClassification flags_)
1618
: source(source_), target(target_), distance(distance_), weight(weight_),
17-
duration(duration_)
19+
duration(duration_), flags(flags_)
1820
{
1921
}
2022

@@ -23,6 +25,7 @@ struct ExtractionSegment
2325
const double distance;
2426
double weight;
2527
double duration;
28+
const NodeBasedEdgeClassification flags;
2629
};
2730
} // namespace osrm::extractor
2831

src/extractor/extraction_containers.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,12 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm
706706
const auto accurate_distance =
707707
util::coordinate_calculation::greatCircleDistance(source_coord, target_coord);
708708

709-
ExtractionSegment segment(source_coord, target_coord, distance, weight, duration);
709+
ExtractionSegment segment(source_coord,
710+
target_coord,
711+
distance,
712+
weight,
713+
duration,
714+
edge_iterator->result.flags);
710715
scripting_environment.ProcessSegment(segment);
711716

712717
auto &edge = edge_iterator->result;

src/extractor/scripting_environment_lua.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,36 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
471471
[](ExtractionRelationContainer &cont, const ExtractionRelation::OsmIDTyped &rel_id)
472472
-> const ExtractionRelation & { return cont.GetRelationData(rel_id); });
473473

474+
context.state.new_usertype<NodeBasedEdgeClassification>(
475+
"NodeBasedEdgeClassification",
476+
"forward",
477+
// can't just do &NodeBasedEdgeClassification::forward with bitfields
478+
sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.forward; }),
479+
"backward",
480+
sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.backward; }),
481+
"is_split",
482+
sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.is_split; }),
483+
"roundabout",
484+
sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.roundabout; }),
485+
"circular",
486+
sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.circular; }),
487+
"startpoint",
488+
sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.startpoint; }),
489+
"restricted",
490+
sol::property([](NodeBasedEdgeClassification &c) -> bool { return c.restricted; }),
491+
"road_classification",
492+
sol::property([](NodeBasedEdgeClassification &c) -> RoadClassification {
493+
return c.road_classification;
494+
}),
495+
"highway_turn_classification",
496+
sol::property([](NodeBasedEdgeClassification &c) -> uint8_t {
497+
return c.highway_turn_classification;
498+
}),
499+
"access_turn_classification",
500+
sol::property([](NodeBasedEdgeClassification &c) -> uint8_t {
501+
return c.access_turn_classification;
502+
}));
503+
474504
context.state.new_usertype<ExtractionSegment>("ExtractionSegment",
475505
"source",
476506
&ExtractionSegment::source,
@@ -481,7 +511,9 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
481511
"weight",
482512
&ExtractionSegment::weight,
483513
"duration",
484-
&ExtractionSegment::duration);
514+
&ExtractionSegment::duration,
515+
"flags",
516+
&ExtractionSegment::flags);
485517

486518
// Keep in mind .location is available only if .pbf is preprocessed to set the location with the
487519
// ref using osmium command "osmium add-locations-to-ways"

0 commit comments

Comments
 (0)