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

Include 'rate' property (reciprocal of weight) on debug tile edges. #4162

Merged
merged 4 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -20,6 +20,7 @@
- #4075 Changed counting of exits on service roundabouts
- Debug Tiles
- added support for visualising turn penalties to the MLD plugin
- added support for showing the rate (reciprocal of weight) on each edge when used
- Bugfixes
- Fixed a copy/paste issue assigning wrong directions in similar turns (left over right)
- #4074: fixed a bug that would announce entering highway ramps as u-turns
Expand Down
34 changes: 34 additions & 0 deletions src/engine/plugins/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
const auto &edge = edges[edge_index];
const auto geometry_id = get_geometry_id(edge);

// Get coordinates for start/end nodes of segment (NodeIDs u and v)
const auto a = facade.GetCoordinateOfNode(edge.u);
const auto b = facade.GetCoordinateOfNode(edge.v);
// Calculate the length in meters
const double length = osrm::util::coordinate_calculation::haversineDistance(a, b);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when trying to refactor this I thought about this line a bit. It adds some overhead for calculating the distances. Whats is you opinion here @danpat on the potential slowdown? I feel it might be alright, but I am not entirely sure. (This length calculation is already happening further down as well)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super-concerned about performance for things like this - unless there's a really easy way to refactor it, I'm inclined to just eat the cost. If https://github.com/mapbox/vector-tile ever grows encoding ability, we could do a big refactor and clean up stuff like that. Until then, I'm totally OK with there being some technical debt here.


// Weight values
const auto forward_weight_vector =
facade.GetUncompressedForwardWeights(geometry_id);
Expand All @@ -439,6 +445,14 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
use_line_value(forward_weight);
use_line_value(reverse_weight);

std::uint32_t forward_rate =
static_cast<std::uint32_t>(round(length / forward_weight * 10.));
std::uint32_t reverse_rate =
static_cast<std::uint32_t>(round(length / reverse_weight * 10.));

use_line_value(forward_rate);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like storing it as int as well here. My first intuition was to store it as double.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - Mapbox GL does some ugly formatting on floats mapbox/mapbox-gl-js#3358, so some of the reasoning for using ints vs doubles in this tile encoder is driven by rendering ugliness :-(

use_line_value(reverse_rate);

// Duration values
const auto forward_duration_vector =
facade.GetUncompressedForwardDurations(geometry_id);
Expand Down Expand Up @@ -518,6 +532,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
&max_datasource_id,
&used_line_ints](const FixedLine &tile_line,
const std::uint32_t speed_kmh,
const std::uint32_t rate,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you feel about making clearer that all of these are offsets? The first time I though these were supposed to be actual values (like the speed is, since we store all 127 possible values).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a vector tile encoding gotcha - I agree, it's a bit unintuitive if you haven't read the spec. I'll rename these, now is as good a time as any.

const std::size_t weight,
const std::size_t duration,
const DatasourceID datasource,
Expand Down Expand Up @@ -564,6 +579,10 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &

field.add_element(130 + max_datasource_id + 1 + used_line_ints.size() +
name_idx); // name value offset

field.add_element(6); // rate tag key offset
field.add_element(130 + max_datasource_id + 1 +
rate); // rate goes in used_line_ints
}
{

Expand All @@ -584,11 +603,18 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
std::uint32_t speed_kmh =
static_cast<std::uint32_t>(round(length / forward_duration * 10 * 3.6));

// Rate values are in meters per weight-unit - and similar to speeds, we
// present 1 decimal place of precision (these values are added as
// double/10) lower down
std::uint32_t rate =
static_cast<std::uint32_t>(round(length / forward_weight * 10.));

auto tile_line = coordinatesToTileLine(a, b, tile_bbox);
if (!tile_line.empty())
{
encode_tile_line(tile_line,
speed_kmh,
rate,
line_int_offsets[forward_weight],
line_int_offsets[forward_duration],
forward_datasource,
Expand All @@ -609,11 +635,18 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
std::uint32_t speed_kmh =
static_cast<std::uint32_t>(round(length / reverse_duration * 10 * 3.6));

// Rate values are in meters per weight-unit - and similar to speeds, we
// present 1 decimal place of precision (these values are added as
// double/10) lower down
std::uint32_t rate =
static_cast<std::uint32_t>(round(length / reverse_weight * 10.));

auto tile_line = coordinatesToTileLine(b, a, tile_bbox);
if (!tile_line.empty())
{
encode_tile_line(tile_line,
speed_kmh,
rate,
line_int_offsets[reverse_weight],
line_int_offsets[reverse_duration],
reverse_datasource,
Expand All @@ -634,6 +667,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "weight");
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "duration");
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "name");
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "rate");

// Now, we write out the possible speed value arrays and possible is_tiny
// values. Field type 4 is the "values" field. It's a variable type field,
Expand Down
15 changes: 11 additions & 4 deletions unit_tests/library/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ template <typename algorithm> void test_tile(algorithm &osrm)
auto property_iter_pair = feature_message.get_packed_uint32();
auto value_begin = property_iter_pair.begin();
auto value_end = property_iter_pair.end();
BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 12);
BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 14);
auto iter = value_begin;
BOOST_CHECK_EQUAL(*iter++, 0); // speed key
BOOST_CHECK_LT(*iter++, 128); // speed value
Expand All @@ -71,6 +71,9 @@ template <typename algorithm> void test_tile(algorithm &osrm)
// name
BOOST_CHECK_EQUAL(*iter++, 5);
BOOST_CHECK_GT(*iter++, 130);
// rate
BOOST_CHECK_EQUAL(*iter++, 6);
BOOST_CHECK_GT(*iter++, 130);
BOOST_CHECK(iter == value_end);
// geometry
feature_message.next();
Expand Down Expand Up @@ -138,7 +141,7 @@ template <typename algorithm> void test_tile(algorithm &osrm)
}
}

BOOST_CHECK_EQUAL(number_of_speed_keys, 6);
BOOST_CHECK_EQUAL(number_of_speed_keys, 7);
BOOST_CHECK_GT(number_of_speed_values, 128); // speed value resolution

tile_message.next();
Expand Down Expand Up @@ -425,8 +428,10 @@ template <typename algorithm> void test_tile_speeds(algorithm &osrm)
std::vector<int> found_speed_indexes;
std::vector<int> found_component_indexes;
std::vector<int> found_datasource_indexes;
std::vector<int> found_weight_indexes;
std::vector<int> found_duration_indexes;
std::vector<int> found_name_indexes;
std::vector<int> found_rate_indexes;

const auto check_feature = [&](protozero::pbf_reader feature_message) {
feature_message.next(); // advance parser to first entry
Expand All @@ -443,7 +448,7 @@ template <typename algorithm> void test_tile_speeds(algorithm &osrm)
auto property_iter_pair = feature_message.get_packed_uint32();
auto value_begin = property_iter_pair.begin();
auto value_end = property_iter_pair.end();
BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 12);
BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 14);
auto iter = value_begin;
BOOST_CHECK_EQUAL(*iter++, 0); // speed key
found_speed_indexes.push_back(*iter++);
Expand All @@ -453,12 +458,14 @@ template <typename algorithm> void test_tile_speeds(algorithm &osrm)
BOOST_CHECK_EQUAL(*iter++, 2); // data source key
found_datasource_indexes.push_back(*iter++);
BOOST_CHECK_EQUAL(*iter++, 3); // weight key
found_duration_indexes.push_back(*iter++);
found_weight_indexes.push_back(*iter++);
BOOST_CHECK_EQUAL(*iter++, 4); // duration key
found_duration_indexes.push_back(*iter++);
// name
BOOST_CHECK_EQUAL(*iter++, 5);
found_name_indexes.push_back(*iter++);
BOOST_CHECK_EQUAL(*iter++, 6);
found_rate_indexes.push_back(*iter++);
BOOST_CHECK(iter == value_end);
// geometry
feature_message.next();
Expand Down