First compiling version of map_match plugin
This commit is contained in:
@@ -26,7 +26,7 @@ class BaseAPI
|
||||
{
|
||||
}
|
||||
|
||||
virtual util::json::Array
|
||||
util::json::Array
|
||||
MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const
|
||||
{
|
||||
BOOST_ASSERT(parameters.coordinates.size() > 0);
|
||||
@@ -47,7 +47,7 @@ class BaseAPI
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual util::json::Object MakeWaypoint(const util::FixedPointCoordinate input_coordinate,
|
||||
util::json::Object MakeWaypoint(const util::FixedPointCoordinate input_coordinate,
|
||||
const PhantomNode &phantom) const
|
||||
{
|
||||
return json::makeWaypoint(phantom.location, facade.get_name_for_id(phantom.name_id),
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
#ifndef ENGINE_API_MATCH_HPP
|
||||
#define ENGINE_API_MATCH_HPP
|
||||
|
||||
#include "engine/api/route_api.hpp"
|
||||
#include "engine/api/match_parameters.hpp"
|
||||
|
||||
#include "engine/datafacade/datafacade_base.hpp"
|
||||
|
||||
#include "engine/internal_route_result.hpp"
|
||||
#include "engine/map_matching/sub_matching.hpp"
|
||||
|
||||
#include "util/integer_range.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
class MatchAPI final : public RouteAPI
|
||||
{
|
||||
public:
|
||||
MatchAPI(const datafacade::BaseDataFacade &facade_, const MatchParameters ¶meters_)
|
||||
: RouteAPI(facade_, parameters_), parameters(parameters_)
|
||||
{
|
||||
}
|
||||
|
||||
void MakeResponse(const std::vector<map_matching::SubMatching> &sub_matchings,
|
||||
const std::vector<InternalRouteResult> &sub_routes,
|
||||
util::json::Object &response) const
|
||||
{
|
||||
auto number_of_routes = sub_matchings.size();
|
||||
util::json::Array routes;
|
||||
routes.values.reserve(number_of_routes);
|
||||
BOOST_ASSERT(sub_matchings.size() == sub_routes.size());
|
||||
for (auto index : util::irange<std::size_t>(0UL, sub_matchings.size()))
|
||||
{
|
||||
auto route = MakeRoute(sub_routes[index].segment_end_coordinates,
|
||||
sub_routes[index].unpacked_path_segments,
|
||||
sub_routes[index].source_traversed_in_reverse,
|
||||
sub_routes[index].target_traversed_in_reverse);
|
||||
route.values["confidence"] = sub_matchings[index].confidence;
|
||||
}
|
||||
response.values["tracepoints"] = MakeTracepoints(sub_matchings);
|
||||
response.values["routes"] = std::move(routes);
|
||||
response.values["code"] = "ok";
|
||||
}
|
||||
|
||||
protected:
|
||||
// FIXME this logic is a little backwards. We should change the output format of the
|
||||
// map_matching
|
||||
// routing algorithm to be easier to consume here.
|
||||
util::json::Array
|
||||
MakeTracepoints(const std::vector<map_matching::SubMatching> &sub_matchings) const
|
||||
{
|
||||
util::json::Array waypoints;
|
||||
waypoints.values.reserve(parameters.coordinates.size());
|
||||
|
||||
struct MatchingIndex
|
||||
{
|
||||
MatchingIndex() = default;
|
||||
MatchingIndex(unsigned sub_matching_index_, unsigned point_index_)
|
||||
: sub_matching_index(sub_matching_index_), point_index(point_index_)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned sub_matching_index = std::numeric_limits<unsigned>::max();
|
||||
unsigned point_index = std::numeric_limits<unsigned>::max();
|
||||
|
||||
bool NotMatched()
|
||||
{
|
||||
return sub_matching_index == std::numeric_limits<unsigned>::max() &&
|
||||
point_index == std::numeric_limits<unsigned>::max();
|
||||
}
|
||||
};
|
||||
|
||||
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())))
|
||||
{
|
||||
for (auto point_index : util::irange(
|
||||
0u, static_cast<unsigned>(sub_matchings[sub_matching_index].indices.size())))
|
||||
{
|
||||
trace_idx_to_matching_idx[sub_matchings[sub_matching_index].indices[point_index]] =
|
||||
MatchingIndex{sub_matching_index, point_index};
|
||||
}
|
||||
}
|
||||
|
||||
for (auto trace_index : util::irange(0UL, parameters.coordinates.size()))
|
||||
{
|
||||
auto matching_index = trace_idx_to_matching_idx[trace_index];
|
||||
if (matching_index.NotMatched())
|
||||
{
|
||||
waypoints.values.push_back(util::json::Null());
|
||||
continue;
|
||||
}
|
||||
const auto &phantom =
|
||||
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
|
||||
auto waypoint = BaseAPI::MakeWaypoint(parameters.coordinates[trace_index], phantom);
|
||||
waypoint.values["matchings_index"] = matching_index.sub_matching_index;
|
||||
waypoint.values["waypoint_index"] = matching_index.point_index;
|
||||
waypoints.values.push_back(std::move(waypoint));
|
||||
}
|
||||
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
const MatchParameters ¶meters;
|
||||
};
|
||||
|
||||
} // ns api
|
||||
} // ns engine
|
||||
} // ns osrm
|
||||
|
||||
#endif
|
||||
@@ -14,10 +14,10 @@ namespace api
|
||||
|
||||
struct MatchParameters : public RouteParameters
|
||||
{
|
||||
std::vector<boost::optional<unsigned>> timestamps;
|
||||
std::vector<unsigned> timestamps;
|
||||
bool IsValid() const
|
||||
{
|
||||
return timestamps.empty() || timestamps.size() == coordinates.size();
|
||||
return RouteParameters::IsValid() && (timestamps.empty() || timestamps.size() == coordinates.size());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace engine
|
||||
namespace api
|
||||
{
|
||||
|
||||
class RouteAPI final : public BaseAPI
|
||||
class RouteAPI : public BaseAPI
|
||||
{
|
||||
public:
|
||||
RouteAPI(const datafacade::BaseDataFacade &facade_, const RouteParameters ¶meters_)
|
||||
@@ -32,8 +32,7 @@ class RouteAPI final : public BaseAPI
|
||||
{
|
||||
}
|
||||
|
||||
virtual void MakeResponse(const InternalRouteResult &raw_route,
|
||||
util::json::Object &response) const
|
||||
void MakeResponse(const InternalRouteResult &raw_route, util::json::Object &response) const
|
||||
{
|
||||
auto number_of_routes = raw_route.has_alternative() ? 2UL : 1UL;
|
||||
util::json::Array routes;
|
||||
@@ -67,11 +66,10 @@ class RouteAPI final : public BaseAPI
|
||||
return json::makeGeoJSONLineString(begin, end);
|
||||
}
|
||||
|
||||
virtual util::json::Object
|
||||
MakeRoute(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
|
||||
util::json::Object MakeRoute(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
|
||||
{
|
||||
std::vector<guidance::RouteLeg> legs;
|
||||
std::vector<guidance::LegGeometry> leg_geometries;
|
||||
|
||||
Reference in New Issue
Block a user