Skip to content

Commit

Permalink
Project-OSRM#5325 show way_ids in annotations - implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nnseva committed Feb 10, 2021
1 parent 9d81eb3 commit 27420e6
Show file tree
Hide file tree
Showing 28 changed files with 232 additions and 22 deletions.
3 changes: 3 additions & 0 deletions include/engine/api/flatbuffers/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

../../../../build/flatbuffers-build/flatc --cpp --no-includes --gen-all --gen-object-api fbresult.fbs
24 changes: 21 additions & 3 deletions include/engine/api/flatbuffers/fbresult_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ struct AnnotationT : public flatbuffers::NativeTable {
std::vector<uint32_t> duration;
std::vector<uint32_t> datasources;
std::vector<uint32_t> nodes;
std::vector<uint32_t> ways;
std::vector<uint32_t> weight;
std::vector<float> speed;
std::unique_ptr<osrm::engine::api::fbresult::MetadataT> metadata;
Expand All @@ -476,9 +477,10 @@ struct Annotation FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_DURATION = 6,
VT_DATASOURCES = 8,
VT_NODES = 10,
VT_WEIGHT = 12,
VT_SPEED = 14,
VT_METADATA = 16
VT_WAYS = 12,
VT_WEIGHT = 14,
VT_SPEED = 16,
VT_METADATA = 18
};
const flatbuffers::Vector<uint32_t> *distance() const {
return GetPointer<const flatbuffers::Vector<uint32_t> *>(VT_DISTANCE);
Expand All @@ -492,6 +494,9 @@ struct Annotation FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const flatbuffers::Vector<uint32_t> *nodes() const {
return GetPointer<const flatbuffers::Vector<uint32_t> *>(VT_NODES);
}
const flatbuffers::Vector<uint32_t> *ways() const {
return GetPointer<const flatbuffers::Vector<uint32_t> *>(VT_WAYS);
}
const flatbuffers::Vector<uint32_t> *weight() const {
return GetPointer<const flatbuffers::Vector<uint32_t> *>(VT_WEIGHT);
}
Expand All @@ -511,6 +516,8 @@ struct Annotation FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
verifier.VerifyVector(datasources()) &&
VerifyOffset(verifier, VT_NODES) &&
verifier.VerifyVector(nodes()) &&
VerifyOffset(verifier, VT_WAYS) &&
verifier.VerifyVector(ways()) &&
VerifyOffset(verifier, VT_WEIGHT) &&
verifier.VerifyVector(weight()) &&
VerifyOffset(verifier, VT_SPEED) &&
Expand Down Expand Up @@ -539,6 +546,9 @@ struct AnnotationBuilder {
void add_nodes(flatbuffers::Offset<flatbuffers::Vector<uint32_t>> nodes) {
fbb_.AddOffset(Annotation::VT_NODES, nodes);
}
void add_ways(flatbuffers::Offset<flatbuffers::Vector<uint32_t>> ways) {
fbb_.AddOffset(Annotation::VT_WAYS, ways);
}
void add_weight(flatbuffers::Offset<flatbuffers::Vector<uint32_t>> weight) {
fbb_.AddOffset(Annotation::VT_WEIGHT, weight);
}
Expand Down Expand Up @@ -566,13 +576,15 @@ inline flatbuffers::Offset<Annotation> CreateAnnotation(
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> duration = 0,
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> datasources = 0,
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> nodes = 0,
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> ways = 0,
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> weight = 0,
flatbuffers::Offset<flatbuffers::Vector<float>> speed = 0,
flatbuffers::Offset<osrm::engine::api::fbresult::Metadata> metadata = 0) {
AnnotationBuilder builder_(_fbb);
builder_.add_metadata(metadata);
builder_.add_speed(speed);
builder_.add_weight(weight);
builder_.add_ways(ways);
builder_.add_nodes(nodes);
builder_.add_datasources(datasources);
builder_.add_duration(duration);
Expand All @@ -586,13 +598,15 @@ inline flatbuffers::Offset<Annotation> CreateAnnotationDirect(
const std::vector<uint32_t> *duration = nullptr,
const std::vector<uint32_t> *datasources = nullptr,
const std::vector<uint32_t> *nodes = nullptr,
const std::vector<uint32_t> *ways = nullptr,
const std::vector<uint32_t> *weight = nullptr,
const std::vector<float> *speed = nullptr,
flatbuffers::Offset<osrm::engine::api::fbresult::Metadata> metadata = 0) {
auto distance__ = distance ? _fbb.CreateVector<uint32_t>(*distance) : 0;
auto duration__ = duration ? _fbb.CreateVector<uint32_t>(*duration) : 0;
auto datasources__ = datasources ? _fbb.CreateVector<uint32_t>(*datasources) : 0;
auto nodes__ = nodes ? _fbb.CreateVector<uint32_t>(*nodes) : 0;
auto ways__ = ways ? _fbb.CreateVector<uint32_t>(*ways) : 0;
auto weight__ = weight ? _fbb.CreateVector<uint32_t>(*weight) : 0;
auto speed__ = speed ? _fbb.CreateVector<float>(*speed) : 0;
return osrm::engine::api::fbresult::CreateAnnotation(
Expand All @@ -601,6 +615,7 @@ inline flatbuffers::Offset<Annotation> CreateAnnotationDirect(
duration__,
datasources__,
nodes__,
ways__,
weight__,
speed__,
metadata);
Expand Down Expand Up @@ -1974,6 +1989,7 @@ inline void Annotation::UnPackTo(AnnotationT *_o, const flatbuffers::resolver_fu
{ auto _e = duration(); if (_e) { _o->duration.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->duration[_i] = _e->Get(_i); } } };
{ auto _e = datasources(); if (_e) { _o->datasources.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->datasources[_i] = _e->Get(_i); } } };
{ auto _e = nodes(); if (_e) { _o->nodes.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->nodes[_i] = _e->Get(_i); } } };
{ auto _e = ways(); if (_e) { _o->ways.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->ways[_i] = _e->Get(_i); } } };
{ auto _e = weight(); if (_e) { _o->weight.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->weight[_i] = _e->Get(_i); } } };
{ auto _e = speed(); if (_e) { _o->speed.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->speed[_i] = _e->Get(_i); } } };
{ auto _e = metadata(); if (_e) _o->metadata = std::unique_ptr<osrm::engine::api::fbresult::MetadataT>(_e->UnPack(_resolver)); };
Expand All @@ -1991,6 +2007,7 @@ inline flatbuffers::Offset<Annotation> CreateAnnotation(flatbuffers::FlatBufferB
auto _duration = _o->duration.size() ? _fbb.CreateVector(_o->duration) : 0;
auto _datasources = _o->datasources.size() ? _fbb.CreateVector(_o->datasources) : 0;
auto _nodes = _o->nodes.size() ? _fbb.CreateVector(_o->nodes) : 0;
auto _ways = _o->ways.size() ? _fbb.CreateVector(_o->ways) : 0;
auto _weight = _o->weight.size() ? _fbb.CreateVector(_o->weight) : 0;
auto _speed = _o->speed.size() ? _fbb.CreateVector(_o->speed) : 0;
auto _metadata = _o->metadata ? CreateMetadata(_fbb, _o->metadata.get(), _rehasher) : 0;
Expand All @@ -2000,6 +2017,7 @@ inline flatbuffers::Offset<Annotation> CreateAnnotation(flatbuffers::FlatBufferB
_duration,
_datasources,
_nodes,
_ways,
_weight,
_speed,
_metadata);
Expand Down
1 change: 1 addition & 0 deletions include/engine/api/flatbuffers/route.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ table Annotation {
duration: [uint];
datasources: [uint];
nodes: [uint];
ways: [uint];
weight: [uint];
speed: [float];
metadata: Metadata;
Expand Down
21 changes: 21 additions & 0 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,17 @@ class RouteAPI : public BaseAPI
nodes.emplace_back(static_cast<uint64_t>(node_id));
}
}
std::vector<uint32_t> ways;
if (requested_annotations & RouteParameters::AnnotationsType::Ways)
{
ways.reserve(leg_geometry.osm_way_ids.size());
for (const auto way_id : leg_geometry.osm_way_ids)
{
ways.emplace_back(static_cast<uint64_t>(way_id));
}
}
auto nodes_vector = fb_result.CreateVector(nodes);
auto ways_vector = fb_result.CreateVector(ways);
// Add any supporting metadata, if needed
bool use_metadata = requested_annotations & RouteParameters::AnnotationsType::Datasources;
flatbuffers::Offset<fbresult::Metadata> metadata_buffer;
Expand All @@ -529,6 +539,7 @@ class RouteAPI : public BaseAPI
annotation.add_weight(weight);
annotation.add_datasources(datasources);
annotation.add_nodes(nodes_vector);
annotation.add_ways(ways_vector);
if (use_metadata)
{
annotation.add_metadata(metadata_buffer);
Expand Down Expand Up @@ -832,6 +843,16 @@ class RouteAPI : public BaseAPI
}
annotation.values["nodes"] = std::move(nodes);
}
if (requested_annotations & RouteParameters::AnnotationsType::Ways)
{
util::json::Array ways;
ways.values.reserve(leg_geometry.osm_way_ids.size());
for (const auto way_id : leg_geometry.osm_way_ids)
{
ways.values.push_back(static_cast<std::uint64_t>(way_id));
}
annotation.values["ways"] = std::move(ways);
}
// Add any supporting metadata, if needed
if (requested_annotations & RouteParameters::AnnotationsType::Datasources)
{
Expand Down
3 changes: 2 additions & 1 deletion include/engine/api/route_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ struct RouteParameters : public BaseParameters
Weight = 0x08,
Datasources = 0x10,
Speed = 0x20,
All = Duration | Nodes | Distance | Weight | Datasources | Speed
Ways = 0x40,
All = Duration | Nodes | Distance | Weight | Datasources | Speed | Ways
};

RouteParameters() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
return segment_data.GetReverseGeometry(id);
}

OSMWayForwardRange GetUncompressedForwardWayIDs(const EdgeID id) const override final
{
return segment_data.GetForwardOSMWayIDs(id);
}
OSMWayReverseRange GetUncompressedReverseWayIDs(const EdgeID id) const override final
{
return segment_data.GetReverseOSMWayIDs(id);
}

DurationForwardRange GetUncompressedForwardDurations(const EdgeID id) const override final
{
return segment_data.GetForwardDurations(id);
Expand Down
7 changes: 7 additions & 0 deletions include/engine/datafacade/datafacade_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class BaseDataFacade
boost::iterator_range<extractor::SegmentDataView::SegmentNodeVector::const_iterator>;
using NodeReverseRange = boost::reversed_range<const NodeForwardRange>;

using OSMWayForwardRange =
boost::iterator_range<extractor::SegmentDataView::SegmentOSMWayVector::const_iterator>;
using OSMWayReverseRange = boost::reversed_range<const OSMWayForwardRange>;

using WeightForwardRange =
boost::iterator_range<extractor::SegmentDataView::SegmentWeightVector::const_iterator>;
using WeightReverseRange = boost::reversed_range<const WeightForwardRange>;
Expand Down Expand Up @@ -85,6 +89,9 @@ class BaseDataFacade

virtual ComponentID GetComponentID(const NodeID id) const = 0;

virtual OSMWayForwardRange GetUncompressedForwardWayIDs(const EdgeID id) const = 0;
virtual OSMWayReverseRange GetUncompressedReverseWayIDs(const EdgeID id) const = 0;

virtual NodeForwardRange GetUncompressedForwardGeometry(const EdgeID id) const = 0;
virtual NodeReverseRange GetUncompressedReverseGeometry(const EdgeID id) const = 0;

Expand Down
5 changes: 5 additions & 0 deletions include/engine/guidance/assemble_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
reversed_source ? source_node.reverse_segment_id.id : source_node.forward_segment_id.id;
const auto source_geometry_id = facade.GetGeometryIndex(source_node_id).id;
const auto source_geometry = facade.GetUncompressedForwardGeometry(source_geometry_id);
//const auto source_osm_way_ids = facade.GetUncompressedForwardWayIDs(source_geometry_id);

geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(source_geometry(source_segment_start_coordinate)));
// geometry.osm_way_ids.push_back(source_osm_way_ids(source_segment_start_coordinate)));

auto cumulative_distance = 0.;
auto current_distance = 0.;
Expand Down Expand Up @@ -100,6 +102,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
path_point.datasource_id});
geometry.locations.push_back(std::move(coordinate));
geometry.osm_node_ids.push_back(osm_node_id);
geometry.osm_way_ids.push_back(path_point.osm_way_id);
}
}
current_distance =
Expand Down Expand Up @@ -158,8 +161,10 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
const auto target_segment_end_coordinate =
target_node.fwd_segment_position + (reversed_target ? 0 : 1);
const auto target_geometry = facade.GetUncompressedForwardGeometry(target_geometry_id);
const auto target_osm_way_ids = facade.GetUncompressedForwardWayIDs(target_geometry_id);
geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(target_geometry(target_segment_end_coordinate)));
geometry.osm_way_ids.push_back(target_osm_way_ids(target_node.fwd_segment_position));

BOOST_ASSERT(geometry.segment_distances.size() == geometry.segment_offsets.size() - 1);
BOOST_ASSERT(geometry.locations.size() > geometry.segment_distances.size());
Expand Down
2 changes: 2 additions & 0 deletions include/engine/guidance/leg_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct LegGeometry
std::vector<double> segment_distances;
// original OSM node IDs for each coordinate
std::vector<OSMNodeID> osm_node_ids;
// original OSM way IDs between every pair of nodes
std::vector<OSMWayID> osm_way_ids;

// Per-coordinate metadata
struct Annotation
Expand Down
2 changes: 2 additions & 0 deletions include/engine/internal_route_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct PathData
{
// from edge-based-node id
NodeID from_edge_based_node;
// OSM Way ID of the edge immediately followed by via node
OSMWayID osm_way_id;
// the internal OSRM id of the OSM node id that is the via node of the turn
NodeID turn_via_node;
// name of the street that leads to the turn
Expand Down
7 changes: 7 additions & 0 deletions include/engine/routing_algorithms/routing_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void annotatePath(const FacadeT &facade,

// datastructures to hold extracted data from geometry
std::vector<NodeID> id_vector;
std::vector<OSMWayID> osm_way_id_vector;
std::vector<SegmentWeight> weight_vector;
std::vector<SegmentDuration> duration_vector;
std::vector<DatasourceID> datasource_vector;
Expand All @@ -157,13 +158,17 @@ void annotatePath(const FacadeT &facade,
if (geometry_index.forward)
{
copy(id_vector, facade.GetUncompressedForwardGeometry(geometry_index.id));
copy(osm_way_id_vector, facade.GetUncompressedForwardWayIDs(geometry_index.id));

copy(weight_vector, facade.GetUncompressedForwardWeights(geometry_index.id));
copy(duration_vector, facade.GetUncompressedForwardDurations(geometry_index.id));
copy(datasource_vector, facade.GetUncompressedForwardDatasources(geometry_index.id));
}
else
{
copy(id_vector, facade.GetUncompressedReverseGeometry(geometry_index.id));
copy(osm_way_id_vector, facade.GetUncompressedReverseWayIDs(geometry_index.id));

copy(weight_vector, facade.GetUncompressedReverseWeights(geometry_index.id));
copy(duration_vector, facade.GetUncompressedReverseDurations(geometry_index.id));
copy(datasource_vector, facade.GetUncompressedReverseDatasources(geometry_index.id));
Expand Down Expand Up @@ -213,6 +218,7 @@ void annotatePath(const FacadeT &facade,
{
unpacked_path.push_back(
PathData{*node_from,
osm_way_id_vector[segment_idx],
id_vector[segment_idx + 1],
name_index,
is_segregated,
Expand Down Expand Up @@ -288,6 +294,7 @@ void annotatePath(const FacadeT &facade,
BOOST_ASSERT(facade.GetTravelMode(target_node_id) > 0);
unpacked_path.push_back(
PathData{target_node_id,
osm_way_id_vector[segment_idx],
id_vector[start_index < end_index ? segment_idx + 1 : segment_idx - 1],
facade.GetNameIndex(target_node_id),
facade.IsSegregated(target_node_id),
Expand Down
3 changes: 2 additions & 1 deletion include/extractor/compressed_edge_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define GEOMETRY_COMPRESSOR_HPP_

#include "extractor/segment_data_container.hpp"
#include "extractor/node_based_edge.hpp"

#include "util/typedefs.hpp"

Expand Down Expand Up @@ -48,7 +49,7 @@ class CompressedEdgeContainer
const SegmentWeight duration);

void InitializeBothwayVector();
unsigned ZipEdges(const unsigned f_edge_pos, const unsigned r_edge_pos);
unsigned ZipEdges(const unsigned f_edge_pos, const unsigned r_edge_pos, OSMWayIDMap &osm_way_id_map);

bool HasEntryForID(const EdgeID edge_id) const;
bool HasZippedEntryForForwardID(const EdgeID edge_id) const;
Expand Down
1 change: 1 addition & 0 deletions include/extractor/extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Extractor
ExtractorConfig config;

std::tuple<LaneDescriptionMap,
OSMWayIDMap,
std::vector<TurnRestriction>,
std::vector<UnresolvedManeuverOverride>>
ParseOSMData(ScriptingEnvironment &scripting_environment, const unsigned number_of_threads);
Expand Down
3 changes: 3 additions & 0 deletions include/extractor/extractor_callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define EXTRACTOR_CALLBACKS_HPP

#include "extractor/class_data.hpp"
#include "extractor/node_based_edge.hpp"
#include "extractor/turn_lane_types.hpp"
#include "util/typedefs.hpp"

Expand Down Expand Up @@ -69,6 +70,7 @@ class ExtractorCallbacks
ExtractionContainers &external_memory;
std::unordered_map<std::string, ClassData> &classes_map;
LaneDescriptionMap &lane_description_map;
OSMWayIDMap &osm_way_id_map;
bool fallback_to_duration;
bool force_split_edges;

Expand All @@ -78,6 +80,7 @@ class ExtractorCallbacks
explicit ExtractorCallbacks(ExtractionContainers &extraction_containers,
std::unordered_map<std::string, ClassData> &classes_map,
LaneDescriptionMap &lane_description_map,
OSMWayIDMap &osm_way_id_map,
const ProfileProperties &properties);

ExtractorCallbacks(const ExtractorCallbacks &) = delete;
Expand Down
3 changes: 2 additions & 1 deletion include/extractor/internal_extractor_edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ struct InternalExtractorEdge

explicit InternalExtractorEdge(OSMNodeID source,
OSMNodeID target,
OSMWayID way,
WeightData weight_data,
DurationData duration_data,
util::Coordinate source_coordinate)
: result(source, target, 0, 0, 0, {}, -1, {}), weight_data(std::move(weight_data)),
: result(source, target, way, 0, 0, 0, {}, -1, {}), weight_data(std::move(weight_data)),
duration_data(std::move(duration_data)), source_coordinate(std::move(source_coordinate))
{
}
Expand Down
Loading

0 comments on commit 27420e6

Please sign in to comment.