2016-01-28 10:28:44 -05:00
|
|
|
#ifndef ENGINE_GUIDANCE_ASSEMBLE_GEOMETRY_HPP
|
|
|
|
#define ENGINE_GUIDANCE_ASSEMBLE_GEOMETRY_HPP
|
|
|
|
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "extractor/guidance/turn_instruction.hpp"
|
|
|
|
#include "extractor/travel_mode.hpp"
|
2016-06-14 06:16:42 -04:00
|
|
|
#include "engine/datafacade/datafacade_base.hpp"
|
2016-01-28 10:28:44 -05:00
|
|
|
#include "engine/guidance/leg_geometry.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "engine/guidance/route_step.hpp"
|
|
|
|
#include "engine/internal_route_result.hpp"
|
|
|
|
#include "engine/phantom_node.hpp"
|
2016-01-28 10:28:44 -05:00
|
|
|
#include "util/coordinate.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "util/coordinate_calculation.hpp"
|
2016-01-28 10:28:44 -05:00
|
|
|
|
2016-03-03 09:45:55 -05:00
|
|
|
#include <utility>
|
2016-05-27 15:05:04 -04:00
|
|
|
#include <vector>
|
2016-01-28 10:28:44 -05:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
|
|
|
namespace guidance
|
|
|
|
{
|
|
|
|
|
|
|
|
// Extracts the geometry for each segment and calculates the traveled distance
|
|
|
|
// Combines the geometry form the phantom node with the PathData
|
|
|
|
// to the full route geometry.
|
|
|
|
//
|
|
|
|
// turn 0 1 2 3 4
|
|
|
|
// s...x...y...z...t
|
|
|
|
// |---|segment 0
|
|
|
|
// |---| segment 1
|
|
|
|
// |---| segment 2
|
|
|
|
// |---| segment 3
|
2016-06-14 06:16:42 -04:00
|
|
|
inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
|
|
|
|
const std::vector<PathData> &leg_data,
|
|
|
|
const PhantomNode &source_node,
|
2016-10-24 22:15:45 -04:00
|
|
|
const PhantomNode &target_node,
|
|
|
|
const bool reversed_source,
|
|
|
|
const bool reversed_target)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
|
|
|
LegGeometry geometry;
|
|
|
|
|
|
|
|
// segment 0 first and last
|
|
|
|
geometry.segment_offsets.push_back(0);
|
|
|
|
geometry.locations.push_back(source_node.location);
|
|
|
|
|
2016-10-24 22:15:45 -04:00
|
|
|
// u * v
|
|
|
|
// 0 -- 1 -- 2 -- 3
|
|
|
|
// fwd_segment_position: 1
|
|
|
|
// source node fwd: 1 1 -> 2 -> 3
|
|
|
|
// source node rev: 2 0 <- 1 <- 2
|
|
|
|
const auto source_segment_start_coordinate =
|
|
|
|
source_node.fwd_segment_position + (reversed_source ? 1 : 0);
|
2016-07-22 12:23:54 -04:00
|
|
|
const std::vector<NodeID> source_geometry =
|
|
|
|
facade.GetUncompressedForwardGeometry(source_node.packed_geometry_id);
|
2016-08-17 03:49:19 -04:00
|
|
|
geometry.osm_node_ids.push_back(
|
2016-10-24 22:15:45 -04:00
|
|
|
facade.GetOSMNodeIDOfNode(source_geometry[source_segment_start_coordinate]));
|
2016-07-20 08:59:16 -04:00
|
|
|
|
2016-05-09 01:58:13 -04:00
|
|
|
auto cumulative_distance = 0.;
|
2016-01-28 10:28:44 -05:00
|
|
|
auto current_distance = 0.;
|
|
|
|
auto prev_coordinate = geometry.locations.front();
|
|
|
|
for (const auto &path_point : leg_data)
|
|
|
|
{
|
|
|
|
auto coordinate = facade.GetCoordinateOfNode(path_point.turn_via_node);
|
2016-05-09 01:58:13 -04:00
|
|
|
current_distance =
|
2016-01-28 10:28:44 -05:00
|
|
|
util::coordinate_calculation::haversineDistance(prev_coordinate, coordinate);
|
2016-05-09 01:58:13 -04:00
|
|
|
cumulative_distance += current_distance;
|
2016-01-28 10:28:44 -05:00
|
|
|
|
2016-03-23 05:41:28 -04:00
|
|
|
// all changes to this check have to be matched with assemble_steps
|
2016-03-21 13:07:28 -04:00
|
|
|
if (path_point.turn_instruction.type != extractor::guidance::TurnType::NoTurn)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
2016-05-09 01:58:13 -04:00
|
|
|
geometry.segment_distances.push_back(cumulative_distance);
|
2016-01-28 10:28:44 -05:00
|
|
|
geometry.segment_offsets.push_back(geometry.locations.size());
|
2016-05-09 01:58:13 -04:00
|
|
|
cumulative_distance = 0.;
|
2016-01-28 10:28:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
prev_coordinate = coordinate;
|
2016-05-12 12:50:10 -04:00
|
|
|
geometry.annotations.emplace_back(
|
|
|
|
LegGeometry::Annotation{current_distance,
|
|
|
|
path_point.duration_until_turn / 10.,
|
|
|
|
path_point.weight_until_turn / 10.,
|
|
|
|
path_point.datasource_id});
|
2016-01-28 10:28:44 -05:00
|
|
|
geometry.locations.push_back(std::move(coordinate));
|
2016-05-18 16:09:14 -04:00
|
|
|
geometry.osm_node_ids.push_back(facade.GetOSMNodeIDOfNode(path_point.turn_via_node));
|
2016-01-28 10:28:44 -05:00
|
|
|
}
|
2016-05-09 01:58:13 -04:00
|
|
|
current_distance =
|
2016-01-28 10:28:44 -05:00
|
|
|
util::coordinate_calculation::haversineDistance(prev_coordinate, target_node.location);
|
2016-05-09 01:58:13 -04:00
|
|
|
cumulative_distance += current_distance;
|
2016-01-28 10:28:44 -05:00
|
|
|
// segment leading to the target node
|
2016-05-09 01:58:13 -04:00
|
|
|
geometry.segment_distances.push_back(cumulative_distance);
|
2016-07-20 08:59:16 -04:00
|
|
|
|
2016-07-22 12:23:54 -04:00
|
|
|
const std::vector<DatasourceID> forward_datasources =
|
|
|
|
facade.GetUncompressedForwardDatasources(target_node.packed_geometry_id);
|
2016-07-20 08:59:16 -04:00
|
|
|
|
2016-05-12 12:50:10 -04:00
|
|
|
// FIXME this is wrong. We need to check for traversal direction here
|
|
|
|
// and for the case of a local path (target and source on the same edge)
|
2016-05-27 15:05:04 -04:00
|
|
|
geometry.annotations.emplace_back(
|
2016-07-29 01:13:17 -04:00
|
|
|
LegGeometry::Annotation{current_distance,
|
2016-05-12 12:50:10 -04:00
|
|
|
target_node.forward_duration / 10.,
|
2016-07-29 01:13:17 -04:00
|
|
|
target_node.forward_weight / 10.,
|
|
|
|
forward_datasources[target_node.fwd_segment_position]});
|
2016-05-12 12:50:10 -04:00
|
|
|
|
2016-01-28 10:28:44 -05:00
|
|
|
geometry.segment_offsets.push_back(geometry.locations.size());
|
|
|
|
geometry.locations.push_back(target_node.location);
|
|
|
|
|
2016-10-24 22:15:45 -04:00
|
|
|
// u * v
|
|
|
|
// 0 -- 1 -- 2 -- 3
|
|
|
|
// fwd_segment_position: 1
|
|
|
|
// target node fwd: 2 0 -> 1 -> 2
|
|
|
|
// target node rev: 1 1 <- 2 <- 3
|
|
|
|
const auto target_segment_end_coordinate =
|
|
|
|
target_node.fwd_segment_position + (reversed_target ? 0 : 1);
|
2016-07-22 12:23:54 -04:00
|
|
|
const std::vector<NodeID> target_geometry =
|
|
|
|
facade.GetUncompressedForwardGeometry(target_node.packed_geometry_id);
|
2016-05-18 16:09:14 -04:00
|
|
|
geometry.osm_node_ids.push_back(
|
2016-10-24 22:15:45 -04:00
|
|
|
facade.GetOSMNodeIDOfNode(target_geometry[target_segment_end_coordinate]));
|
2016-05-18 16:09:14 -04:00
|
|
|
|
2016-01-28 10:28:44 -05:00
|
|
|
BOOST_ASSERT(geometry.segment_distances.size() == geometry.segment_offsets.size() - 1);
|
|
|
|
BOOST_ASSERT(geometry.locations.size() > geometry.segment_distances.size());
|
2016-05-09 01:58:13 -04:00
|
|
|
BOOST_ASSERT(geometry.annotations.size() == geometry.locations.size() - 1);
|
2016-01-28 10:28:44 -05:00
|
|
|
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|