Updated changelog entry
This commit is contained in:
@@ -72,32 +72,42 @@ class BaseAPI
|
||||
}
|
||||
}
|
||||
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> MakeWaypoints(flatbuffers::FlatBufferBuilder& builder, const std::vector<PhantomNodes> &segment_end_coordinates) const
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
|
||||
MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
|
||||
const std::vector<PhantomNodes> &segment_end_coordinates) const
|
||||
{
|
||||
BOOST_ASSERT(parameters.coordinates.size() > 0);
|
||||
BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1);
|
||||
|
||||
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
|
||||
waypoints.resize(parameters.coordinates.size());
|
||||
waypoints[0] = MakeWaypoint(builder, segment_end_coordinates.front().source_phantom).Finish();
|
||||
waypoints[0] =
|
||||
MakeWaypoint(builder, segment_end_coordinates.front().source_phantom).Finish();
|
||||
|
||||
std::transform(segment_end_coordinates.begin(), segment_end_coordinates.end(), std::next(waypoints.begin()), [this, &builder](const PhantomNodes &phantom_pair) {
|
||||
return MakeWaypoint(builder, phantom_pair.target_phantom).Finish();
|
||||
});
|
||||
std::transform(segment_end_coordinates.begin(),
|
||||
segment_end_coordinates.end(),
|
||||
std::next(waypoints.begin()),
|
||||
[this, &builder](const PhantomNodes &phantom_pair) {
|
||||
return MakeWaypoint(builder, phantom_pair.target_phantom).Finish();
|
||||
});
|
||||
return builder.CreateVector(waypoints);
|
||||
}
|
||||
|
||||
// FIXME: gcc 4.9 does not like MakeWaypoints to be protected
|
||||
// protected:
|
||||
fbresult::WaypointBuilder MakeWaypoint(flatbuffers::FlatBufferBuilder& builder, const PhantomNode &phantom) const
|
||||
fbresult::WaypointBuilder MakeWaypoint(flatbuffers::FlatBufferBuilder &builder,
|
||||
const PhantomNode &phantom) const
|
||||
{
|
||||
|
||||
auto location = fbresult::Position(static_cast<double>(util::toFloating(phantom.location.lon)), static_cast<double>(util::toFloating(phantom.location.lat)));
|
||||
auto location =
|
||||
fbresult::Position(static_cast<double>(util::toFloating(phantom.location.lon)),
|
||||
static_cast<double>(util::toFloating(phantom.location.lat)));
|
||||
fbresult::WaypointBuilder waypoint(builder);
|
||||
waypoint.add_location(&location);
|
||||
waypoint.add_distance(util::coordinate_calculation::fccApproximateDistance(phantom.location,
|
||||
phantom.input_location));
|
||||
auto name_string = builder.CreateString(facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string());
|
||||
waypoint.add_distance(util::coordinate_calculation::fccApproximateDistance(
|
||||
phantom.location, phantom.input_location));
|
||||
auto name_string = builder.CreateString(
|
||||
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string());
|
||||
waypoint.add_name(name_string);
|
||||
if (parameters.generate_hints)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
using ResultT = mapbox::util::variant<util::json::Object, std::string, flatbuffers::FlatBufferBuilder>;
|
||||
using ResultT =
|
||||
mapbox::util::variant<util::json::Object, std::string, flatbuffers::FlatBufferBuilder>;
|
||||
} // ns api
|
||||
} // ns engine
|
||||
} // ns osrm
|
||||
|
||||
@@ -34,10 +34,13 @@ class MatchAPI final : public RouteAPI
|
||||
osrm::engine::api::ResultT &response) const
|
||||
{
|
||||
BOOST_ASSERT(sub_matchings.size() == sub_routes.size());
|
||||
if (response.is<flatbuffers::FlatBufferBuilder>()) {
|
||||
if (response.is<flatbuffers::FlatBufferBuilder>())
|
||||
{
|
||||
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
|
||||
MakeResponse(sub_matchings, sub_routes, fb_result);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &json_result = response.get<util::json::Object>();
|
||||
MakeResponse(sub_matchings, sub_routes, json_result);
|
||||
}
|
||||
@@ -46,7 +49,9 @@ class MatchAPI final : public RouteAPI
|
||||
const std::vector<InternalRouteResult> &sub_routes,
|
||||
flatbuffers::FlatBufferBuilder &fb_result) const
|
||||
{
|
||||
auto response = MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_matchings]() { return MakeTracepoints(fb_result, sub_matchings); });
|
||||
auto response = MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_matchings]() {
|
||||
return MakeTracepoints(fb_result, sub_matchings);
|
||||
});
|
||||
|
||||
fb_result.Finish(response.Finish());
|
||||
}
|
||||
@@ -79,7 +84,7 @@ class MatchAPI final : public RouteAPI
|
||||
{
|
||||
MatchingIndex() = default;
|
||||
MatchingIndex(unsigned sub_matching_index_, unsigned point_index_)
|
||||
: sub_matching_index(sub_matching_index_), point_index(point_index_)
|
||||
: sub_matching_index(sub_matching_index_), point_index(point_index_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -94,7 +99,8 @@ class MatchAPI final : public RouteAPI
|
||||
};
|
||||
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
|
||||
MakeTracepoints(flatbuffers::FlatBufferBuilder &fb_result, const std::vector<map_matching::SubMatching> &sub_matchings) const
|
||||
MakeTracepoints(flatbuffers::FlatBufferBuilder &fb_result,
|
||||
const std::vector<map_matching::SubMatching> &sub_matchings) const
|
||||
{
|
||||
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
|
||||
waypoints.reserve(parameters.coordinates.size());
|
||||
@@ -119,11 +125,11 @@ class MatchAPI final : public RouteAPI
|
||||
continue;
|
||||
}
|
||||
const auto &phantom =
|
||||
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
|
||||
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
|
||||
auto waypoint = BaseAPI::MakeWaypoint(fb_result, phantom);
|
||||
waypoint.add_matchings_index(matching_index.sub_matching_index);
|
||||
waypoint.add_alternatives_count(sub_matchings[matching_index.sub_matching_index]
|
||||
.alternatives_count[matching_index.point_index]);
|
||||
.alternatives_count[matching_index.point_index]);
|
||||
// waypoint indices need to be adjusted if route legs were collapsed
|
||||
// waypoint parameter assumes there is only one match object
|
||||
if (!parameters.waypoints.empty())
|
||||
@@ -137,7 +143,9 @@ class MatchAPI final : public RouteAPI
|
||||
{
|
||||
waypoint.add_waypoint_index(0);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
waypoint.add_waypoint_index(matching_index.point_index);
|
||||
}
|
||||
waypoints.push_back(waypoint.Finish());
|
||||
@@ -198,20 +206,24 @@ class MatchAPI final : public RouteAPI
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
std::vector<MatchingIndex> MakeMatchingIndices(const std::vector<map_matching::SubMatching> &sub_matchings) const {
|
||||
std::vector<MatchingIndex>
|
||||
MakeMatchingIndices(const std::vector<map_matching::SubMatching> &sub_matchings) const
|
||||
{
|
||||
std::vector<MatchingIndex> trace_idx_to_matching_idx(parameters.coordinates.size());
|
||||
for (auto sub_matching_index :
|
||||
util::irange(0u, static_cast<unsigned>(sub_matchings.size()))) {
|
||||
util::irange(0u, static_cast<unsigned>(sub_matchings.size())))
|
||||
{
|
||||
for (auto point_index : util::irange(
|
||||
0u, static_cast<unsigned>(sub_matchings[sub_matching_index].indices.size()))) {
|
||||
0u, static_cast<unsigned>(sub_matchings[sub_matching_index].indices.size())))
|
||||
{
|
||||
// tidied_to_original: index of the input coordinate that a tidied coordinate
|
||||
// corresponds to.
|
||||
// sub_matching indices: index of the coordinate passed to map matching plugin that
|
||||
// a matched node corresponds to.
|
||||
trace_idx_to_matching_idx[tidy_result
|
||||
.tidied_to_original[sub_matchings[sub_matching_index]
|
||||
.indices[point_index]]] =
|
||||
MatchingIndex{sub_matching_index, point_index};
|
||||
.tidied_to_original[sub_matchings[sub_matching_index]
|
||||
.indices[point_index]]] =
|
||||
MatchingIndex{sub_matching_index, point_index};
|
||||
}
|
||||
}
|
||||
return trace_idx_to_matching_idx;
|
||||
|
||||
@@ -27,21 +27,21 @@ class NearestAPI final : public BaseAPI
|
||||
}
|
||||
|
||||
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
|
||||
osrm::engine::api::ResultT &response) const {
|
||||
osrm::engine::api::ResultT &response) const
|
||||
{
|
||||
BOOST_ASSERT(phantom_nodes.size() == 1);
|
||||
BOOST_ASSERT(parameters.coordinates.size() == 1);
|
||||
|
||||
if(response.is<flatbuffers::FlatBufferBuilder>())
|
||||
if (response.is<flatbuffers::FlatBufferBuilder>())
|
||||
{
|
||||
auto& fb_result = response.get<flatbuffers::FlatBufferBuilder>();
|
||||
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
|
||||
MakeResponse(phantom_nodes, fb_result);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& json_result = response.get<util::json::Object>();
|
||||
auto &json_result = response.get<util::json::Object>();
|
||||
MakeResponse(phantom_nodes, json_result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
|
||||
@@ -51,49 +51,47 @@ class NearestAPI final : public BaseAPI
|
||||
|
||||
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
|
||||
waypoints.resize(phantom_nodes.front().size());
|
||||
std::transform(
|
||||
phantom_nodes.front().begin(),
|
||||
phantom_nodes.front().end(),
|
||||
waypoints.begin(),
|
||||
[this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) {
|
||||
auto &phantom_node = phantom_with_distance.phantom_node;
|
||||
std::transform(phantom_nodes.front().begin(),
|
||||
phantom_nodes.front().end(),
|
||||
waypoints.begin(),
|
||||
[this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) {
|
||||
auto &phantom_node = phantom_with_distance.phantom_node;
|
||||
|
||||
auto node_values = MakeNodes(phantom_node);
|
||||
fbresult::Uint64Pair nodes{node_values.first, node_values.second};
|
||||
auto node_values = MakeNodes(phantom_node);
|
||||
fbresult::Uint64Pair nodes{node_values.first, node_values.second};
|
||||
|
||||
auto waypoint = MakeWaypoint(fb_result,phantom_node);
|
||||
waypoint.add_nodes(&nodes);
|
||||
auto waypoint = MakeWaypoint(fb_result, phantom_node);
|
||||
waypoint.add_nodes(&nodes);
|
||||
|
||||
return waypoint.Finish();
|
||||
});
|
||||
return waypoint.Finish();
|
||||
});
|
||||
|
||||
auto waypoints_vector = fb_result.CreateVector(waypoints);
|
||||
response.add_waypoints(waypoints_vector);
|
||||
fb_result.Finish(response.Finish());
|
||||
}
|
||||
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
|
||||
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
|
||||
util::json::Object &response) const
|
||||
{
|
||||
util::json::Array waypoints;
|
||||
waypoints.values.resize(phantom_nodes.front().size());
|
||||
std::transform(
|
||||
phantom_nodes.front().begin(),
|
||||
phantom_nodes.front().end(),
|
||||
waypoints.values.begin(),
|
||||
[this](const PhantomNodeWithDistance &phantom_with_distance) {
|
||||
auto &phantom_node = phantom_with_distance.phantom_node;
|
||||
auto waypoint = MakeWaypoint(phantom_node);
|
||||
std::transform(phantom_nodes.front().begin(),
|
||||
phantom_nodes.front().end(),
|
||||
waypoints.values.begin(),
|
||||
[this](const PhantomNodeWithDistance &phantom_with_distance) {
|
||||
auto &phantom_node = phantom_with_distance.phantom_node;
|
||||
auto waypoint = MakeWaypoint(phantom_node);
|
||||
|
||||
util::json::Array nodes;
|
||||
util::json::Array nodes;
|
||||
|
||||
auto node_values = MakeNodes(phantom_node);
|
||||
auto node_values = MakeNodes(phantom_node);
|
||||
|
||||
nodes.values.push_back(node_values.first);
|
||||
nodes.values.push_back(node_values.second);
|
||||
waypoint.values["nodes"] = std::move(nodes);
|
||||
nodes.values.push_back(node_values.first);
|
||||
nodes.values.push_back(node_values.second);
|
||||
waypoint.values["nodes"] = std::move(nodes);
|
||||
|
||||
return waypoint;
|
||||
});
|
||||
return waypoint;
|
||||
});
|
||||
|
||||
response.values["code"] = "Ok";
|
||||
response.values["waypoints"] = std::move(waypoints);
|
||||
@@ -101,8 +99,9 @@ class NearestAPI final : public BaseAPI
|
||||
|
||||
const NearestParameters ¶meters;
|
||||
|
||||
protected:
|
||||
std::pair<uint64_t, uint64_t> MakeNodes(const PhantomNode& phantom_node) const {
|
||||
protected:
|
||||
std::pair<uint64_t, uint64_t> MakeNodes(const PhantomNode &phantom_node) const
|
||||
{
|
||||
std::uint64_t from_node = 0;
|
||||
std::uint64_t to_node = 0;
|
||||
|
||||
@@ -113,8 +112,8 @@ protected:
|
||||
const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
|
||||
forward_geometry = facade.GetUncompressedForwardGeometry(geometry_id);
|
||||
|
||||
auto osm_node_id = facade.GetOSMNodeIDOfNode(
|
||||
forward_geometry(phantom_node.fwd_segment_position));
|
||||
auto osm_node_id =
|
||||
facade.GetOSMNodeIDOfNode(forward_geometry(phantom_node.fwd_segment_position));
|
||||
to_node = static_cast<std::uint64_t>(osm_node_id);
|
||||
}
|
||||
|
||||
@@ -124,15 +123,14 @@ protected:
|
||||
const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
|
||||
const auto geometry = facade.GetUncompressedForwardGeometry(geometry_id);
|
||||
auto osm_node_id =
|
||||
facade.GetOSMNodeIDOfNode(geometry(phantom_node.fwd_segment_position + 1));
|
||||
facade.GetOSMNodeIDOfNode(geometry(phantom_node.fwd_segment_position + 1));
|
||||
from_node = static_cast<std::uint64_t>(osm_node_id);
|
||||
}
|
||||
else if (phantom_node.forward_segment_id.enabled &&
|
||||
phantom_node.fwd_segment_position > 0)
|
||||
else if (phantom_node.forward_segment_id.enabled && phantom_node.fwd_segment_position > 0)
|
||||
{
|
||||
// In the case of one way, rely on forward segment only
|
||||
auto osm_node_id = facade.GetOSMNodeIDOfNode(
|
||||
forward_geometry(phantom_node.fwd_segment_position - 1));
|
||||
auto osm_node_id =
|
||||
facade.GetOSMNodeIDOfNode(forward_geometry(phantom_node.fwd_segment_position - 1));
|
||||
from_node = static_cast<std::uint64_t>(osm_node_id);
|
||||
}
|
||||
|
||||
|
||||
+311
-232
@@ -36,23 +36,29 @@ namespace engine
|
||||
namespace api
|
||||
{
|
||||
|
||||
class RouteAPI : public BaseAPI {
|
||||
public:
|
||||
class RouteAPI : public BaseAPI
|
||||
{
|
||||
public:
|
||||
RouteAPI(const datafacade::BaseDataFacade &facade_, const RouteParameters ¶meters_)
|
||||
: BaseAPI(facade_, parameters_), parameters(parameters_) {
|
||||
: BaseAPI(facade_, parameters_), parameters(parameters_)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
MakeResponse(const InternalManyRoutesResult &raw_routes,
|
||||
const std::vector<PhantomNodes>
|
||||
&all_start_end_points, // all used coordinates, ignoring waypoints= parameter
|
||||
osrm::engine::api::ResultT &response) const {
|
||||
&all_start_end_points, // all used coordinates, ignoring waypoints= parameter
|
||||
osrm::engine::api::ResultT &response) const
|
||||
{
|
||||
BOOST_ASSERT(!raw_routes.routes.empty());
|
||||
|
||||
if (response.is<flatbuffers::FlatBufferBuilder>()) {
|
||||
if (response.is<flatbuffers::FlatBufferBuilder>())
|
||||
{
|
||||
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
|
||||
MakeResponse(raw_routes, all_start_end_points, fb_result);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &json_result = response.get<util::json::Object>();
|
||||
MakeResponse(raw_routes, all_start_end_points, json_result);
|
||||
}
|
||||
@@ -61,12 +67,13 @@ public:
|
||||
void
|
||||
MakeResponse(const InternalManyRoutesResult &raw_routes,
|
||||
const std::vector<PhantomNodes>
|
||||
&all_start_end_points, // all used coordinates, ignoring waypoints= parameter
|
||||
&all_start_end_points, // all used coordinates, ignoring waypoints= parameter
|
||||
flatbuffers::FlatBufferBuilder &fb_result) const
|
||||
{
|
||||
auto response = MakeFBResponse(raw_routes, fb_result, [this, &all_start_end_points, &fb_result]() {
|
||||
return BaseAPI::MakeWaypoints(fb_result, all_start_end_points);
|
||||
});
|
||||
auto response =
|
||||
MakeFBResponse(raw_routes, fb_result, [this, &all_start_end_points, &fb_result]() {
|
||||
return BaseAPI::MakeWaypoints(fb_result, all_start_end_points);
|
||||
});
|
||||
|
||||
auto data_timestamp = facade.GetTimestamp();
|
||||
if (!data_timestamp.empty())
|
||||
@@ -109,10 +116,9 @@ public:
|
||||
|
||||
protected:
|
||||
template <typename GetWptsFn>
|
||||
fbresult::FBResultBuilder
|
||||
MakeFBResponse(const InternalManyRoutesResult &raw_routes,
|
||||
flatbuffers::FlatBufferBuilder &fb_result,
|
||||
GetWptsFn getWaypoints) const
|
||||
fbresult::FBResultBuilder MakeFBResponse(const InternalManyRoutesResult &raw_routes,
|
||||
flatbuffers::FlatBufferBuilder &fb_result,
|
||||
GetWptsFn getWaypoints) const
|
||||
{
|
||||
|
||||
fbresult::FBResultBuilder response(fb_result);
|
||||
@@ -140,37 +146,47 @@ public:
|
||||
template <typename BuilderType, typename ForwardIter>
|
||||
void MakeGeometry(BuilderType builder, ForwardIter begin, ForwardIter end) const
|
||||
{
|
||||
if (parameters.geometries == RouteParameters::GeometriesType::Polyline) {
|
||||
if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
|
||||
{
|
||||
auto polyline_string = builder.fbb_.CreateString(encodePolyline<100000>(begin, end));
|
||||
builder.add_polyline(polyline_string);
|
||||
} else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6) {
|
||||
}
|
||||
else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
|
||||
{
|
||||
auto polyline_string = builder.fbb_.CreateString(encodePolyline<1000000>(begin, end));
|
||||
builder.add_polyline(polyline_string);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<fbresult::Position> coordinates;
|
||||
coordinates.resize(std::distance(begin, end));
|
||||
std::transform(begin, end, coordinates.begin(), [](const Coordinate &c) {
|
||||
return fbresult::Position{static_cast<float>(util::toFloating(c.lon).__value),
|
||||
static_cast<float>(util::toFloating(c.lat).__value)};
|
||||
static_cast<float>(util::toFloating(c.lat).__value)};
|
||||
});
|
||||
auto coordinates_vector = builder.fbb_.CreateVectorOfStructs(coordinates);
|
||||
builder.add_coordinates(coordinates_vector);
|
||||
}
|
||||
}
|
||||
|
||||
boost::optional<util::json::Value> MakeGeometry(boost::optional<std::vector<Coordinate>>&& annotations) const
|
||||
boost::optional<util::json::Value>
|
||||
MakeGeometry(boost::optional<std::vector<Coordinate>> &&annotations) const
|
||||
{
|
||||
boost::optional<util::json::Value> json_geometry;
|
||||
if (annotations) {
|
||||
if (annotations)
|
||||
{
|
||||
auto begin = annotations->begin();
|
||||
auto end = annotations->end();
|
||||
if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
|
||||
{
|
||||
json_geometry = json::makePolyline<100000>(begin, end);
|
||||
} else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
|
||||
}
|
||||
else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
|
||||
{
|
||||
json_geometry = json::makePolyline<1000000>(begin, end);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ASSERT(parameters.geometries == RouteParameters::GeometriesType::GeoJSON);
|
||||
json_geometry = json::makeGeoJSONGeometry(begin, end);
|
||||
}
|
||||
@@ -179,7 +195,8 @@ public:
|
||||
}
|
||||
|
||||
template <typename ValueType, typename GetFn>
|
||||
flatbuffers::Offset<flatbuffers::Vector<ValueType>> GetAnnotations(flatbuffers::FlatBufferBuilder& fb_result, guidance::LegGeometry &leg, GetFn Get) const
|
||||
flatbuffers::Offset<flatbuffers::Vector<ValueType>> GetAnnotations(
|
||||
flatbuffers::FlatBufferBuilder &fb_result, guidance::LegGeometry &leg, GetFn Get) const
|
||||
{
|
||||
std::vector<ValueType> annotations_store;
|
||||
annotations_store.reserve(leg.annotations.size());
|
||||
@@ -206,76 +223,85 @@ public:
|
||||
return annotations_store;
|
||||
}
|
||||
|
||||
fbresult::ManeuverType WaypointTypeToFB(guidance::WaypointType type) const {
|
||||
switch(type) {
|
||||
case guidance::WaypointType::Arrive:
|
||||
return fbresult::ManeuverType_Arrive;
|
||||
case guidance::WaypointType::Depart:
|
||||
return fbresult::ManeuverType_Depart;
|
||||
default:
|
||||
return fbresult::ManeuverType_Notification;
|
||||
fbresult::ManeuverType WaypointTypeToFB(guidance::WaypointType type) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case guidance::WaypointType::Arrive:
|
||||
return fbresult::ManeuverType_Arrive;
|
||||
case guidance::WaypointType::Depart:
|
||||
return fbresult::ManeuverType_Depart;
|
||||
default:
|
||||
return fbresult::ManeuverType_Notification;
|
||||
}
|
||||
}
|
||||
|
||||
fbresult::ManeuverType TurnTypeToFB(osrm::guidance::TurnType::Enum turn) const {
|
||||
static std::map<osrm::guidance::TurnType::Enum, fbresult::ManeuverType> mappings={
|
||||
{osrm::guidance::TurnType::Invalid, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::NewName, fbresult::ManeuverType_NewName},
|
||||
{osrm::guidance::TurnType::Continue, fbresult::ManeuverType_Continue},
|
||||
{osrm::guidance::TurnType::Turn, fbresult::ManeuverType_Turn},
|
||||
{osrm::guidance::TurnType::Merge, fbresult::ManeuverType_Merge},
|
||||
{osrm::guidance::TurnType::OnRamp, fbresult::ManeuverType_OnRamp},
|
||||
{osrm::guidance::TurnType::OffRamp, fbresult::ManeuverType_OffRamp},
|
||||
{osrm::guidance::TurnType::Fork, fbresult::ManeuverType_Fork},
|
||||
{osrm::guidance::TurnType::EndOfRoad, fbresult::ManeuverType_EndOfRoad},
|
||||
{osrm::guidance::TurnType::Notification, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::EnterRoundabout, fbresult::ManeuverType_Roundabout},
|
||||
{osrm::guidance::TurnType::EnterAndExitRoundabout, fbresult::ManeuverType_ExitRoundabout},
|
||||
{osrm::guidance::TurnType::EnterRotary, fbresult::ManeuverType_Rotary},
|
||||
{osrm::guidance::TurnType::EnterAndExitRotary, fbresult::ManeuverType_ExitRotary},
|
||||
{osrm::guidance::TurnType::EnterRoundaboutIntersection, fbresult::ManeuverType_Roundabout},
|
||||
{osrm::guidance::TurnType::EnterAndExitRoundaboutIntersection, fbresult::ManeuverType_ExitRoundabout},
|
||||
{osrm::guidance::TurnType::NoTurn, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::Suppressed, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::EnterRoundaboutAtExit, fbresult::ManeuverType_Roundabout},
|
||||
{osrm::guidance::TurnType::ExitRoundabout, fbresult::ManeuverType_ExitRoundabout},
|
||||
{osrm::guidance::TurnType::EnterRotaryAtExit, fbresult::ManeuverType_Rotary},
|
||||
{osrm::guidance::TurnType::ExitRotary, fbresult::ManeuverType_ExitRotary},
|
||||
{osrm::guidance::TurnType::EnterRoundaboutIntersectionAtExit, fbresult::ManeuverType_Roundabout},
|
||||
{osrm::guidance::TurnType::ExitRoundaboutIntersection, fbresult::ManeuverType_ExitRoundabout},
|
||||
{osrm::guidance::TurnType::StayOnRoundabout, fbresult::ManeuverType_RoundaboutTurn},
|
||||
{osrm::guidance::TurnType::Sliproad, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::MaxTurnType, fbresult::ManeuverType_Notification}
|
||||
};
|
||||
fbresult::ManeuverType TurnTypeToFB(osrm::guidance::TurnType::Enum turn) const
|
||||
{
|
||||
static std::map<osrm::guidance::TurnType::Enum, fbresult::ManeuverType> mappings = {
|
||||
{osrm::guidance::TurnType::Invalid, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::NewName, fbresult::ManeuverType_NewName},
|
||||
{osrm::guidance::TurnType::Continue, fbresult::ManeuverType_Continue},
|
||||
{osrm::guidance::TurnType::Turn, fbresult::ManeuverType_Turn},
|
||||
{osrm::guidance::TurnType::Merge, fbresult::ManeuverType_Merge},
|
||||
{osrm::guidance::TurnType::OnRamp, fbresult::ManeuverType_OnRamp},
|
||||
{osrm::guidance::TurnType::OffRamp, fbresult::ManeuverType_OffRamp},
|
||||
{osrm::guidance::TurnType::Fork, fbresult::ManeuverType_Fork},
|
||||
{osrm::guidance::TurnType::EndOfRoad, fbresult::ManeuverType_EndOfRoad},
|
||||
{osrm::guidance::TurnType::Notification, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::EnterRoundabout, fbresult::ManeuverType_Roundabout},
|
||||
{osrm::guidance::TurnType::EnterAndExitRoundabout,
|
||||
fbresult::ManeuverType_ExitRoundabout},
|
||||
{osrm::guidance::TurnType::EnterRotary, fbresult::ManeuverType_Rotary},
|
||||
{osrm::guidance::TurnType::EnterAndExitRotary, fbresult::ManeuverType_ExitRotary},
|
||||
{osrm::guidance::TurnType::EnterRoundaboutIntersection,
|
||||
fbresult::ManeuverType_Roundabout},
|
||||
{osrm::guidance::TurnType::EnterAndExitRoundaboutIntersection,
|
||||
fbresult::ManeuverType_ExitRoundabout},
|
||||
{osrm::guidance::TurnType::NoTurn, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::Suppressed, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::EnterRoundaboutAtExit, fbresult::ManeuverType_Roundabout},
|
||||
{osrm::guidance::TurnType::ExitRoundabout, fbresult::ManeuverType_ExitRoundabout},
|
||||
{osrm::guidance::TurnType::EnterRotaryAtExit, fbresult::ManeuverType_Rotary},
|
||||
{osrm::guidance::TurnType::ExitRotary, fbresult::ManeuverType_ExitRotary},
|
||||
{osrm::guidance::TurnType::EnterRoundaboutIntersectionAtExit,
|
||||
fbresult::ManeuverType_Roundabout},
|
||||
{osrm::guidance::TurnType::ExitRoundaboutIntersection,
|
||||
fbresult::ManeuverType_ExitRoundabout},
|
||||
{osrm::guidance::TurnType::StayOnRoundabout, fbresult::ManeuverType_RoundaboutTurn},
|
||||
{osrm::guidance::TurnType::Sliproad, fbresult::ManeuverType_Notification},
|
||||
{osrm::guidance::TurnType::MaxTurnType, fbresult::ManeuverType_Notification}};
|
||||
return mappings[turn];
|
||||
}
|
||||
|
||||
fbresult::Turn TurnModifierToFB(osrm::guidance::DirectionModifier::Enum modifier) const {
|
||||
static std::map<osrm::guidance::DirectionModifier::Enum, fbresult::Turn> mappings={
|
||||
{osrm::guidance::DirectionModifier::UTurn, fbresult::Turn_UTurn},
|
||||
{osrm::guidance::DirectionModifier::SharpRight, fbresult::Turn_SharpRight},
|
||||
{osrm::guidance::DirectionModifier::Right, fbresult::Turn_Right},
|
||||
{osrm::guidance::DirectionModifier::SlightRight, fbresult::Turn_SlightRight},
|
||||
{osrm::guidance::DirectionModifier::Straight, fbresult::Turn_Straight},
|
||||
{osrm::guidance::DirectionModifier::SlightLeft, fbresult::Turn_SlightLeft},
|
||||
{osrm::guidance::DirectionModifier::Left, fbresult::Turn_Left},
|
||||
{osrm::guidance::DirectionModifier::SharpLeft, fbresult::Turn_SharpLeft},
|
||||
fbresult::Turn TurnModifierToFB(osrm::guidance::DirectionModifier::Enum modifier) const
|
||||
{
|
||||
static std::map<osrm::guidance::DirectionModifier::Enum, fbresult::Turn> mappings = {
|
||||
{osrm::guidance::DirectionModifier::UTurn, fbresult::Turn_UTurn},
|
||||
{osrm::guidance::DirectionModifier::SharpRight, fbresult::Turn_SharpRight},
|
||||
{osrm::guidance::DirectionModifier::Right, fbresult::Turn_Right},
|
||||
{osrm::guidance::DirectionModifier::SlightRight, fbresult::Turn_SlightRight},
|
||||
{osrm::guidance::DirectionModifier::Straight, fbresult::Turn_Straight},
|
||||
{osrm::guidance::DirectionModifier::SlightLeft, fbresult::Turn_SlightLeft},
|
||||
{osrm::guidance::DirectionModifier::Left, fbresult::Turn_Left},
|
||||
{osrm::guidance::DirectionModifier::SharpLeft, fbresult::Turn_SharpLeft},
|
||||
};
|
||||
return mappings[modifier];
|
||||
}
|
||||
|
||||
std::vector<int8_t> TurnLaneTypeToFB(const extractor::TurnLaneType::Mask lane_type) const {
|
||||
std::vector<int8_t> TurnLaneTypeToFB(const extractor::TurnLaneType::Mask lane_type) const
|
||||
{
|
||||
const static fbresult::Turn mapping[] = {fbresult::Turn_None,
|
||||
fbresult::Turn_Straight,
|
||||
fbresult::Turn_SharpLeft,
|
||||
fbresult::Turn_Left,
|
||||
fbresult::Turn_SlightLeft,
|
||||
fbresult::Turn_SlightRight,
|
||||
fbresult::Turn_Right,
|
||||
fbresult::Turn_SharpRight,
|
||||
fbresult::Turn_UTurn,
|
||||
fbresult::Turn_SlightLeft,
|
||||
fbresult::Turn_SlightRight};
|
||||
fbresult::Turn_Straight,
|
||||
fbresult::Turn_SharpLeft,
|
||||
fbresult::Turn_Left,
|
||||
fbresult::Turn_SlightLeft,
|
||||
fbresult::Turn_SlightRight,
|
||||
fbresult::Turn_Right,
|
||||
fbresult::Turn_SharpRight,
|
||||
fbresult::Turn_UTurn,
|
||||
fbresult::Turn_SlightLeft,
|
||||
fbresult::Turn_SlightRight};
|
||||
std::vector<int8_t> result;
|
||||
std::bitset<8 * sizeof(extractor::TurnLaneType::Mask)> mask(lane_type);
|
||||
for (auto index : util::irange<std::size_t>(0, extractor::TurnLaneType::NUM_TYPES))
|
||||
@@ -286,22 +312,24 @@ public:
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
flatbuffers::Offset<fbresult::RouteObject>
|
||||
MakeRoute(flatbuffers::FlatBufferBuilder &fb_result,
|
||||
const std::vector<PhantomNodes> &segment_end_coordinates,
|
||||
const std::vector<std::vector<PathData>> &unpacked_path_segments,
|
||||
const std::vector<bool> &source_traversed_in_reverse,
|
||||
const std::vector<bool> &target_traversed_in_reverse) const
|
||||
MakeRoute(flatbuffers::FlatBufferBuilder &fb_result,
|
||||
const std::vector<PhantomNodes> &segment_end_coordinates,
|
||||
const std::vector<std::vector<PathData>> &unpacked_path_segments,
|
||||
const std::vector<bool> &source_traversed_in_reverse,
|
||||
const std::vector<bool> &target_traversed_in_reverse) const
|
||||
{
|
||||
fbresult::RouteObjectBuilder routeObject(fb_result);
|
||||
|
||||
auto legs_info = MakeLegs(segment_end_coordinates, unpacked_path_segments, source_traversed_in_reverse, target_traversed_in_reverse);
|
||||
auto legs_info = MakeLegs(segment_end_coordinates,
|
||||
unpacked_path_segments,
|
||||
source_traversed_in_reverse,
|
||||
target_traversed_in_reverse);
|
||||
std::vector<guidance::RouteLeg> legs = legs_info.first;
|
||||
std::vector<guidance::LegGeometry> leg_geometries = legs_info.second;
|
||||
|
||||
//Fill basix route info
|
||||
// Fill basix route info
|
||||
auto route = guidance::assembleRoute(legs);
|
||||
routeObject.add_distance(route.distance);
|
||||
routeObject.add_duration(route.duration);
|
||||
@@ -309,137 +337,175 @@ public:
|
||||
auto weight_name_string = fb_result.CreateString(facade.GetWeightName());
|
||||
routeObject.add_weight_name(weight_name_string);
|
||||
|
||||
//Fill legs
|
||||
// Fill legs
|
||||
std::vector<flatbuffers::Offset<fbresult::Leg>> routeLegs;
|
||||
routeLegs.reserve(legs.size());
|
||||
for (const auto idx : util::irange<std::size_t>(0UL, legs.size())) {
|
||||
for (const auto idx : util::irange<std::size_t>(0UL, legs.size()))
|
||||
{
|
||||
auto leg = legs[idx];
|
||||
auto &leg_geometry = leg_geometries[idx];
|
||||
fbresult::LegBuilder legBuilder(fb_result);
|
||||
legBuilder.add_distance(leg.distance);
|
||||
legBuilder.add_duration(leg.duration);
|
||||
legBuilder.add_weight(leg.weight);
|
||||
if (!leg.summary.empty()) {
|
||||
if (!leg.summary.empty())
|
||||
{
|
||||
auto summary_string = fb_result.CreateString(leg.summary);
|
||||
legBuilder.add_summary(summary_string);
|
||||
}
|
||||
|
||||
//Fill steps
|
||||
if (!leg.steps.empty()) {
|
||||
// Fill steps
|
||||
if (!leg.steps.empty())
|
||||
{
|
||||
std::vector<flatbuffers::Offset<fbresult::Step>> legSteps;
|
||||
legSteps.resize(leg.steps.size());
|
||||
std::transform(leg.steps.begin(), leg.steps.end(), legSteps.begin(), [this, &leg_geometry, &fb_result](const guidance::RouteStep& step) {
|
||||
fbresult::StepBuilder stepBuilder(fb_result);
|
||||
stepBuilder.add_duration(step.duration);
|
||||
stepBuilder.add_distance(step.distance);
|
||||
stepBuilder.add_weight(step.weight);
|
||||
auto name_string = fb_result.CreateString(step.name);
|
||||
stepBuilder.add_name(name_string);
|
||||
if (!step.ref.empty()) {
|
||||
auto ref_string = fb_result.CreateString(step.ref);
|
||||
stepBuilder.add_ref(ref_string);
|
||||
}
|
||||
if (!step.pronunciation.empty()) {
|
||||
auto pronunciation_string = fb_result.CreateString(step.pronunciation);
|
||||
stepBuilder.add_pronunciation(pronunciation_string);
|
||||
}
|
||||
if (!step.destinations.empty()) {
|
||||
auto destinations_string = fb_result.CreateString(step.destinations);
|
||||
stepBuilder.add_destinations(destinations_string);
|
||||
}
|
||||
if (!step.exits.empty()) {
|
||||
auto exists_string = fb_result.CreateString(step.exits);
|
||||
stepBuilder.add_exits(exists_string);
|
||||
}
|
||||
if(!step.rotary_name.empty()) {
|
||||
auto rotary_name_string = fb_result.CreateString(step.rotary_name);
|
||||
stepBuilder.add_rotary_name(rotary_name_string);
|
||||
if (!step.rotary_pronunciation.empty()) {
|
||||
auto rotary_pronunciation_string = fb_result.CreateString(step.rotary_pronunciation);
|
||||
stepBuilder.add_rotary_pronunciation(rotary_pronunciation_string);
|
||||
std::transform(
|
||||
leg.steps.begin(),
|
||||
leg.steps.end(),
|
||||
legSteps.begin(),
|
||||
[this, &leg_geometry, &fb_result](const guidance::RouteStep &step) {
|
||||
fbresult::StepBuilder stepBuilder(fb_result);
|
||||
stepBuilder.add_duration(step.duration);
|
||||
stepBuilder.add_distance(step.distance);
|
||||
stepBuilder.add_weight(step.weight);
|
||||
auto name_string = fb_result.CreateString(step.name);
|
||||
stepBuilder.add_name(name_string);
|
||||
if (!step.ref.empty())
|
||||
{
|
||||
auto ref_string = fb_result.CreateString(step.ref);
|
||||
stepBuilder.add_ref(ref_string);
|
||||
}
|
||||
}
|
||||
auto mode_string = fb_result.CreateString(extractor::travelModeToString(step.mode));
|
||||
stepBuilder.add_mode(mode_string);
|
||||
stepBuilder.add_driving_side(step.is_left_hand_driving);
|
||||
|
||||
//Geometry
|
||||
MakeGeometry(stepBuilder, leg_geometry.locations.begin() + step.geometry_begin, leg_geometry.locations.begin() + step.geometry_end);
|
||||
//Maneuver
|
||||
fbresult::StepManeuverBuilder maneuver(fb_result);
|
||||
fbresult::Position maneuverPosition{static_cast<float>(util::toFloating(step.maneuver.location.lon).__value),
|
||||
static_cast<float>(util::toFloating(step.maneuver.location.lat).__value)};
|
||||
maneuver.add_location(&maneuverPosition);
|
||||
maneuver.add_bearing_before(step.maneuver.bearing_before);
|
||||
maneuver.add_bearing_after(step.maneuver.bearing_after);
|
||||
if (step.maneuver.waypoint_type == guidance::WaypointType::None)
|
||||
maneuver.add_type(TurnTypeToFB(step.maneuver.instruction.type));
|
||||
else
|
||||
maneuver.add_type(WaypointTypeToFB(step.maneuver.waypoint_type));
|
||||
if (osrm::engine::api::json::detail::isValidModifier(step.maneuver)) {
|
||||
maneuver.add_modifier(TurnModifierToFB(step.maneuver.instruction.direction_modifier));
|
||||
}
|
||||
if (step.maneuver.exit != 0) {
|
||||
maneuver.add_exit(step.maneuver.exit);
|
||||
}
|
||||
|
||||
//intersections
|
||||
std::vector<flatbuffers::Offset<fbresult::Intersection>> intersections;
|
||||
intersections.resize(step.intersections.size());
|
||||
std::transform(step.intersections.begin(), step.intersections.end(), intersections.begin(), [&fb_result, this](const guidance::IntermediateIntersection& intersection) {
|
||||
fbresult::IntersectionBuilder intersectionBuilder(fb_result);
|
||||
fbresult::Position maneuverPosition{static_cast<float>(util::toFloating(intersection.location.lon).__value),
|
||||
static_cast<float>(util::toFloating(intersection.location.lat).__value)};
|
||||
intersectionBuilder.add_location(&maneuverPosition);
|
||||
auto bearings_vector = fb_result.CreateVector(intersection.bearings);
|
||||
intersectionBuilder.add_bearings(bearings_vector);
|
||||
std::vector<flatbuffers::Offset<flatbuffers::String>> classes;
|
||||
classes.resize(intersection.classes.size());
|
||||
std::transform(intersection.classes.begin(), intersection.classes.end(), classes.begin(), [&fb_result](const std::string cls) {
|
||||
return fb_result.CreateString(cls);
|
||||
});
|
||||
auto classes_vector = fb_result.CreateVector(classes);
|
||||
intersectionBuilder.add_classes(classes_vector);
|
||||
auto entry_vector = fb_result.CreateVector(intersection.entry);
|
||||
intersectionBuilder.add_entry(entry_vector);
|
||||
intersectionBuilder.add_in(intersection.in);
|
||||
intersectionBuilder.add_out(intersection.out);
|
||||
if (api::json::detail::hasValidLanes(intersection)) {
|
||||
BOOST_ASSERT(intersection.lanes.lanes_in_turn >= 1);
|
||||
std::vector<flatbuffers::Offset<fbresult::Lane>> lanes;
|
||||
lanes.resize(intersection.lane_description.size());
|
||||
LaneID lane_id = intersection.lane_description.size();
|
||||
|
||||
for (const auto &lane_desc : intersection.lane_description)
|
||||
if (!step.pronunciation.empty())
|
||||
{
|
||||
auto pronunciation_string = fb_result.CreateString(step.pronunciation);
|
||||
stepBuilder.add_pronunciation(pronunciation_string);
|
||||
}
|
||||
if (!step.destinations.empty())
|
||||
{
|
||||
auto destinations_string = fb_result.CreateString(step.destinations);
|
||||
stepBuilder.add_destinations(destinations_string);
|
||||
}
|
||||
if (!step.exits.empty())
|
||||
{
|
||||
auto exists_string = fb_result.CreateString(step.exits);
|
||||
stepBuilder.add_exits(exists_string);
|
||||
}
|
||||
if (!step.rotary_name.empty())
|
||||
{
|
||||
auto rotary_name_string = fb_result.CreateString(step.rotary_name);
|
||||
stepBuilder.add_rotary_name(rotary_name_string);
|
||||
if (!step.rotary_pronunciation.empty())
|
||||
{
|
||||
--lane_id;
|
||||
fbresult::LaneBuilder laneBuilder(fb_result);
|
||||
auto indications_vector = fb_result.CreateVector(TurnLaneTypeToFB(lane_desc));
|
||||
laneBuilder.add_indications(indications_vector);
|
||||
if (lane_id >= intersection.lanes.first_lane_from_the_right &&
|
||||
lane_id <
|
||||
intersection.lanes.first_lane_from_the_right + intersection.lanes.lanes_in_turn)
|
||||
laneBuilder.add_valid(true);
|
||||
else
|
||||
laneBuilder.add_valid(false);
|
||||
|
||||
lanes.emplace_back(laneBuilder.Finish());
|
||||
auto rotary_pronunciation_string =
|
||||
fb_result.CreateString(step.rotary_pronunciation);
|
||||
stepBuilder.add_rotary_pronunciation(rotary_pronunciation_string);
|
||||
}
|
||||
auto lanes_vector = fb_result.CreateVector(lanes);
|
||||
intersectionBuilder.add_lanes(lanes_vector);
|
||||
}
|
||||
auto mode_string =
|
||||
fb_result.CreateString(extractor::travelModeToString(step.mode));
|
||||
stepBuilder.add_mode(mode_string);
|
||||
stepBuilder.add_driving_side(step.is_left_hand_driving);
|
||||
|
||||
// Geometry
|
||||
MakeGeometry(stepBuilder,
|
||||
leg_geometry.locations.begin() + step.geometry_begin,
|
||||
leg_geometry.locations.begin() + step.geometry_end);
|
||||
// Maneuver
|
||||
fbresult::StepManeuverBuilder maneuver(fb_result);
|
||||
fbresult::Position maneuverPosition{
|
||||
static_cast<float>(
|
||||
util::toFloating(step.maneuver.location.lon).__value),
|
||||
static_cast<float>(
|
||||
util::toFloating(step.maneuver.location.lat).__value)};
|
||||
maneuver.add_location(&maneuverPosition);
|
||||
maneuver.add_bearing_before(step.maneuver.bearing_before);
|
||||
maneuver.add_bearing_after(step.maneuver.bearing_after);
|
||||
if (step.maneuver.waypoint_type == guidance::WaypointType::None)
|
||||
maneuver.add_type(TurnTypeToFB(step.maneuver.instruction.type));
|
||||
else
|
||||
maneuver.add_type(WaypointTypeToFB(step.maneuver.waypoint_type));
|
||||
if (osrm::engine::api::json::detail::isValidModifier(step.maneuver))
|
||||
{
|
||||
maneuver.add_modifier(
|
||||
TurnModifierToFB(step.maneuver.instruction.direction_modifier));
|
||||
}
|
||||
if (step.maneuver.exit != 0)
|
||||
{
|
||||
maneuver.add_exit(step.maneuver.exit);
|
||||
}
|
||||
|
||||
return intersectionBuilder.Finish();
|
||||
// intersections
|
||||
std::vector<flatbuffers::Offset<fbresult::Intersection>> intersections;
|
||||
intersections.resize(step.intersections.size());
|
||||
std::transform(
|
||||
step.intersections.begin(),
|
||||
step.intersections.end(),
|
||||
intersections.begin(),
|
||||
[&fb_result,
|
||||
this](const guidance::IntermediateIntersection &intersection) {
|
||||
fbresult::IntersectionBuilder intersectionBuilder(fb_result);
|
||||
fbresult::Position maneuverPosition{
|
||||
static_cast<float>(
|
||||
util::toFloating(intersection.location.lon).__value),
|
||||
static_cast<float>(
|
||||
util::toFloating(intersection.location.lat).__value)};
|
||||
intersectionBuilder.add_location(&maneuverPosition);
|
||||
auto bearings_vector =
|
||||
fb_result.CreateVector(intersection.bearings);
|
||||
intersectionBuilder.add_bearings(bearings_vector);
|
||||
std::vector<flatbuffers::Offset<flatbuffers::String>> classes;
|
||||
classes.resize(intersection.classes.size());
|
||||
std::transform(intersection.classes.begin(),
|
||||
intersection.classes.end(),
|
||||
classes.begin(),
|
||||
[&fb_result](const std::string cls) {
|
||||
return fb_result.CreateString(cls);
|
||||
});
|
||||
auto classes_vector = fb_result.CreateVector(classes);
|
||||
intersectionBuilder.add_classes(classes_vector);
|
||||
auto entry_vector = fb_result.CreateVector(intersection.entry);
|
||||
intersectionBuilder.add_entry(entry_vector);
|
||||
intersectionBuilder.add_in(intersection.in);
|
||||
intersectionBuilder.add_out(intersection.out);
|
||||
if (api::json::detail::hasValidLanes(intersection))
|
||||
{
|
||||
BOOST_ASSERT(intersection.lanes.lanes_in_turn >= 1);
|
||||
std::vector<flatbuffers::Offset<fbresult::Lane>> lanes;
|
||||
lanes.resize(intersection.lane_description.size());
|
||||
LaneID lane_id = intersection.lane_description.size();
|
||||
|
||||
for (const auto &lane_desc : intersection.lane_description)
|
||||
{
|
||||
--lane_id;
|
||||
fbresult::LaneBuilder laneBuilder(fb_result);
|
||||
auto indications_vector =
|
||||
fb_result.CreateVector(TurnLaneTypeToFB(lane_desc));
|
||||
laneBuilder.add_indications(indications_vector);
|
||||
if (lane_id >=
|
||||
intersection.lanes.first_lane_from_the_right &&
|
||||
lane_id < intersection.lanes.first_lane_from_the_right +
|
||||
intersection.lanes.lanes_in_turn)
|
||||
laneBuilder.add_valid(true);
|
||||
else
|
||||
laneBuilder.add_valid(false);
|
||||
|
||||
lanes.emplace_back(laneBuilder.Finish());
|
||||
}
|
||||
auto lanes_vector = fb_result.CreateVector(lanes);
|
||||
intersectionBuilder.add_lanes(lanes_vector);
|
||||
}
|
||||
|
||||
return intersectionBuilder.Finish();
|
||||
});
|
||||
auto intersections_vector = fb_result.CreateVector(intersections);
|
||||
stepBuilder.add_intersections(intersections_vector);
|
||||
return stepBuilder.Finish();
|
||||
});
|
||||
auto intersections_vector = fb_result.CreateVector(intersections);
|
||||
stepBuilder.add_intersections(intersections_vector);
|
||||
return stepBuilder.Finish();
|
||||
});
|
||||
auto steps_vector = fb_result.CreateVector(legSteps);
|
||||
legBuilder.add_steps(steps_vector);
|
||||
}
|
||||
|
||||
//Fill annotations
|
||||
// Fill annotations
|
||||
// To maintain support for uses of the old default constructors, we check
|
||||
// if annotations property was set manually after default construction
|
||||
auto requested_annotations = parameters.annotations_type;
|
||||
@@ -458,50 +524,53 @@ public:
|
||||
{
|
||||
double prev_speed = 0;
|
||||
auto speed = GetAnnotations<float>(
|
||||
fb_result, leg_geometry, [&prev_speed](const guidance::LegGeometry::Annotation &anno) {
|
||||
if (anno.duration < std::numeric_limits<float>::min())
|
||||
{
|
||||
return prev_speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto speed = std::round(anno.distance / anno.duration * 10.) / 10.;
|
||||
prev_speed = speed;
|
||||
return util::json::clamp_float(speed);
|
||||
}
|
||||
});
|
||||
fb_result,
|
||||
leg_geometry,
|
||||
[&prev_speed](const guidance::LegGeometry::Annotation &anno) {
|
||||
if (anno.duration < std::numeric_limits<float>::min())
|
||||
{
|
||||
return prev_speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto speed = std::round(anno.distance / anno.duration * 10.) / 10.;
|
||||
prev_speed = speed;
|
||||
return util::json::clamp_float(speed);
|
||||
}
|
||||
});
|
||||
annotation.add_speed(speed);
|
||||
}
|
||||
|
||||
if (requested_annotations & RouteParameters::AnnotationsType::Duration)
|
||||
{
|
||||
auto duration = GetAnnotations<uint32_t>(
|
||||
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
||||
return anno.duration;
|
||||
});
|
||||
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
||||
return anno.duration;
|
||||
});
|
||||
annotation.add_duration(duration);
|
||||
}
|
||||
if (requested_annotations & RouteParameters::AnnotationsType::Distance)
|
||||
{
|
||||
auto distance = GetAnnotations<uint32_t>(
|
||||
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
||||
return anno.distance;
|
||||
});
|
||||
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
||||
return anno.distance;
|
||||
});
|
||||
annotation.add_distance(distance);
|
||||
}
|
||||
if (requested_annotations & RouteParameters::AnnotationsType::Weight)
|
||||
{
|
||||
auto weight = GetAnnotations<uint32_t>(
|
||||
fb_result, leg_geometry,
|
||||
[](const guidance::LegGeometry::Annotation &anno) { return anno.weight; });
|
||||
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
||||
return anno.weight;
|
||||
});
|
||||
annotation.add_weight(weight);
|
||||
}
|
||||
if (requested_annotations & RouteParameters::AnnotationsType::Datasources)
|
||||
{
|
||||
auto datasources = GetAnnotations<uint32_t>(
|
||||
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
||||
return anno.datasource;
|
||||
});
|
||||
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
||||
return anno.datasource;
|
||||
});
|
||||
annotation.add_datasources(datasources);
|
||||
}
|
||||
if (requested_annotations & RouteParameters::AnnotationsType::Nodes)
|
||||
@@ -527,7 +596,8 @@ public:
|
||||
// Length of 0 indicates the first empty name, so we can stop here
|
||||
if (name.size() == 0)
|
||||
break;
|
||||
names.emplace_back(fb_result.CreateString(std::string(facade.GetDatasourceName(i))));
|
||||
names.emplace_back(
|
||||
fb_result.CreateString(std::string(facade.GetDatasourceName(i))));
|
||||
}
|
||||
auto datasource_names_vector = fb_result.CreateVector(names);
|
||||
metadata.add_datasource_names(datasource_names_vector);
|
||||
@@ -542,9 +612,10 @@ public:
|
||||
auto legs_vector = fb_result.CreateVector(routeLegs);
|
||||
routeObject.add_legs(legs_vector);
|
||||
|
||||
//Fill geometry
|
||||
// Fill geometry
|
||||
auto overview = MakeOverview(leg_geometries);
|
||||
if(overview) {
|
||||
if (overview)
|
||||
{
|
||||
MakeGeometry(routeObject, overview->begin(), overview->end());
|
||||
}
|
||||
|
||||
@@ -556,12 +627,16 @@ public:
|
||||
const std::vector<bool> &source_traversed_in_reverse,
|
||||
const std::vector<bool> &target_traversed_in_reverse) const
|
||||
{
|
||||
auto legs_info = MakeLegs(segment_end_coordinates, unpacked_path_segments, source_traversed_in_reverse, target_traversed_in_reverse);
|
||||
auto legs_info = MakeLegs(segment_end_coordinates,
|
||||
unpacked_path_segments,
|
||||
source_traversed_in_reverse,
|
||||
target_traversed_in_reverse);
|
||||
std::vector<guidance::RouteLeg> legs = legs_info.first;
|
||||
std::vector<guidance::LegGeometry> leg_geometries = legs_info.second;
|
||||
|
||||
auto route = guidance::assembleRoute(legs);
|
||||
boost::optional<util::json::Value> json_overview = MakeGeometry(MakeOverview(leg_geometries));
|
||||
boost::optional<util::json::Value> json_overview =
|
||||
MakeGeometry(MakeOverview(leg_geometries));
|
||||
|
||||
std::vector<util::json::Value> step_geometries;
|
||||
const auto total_step_count =
|
||||
@@ -712,10 +787,12 @@ public:
|
||||
MakeLegs(const std::vector<PhantomNodes> &segment_end_coordinates,
|
||||
const std::vector<std::vector<PathData>> &unpacked_path_segments,
|
||||
const std::vector<bool> &source_traversed_in_reverse,
|
||||
const std::vector<bool> &target_traversed_in_reverse) const {
|
||||
auto result = std::make_pair(std::vector<guidance::RouteLeg>(), std::vector<guidance::LegGeometry>());
|
||||
auto& legs = result.first;
|
||||
auto& leg_geometries = result.second;
|
||||
const std::vector<bool> &target_traversed_in_reverse) const
|
||||
{
|
||||
auto result =
|
||||
std::make_pair(std::vector<guidance::RouteLeg>(), std::vector<guidance::LegGeometry>());
|
||||
auto &legs = result.first;
|
||||
auto &leg_geometries = result.second;
|
||||
auto number_of_legs = segment_end_coordinates.size();
|
||||
legs.reserve(number_of_legs);
|
||||
leg_geometries.reserve(number_of_legs);
|
||||
@@ -811,12 +888,14 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
boost::optional<std::vector<Coordinate>> MakeOverview(const std::vector<guidance::LegGeometry>& leg_geometries) const {
|
||||
boost::optional<std::vector<Coordinate>>
|
||||
MakeOverview(const std::vector<guidance::LegGeometry> &leg_geometries) const
|
||||
{
|
||||
boost::optional<std::vector<Coordinate>> overview;
|
||||
if (parameters.overview != RouteParameters::OverviewType::False)
|
||||
{
|
||||
const auto use_simplification =
|
||||
parameters.overview == RouteParameters::OverviewType::Simplified;
|
||||
parameters.overview == RouteParameters::OverviewType::Simplified;
|
||||
BOOST_ASSERT(use_simplification ||
|
||||
parameters.overview == RouteParameters::OverviewType::Full);
|
||||
|
||||
|
||||
@@ -51,13 +51,14 @@ class TableAPI final : public BaseAPI
|
||||
const std::vector<TableCellRef> &fallback_speed_cells,
|
||||
osrm::engine::api::ResultT &response) const
|
||||
{
|
||||
if(response.is<flatbuffers::FlatBufferBuilder>()) {
|
||||
auto& fb_result = response.get<flatbuffers::FlatBufferBuilder>();
|
||||
if (response.is<flatbuffers::FlatBufferBuilder>())
|
||||
{
|
||||
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
|
||||
MakeResponse(tables, phantoms, fallback_speed_cells, fb_result);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& json_result = response.get<util::json::Object>();
|
||||
auto &json_result = response.get<util::json::Object>();
|
||||
MakeResponse(tables, phantoms, fallback_speed_cells, json_result);
|
||||
}
|
||||
}
|
||||
@@ -66,7 +67,8 @@ class TableAPI final : public BaseAPI
|
||||
MakeResponse(const std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>> &tables,
|
||||
const std::vector<PhantomNode> &phantoms,
|
||||
const std::vector<TableCellRef> &fallback_speed_cells,
|
||||
flatbuffers::FlatBufferBuilder &fb_result) const {
|
||||
flatbuffers::FlatBufferBuilder &fb_result) const
|
||||
{
|
||||
auto number_of_sources = parameters.sources.size();
|
||||
auto number_of_destinations = parameters.destinations.size();
|
||||
|
||||
@@ -169,21 +171,22 @@ class TableAPI final : public BaseAPI
|
||||
|
||||
protected:
|
||||
virtual flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
|
||||
MakeWaypoints(flatbuffers::FlatBufferBuilder& builder, const std::vector<PhantomNode> &phantoms) const
|
||||
MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
|
||||
const std::vector<PhantomNode> &phantoms) const
|
||||
{
|
||||
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
|
||||
waypoints.reserve(phantoms.size());
|
||||
BOOST_ASSERT(phantoms.size() == parameters.coordinates.size());
|
||||
|
||||
boost::range::transform(
|
||||
phantoms,
|
||||
std::back_inserter(waypoints),
|
||||
[this, &builder](const PhantomNode &phantom) { return BaseAPI::MakeWaypoint(builder, phantom).Finish(); });
|
||||
phantoms, std::back_inserter(waypoints), [this, &builder](const PhantomNode &phantom) {
|
||||
return BaseAPI::MakeWaypoint(builder, phantom).Finish();
|
||||
});
|
||||
return builder.CreateVector(waypoints);
|
||||
}
|
||||
|
||||
virtual flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
|
||||
MakeWaypoints(flatbuffers::FlatBufferBuilder& builder,
|
||||
MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
|
||||
const std::vector<PhantomNode> &phantoms,
|
||||
const std::vector<std::size_t> &indices) const
|
||||
{
|
||||
@@ -199,49 +202,53 @@ class TableAPI final : public BaseAPI
|
||||
}
|
||||
|
||||
virtual flatbuffers::Offset<flatbuffers::Vector<float>>
|
||||
MakeDurationTable(flatbuffers::FlatBufferBuilder& builder,
|
||||
MakeDurationTable(flatbuffers::FlatBufferBuilder &builder,
|
||||
const std::vector<EdgeWeight> &values) const
|
||||
{
|
||||
std::vector<float> distance_table;
|
||||
distance_table.resize(values.size());
|
||||
std::transform(values.begin(), values.end(), distance_table.begin(), [](const EdgeWeight duration) {
|
||||
if (duration == MAXIMAL_EDGE_DURATION) {
|
||||
return 0.;
|
||||
}
|
||||
return duration / 10.;
|
||||
});
|
||||
std::transform(
|
||||
values.begin(), values.end(), distance_table.begin(), [](const EdgeWeight duration) {
|
||||
if (duration == MAXIMAL_EDGE_DURATION)
|
||||
{
|
||||
return 0.;
|
||||
}
|
||||
return duration / 10.;
|
||||
});
|
||||
return builder.CreateVector(distance_table);
|
||||
}
|
||||
|
||||
virtual flatbuffers::Offset<flatbuffers::Vector<float>>
|
||||
MakeDistanceTable(flatbuffers::FlatBufferBuilder& builder,
|
||||
MakeDistanceTable(flatbuffers::FlatBufferBuilder &builder,
|
||||
const std::vector<EdgeDistance> &values) const
|
||||
{
|
||||
std::vector<float> duration_table;
|
||||
duration_table.resize(values.size());
|
||||
std::transform(values.begin(), values.end(), duration_table.begin(), [](const EdgeDistance distance) {
|
||||
if (distance == INVALID_EDGE_DISTANCE) {
|
||||
return 0.;
|
||||
}
|
||||
return std::round(distance * 10) / 10.;
|
||||
});
|
||||
std::transform(
|
||||
values.begin(), values.end(), duration_table.begin(), [](const EdgeDistance distance) {
|
||||
if (distance == INVALID_EDGE_DISTANCE)
|
||||
{
|
||||
return 0.;
|
||||
}
|
||||
return std::round(distance * 10) / 10.;
|
||||
});
|
||||
return builder.CreateVector(duration_table);
|
||||
}
|
||||
|
||||
virtual flatbuffers::Offset<flatbuffers::Vector<uint32_t>>
|
||||
MakeEstimatesTable(flatbuffers::FlatBufferBuilder& builder, const std::vector<TableCellRef> &fallback_speed_cells) const
|
||||
MakeEstimatesTable(flatbuffers::FlatBufferBuilder &builder,
|
||||
const std::vector<TableCellRef> &fallback_speed_cells) const
|
||||
{
|
||||
std::vector<uint32_t> fb_table;
|
||||
fb_table.reserve(fallback_speed_cells.size());
|
||||
std::for_each(
|
||||
fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) {
|
||||
fb_table.push_back(cell.row);
|
||||
fb_table.push_back(cell.column);
|
||||
});
|
||||
fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) {
|
||||
fb_table.push_back(cell.row);
|
||||
fb_table.push_back(cell.column);
|
||||
});
|
||||
return builder.CreateVector(fb_table);
|
||||
}
|
||||
|
||||
|
||||
virtual util::json::Array MakeWaypoints(const std::vector<PhantomNode> &phantoms) const
|
||||
{
|
||||
util::json::Array json_waypoints;
|
||||
|
||||
@@ -31,21 +31,26 @@ class TripAPI final : public RouteAPI
|
||||
{
|
||||
BOOST_ASSERT(sub_trips.size() == sub_routes.size());
|
||||
|
||||
if (response.is<flatbuffers::FlatBufferBuilder>()) {
|
||||
if (response.is<flatbuffers::FlatBufferBuilder>())
|
||||
{
|
||||
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
|
||||
MakeResponse(sub_trips, sub_routes, phantoms, fb_result);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &json_result = response.get<util::json::Object>();
|
||||
MakeResponse(sub_trips, sub_routes, phantoms, json_result);
|
||||
}
|
||||
|
||||
}
|
||||
void MakeResponse(const std::vector<std::vector<NodeID>> &sub_trips,
|
||||
const std::vector<InternalRouteResult> &sub_routes,
|
||||
const std::vector<PhantomNode> &phantoms,
|
||||
flatbuffers::FlatBufferBuilder &fb_result) const
|
||||
{
|
||||
auto response = MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_trips, &phantoms]() { return MakeWaypoints(fb_result, sub_trips, phantoms); });
|
||||
auto response =
|
||||
MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_trips, &phantoms]() {
|
||||
return MakeWaypoints(fb_result, sub_trips, phantoms);
|
||||
});
|
||||
|
||||
fb_result.Finish(response.Finish());
|
||||
}
|
||||
@@ -74,25 +79,29 @@ class TripAPI final : public RouteAPI
|
||||
// FIXME this logic is a little backwards. We should change the output format of the
|
||||
// trip plugin routing algorithm to be easier to consume here.
|
||||
|
||||
struct TripIndex {
|
||||
struct TripIndex
|
||||
{
|
||||
TripIndex() = default;
|
||||
|
||||
TripIndex(unsigned sub_trip_index_, unsigned point_index_)
|
||||
: sub_trip_index(sub_trip_index_), point_index(point_index_) {
|
||||
: sub_trip_index(sub_trip_index_), point_index(point_index_)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned sub_trip_index = std::numeric_limits<unsigned>::max();
|
||||
unsigned point_index = std::numeric_limits<unsigned>::max();
|
||||
|
||||
bool NotUsed() {
|
||||
bool NotUsed()
|
||||
{
|
||||
return sub_trip_index == std::numeric_limits<unsigned>::max() &&
|
||||
point_index == std::numeric_limits<unsigned>::max();
|
||||
}
|
||||
};
|
||||
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> MakeWaypoints(flatbuffers::FlatBufferBuilder &fb_result,
|
||||
const std::vector<std::vector<NodeID>> &sub_trips,
|
||||
const std::vector<PhantomNode> &phantoms) const
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
|
||||
MakeWaypoints(flatbuffers::FlatBufferBuilder &fb_result,
|
||||
const std::vector<std::vector<NodeID>> &sub_trips,
|
||||
const std::vector<PhantomNode> &phantoms) const
|
||||
{
|
||||
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
|
||||
waypoints.reserve(parameters.coordinates.size());
|
||||
@@ -135,13 +144,15 @@ class TripAPI final : public RouteAPI
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
std::vector<TripIndex>
|
||||
MakeTripIndices(const std::vector<std::vector<NodeID>> &sub_trips) const {
|
||||
std::vector<TripIndex> MakeTripIndices(const std::vector<std::vector<NodeID>> &sub_trips) const
|
||||
{
|
||||
std::vector<TripIndex> input_idx_to_trip_idx(parameters.coordinates.size());
|
||||
for (auto sub_trip_index : util::irange<unsigned>(0u, sub_trips.size())) {
|
||||
for (auto point_index : util::irange<unsigned>(0u, sub_trips[sub_trip_index].size())) {
|
||||
for (auto sub_trip_index : util::irange<unsigned>(0u, sub_trips.size()))
|
||||
{
|
||||
for (auto point_index : util::irange<unsigned>(0u, sub_trips[sub_trip_index].size()))
|
||||
{
|
||||
input_idx_to_trip_idx[sub_trips[sub_trip_index][point_index]] =
|
||||
TripIndex{sub_trip_index, point_index};
|
||||
TripIndex{sub_trip_index, point_index};
|
||||
}
|
||||
}
|
||||
return input_idx_to_trip_idx;
|
||||
|
||||
+11
-22
@@ -32,18 +32,13 @@ class EngineInterface
|
||||
{
|
||||
public:
|
||||
virtual ~EngineInterface() = default;
|
||||
virtual Status Route(const api::RouteParameters ¶meters,
|
||||
api::ResultT &result) const = 0;
|
||||
virtual Status Table(const api::TableParameters ¶meters,
|
||||
api::ResultT &result) const = 0;
|
||||
virtual Status Route(const api::RouteParameters ¶meters, api::ResultT &result) const = 0;
|
||||
virtual Status Table(const api::TableParameters ¶meters, api::ResultT &result) const = 0;
|
||||
virtual Status Nearest(const api::NearestParameters ¶meters,
|
||||
api::ResultT &result) const = 0;
|
||||
virtual Status Trip(const api::TripParameters ¶meters,
|
||||
api::ResultT &result) const = 0;
|
||||
virtual Status Match(const api::MatchParameters ¶meters,
|
||||
api::ResultT &result) const = 0;
|
||||
virtual Status Tile(const api::TileParameters ¶meters,
|
||||
api::ResultT &result) const = 0;
|
||||
virtual Status Trip(const api::TripParameters ¶meters, api::ResultT &result) const = 0;
|
||||
virtual Status Match(const api::MatchParameters ¶meters, api::ResultT &result) const = 0;
|
||||
virtual Status Tile(const api::TileParameters ¶meters, api::ResultT &result) const = 0;
|
||||
};
|
||||
|
||||
template <typename Algorithm> class Engine final : public EngineInterface
|
||||
@@ -90,38 +85,32 @@ template <typename Algorithm> class Engine final : public EngineInterface
|
||||
Engine &operator=(const Engine &) = delete;
|
||||
virtual ~Engine() = default;
|
||||
|
||||
Status Route(const api::RouteParameters ¶ms,
|
||||
api::ResultT &result) const override final
|
||||
Status Route(const api::RouteParameters ¶ms, api::ResultT &result) const override final
|
||||
{
|
||||
return route_plugin.HandleRequest(GetAlgorithms(params), params, result);
|
||||
}
|
||||
|
||||
Status Table(const api::TableParameters ¶ms,
|
||||
api::ResultT &result) const override final
|
||||
Status Table(const api::TableParameters ¶ms, api::ResultT &result) const override final
|
||||
{
|
||||
return table_plugin.HandleRequest(GetAlgorithms(params), params, result);
|
||||
}
|
||||
|
||||
Status Nearest(const api::NearestParameters ¶ms,
|
||||
api::ResultT &result) const override final
|
||||
Status Nearest(const api::NearestParameters ¶ms, api::ResultT &result) const override final
|
||||
{
|
||||
return nearest_plugin.HandleRequest(GetAlgorithms(params), params, result);
|
||||
}
|
||||
|
||||
Status Trip(const api::TripParameters ¶ms,
|
||||
api::ResultT &result) const override final
|
||||
Status Trip(const api::TripParameters ¶ms, api::ResultT &result) const override final
|
||||
{
|
||||
return trip_plugin.HandleRequest(GetAlgorithms(params), params, result);
|
||||
}
|
||||
|
||||
Status Match(const api::MatchParameters ¶ms,
|
||||
api::ResultT &result) const override final
|
||||
Status Match(const api::MatchParameters ¶ms, api::ResultT &result) const override final
|
||||
{
|
||||
return match_plugin.HandleRequest(GetAlgorithms(params), params, result);
|
||||
}
|
||||
|
||||
Status Tile(const api::TileParameters ¶ms,
|
||||
api::ResultT &result) const override final
|
||||
Status Tile(const api::TileParameters ¶ms, api::ResultT &result) const override final
|
||||
{
|
||||
return tile_plugin.HandleRequest(GetAlgorithms(params), params, result);
|
||||
}
|
||||
|
||||
@@ -64,17 +64,21 @@ class BasePlugin
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ErrorRenderer {
|
||||
struct ErrorRenderer
|
||||
{
|
||||
std::string code;
|
||||
std::string message;
|
||||
|
||||
ErrorRenderer(std::string code, std::string message) : code(std::move(code)), message(std::move(message)) {};
|
||||
ErrorRenderer(std::string code, std::string message)
|
||||
: code(std::move(code)), message(std::move(message)){};
|
||||
|
||||
void operator()(util::json::Object& json_result) {
|
||||
void operator()(util::json::Object &json_result)
|
||||
{
|
||||
json_result.values["code"] = code;
|
||||
json_result.values["message"] = message;
|
||||
};
|
||||
void operator()(flatbuffers::FlatBufferBuilder& fb_result) {
|
||||
void operator()(flatbuffers::FlatBufferBuilder &fb_result)
|
||||
{
|
||||
api::fbresult::FBResultBuilder error(fb_result);
|
||||
error.add_error(true);
|
||||
|
||||
@@ -84,7 +88,8 @@ class BasePlugin
|
||||
error.add_code(codeBuilder.Finish());
|
||||
fb_result.Finish(error.Finish());
|
||||
};
|
||||
void operator()(std::string& str_result) {
|
||||
void operator()(std::string &str_result)
|
||||
{
|
||||
str_result = str(boost::format("code=%1% message=%2%") % code % message);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -28,9 +28,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef OSRM_HPP
|
||||
#define OSRM_HPP
|
||||
|
||||
#include "engine/api/base_result.hpp"
|
||||
#include "osrm/osrm_fwd.hpp"
|
||||
#include "osrm/status.hpp"
|
||||
#include "engine/api/base_result.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -169,10 +169,11 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
|
||||
qi::lit("snapping=") >
|
||||
snapping_type[ph::bind(&engine::api::BaseParameters::snapping, qi::_r1) = qi::_1];
|
||||
|
||||
format_type.add(".json", engine::api::BaseParameters::OutputFormatType::JSON)
|
||||
(".flatbuffers", engine::api::BaseParameters::OutputFormatType::FLATBUFFERS);
|
||||
format_type.add(".json", engine::api::BaseParameters::OutputFormatType::JSON)(
|
||||
".flatbuffers", engine::api::BaseParameters::OutputFormatType::FLATBUFFERS);
|
||||
|
||||
format_rule = -format_type[ph::bind(&engine::api::BaseParameters::format, qi::_r1) = qi::_1];
|
||||
format_rule =
|
||||
-format_type[ph::bind(&engine::api::BaseParameters::format, qi::_r1) = qi::_1];
|
||||
|
||||
exclude_rule = qi::lit("exclude=") >
|
||||
(qi::as_string[+qi::char_("a-zA-Z0-9")] %
|
||||
|
||||
@@ -22,8 +22,9 @@ class MatchService final : public BaseService
|
||||
public:
|
||||
MatchService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||
|
||||
engine::Status
|
||||
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override;
|
||||
engine::Status RunQuery(std::size_t prefix_length,
|
||||
std::string &query,
|
||||
osrm::engine::api::ResultT &result) final override;
|
||||
|
||||
unsigned GetVersion() final override { return 1; }
|
||||
};
|
||||
|
||||
@@ -22,8 +22,9 @@ class NearestService final : public BaseService
|
||||
public:
|
||||
NearestService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||
|
||||
engine::Status
|
||||
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override;
|
||||
engine::Status RunQuery(std::size_t prefix_length,
|
||||
std::string &query,
|
||||
osrm::engine::api::ResultT &result) final override;
|
||||
|
||||
unsigned GetVersion() final override { return 1; }
|
||||
};
|
||||
|
||||
@@ -22,8 +22,9 @@ class RouteService final : public BaseService
|
||||
public:
|
||||
RouteService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||
|
||||
engine::Status
|
||||
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override;
|
||||
engine::Status RunQuery(std::size_t prefix_length,
|
||||
std::string &query,
|
||||
osrm::engine::api::ResultT &result) final override;
|
||||
|
||||
unsigned GetVersion() final override { return 1; }
|
||||
};
|
||||
|
||||
@@ -22,8 +22,9 @@ class TableService final : public BaseService
|
||||
public:
|
||||
TableService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||
|
||||
engine::Status
|
||||
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override;
|
||||
engine::Status RunQuery(std::size_t prefix_length,
|
||||
std::string &query,
|
||||
osrm::engine::api::ResultT &result) final override;
|
||||
|
||||
unsigned GetVersion() final override { return 1; }
|
||||
};
|
||||
|
||||
@@ -22,8 +22,9 @@ class TileService final : public BaseService
|
||||
public:
|
||||
TileService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||
|
||||
engine::Status
|
||||
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override;
|
||||
engine::Status RunQuery(std::size_t prefix_length,
|
||||
std::string &query,
|
||||
osrm::engine::api::ResultT &result) final override;
|
||||
|
||||
unsigned GetVersion() final override { return 1; }
|
||||
};
|
||||
|
||||
@@ -22,8 +22,9 @@ class TripService final : public BaseService
|
||||
public:
|
||||
TripService(OSRM &routing_machine) : BaseService(routing_machine) {}
|
||||
|
||||
engine::Status
|
||||
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override;
|
||||
engine::Status RunQuery(std::size_t prefix_length,
|
||||
std::string &query,
|
||||
osrm::engine::api::ResultT &result) final override;
|
||||
|
||||
unsigned GetVersion() final override { return 1; }
|
||||
};
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include "server/service/base_service.hpp"
|
||||
|
||||
#include "osrm/osrm.hpp"
|
||||
#include "engine/api/base_api.hpp"
|
||||
#include "osrm/osrm.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user