2016-04-26 07:27:40 -04:00
|
|
|
#include "extractor/guidance/turn_classification.hpp"
|
|
|
|
|
|
|
|
#include "util/simple_logger.hpp"
|
|
|
|
|
2016-05-09 09:39:11 -04:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iomanip>
|
|
|
|
|
2016-04-26 07:27:40 -04:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace extractor
|
|
|
|
{
|
|
|
|
namespace guidance
|
|
|
|
{
|
|
|
|
|
|
|
|
struct TurnPossibility
|
|
|
|
{
|
2016-05-10 02:37:45 -04:00
|
|
|
TurnPossibility(bool entry_allowed, double bearing)
|
|
|
|
: entry_allowed(entry_allowed), bearing(std::move(bearing))
|
2016-04-26 07:27:40 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-10 02:37:45 -04:00
|
|
|
TurnPossibility() : entry_allowed(false), bearing(0) {}
|
2016-04-26 07:27:40 -04:00
|
|
|
|
|
|
|
bool entry_allowed;
|
|
|
|
double bearing;
|
2016-05-09 09:39:11 -04:00
|
|
|
};
|
|
|
|
|
2016-04-26 07:27:40 -04:00
|
|
|
std::pair<util::guidance::EntryClass, util::guidance::BearingClass>
|
2016-08-17 03:49:19 -04:00
|
|
|
classifyIntersection(Intersection intersection)
|
2016-04-26 07:27:40 -04:00
|
|
|
{
|
2016-05-09 09:39:11 -04:00
|
|
|
if (intersection.empty())
|
|
|
|
return {};
|
2016-04-26 07:27:40 -04:00
|
|
|
|
2016-08-17 03:49:19 -04:00
|
|
|
std::sort(intersection.begin(),
|
|
|
|
intersection.end(),
|
|
|
|
[](const ConnectedRoad &left, const ConnectedRoad &right) {
|
|
|
|
return left.turn.bearing < right.turn.bearing;
|
|
|
|
});
|
2016-04-26 07:27:40 -04:00
|
|
|
|
|
|
|
util::guidance::EntryClass entry_class;
|
|
|
|
util::guidance::BearingClass bearing_class;
|
|
|
|
|
2016-05-10 02:37:45 -04:00
|
|
|
const bool canBeDiscretized = [&]() {
|
2016-08-17 03:49:19 -04:00
|
|
|
if (intersection.size() <= 1)
|
2016-05-10 02:37:45 -04:00
|
|
|
return true;
|
|
|
|
|
2016-08-17 03:49:19 -04:00
|
|
|
DiscreteBearing last_discrete_bearing = util::guidance::BearingClass::getDiscreteBearing(
|
|
|
|
std::round(intersection.back().turn.bearing));
|
|
|
|
for (const auto road : intersection)
|
2016-05-10 02:37:45 -04:00
|
|
|
{
|
|
|
|
const DiscreteBearing discrete_bearing =
|
2016-08-17 03:49:19 -04:00
|
|
|
util::guidance::BearingClass::getDiscreteBearing(std::round(road.turn.bearing));
|
2016-05-10 02:37:45 -04:00
|
|
|
if (discrete_bearing == last_discrete_bearing)
|
|
|
|
return false;
|
|
|
|
last_discrete_bearing = discrete_bearing;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}();
|
|
|
|
|
2016-05-09 09:39:11 -04:00
|
|
|
// finally transfer data to the entry/bearing classes
|
|
|
|
std::size_t number = 0;
|
2016-05-10 02:37:45 -04:00
|
|
|
if (canBeDiscretized)
|
2016-04-26 07:27:40 -04:00
|
|
|
{
|
2016-08-17 03:49:19 -04:00
|
|
|
if (util::guidance::BearingClass::getDiscreteBearing(intersection.back().turn.bearing) <
|
|
|
|
util::guidance::BearingClass::getDiscreteBearing(intersection.front().turn.bearing))
|
2016-05-12 05:16:52 -04:00
|
|
|
{
|
2016-08-17 03:49:19 -04:00
|
|
|
intersection.insert(intersection.begin(), intersection.back());
|
|
|
|
intersection.pop_back();
|
2016-05-12 05:16:52 -04:00
|
|
|
}
|
2016-08-17 03:49:19 -04:00
|
|
|
for (const auto &road : intersection)
|
2016-05-10 02:37:45 -04:00
|
|
|
{
|
2016-08-17 03:49:19 -04:00
|
|
|
if (road.entry_allowed)
|
2016-05-10 02:37:45 -04:00
|
|
|
entry_class.activate(number);
|
|
|
|
auto discrete_bearing_class =
|
2016-08-17 03:49:19 -04:00
|
|
|
util::guidance::BearingClass::getDiscreteBearing(std::round(road.turn.bearing));
|
2016-05-10 02:37:45 -04:00
|
|
|
bearing_class.add(std::round(discrete_bearing_class *
|
|
|
|
util::guidance::BearingClass::discrete_step_size));
|
|
|
|
++number;
|
|
|
|
}
|
2016-04-26 07:27:40 -04:00
|
|
|
}
|
2016-05-10 02:37:45 -04:00
|
|
|
else
|
2016-04-26 07:27:40 -04:00
|
|
|
{
|
2016-08-17 03:49:19 -04:00
|
|
|
for (const auto &road : intersection)
|
2016-04-26 07:27:40 -04:00
|
|
|
{
|
2016-08-17 03:49:19 -04:00
|
|
|
if (road.entry_allowed)
|
2016-05-10 02:37:45 -04:00
|
|
|
entry_class.activate(number);
|
2016-08-17 03:49:19 -04:00
|
|
|
bearing_class.add(std::round(road.turn.bearing));
|
2016-05-10 02:37:45 -04:00
|
|
|
++number;
|
2016-04-26 07:27:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::make_pair(entry_class, bearing_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace guidance
|
|
|
|
} // namespace extractor
|
|
|
|
} // namespace osrm
|