Refactor isThroughStreet/Intersection options (#4751)

* refactor isThroughStreet 
* refactor HaveIdenticalName
* fix a typo in the unit tests
This commit is contained in:
Kajari Ghosh
2018-01-19 13:49:00 -05:00
committed by GitHub
parent 341a5345da
commit 155772f01f
18 changed files with 229 additions and 107 deletions
@@ -0,0 +1,33 @@
#ifndef OSRM_EXTRACTOR_GUIDANCE_HAVE_IDENTICAL_NAMES_HPP_
#define OSRM_EXTRACTOR_GUIDANCE_HAVE_IDENTICAL_NAMES_HPP_
#include "util/guidance/name_announcements.hpp"
namespace osrm
{
namespace extractor
{
namespace guidance
{
// check if two name ids can be seen as identical (in presence of refs/others)
// in our case this translates into no name announcement in either direction (lhs->rhs and
// rhs->lhs)
bool HaveIdenticalNames(const NameID lhs,
const NameID rhs,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table)
{
const auto non_empty = (lhs != EMPTY_NAMEID) && (rhs != EMPTY_NAMEID);
// symmetrical check for announcements
return non_empty &&
!util::guidance::requiresNameAnnounced(lhs, rhs, name_table, street_name_suffix_table) &&
!util::guidance::requiresNameAnnounced(rhs, lhs, name_table, street_name_suffix_table);
}
} // namespace guidance
} // namespace extractor
} // namespace osrm
#endif /*OSRM_EXTRACTOR_GUIDANCE_HAVE_IDENTICAL_NAMES_HPP_*/
@@ -418,44 +418,6 @@ void IntersectionHandler::assignTrivialTurns(const EdgeID via_eid,
}
}
bool IntersectionHandler::isThroughStreet(const std::size_t index,
const Intersection &intersection) const
{
const auto &data_at_index = node_data_container.GetAnnotation(
node_based_graph.GetEdgeData(intersection[index].eid).annotation_data);
if (data_at_index.name_id == EMPTY_NAMEID)
return false;
// a through street cannot start at our own position -> index 1
for (std::size_t road_index = 1; road_index < intersection.size(); ++road_index)
{
if (road_index == index)
continue;
const auto &road = intersection[road_index];
const auto &road_data = node_data_container.GetAnnotation(
node_based_graph.GetEdgeData(road.eid).annotation_data);
// roads have a near straight angle (180 degree)
const bool is_nearly_straight = angularDeviation(road.angle, intersection[index].angle) >
(STRAIGHT_ANGLE - FUZZY_ANGLE_DIFFERENCE);
const bool have_same_name =
road_data.name_id != EMPTY_NAMEID &&
!util::guidance::requiresNameAnnounced(
data_at_index.name_id, road_data.name_id, name_table, street_name_suffix_table);
const bool have_same_category =
node_based_graph.GetEdgeData(intersection[index].eid).flags.road_classification ==
node_based_graph.GetEdgeData(road.eid).flags.road_classification;
if (is_nearly_straight && have_same_name && have_same_category)
return true;
}
return false;
}
boost::optional<IntersectionHandler::IntersectionViewAndNode>
IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) const
{
@@ -122,16 +122,6 @@ bool MergableRoadDetector::CanMergeRoad(const NodeID intersection_node,
!IsCircularShape(intersection_node, lhs, rhs);
}
bool MergableRoadDetector::HaveIdenticalNames(const NameID lhs, const NameID rhs) const
{
const auto non_empty = (lhs != EMPTY_NAMEID) && (rhs != EMPTY_NAMEID);
// symmetrical check for announcements
return non_empty &&
!util::guidance::requiresNameAnnounced(lhs, rhs, name_table, street_name_suffix_table) &&
!util::guidance::requiresNameAnnounced(rhs, lhs, name_table, street_name_suffix_table);
}
bool MergableRoadDetector::IsDistinctFrom(const MergableRoadData &lhs,
const MergableRoadData &rhs) const
{
@@ -143,7 +133,9 @@ bool MergableRoadDetector::IsDistinctFrom(const MergableRoadData &lhs,
node_data_container.GetAnnotation(node_based_graph.GetEdgeData(lhs.eid).annotation_data)
.name_id,
node_data_container.GetAnnotation(node_based_graph.GetEdgeData(rhs.eid).annotation_data)
.name_id);
.name_id,
name_table,
street_name_suffix_table);
}
bool MergableRoadDetector::EdgeDataSupportsMerge(
@@ -165,7 +157,8 @@ bool MergableRoadDetector::EdgeDataSupportsMerge(
return false;
// we require valid names
if (!HaveIdenticalNames(lhs_annotation.name_id, rhs_annotation.name_id))
if (!HaveIdenticalNames(
lhs_annotation.name_id, rhs_annotation.name_id, name_table, street_name_suffix_table))
return false;
return lhs_flags.road_classification == rhs_flags.road_classification;
+38 -7
View File
@@ -239,7 +239,12 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in
intersection[1].instruction =
getInstructionForObvious(intersection.size(),
via_eid,
isThroughStreet(1, intersection),
isThroughStreet(1,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
intersection[1]);
}
else
@@ -253,8 +258,16 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in
if (road.angle == continue_angle)
{
road.instruction = getInstructionForObvious(
intersection.size(), via_eid, isThroughStreet(1, intersection), road);
road.instruction =
getInstructionForObvious(intersection.size(),
via_eid,
isThroughStreet(1,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
road);
}
else if (road.angle < continue_angle)
{
@@ -353,8 +366,16 @@ Intersection MotorwayHandler::fromRamp(const EdgeID via_eid, Intersection inters
BOOST_ASSERT(!intersection[0].entry_allowed);
BOOST_ASSERT(isMotorwayClass(intersection[1].eid, node_based_graph));
intersection[1].instruction = getInstructionForObvious(
intersection.size(), via_eid, isThroughStreet(1, intersection), intersection[1]);
intersection[1].instruction =
getInstructionForObvious(intersection.size(),
via_eid,
isThroughStreet(1,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
intersection[1]);
}
else if (intersection.size() == 3)
{
@@ -404,7 +425,12 @@ Intersection MotorwayHandler::fromRamp(const EdgeID via_eid, Intersection inters
intersection[1].instruction =
getInstructionForObvious(intersection.size(),
via_eid,
isThroughStreet(1, intersection),
isThroughStreet(1,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
intersection[1]);
}
}
@@ -429,7 +455,12 @@ Intersection MotorwayHandler::fromRamp(const EdgeID via_eid, Intersection inters
intersection[2].instruction =
getInstructionForObvious(intersection.size(),
via_eid,
isThroughStreet(2, intersection),
isThroughStreet(2,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
intersection[2]);
}
}
+10 -2
View File
@@ -478,8 +478,16 @@ Intersection RoundaboutHandler::handleRoundabouts(const RoundaboutType roundabou
if (util::angularDeviation(turn.angle, STRAIGHT_ANGLE) < FUZZY_ANGLE_DIFFERENCE &&
crossing_roundabout)
{
turn.instruction = getInstructionForObvious(
intersection.size(), via_eid, isThroughStreet(idx, intersection), turn);
turn.instruction =
getInstructionForObvious(intersection.size(),
via_eid,
isThroughStreet(idx,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
turn);
}
else
{
+17 -28
View File
@@ -344,9 +344,24 @@ operator()(const NodeID /*nid*/, const EdgeID source_edge_id, Intersection inter
}
// If the sliproad candidate is a through street, we cannot handle it as a sliproad.
if (isThroughStreet(sliproad_edge, target_intersection))
auto sliproad_in_target_intersection =
std::find_if(begin(target_intersection),
end(target_intersection),
[&](const auto &road) { return road.eid == sliproad_edge; });
if (sliproad_in_target_intersection != target_intersection.end())
{
continue;
auto index_of_sliproad_in_target_intersection =
sliproad_in_target_intersection - target_intersection.begin();
if (isThroughStreet<IntersectionView>(index_of_sliproad_in_target_intersection,
target_intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table))
{
continue;
}
}
// The turn off of the Sliproad has to be obvious and a narrow turn and must not be a
@@ -689,32 +704,6 @@ bool SliproadHandler::nextIntersectionIsTooFarAway(const NodeID start, const Edg
return accumulator.too_far_away;
}
bool SliproadHandler::isThroughStreet(const EdgeID from, const IntersectionView &intersection) const
{
BOOST_ASSERT(from != SPECIAL_EDGEID);
BOOST_ASSERT(!intersection.empty());
const auto from_annotation_id = node_based_graph.GetEdgeData(from).annotation_data;
const auto &edge_name_id = node_data_container.GetAnnotation(from_annotation_id).name_id;
auto first = begin(intersection) + 1; // Skip UTurn road
auto last = end(intersection);
auto same_name = [&](const auto &road) {
const auto annotation_id = node_based_graph.GetEdgeData(road.eid).annotation_data;
const auto &road_name_id = node_data_container.GetAnnotation(annotation_id).name_id;
return edge_name_id != EMPTY_NAMEID && //
road_name_id != EMPTY_NAMEID && //
!util::guidance::requiresNameAnnounced(edge_name_id,
road_name_id,
name_table,
street_name_suffix_table); //
};
return std::find_if(first, last, same_name) != last;
}
bool SliproadHandler::roadContinues(const EdgeID current, const EdgeID next) const
{
const auto &current_data =
+26 -5
View File
@@ -287,8 +287,16 @@ Intersection TurnHandler::handleThreeWayTurn(const EdgeID via_edge, Intersection
const auto direction_at_two = getTurnDirection(intersection[2].angle);
if (obvious_index == 1)
{
intersection[1].instruction = getInstructionForObvious(
3, via_edge, isThroughStreet(1, intersection), intersection[1]);
intersection[1].instruction =
getInstructionForObvious(3,
via_edge,
isThroughStreet(1,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
intersection[1]);
const auto second_direction = (direction_at_one == direction_at_two &&
direction_at_two == DirectionModifier::Straight)
? DirectionModifier::SlightLeft
@@ -300,8 +308,16 @@ Intersection TurnHandler::handleThreeWayTurn(const EdgeID via_edge, Intersection
else
{
BOOST_ASSERT(obvious_index == 2);
intersection[2].instruction = getInstructionForObvious(
3, via_edge, isThroughStreet(2, intersection), intersection[2]);
intersection[2].instruction =
getInstructionForObvious(3,
via_edge,
isThroughStreet(2,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
intersection[2]);
const auto first_direction = (direction_at_one == direction_at_two &&
direction_at_one == DirectionModifier::Straight)
? DirectionModifier::SlightRight
@@ -336,7 +352,12 @@ Intersection TurnHandler::handleComplexTurn(const EdgeID via_edge, Intersection
intersection[obvious_index].instruction =
getInstructionForObvious(intersection.size(),
via_edge,
isThroughStreet(obvious_index, intersection),
isThroughStreet(obvious_index,
intersection,
node_based_graph,
node_data_container,
name_table,
street_name_suffix_table),
intersection[obvious_index]);
// assign left/right turns