Prints turn types and modifiers as strings
This commit is contained in:
committed by
Daniel J. H
parent
c5b48e3506
commit
aed7bd852d
@@ -33,22 +33,8 @@ namespace json
|
||||
namespace detail
|
||||
{
|
||||
|
||||
std::string instructionTypeToString(extractor::guidance::TurnType::Enum type);
|
||||
std::string instructionModifierToString(extractor::guidance::DirectionModifier::Enum modifier);
|
||||
|
||||
/**
|
||||
* Returns a string representing all instruction types (including internal types that
|
||||
* are normally not exposed in route responses)
|
||||
*
|
||||
* @param type the TurnType value to convert into a string
|
||||
* @return a string representing the turn type (e.g. `turn` or `continue`)
|
||||
*/
|
||||
std::string internalInstructionTypeToString(extractor::guidance::TurnType::Enum type);
|
||||
|
||||
util::json::Array coordinateToLonLat(const util::Coordinate coordinate);
|
||||
|
||||
std::string modeToString(const extractor::TravelMode mode);
|
||||
|
||||
/**
|
||||
* Ensures that a bearing value is a whole number, and clamped to the range 0-359
|
||||
*/
|
||||
|
||||
@@ -123,7 +123,7 @@ inline void RouteStep::Invalidate()
|
||||
duration = 0;
|
||||
distance = 0;
|
||||
weight = 0;
|
||||
mode = TRAVEL_MODE_INACCESSIBLE;
|
||||
mode = extractor::TRAVEL_MODE_INACCESSIBLE;
|
||||
maneuver = getInvalidStepManeuver();
|
||||
geometry_begin = 0;
|
||||
geometry_end = 0;
|
||||
|
||||
@@ -55,8 +55,8 @@ struct ExtractionWay
|
||||
turn_lanes_forward.clear();
|
||||
turn_lanes_backward.clear();
|
||||
road_classification = guidance::RoadClassification();
|
||||
forward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
|
||||
backward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
|
||||
forward_travel_mode = extractor::TRAVEL_MODE_INACCESSIBLE;
|
||||
backward_travel_mode = extractor::TRAVEL_MODE_INACCESSIBLE;
|
||||
roundabout = false;
|
||||
circular = false;
|
||||
is_startpoint = true;
|
||||
@@ -112,8 +112,8 @@ struct ExtractionWay
|
||||
std::string turn_lanes_forward;
|
||||
std::string turn_lanes_backward;
|
||||
guidance::RoadClassification road_classification;
|
||||
TravelMode forward_travel_mode : 4;
|
||||
TravelMode backward_travel_mode : 4;
|
||||
extractor::TravelMode forward_travel_mode : 4;
|
||||
extractor::TravelMode backward_travel_mode : 4;
|
||||
|
||||
// Boolean flags
|
||||
bool roundabout : 1;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "extractor/guidance/intersection.hpp"
|
||||
#include "extractor/guidance/intersection_handler.hpp"
|
||||
#include "extractor/guidance/turn_instruction.hpp"
|
||||
|
||||
#include "util/log.hpp"
|
||||
|
||||
@@ -45,12 +46,12 @@ class StatisticsHandler final : public IntersectionHandler
|
||||
util::Log() << "Assigned turn instruction types";
|
||||
|
||||
for (const auto &kv : type_hist)
|
||||
util::Log() << (int)kv.first << ": " << kv.second;
|
||||
util::Log() << internalInstructionTypeToString(kv.first) << ": " << kv.second;
|
||||
|
||||
util::Log() << "Assigned turn instruction modifiers";
|
||||
|
||||
for (const auto &kv : modifier_hist)
|
||||
util::Log() << (int)kv.first << ": " << kv.second;
|
||||
util::Log() << instructionModifierToString(kv.first) << ": " << kv.second;
|
||||
}
|
||||
|
||||
bool canProcess(const NodeID, const EdgeID, const Intersection &) const override final
|
||||
|
||||
@@ -309,6 +309,86 @@ inline DirectionModifier::Enum bearingToDirectionModifier(const double bearing)
|
||||
return extractor::guidance::DirectionModifier::Left;
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
const constexpr char *modifier_names[] = {"uturn",
|
||||
"sharp right",
|
||||
"right",
|
||||
"slight right",
|
||||
"straight",
|
||||
"slight left",
|
||||
"left",
|
||||
"sharp left"};
|
||||
|
||||
/**
|
||||
* Human readable values for TurnType enum values
|
||||
*/
|
||||
struct TurnTypeName
|
||||
{
|
||||
// String value we return with our API
|
||||
const char *external_name;
|
||||
// Internal only string name for the turn type - useful for debugging
|
||||
// and used by debug tiles for visualizing hidden turn types
|
||||
const char *internal_name;
|
||||
};
|
||||
|
||||
// Indexes in this list correspond to the Enum values of osrm::extractor::guidance::TurnType
|
||||
const constexpr TurnTypeName turn_type_names[] = {
|
||||
{"invalid", "(not set)"},
|
||||
{"new name", "new name"},
|
||||
{"continue", "continue"},
|
||||
{"turn", "turn"},
|
||||
{"merge", "merge"},
|
||||
{"on ramp", "on ramp"},
|
||||
{"off ramp", "off ramp"},
|
||||
{"fork", "fork"},
|
||||
{"end of road", "end of road"},
|
||||
{"notification", "notification"},
|
||||
{"roundabout", "enter roundabout"},
|
||||
{"exit roundabout", "enter and exit roundabout"},
|
||||
{"rotary", "enter rotary"},
|
||||
{"exit rotary", "enter and exit rotary"},
|
||||
{"roundabout turn", "enter roundabout turn"},
|
||||
{"roundabout turn", "enter and exit roundabout turn"},
|
||||
{"use lane", "use lane"},
|
||||
{"invalid", "(noturn)"},
|
||||
{"invalid", "(suppressed)"},
|
||||
{"roundabout", "roundabout"},
|
||||
{"exit roundabout", "exit roundabout"},
|
||||
{"rotary", "rotary"},
|
||||
{"exit rotary", "exit rotary"},
|
||||
{"roundabout turn", "roundabout turn"},
|
||||
{"exit roundabout", "exit roundabout turn"},
|
||||
{"invalid", "(stay on roundabout)"},
|
||||
{"invalid", "(sliproad)"}};
|
||||
|
||||
} // ns detail
|
||||
|
||||
inline std::string instructionTypeToString(const TurnType::Enum type)
|
||||
{
|
||||
static_assert(sizeof(detail::turn_type_names) / sizeof(detail::turn_type_names[0]) >=
|
||||
TurnType::MaxTurnType,
|
||||
"Some turn types have no string representation.");
|
||||
return detail::turn_type_names[static_cast<std::size_t>(type)].external_name;
|
||||
}
|
||||
|
||||
inline std::string internalInstructionTypeToString(const TurnType::Enum type)
|
||||
{
|
||||
static_assert(sizeof(detail::turn_type_names) / sizeof(detail::turn_type_names[0]) >=
|
||||
TurnType::MaxTurnType,
|
||||
"Some turn types have no string representation.");
|
||||
return detail::turn_type_names[static_cast<std::size_t>(type)].internal_name;
|
||||
}
|
||||
|
||||
inline std::string instructionModifierToString(const DirectionModifier::Enum modifier)
|
||||
{
|
||||
static_assert(sizeof(detail::modifier_names) / sizeof(detail::modifier_names[0]) >=
|
||||
DirectionModifier::MaxDirectionModifier,
|
||||
"Some direction modifiers have no string representation.");
|
||||
return detail::modifier_names[static_cast<std::size_t>(modifier)];
|
||||
}
|
||||
|
||||
} // namespace guidance
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
@@ -21,7 +21,7 @@ struct OriginalEdgeData
|
||||
LaneDataID lane_data_id,
|
||||
guidance::TurnInstruction turn_instruction,
|
||||
EntryClassID entry_classid,
|
||||
TravelMode travel_mode,
|
||||
extractor::TravelMode travel_mode,
|
||||
util::guidance::TurnBearing pre_turn_bearing,
|
||||
util::guidance::TurnBearing post_turn_bearing)
|
||||
: via_geometry(via_geometry), name_id(name_id), entry_classid(entry_classid),
|
||||
@@ -34,7 +34,8 @@ struct OriginalEdgeData
|
||||
: via_geometry{std::numeric_limits<unsigned>::max() >> 1, false},
|
||||
name_id(std::numeric_limits<unsigned>::max()), entry_classid(INVALID_ENTRY_CLASSID),
|
||||
lane_data_id(INVALID_LANE_DATAID), turn_instruction(guidance::TurnInstruction::INVALID()),
|
||||
travel_mode(TRAVEL_MODE_INACCESSIBLE), pre_turn_bearing(0.0), post_turn_bearing(0.0)
|
||||
travel_mode(extractor::TRAVEL_MODE_INACCESSIBLE), pre_turn_bearing(0.0),
|
||||
post_turn_bearing(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ struct OriginalEdgeData
|
||||
EntryClassID entry_classid;
|
||||
LaneDataID lane_data_id;
|
||||
guidance::TurnInstruction turn_instruction;
|
||||
TravelMode travel_mode;
|
||||
extractor::TravelMode travel_mode;
|
||||
util::guidance::TurnBearing pre_turn_bearing;
|
||||
util::guidance::TurnBearing post_turn_bearing;
|
||||
};
|
||||
|
||||
@@ -29,6 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define TRAVEL_MODE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -38,8 +39,6 @@ namespace extractor
|
||||
// This is a char instead of a typed enum, so that we can
|
||||
// pack it into e.g. a "TravelMode mode : 4" packed bitfield
|
||||
using TravelMode = std::uint8_t;
|
||||
}
|
||||
}
|
||||
|
||||
const constexpr osrm::extractor::TravelMode TRAVEL_MODE_INACCESSIBLE = 0;
|
||||
const constexpr osrm::extractor::TravelMode TRAVEL_MODE_DRIVING = 1;
|
||||
@@ -55,4 +54,56 @@ const constexpr osrm::extractor::TravelMode TRAVEL_MODE_RIVER_UP = 10;
|
||||
const constexpr osrm::extractor::TravelMode TRAVEL_MODE_RIVER_DOWN = 11;
|
||||
const constexpr osrm::extractor::TravelMode TRAVEL_MODE_ROUTE = 12;
|
||||
|
||||
// FIXME this actually needs to be configurable from the profiles
|
||||
inline std::string travelModeToString(const TravelMode mode)
|
||||
{
|
||||
std::string token;
|
||||
switch (mode)
|
||||
{
|
||||
case TRAVEL_MODE_INACCESSIBLE:
|
||||
token = "inaccessible";
|
||||
break;
|
||||
case TRAVEL_MODE_DRIVING:
|
||||
token = "driving";
|
||||
break;
|
||||
case TRAVEL_MODE_CYCLING:
|
||||
token = "cycling";
|
||||
break;
|
||||
case TRAVEL_MODE_WALKING:
|
||||
token = "walking";
|
||||
break;
|
||||
case TRAVEL_MODE_FERRY:
|
||||
token = "ferry";
|
||||
break;
|
||||
case TRAVEL_MODE_TRAIN:
|
||||
token = "train";
|
||||
break;
|
||||
case TRAVEL_MODE_PUSHING_BIKE:
|
||||
token = "pushing bike";
|
||||
break;
|
||||
case TRAVEL_MODE_STEPS_UP:
|
||||
token = "steps up";
|
||||
break;
|
||||
case TRAVEL_MODE_STEPS_DOWN:
|
||||
token = "steps down";
|
||||
break;
|
||||
case TRAVEL_MODE_RIVER_UP:
|
||||
token = "river upstream";
|
||||
break;
|
||||
case TRAVEL_MODE_RIVER_DOWN:
|
||||
token = "river downstream";
|
||||
break;
|
||||
case TRAVEL_MODE_ROUTE:
|
||||
token = "route";
|
||||
break;
|
||||
default:
|
||||
token = "other";
|
||||
break;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
} // ns extractor
|
||||
} // ns osrm
|
||||
|
||||
#endif /* TRAVEL_MODE_HPP */
|
||||
|
||||
Reference in New Issue
Block a user