osrm-backend/include/extractor/guidance/classification_data.hpp

107 lines
3.1 KiB
C++
Raw Normal View History

2016-03-01 16:30:31 -05:00
#ifndef OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_
#define OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_
#include "util/simple_logger.hpp"
2016-02-24 04:29:23 -05:00
#include <cstdint>
2016-02-24 04:29:23 -05:00
#include <string>
#include <unordered_map>
// Forward Declaration to allow usage of external osmium::Way
namespace osmium
{
class Way;
}
namespace osrm
{
2016-03-01 16:30:31 -05:00
namespace extractor
2016-02-24 04:29:23 -05:00
{
namespace guidance
{
enum class FunctionalRoadClass : std::uint8_t
2016-02-24 04:29:23 -05:00
{
2016-03-01 16:30:31 -05:00
UNKNOWN = 0,
2016-02-24 04:29:23 -05:00
MOTORWAY,
MOTORWAY_LINK,
TRUNK,
TRUNK_LINK,
PRIMARY,
PRIMARY_LINK,
SECONDARY,
SECONDARY_LINK,
TERTIARY,
TERTIARY_LINK,
UNCLASSIFIED,
RESIDENTIAL,
SERVICE,
LIVING_STREET,
2016-03-01 16:30:31 -05:00
LOW_PRIORITY_ROAD // a road simply included for connectivity. Should be avoided at all cost
2016-02-24 04:29:23 -05:00
};
inline FunctionalRoadClass functionalRoadClassFromTag(std::string const &value)
{
2016-03-03 09:36:03 -05:00
// FIXME at some point this should be part of the profiles
const static auto class_hash = []
2016-02-24 04:29:23 -05:00
{
std::unordered_map<std::string, FunctionalRoadClass> hash;
hash["motorway"] = FunctionalRoadClass::MOTORWAY;
hash["motorway_link"] = FunctionalRoadClass::MOTORWAY_LINK;
hash["trunk"] = FunctionalRoadClass::TRUNK;
hash["trunk_link"] = FunctionalRoadClass::TRUNK_LINK;
hash["primary"] = FunctionalRoadClass::PRIMARY;
hash["primary_link"] = FunctionalRoadClass::PRIMARY_LINK;
hash["secondary"] = FunctionalRoadClass::SECONDARY;
hash["secondary_link"] = FunctionalRoadClass::SECONDARY_LINK;
hash["tertiary"] = FunctionalRoadClass::TERTIARY;
hash["tertiary_link"] = FunctionalRoadClass::TERTIARY_LINK;
hash["unclassified"] = FunctionalRoadClass::UNCLASSIFIED;
hash["residential"] = FunctionalRoadClass::RESIDENTIAL;
hash["service"] = FunctionalRoadClass::SERVICE;
hash["living_street"] = FunctionalRoadClass::LIVING_STREET;
hash["track"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
hash["road"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
hash["path"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
hash["driveway"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
return hash;
}();
2016-02-24 04:29:23 -05:00
if (class_hash.find(value) != class_hash.end())
{
return class_hash.find(value)->second;
}
else
{
util::SimpleLogger().Write(logDEBUG) << "Unknown road class encountered: " << value;
return FunctionalRoadClass::UNKNOWN;
}
}
inline bool isRampClass(const FunctionalRoadClass road_class)
{
// Primary Roads and down are usually too small to announce their links as ramps
2016-03-01 16:30:31 -05:00
return road_class == FunctionalRoadClass::MOTORWAY_LINK ||
road_class == FunctionalRoadClass::TRUNK_LINK;
2016-02-24 04:29:23 -05:00
}
// TODO augment this with all data required for guidance generation
struct RoadClassificationData
{
2016-03-01 16:30:31 -05:00
FunctionalRoadClass road_class = FunctionalRoadClass::UNKNOWN;
2016-02-24 04:29:23 -05:00
void augment(const osmium::Way &way);
};
2016-03-01 16:30:31 -05:00
inline bool operator==(const RoadClassificationData lhs, const RoadClassificationData rhs)
2016-02-26 11:33:18 -05:00
{
2016-03-01 16:30:31 -05:00
return lhs.road_class == rhs.road_class;
2016-02-26 11:33:18 -05:00
}
2016-02-24 04:29:23 -05:00
} // namespace guidance
2016-03-01 16:30:31 -05:00
} // namespace extractor
2016-02-24 04:29:23 -05:00
} // namespace osrm
2016-03-01 16:30:31 -05:00
#endif // OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_