2016-04-08 06:49:14 -04:00
|
|
|
#include "extractor/guidance/intersection.hpp"
|
2016-05-13 13:18:00 -04:00
|
|
|
#include "extractor/guidance/toolkit.hpp"
|
2016-04-08 06:49:14 -04:00
|
|
|
|
2016-11-03 05:18:27 -04:00
|
|
|
#include <boost/range/adaptor/transformed.hpp>
|
|
|
|
#include <boost/range/algorithm/find_if.hpp>
|
|
|
|
|
2016-11-03 10:26:51 -04:00
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
2016-11-03 05:18:27 -04:00
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
|
|
|
#include <limits>
|
|
|
|
|
2016-04-08 06:49:14 -04:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace extractor
|
|
|
|
{
|
|
|
|
namespace guidance
|
|
|
|
{
|
|
|
|
|
2016-11-15 05:21:26 -05:00
|
|
|
ConnectedRoad::ConnectedRoad(const TurnOperation turn,
|
|
|
|
const bool entry_allowed,
|
|
|
|
boost::optional<double> segment_length)
|
|
|
|
: TurnOperation(turn), entry_allowed(entry_allowed), segment_length(segment_length)
|
2016-11-03 05:18:27 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnectedRoad::compareByAngle(const ConnectedRoad &other) const { return angle < other.angle; }
|
|
|
|
|
|
|
|
void ConnectedRoad::mirror()
|
|
|
|
{
|
|
|
|
const constexpr DirectionModifier::Enum mirrored_modifiers[] = {DirectionModifier::UTurn,
|
|
|
|
DirectionModifier::SharpLeft,
|
|
|
|
DirectionModifier::Left,
|
|
|
|
DirectionModifier::SlightLeft,
|
|
|
|
DirectionModifier::Straight,
|
|
|
|
DirectionModifier::SlightRight,
|
|
|
|
DirectionModifier::Right,
|
|
|
|
DirectionModifier::SharpRight};
|
|
|
|
|
|
|
|
static_assert(sizeof(mirrored_modifiers) / sizeof(DirectionModifier::Enum) ==
|
|
|
|
DirectionModifier::MaxDirectionModifier,
|
|
|
|
"The list of mirrored modifiers needs to match the available modifiers in size.");
|
|
|
|
|
|
|
|
if (angularDeviation(angle, 0) > std::numeric_limits<double>::epsilon())
|
|
|
|
{
|
|
|
|
angle = 360 - angle;
|
|
|
|
instruction.direction_modifier = mirrored_modifiers[instruction.direction_modifier];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectedRoad ConnectedRoad::getMirroredCopy() const
|
2016-04-08 06:49:14 -04:00
|
|
|
{
|
2016-11-03 05:18:27 -04:00
|
|
|
ConnectedRoad copy(*this);
|
|
|
|
copy.mirror();
|
|
|
|
return copy;
|
2016-04-08 06:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string toString(const ConnectedRoad &road)
|
|
|
|
{
|
|
|
|
std::string result = "[connection] ";
|
2016-11-03 05:18:27 -04:00
|
|
|
result += std::to_string(road.eid);
|
2016-04-08 06:49:14 -04:00
|
|
|
result += " allows entry: ";
|
|
|
|
result += std::to_string(road.entry_allowed);
|
|
|
|
result += " angle: ";
|
2016-11-03 05:18:27 -04:00
|
|
|
result += std::to_string(road.angle);
|
2016-08-17 03:49:19 -04:00
|
|
|
result += " bearing: ";
|
2016-11-03 05:18:27 -04:00
|
|
|
result += std::to_string(road.bearing);
|
2016-04-08 06:49:14 -04:00
|
|
|
result += " instruction: ";
|
2016-11-03 05:18:27 -04:00
|
|
|
result += std::to_string(static_cast<std::int32_t>(road.instruction.type)) + " " +
|
|
|
|
std::to_string(static_cast<std::int32_t>(road.instruction.direction_modifier)) + " " +
|
|
|
|
std::to_string(static_cast<std::int32_t>(road.lane_data_id));
|
2016-04-08 06:49:14 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-03 05:18:27 -04:00
|
|
|
Intersection::Base::iterator Intersection::findClosestTurn(double angle)
|
|
|
|
{
|
|
|
|
// use the const operator to avoid code duplication
|
|
|
|
return begin() +
|
|
|
|
std::distance(cbegin(), static_cast<const Intersection *>(this)->findClosestTurn(angle));
|
|
|
|
}
|
|
|
|
|
|
|
|
Intersection::Base::const_iterator Intersection::findClosestTurn(double angle) const
|
|
|
|
{
|
|
|
|
return std::min_element(
|
|
|
|
begin(), end(), [angle](const ConnectedRoad &lhs, const ConnectedRoad &rhs) {
|
|
|
|
return util::guidance::angularDeviation(lhs.angle, angle) <
|
|
|
|
util::guidance::angularDeviation(rhs.angle, angle);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Intersection::valid() const
|
2016-05-13 13:18:00 -04:00
|
|
|
{
|
2016-11-03 05:18:27 -04:00
|
|
|
return !empty() &&
|
|
|
|
std::is_sorted(begin(), end(), std::mem_fn(&ConnectedRoad::compareByAngle)) &&
|
|
|
|
operator[](0).angle < std::numeric_limits<double>::epsilon();
|
2016-05-13 13:18:00 -04:00
|
|
|
}
|
2016-11-03 05:18:27 -04:00
|
|
|
|
2016-11-03 10:26:51 -04:00
|
|
|
std::uint8_t
|
|
|
|
Intersection::getHighestConnectedLaneCount(const util::NodeBasedDynamicGraph &graph) const
|
2016-05-13 13:18:00 -04:00
|
|
|
{
|
2016-11-03 05:18:27 -04:00
|
|
|
BOOST_ASSERT(valid()); // non empty()
|
2016-11-03 10:26:51 -04:00
|
|
|
|
2016-11-03 11:58:57 -04:00
|
|
|
const std::function<std::uint8_t(const ConnectedRoad &)> to_lane_count =
|
|
|
|
[&](const ConnectedRoad &road) {
|
|
|
|
return graph.GetEdgeData(road.eid).road_classification.GetNumberOfLanes();
|
|
|
|
};
|
2016-11-03 05:18:27 -04:00
|
|
|
|
|
|
|
std::uint8_t max_lanes = 0;
|
|
|
|
const auto extract_maximal_value = [&max_lanes](std::uint8_t value) {
|
|
|
|
max_lanes = std::max(max_lanes, value);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2016-11-03 10:26:51 -04:00
|
|
|
const auto view = *this | boost::adaptors::transformed(to_lane_count);
|
2016-11-03 05:18:27 -04:00
|
|
|
boost::range::find_if(view, extract_maximal_value);
|
|
|
|
return max_lanes;
|
2016-05-13 13:18:00 -04:00
|
|
|
}
|
|
|
|
|
2016-04-08 06:49:14 -04:00
|
|
|
} // namespace guidance
|
|
|
|
} // namespace extractor
|
|
|
|
} // namespace osrm
|