initial version of intersection classification

This commit is contained in:
Moritz Kobitzsch
2016-04-26 13:27:40 +02:00
committed by Patrick Niklaus
parent 6aa97048df
commit ba074b0116
33 changed files with 1065 additions and 262 deletions
+68
View File
@@ -0,0 +1,68 @@
#include "extractor/guidance/discrete_angle.hpp"
#include "util/guidance/bearing_class.hpp"
#include <boost/assert.hpp>
namespace osrm
{
namespace util
{
namespace guidance
{
static_assert(
360 / BearingClass::discrete_angle_step_size <= 8 * sizeof(BearingClass::FlagBaseType),
"The number of expressable bearings does not fit into the datatype used for storage.");
std::uint8_t BearingClass::discreteBearingID(double angle)
{
BOOST_ASSERT(angle >= 0. && angle <= 360.);
// shift angle by half the step size to have the class be located around the center
angle = (angle + 0.5 * BearingClass::discrete_angle_step_size);
if (angle > 360)
angle -= 360;
return std::uint8_t(angle / BearingClass::discrete_angle_step_size);
}
BearingClass::BearingClass() : available_bearings_mask(0) {}
bool BearingClass::operator==(const BearingClass &other) const
{
return other.available_bearings_mask == available_bearings_mask;
}
bool BearingClass::operator<(const BearingClass &other) const
{
return available_bearings_mask < other.available_bearings_mask;
}
bool BearingClass::addContinuous(const double angle)
{
return addDiscreteID(discreteBearingID(angle));
}
bool BearingClass::addDiscreteID(const std::uint8_t discrete_id)
{
const auto mask = (1 << discrete_id);
const auto is_new = (0 == (available_bearings_mask & mask));
available_bearings_mask |= mask;
return is_new;
}
std::vector<double> BearingClass::getAvailableBearings() const
{
std::vector<double> result;
// account for some basic inaccuracries of double
for (std::size_t discrete_id = 0; discrete_id * discrete_angle_step_size <= 361; ++discrete_id)
{
// ervery set bit indicates a bearing
if (available_bearings_mask & (1 << discrete_id))
result.push_back(discrete_id * discrete_angle_step_size);
}
return result;
}
} // namespace guidance
} // namespace extractor
} // namespace osrm
+38
View File
@@ -0,0 +1,38 @@
#include "util/guidance/entry_class.hpp"
#include <boost/assert.hpp>
namespace osrm
{
namespace util
{
namespace guidance
{
EntryClass::EntryClass() : enabled_entries_flags(0) {}
void EntryClass::activate(std::uint32_t index)
{
BOOST_ASSERT(index < 8 * sizeof(FlagBaseType));
enabled_entries_flags |= (1 << index);
}
bool EntryClass::allowsEntry(std::uint32_t index) const
{
BOOST_ASSERT(index < 8 * sizeof(FlagBaseType));
return 0 != (enabled_entries_flags & (1 << index));
}
bool EntryClass::operator==(const EntryClass &other) const
{
return enabled_entries_flags == other.enabled_entries_flags;
}
bool EntryClass::operator<(const EntryClass &other) const
{
return enabled_entries_flags < other.enabled_entries_flags;
}
} // namespace guidance
} // namespace extractor
} // namespace osrm