Skip to content

Commit d1f1358

Browse files
author
Moritz Kobitzsch
committed
adjust for comments by daniel-j-h
1 parent 805d939 commit d1f1358

File tree

8 files changed

+179
-161
lines changed

8 files changed

+179
-161
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- Bugfixes
1111
- fixed a bug where polyline decoding on a defective polyline could end up in out-of-bound access on a vector
1212
- fixed compile errors in tile unit-test framework
13+
- Debug Tiles
14+
- Added support for turn penalties
1315

1416
# 5.4.0
1517
- Changes from 5.3.0

include/engine/edge_unpacker.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include "util/guidance/turn_lanes.hpp"
99
#include "util/typedefs.hpp"
1010

11-
#include <vector>
1211
#include <stack>
12+
#include <vector>
1313

1414
namespace osrm
1515
{
@@ -37,16 +37,19 @@ namespace engine
3737
* original edge found.
3838
*/
3939

40-
template <typename DataFacadeT, typename RandomIter, typename Callback>
41-
inline void UnpackCHEdge(DataFacadeT *facade,
42-
RandomIter packed_path_begin,
43-
RandomIter packed_path_end,
44-
const Callback &callback)
40+
template <typename DataFacadeT, typename BidirectionalIterator, typename Callback>
41+
inline void UnpackCHPath(const DataFacadeT &facade,
42+
BidirectionalIterator packed_path_begin,
43+
BidirectionalIterator packed_path_end,
44+
Callback &&callback)
4545
{
46+
// make sure we have at least something to unpack
47+
if( packed_path_begin == packed_path_end )
48+
return;
4649

4750
using EdgeData = typename DataFacadeT::EdgeData;
4851

49-
std::stack<std::pair<NodeID, NodeID>> recursion_stack;
52+
std::stack<std::pair<NodeID,NodeID>> recursion_stack;
5053

5154
// We have to push the path in reverse order onto the stack because it's LIFO.
5255
for (auto current = std::prev(packed_path_end); current != packed_path_begin;
@@ -62,23 +65,23 @@ inline void UnpackCHEdge(DataFacadeT *facade,
6265
recursion_stack.pop();
6366

6467
// Look for an edge on the forward CH graph (.forward)
65-
EdgeID smaller_edge_id = facade->FindSmallestEdge(
68+
EdgeID smaller_edge_id = facade.FindSmallestEdge(
6669
edge.first, edge.second, [](const EdgeData &data) { return data.forward; });
6770

6871
// If we didn't find one there, the we might be looking at a part of the path that
6972
// was found using the backward search. Here, we flip the node order (.second, .first)
7073
// and only consider edges with the `.backward` flag.
7174
if (SPECIAL_EDGEID == smaller_edge_id)
7275
{
73-
smaller_edge_id = facade->FindSmallestEdge(
76+
smaller_edge_id = facade.FindSmallestEdge(
7477
edge.second, edge.first, [](const EdgeData &data) { return data.backward; });
7578
}
7679

7780
// If we didn't find anything *still*, then something is broken and someone has
7881
// called this function with bad values.
7982
BOOST_ASSERT_MSG(smaller_edge_id != SPECIAL_EDGEID, "Invalid smaller edge ID");
8083

81-
const auto &data = facade->GetEdgeData(smaller_edge_id);
84+
const auto &data = facade.GetEdgeData(smaller_edge_id);
8285
BOOST_ASSERT_MSG(data.distance != std::numeric_limits<EdgeWeight>::max(),
8386
"edge weight invalid");
8487

@@ -94,7 +97,7 @@ inline void UnpackCHEdge(DataFacadeT *facade,
9497
else
9598
{
9699
// We found an original edge, call our callback.
97-
callback(edge, data);
100+
std::forward<Callback>(callback)(edge, data);
98101
}
99102
}
100103
}

include/engine/routing_algorithms/routing_base.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -229,26 +229,26 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
229229
*std::prev(packed_path_end) == phantom_node_pair.target_phantom.forward_segment_id.id ||
230230
*std::prev(packed_path_end) == phantom_node_pair.target_phantom.reverse_segment_id.id);
231231

232-
UnpackCHEdge(
233-
facade,
232+
UnpackCHPath(
233+
*facade,
234234
packed_path_begin,
235235
packed_path_end,
236236
[this,
237237
&unpacked_path,
238238
&phantom_node_pair,
239239
&start_traversed_in_reverse,
240240
&target_traversed_in_reverse](std::pair<NodeID, NodeID> & /* edge */,
241-
const EdgeData &data) {
241+
const EdgeData &edge_data) {
242242

243-
BOOST_ASSERT_MSG(!data.shortcut, "original edge flagged as shortcut");
244-
unsigned name_index = facade->GetNameIndexFromEdgeID(data.id);
245-
const auto turn_instruction = facade->GetTurnInstructionForEdgeID(data.id);
243+
BOOST_ASSERT_MSG(!edge_data.shortcut, "original edge flagged as shortcut");
244+
const auto name_index = facade->GetNameIndexFromEdgeID(edge_data.id);
245+
const auto turn_instruction = facade->GetTurnInstructionForEdgeID(edge_data.id);
246246
const extractor::TravelMode travel_mode =
247247
(unpacked_path.empty() && start_traversed_in_reverse)
248248
? phantom_node_pair.source_phantom.backward_travel_mode
249-
: facade->GetTravelModeForEdgeID(data.id);
249+
: facade->GetTravelModeForEdgeID(edge_data.id);
250250

251-
const auto geometry_index = facade->GetGeometryIndexForEdgeID(data.id);
251+
const auto geometry_index = facade->GetGeometryIndexForEdgeID(edge_data.id);
252252
std::vector<NodeID> id_vector;
253253
facade->GetUncompressedGeometry(geometry_index, id_vector);
254254
BOOST_ASSERT(id_vector.size() > 0);
@@ -260,7 +260,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
260260
std::vector<DatasourceID> datasource_vector;
261261
facade->GetUncompressedDatasources(geometry_index, datasource_vector);
262262

263-
auto total_weight = std::accumulate(weight_vector.begin(), weight_vector.end(), 0);
263+
const auto total_weight = std::accumulate(weight_vector.begin(), weight_vector.end(), 0);
264264

265265
BOOST_ASSERT(weight_vector.size() == id_vector.size());
266266
const bool is_first_segment = unpacked_path.empty();
@@ -289,12 +289,12 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
289289
datasource_vector[i]});
290290
}
291291
BOOST_ASSERT(unpacked_path.size() > 0);
292-
if (facade->hasLaneData(data.id))
293-
unpacked_path.back().lane_data = facade->GetLaneData(data.id);
292+
if (facade->hasLaneData(edge_data.id))
293+
unpacked_path.back().lane_data = facade->GetLaneData(edge_data.id);
294294

295-
unpacked_path.back().entry_classid = facade->GetEntryClassID(data.id);
295+
unpacked_path.back().entry_classid = facade->GetEntryClassID(edge_data.id);
296296
unpacked_path.back().turn_instruction = turn_instruction;
297-
unpacked_path.back().duration_until_turn += (data.distance - total_weight);
297+
unpacked_path.back().duration_until_turn += (edge_data.distance - total_weight);
298298
});
299299

300300
std::size_t start_index = 0, end_index = 0;
@@ -415,8 +415,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
415415
void UnpackEdge(const NodeID from, const NodeID to, std::vector<NodeID> &unpacked_path) const
416416
{
417417
std::array<NodeID, 2> path{{from, to}};
418-
UnpackCHEdge(
419-
facade,
418+
UnpackCHPath(
419+
*facade,
420420
path.begin(),
421421
path.end(),
422422
[&unpacked_path](const std::pair<NodeID, NodeID> &edge, const EdgeData & /* data */) {

include/util/static_graph.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
160160
* matching edge is found.
161161
*/
162162
template <typename FilterFunction>
163-
EdgeIterator FindSmallestEdge(const NodeIterator from,
164-
const NodeIterator to,
165-
const FilterFunction filter) const
163+
EdgeIterator
164+
FindSmallestEdge(const NodeIterator from, const NodeIterator to, FilterFunction &&filter) const
166165
{
167166
EdgeIterator smallest_edge = SPECIAL_EDGEID;
168167
EdgeWeight smallest_weight = INVALID_EDGE_WEIGHT;
169168
for (auto edge : GetAdjacentEdgeRange(from))
170169
{
171170
const NodeID target = GetTarget(edge);
172-
const auto data = GetEdgeData(edge);
173-
if (target == to && data.distance < smallest_weight && filter(data))
171+
const auto &data = GetEdgeData(edge);
172+
if (target == to && data.distance < smallest_weight &&
173+
std::forward<FilterFunction>(filter)(data))
174174
{
175175
smallest_edge = edge;
176176
smallest_weight = data.distance;

include/util/typedefs.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::m
8585

8686
using DatasourceID = std::uint8_t;
8787

88-
using DatasourceID = std::uint8_t;
89-
9088
struct SegmentID
9189
{
9290
SegmentID(const NodeID id_, const bool enabled_) : id{id_}, enabled{enabled_}

include/util/vector_tile.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@ namespace util
1010
namespace vector_tile
1111
{
1212

13-
const constexpr std::uint32_t LAYER_TAG = 3;
13+
const constexpr std::uint32_t ID_TAG = 1;
1414
const constexpr std::uint32_t NAME_TAG = 1;
15-
const constexpr std::uint32_t VERSION_TAG = 15;
16-
const constexpr std::uint32_t EXTENT_TAG = 5;
1715
const constexpr std::uint32_t FEATURE_TAG = 2;
16+
const constexpr std::uint32_t LAYER_TAG = 3;
1817
const constexpr std::uint32_t GEOMETRY_TAG = 3;
19-
const constexpr std::uint32_t VARIANT_TAG = 4;
2018
const constexpr std::uint32_t KEY_TAG = 3;
21-
const constexpr std::uint32_t ID_TAG = 1;
22-
const constexpr std::uint32_t GEOMETRY_TYPE_POINT = 1;
23-
const constexpr std::uint32_t GEOMETRY_TYPE_LINE = 2;
19+
const constexpr std::uint32_t VARIANT_TAG = 4;
20+
const constexpr std::uint32_t EXTENT_TAG = 5;
21+
const constexpr std::uint32_t VERSION_TAG = 15;
22+
2423
const constexpr std::uint32_t FEATURE_ATTRIBUTES_TAG = 2;
2524
const constexpr std::uint32_t FEATURE_GEOMETRIES_TAG = 4;
25+
26+
const constexpr std::uint32_t GEOMETRY_TYPE_POINT = 1;
27+
const constexpr std::uint32_t GEOMETRY_TYPE_LINE = 2;
28+
29+
const constexpr std::uint32_t VARIANT_TYPE_STRING = 1;
30+
const constexpr std::uint32_t VARIANT_TYPE_FLOAT = 2;
31+
const constexpr std::uint32_t VARIANT_TYPE_DOUBLE = 3;
32+
2633
const constexpr std::uint32_t VARIANT_TYPE_UINT64 = 5;
2734
const constexpr std::uint32_t VARIANT_TYPE_SINT64 = 6;
2835
const constexpr std::uint32_t VARIANT_TYPE_BOOL = 7;
29-
const constexpr std::uint32_t VARIANT_TYPE_STRING = 1;
30-
const constexpr std::uint32_t VARIANT_TYPE_DOUBLE = 3;
31-
const constexpr std::uint32_t VARIANT_TYPE_FLOAT = 2;
3236

3337
// Vector tiles are 4096 virtual pixels on each side
3438
const constexpr double EXTENT = 4096.0;

0 commit comments

Comments
 (0)