Skip to content

Commit a1127c3

Browse files
author
Moritz Kobitzsch
committed
reduce numbers of intersections in findNextIntersection, don't normalise for turn lanes
1 parent 01a57ff commit a1127c3

17 files changed

+204
-126
lines changed

Diff for: features/guidance/collapse.feature

+11-11
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ Feature: Collapse
338338
Given the node map
339339
"""
340340
a f g
341-
342-
b e
343-
344-
341+
| | . '
342+
b-e '
343+
/ /
344+
/ /
345345
c d
346346
"""
347347

@@ -353,13 +353,13 @@ Feature: Collapse
353353
| ge | primary | second | no |
354354

355355
When I route I should get
356-
| waypoints | route | turns |
357-
| d,c | first,first,first | depart,continue uturn,arrive |
358-
| a,f | first,first,first | depart,continue uturn,arrive |
359-
| a,g | first,second,second | depart,turn left,arrive |
360-
| d,g | first,second,second | depart,turn right,arrive |
361-
| g,f | second,first,first | depart,turn right,arrive |
362-
| g,c | second,first,first | depart,end of road left,arrive |
356+
| waypoints | route | turns |
357+
| d,c | first,first,first | depart,continue uturn,arrive |
358+
| a,f | first,first,first | depart,continue uturn,arrive |
359+
| a,g | first,second,second | depart,turn left,arrive |
360+
| d,g | first,second,second | depart,turn right,arrive |
361+
| g,f | second,first,first | depart,turn right,arrive |
362+
| g,c | second,first,first | depart,turn left,arrive |
363363

364364
Scenario: Do not collapse turning roads
365365
Given the node map

Diff for: include/engine/datafacade/process_memory_datafacade.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
// implements all data storage when shared memory is _NOT_ used
55

6-
#include "engine/datafacade/contiguous_internalmem_datafacade_base.hpp"
76
#include "storage/storage.hpp"
7+
#include "engine/datafacade/contiguous_internalmem_datafacade_base.hpp"
88

99
namespace osrm
1010
{

Diff for: include/extractor/extraction_way.hpp

+27-22
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ namespace extractor
1515
{
1616
namespace detail
1717
{
18-
inline void maybeSetString(std::string &str, const char* value)
18+
inline void maybeSetString(std::string &str, const char *value)
19+
{
20+
if (value == nullptr)
21+
{
22+
str.clear();
23+
}
24+
else
1925
{
20-
if (value == nullptr)
21-
{
22-
str.clear();
23-
}
24-
else
25-
{
26-
str = std::string(value);
27-
}
26+
str = std::string(value);
2827
}
2928
}
30-
29+
}
3130

3231
/**
3332
* This struct is the direct result of the call to ```way_function```
@@ -67,18 +66,24 @@ struct ExtractionWay
6766
TravelMode get_backward_mode() const { return backward_travel_mode; }
6867

6968
// wrappers to allow assigning nil (nullptr) to string values
70-
void SetName(const char* value) { detail::maybeSetString(name, value); }
71-
const char* GetName() const { return name.c_str(); }
72-
void SetRef(const char* value) { detail::maybeSetString(ref, value); }
73-
const char* GetRef() const { return ref.c_str(); }
74-
void SetDestinations(const char* value) { detail::maybeSetString(destinations, value); }
75-
const char* GetDestinations() const { return destinations.c_str(); }
76-
void SetPronunciation(const char* value) { detail::maybeSetString(pronunciation, value); }
77-
const char* GetPronunciation() const { return pronunciation.c_str(); }
78-
void SetTurnLanesForward(const char* value) { detail::maybeSetString(turn_lanes_forward, value); }
79-
const char* GetTurnLanesForward() const { return turn_lanes_forward.c_str(); }
80-
void SetTurnLanesBackward(const char* value) { detail::maybeSetString(turn_lanes_backward, value); }
81-
const char* GetTurnLanesBackward() const { return turn_lanes_backward.c_str(); }
69+
void SetName(const char *value) { detail::maybeSetString(name, value); }
70+
const char *GetName() const { return name.c_str(); }
71+
void SetRef(const char *value) { detail::maybeSetString(ref, value); }
72+
const char *GetRef() const { return ref.c_str(); }
73+
void SetDestinations(const char *value) { detail::maybeSetString(destinations, value); }
74+
const char *GetDestinations() const { return destinations.c_str(); }
75+
void SetPronunciation(const char *value) { detail::maybeSetString(pronunciation, value); }
76+
const char *GetPronunciation() const { return pronunciation.c_str(); }
77+
void SetTurnLanesForward(const char *value)
78+
{
79+
detail::maybeSetString(turn_lanes_forward, value);
80+
}
81+
const char *GetTurnLanesForward() const { return turn_lanes_forward.c_str(); }
82+
void SetTurnLanesBackward(const char *value)
83+
{
84+
detail::maybeSetString(turn_lanes_backward, value);
85+
}
86+
const char *GetTurnLanesBackward() const { return turn_lanes_backward.c_str(); }
8287

8388
double forward_speed;
8489
double backward_speed;

Diff for: include/extractor/guidance/coordinate_extractor.hpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef OSRM_EXTRACTOR_COORDINATE_EXTRACTOR_HPP_
22
#define OSRM_EXTRACTOR_COORDINATE_EXTRACTOR_HPP_
33

4+
#include <utility>
45
#include <vector>
56

67
#include "extractor/compressed_edge_container.hpp"
@@ -28,6 +29,7 @@ class CoordinateExtractor
2829
/* Find a interpolated coordinate a long the compressed geometries. The desired coordinate
2930
* should be in a certain distance. This method is dedicated to find representative coordinates
3031
* at turns.
32+
* Since we are computing the length of the segment anyhow, we also return it.
3133
*/
3234
OSRM_ATTR_WARN_UNUSED
3335
util::Coordinate GetCoordinateAlongRoad(const NodeID intersection_node,
@@ -36,12 +38,23 @@ class CoordinateExtractor
3638
const NodeID to_node,
3739
const std::uint8_t number_of_in_lanes) const;
3840

39-
// instead of finding only a single coordinate, we can also list all coordinates along a road.
41+
// same as above, only with precomputed coordinate vector (move it in)
4042
OSRM_ATTR_WARN_UNUSED
41-
std::vector<util::Coordinate> GetCoordinatesAlongRoad(const NodeID intersection_node,
42-
const EdgeID turn_edge,
43-
const bool traversed_in_reverse,
44-
const NodeID to_node) const;
43+
util::Coordinate
44+
ExtractRepresentativeCoordinate(const NodeID intersection_node,
45+
const EdgeID turn_edge,
46+
const bool traversed_in_reverse,
47+
const NodeID to_node,
48+
const std::uint8_t intersection_lanes,
49+
std::vector<util::Coordinate> coordinates) const;
50+
51+
// instead of finding only a single coordinate, we can also list all coordinates along a
52+
// road.
53+
OSRM_ATTR_WARN_UNUSED std::vector<util::Coordinate>
54+
GetCoordinatesAlongRoad(const NodeID intersection_node,
55+
const EdgeID turn_edge,
56+
const bool traversed_in_reverse,
57+
const NodeID to_node) const;
4558

4659
// wrapper in case of normal forward edges (traversed_in_reverse = false, to_node =
4760
// node_based_graph.GetTarget(turn_edge)

Diff for: include/extractor/guidance/intersection.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "util/node_based_graph.hpp"
1010
#include "util/typedefs.hpp" // EdgeID
1111

12+
#include <boost/optional.hpp>
13+
1214
namespace osrm
1315
{
1416
namespace extractor
@@ -53,10 +55,13 @@ struct ConnectedRoad final : public TurnOperation
5355
{
5456
using Base = TurnOperation;
5557

56-
ConnectedRoad(const TurnOperation turn, const bool entry_allowed = false);
58+
ConnectedRoad(const TurnOperation turn,
59+
const bool entry_allowed = false,
60+
const boost::optional<double> segment_length = {});
5761

5862
// a turn may be relevant to good instructions, even if we cannot enter the road
5963
bool entry_allowed;
64+
boost::optional<double> segment_length;
6065

6166
// used to sort the set of connected roads (we require sorting throughout turn handling)
6267
bool compareByAngle(const ConnectedRoad &other) const;

Diff for: include/extractor/guidance/turn_analysis.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class TurnAnalysis
6868
std::vector<TurnOperation>
6969
transformIntersectionIntoTurns(const Intersection &intersection) const;
7070

71+
Intersection
72+
assignTurnTypes(const NodeID from_node, const EdgeID via_eid, Intersection intersection) const;
73+
7174
const IntersectionGenerator &GetIntersectionGenerator() const;
7275

7376
private:
@@ -79,9 +82,6 @@ class TurnAnalysis
7982
const TurnHandler turn_handler;
8083
const SliproadHandler sliproad_handler;
8184

82-
Intersection
83-
assignTurnTypes(const NodeID from_node, const EdgeID via_eid, Intersection intersection) const;
84-
8585
// Utility function, setting basic turn types. Prepares for normal turn handling.
8686
Intersection
8787
setTurnTypes(const NodeID from, const EdgeID via_edge, Intersection intersection) const;

Diff for: include/extractor/guidance/turn_discovery.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace lanes
2222
bool findPreviousIntersection(
2323
const NodeID node,
2424
const EdgeID via_edge,
25-
const Intersection intersection,
25+
const Intersection &intersection,
2626
const IntersectionGenerator &intersection_generator,
2727
const util::NodeBasedDynamicGraph &node_based_graph, // query edge data
2828
// output parameters, will be in an arbitrary state on failure

Diff for: include/storage/shared_datatype.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ struct DataLayout
134134
// Interface Similar to [ptr.align] but omits space computation.
135135
// The method can be removed and changed directly to an std::align
136136
// function call after dropping gcc < 5 support.
137-
inline void* align(std::size_t align, std::size_t , void*& ptr) const noexcept
137+
inline void *align(std::size_t align, std::size_t, void *&ptr) const noexcept
138138
{
139139
const auto intptr = reinterpret_cast<uintptr_t>(ptr);
140140
const auto aligned = (intptr - 1u + align) & -align;
141-
return ptr = reinterpret_cast<void*>(aligned);
141+
return ptr = reinterpret_cast<void *>(aligned);
142142
}
143143

144144
inline void *GetAlignedBlockPtr(void *ptr, BlockID bid) const

Diff for: src/engine/plugins/match.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#include <string>
2020
#include <vector>
2121

22-
static double search_radius_for_gps_radius(double gps_radius) {
22+
static double search_radius_for_gps_radius(double gps_radius)
23+
{
2324
// For a given GPS radius, determine the radius we need to search for candidate street segments
2425
// to have a 99.9% chance of finding the correct segment.
2526
// For more detail, see the analysis at https://github.com/Project-OSRM/osrm-backend/pull/3184

Diff for: src/extractor/guidance/coordinate_extractor.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,29 @@ CoordinateExtractor::GetCoordinateAlongRoad(const NodeID intersection_node,
5656
const NodeID to_node,
5757
const std::uint8_t intersection_lanes) const
5858
{
59-
const auto considered_lanes =
60-
(intersection_lanes == 0) ? ASSUMED_LANE_COUNT : intersection_lanes;
61-
6259
// we first extract all coordinates from the road
6360
auto coordinates =
6461
GetCoordinatesAlongRoad(intersection_node, turn_edge, traversed_in_reverse, to_node);
6562

63+
return ExtractRepresentativeCoordinate(intersection_node,
64+
turn_edge,
65+
traversed_in_reverse,
66+
to_node,
67+
intersection_lanes,
68+
std::move(coordinates));
69+
}
70+
71+
util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate(
72+
const NodeID intersection_node,
73+
const EdgeID turn_edge,
74+
const bool traversed_in_reverse,
75+
const NodeID to_node,
76+
const std::uint8_t intersection_lanes,
77+
std::vector<util::Coordinate> coordinates) const
78+
{
79+
const auto considered_lanes =
80+
(intersection_lanes == 0) ? ASSUMED_LANE_COUNT : intersection_lanes;
81+
6682
/* if we are looking at a straight line, we don't care where exactly the coordinate
6783
* is. Simply return the final coordinate. Turn angles/turn vectors are the same no matter which
6884
* coordinate we look at.
@@ -406,10 +422,12 @@ CoordinateExtractor::GetCoordinatesAlongRoad(const NodeID intersection_node,
406422
geometry.rend(),
407423
std::back_inserter(result),
408424
compressedGeometryToCoordinate);
425+
BOOST_ASSERT(intersection_node < node_coordinates.size());
409426
result.push_back(node_coordinates[intersection_node]);
410427
}
411428
else
412429
{
430+
BOOST_ASSERT(intersection_node < node_coordinates.size());
413431
result.push_back(node_coordinates[intersection_node]);
414432
std::transform(geometry.begin(),
415433
geometry.end(),

Diff for: src/extractor/guidance/intersection.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ namespace extractor
1717
namespace guidance
1818
{
1919

20-
ConnectedRoad::ConnectedRoad(const TurnOperation turn, const bool entry_allowed)
21-
: TurnOperation(turn), entry_allowed(entry_allowed)
20+
ConnectedRoad::ConnectedRoad(const TurnOperation turn,
21+
const bool entry_allowed,
22+
boost::optional<double> segment_length)
23+
: TurnOperation(turn), entry_allowed(entry_allowed), segment_length(segment_length)
2224
{
2325
}
2426

0 commit comments

Comments
 (0)