expose lanes as enums, adjusted for comments

This commit is contained in:
Moritz Kobitzsch
2016-06-21 10:41:08 +02:00
parent 5d91b759d1
commit 5905708111
45 changed files with 1020 additions and 722 deletions
+14 -10
View File
@@ -13,6 +13,7 @@
#include "extractor/guidance/turn_analysis.hpp"
#include "extractor/guidance/turn_instruction.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
#include "util/guidance/bearing_class.hpp"
#include "util/guidance/entry_class.hpp"
@@ -48,15 +49,17 @@ class EdgeBasedGraphFactory
EdgeBasedGraphFactory(const EdgeBasedGraphFactory &) = delete;
EdgeBasedGraphFactory &operator=(const EdgeBasedGraphFactory &) = delete;
explicit EdgeBasedGraphFactory(std::shared_ptr<util::NodeBasedDynamicGraph> node_based_graph,
const CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<QueryNode> &node_info_list,
ProfileProperties profile_properties,
const util::NameTable &name_table,
const util::NameTable &turn_lanes);
explicit EdgeBasedGraphFactory(
std::shared_ptr<util::NodeBasedDynamicGraph> node_based_graph,
const CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<QueryNode> &node_info_list,
ProfileProperties profile_properties,
const util::NameTable &name_table,
const std::vector<std::uint32_t> &turn_lane_offsets,
const std::vector<guidance::TurnLaneType::Mask> &turn_lane_masks);
void Run(const std::string &original_edge_data_filename,
const std::string &turn_lane_data_filename,
@@ -119,7 +122,8 @@ class EdgeBasedGraphFactory
ProfileProperties profile_properties;
const util::NameTable &name_table;
const util::NameTable &turn_lanes;
const std::vector<std::uint32_t> &turn_lane_offsets;
const std::vector<guidance::TurnLaneType::Mask> &turn_lane_masks;
void CompressGeometry();
unsigned RenumberEdges();
+8 -2
View File
@@ -3,12 +3,14 @@
#include "extractor/external_memory_node.hpp"
#include "extractor/first_and_last_segment_of_way.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/internal_extractor_edge.hpp"
#include "extractor/restriction.hpp"
#include "extractor/scripting_environment.hpp"
#include <stxxl/vector>
#include <unordered_map>
#include <cstdint>
namespace osrm
{
@@ -40,6 +42,9 @@ class ExtractionContainers
void WriteCharData(const std::string &file_name,
const stxxl::vector<unsigned> &offests,
const stxxl::vector<char> &char_data) const;
void WriteTurnLaneMasks(const std::string &file_name,
const stxxl::vector<std::uint32_t> &turn_lane_offsets,
const stxxl::vector<guidance::TurnLaneType::Mask> &turn_lane_masks) const;
public:
using STXXLNodeIDVector = stxxl::vector<OSMNodeID>;
@@ -53,8 +58,9 @@ class ExtractionContainers
STXXLEdgeVector all_edges_list;
stxxl::vector<char> name_char_data;
stxxl::vector<unsigned> name_lengths;
stxxl::vector<char> turn_lane_char_data;
stxxl::vector<unsigned> turn_lane_lengths;
// an adjacency array containing all turn lane masks
stxxl::vector<std::uint32_t> turn_lane_offsets;
stxxl::vector<guidance::TurnLaneType::Mask> turn_lane_masks;
STXXLRestrictionsVector restrictions_list;
STXXLWayIDStartEndVector way_start_end_id_list;
std::unordered_map<OSMNodeID, NodeID> external_to_internal_node_id_map;
+3 -1
View File
@@ -2,6 +2,8 @@
#define EXTRACTOR_CALLBACKS_HPP
#include "util/typedefs.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
#include <boost/functional/hash.hpp>
#include <boost/optional/optional_fwd.hpp>
@@ -38,7 +40,7 @@ class ExtractorCallbacks
using MapKey = std::pair<std::string, std::string>;
using MapVal = unsigned;
std::unordered_map<MapKey, MapVal, boost::hash<MapKey>> string_map;
std::unordered_map<std::string, LaneStringID> lane_map;
std::unordered_map<guidance::TurnLaneDescription,LaneDescriptionID,guidance::TurnLaneDescription_hash> lane_description_map;
ExtractionContainers &external_memory;
public:
+2 -2
View File
@@ -61,7 +61,7 @@ struct ExtractorConfig
output_file_name = basepath + ".osrm";
restriction_file_name = basepath + ".osrm.restrictions";
names_file_name = basepath + ".osrm.names";
turn_lane_strings_file_name = basepath + ".osrm.tls";
turn_lane_descriptions_file_name = basepath + ".osrm.tls";
turn_lane_data_file_name = basepath + ".osrm.tld";
timestamp_file_name = basepath + ".osrm.timestamp";
geometry_output_path = basepath + ".osrm.geometry";
@@ -85,7 +85,7 @@ struct ExtractorConfig
std::string restriction_file_name;
std::string names_file_name;
std::string turn_lane_data_file_name;
std::string turn_lane_strings_file_name;
std::string turn_lane_descriptions_file_name;
std::string timestamp_file_name;
std::string geometry_output_path;
std::string edge_output_path;
-46
View File
@@ -1,46 +0,0 @@
#ifndef OSRM_EXTRACTOR_GUIDANCE_DEBUG_HPP_
#define OSRM_EXTRACTOR_GUIDANCE_DEBUG_HPP_
#include <iomanip>
#include <iostream>
#include <string>
namespace osrm
{
namespace extractor
{
namespace guidance
{
inline void print(const LaneDataVector &turn_lane_data)
{
std::cout << " Tags:\n";
for (auto entry : turn_lane_data)
std::cout << "\t" << entry.tag << " from: " << static_cast<int>(entry.from)
<< " to: " << static_cast<int>(entry.to) << "\n";
std::cout << std::flush;
}
inline void printTurnAssignmentData(const NodeID at,
const LaneDataVector &turn_lane_data,
const Intersection &intersection,
const std::vector<QueryNode> &node_info_list)
{
std::cout << "[Turn Assignment Progress]\nLocation:";
auto coordinate = node_info_list[at];
std::cout << std::setprecision(12) << toFloating(coordinate.lat) << " "
<< toFloating(coordinate.lon) << "\n";
std::cout << " Intersection:\n";
for (const auto &road)
std::cout << "\t" << toString(road) << "\n";
// flushes as well
print(turn_lane_data);
}
} // namespace guidance
} // namespace extractor
} // namespace osrm
#endif /* OSRM_EXTRACTOR_GUIDANCE_DEBUG_HPP_ */
@@ -2,6 +2,7 @@
#define OSRM_EXTRACTOR_GUIDANCE_TURN_LANE_DATA_HPP_
#include "util/typedefs.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
#include <string>
#include <vector>
@@ -16,7 +17,7 @@ namespace lanes
struct TurnLaneData
{
std::string tag;
TurnLaneType::Mask tag;
LaneID from;
LaneID to;
@@ -25,13 +26,14 @@ struct TurnLaneData
typedef std::vector<TurnLaneData> LaneDataVector;
// convertes a string given in the OSM format into a TurnLaneData vector
LaneDataVector laneDataFromString(std::string turn_lane_string);
LaneDataVector laneDataFromDescription(const TurnLaneDescription &turn_lane_description);
// Locate A Tag in a lane data vector
LaneDataVector::const_iterator findTag(const std::string &tag, const LaneDataVector &data);
LaneDataVector::iterator findTag(const std::string &tag, LaneDataVector &data);
// Locate A Tag in a lane data vector (if multiple tags are set, the first one found is returned)
LaneDataVector::const_iterator findTag(const TurnLaneType::Mask tag, const LaneDataVector &data);
LaneDataVector::iterator findTag(const TurnLaneType::Mask tag, LaneDataVector &data);
bool hasTag(const std::string &tag, const LaneDataVector &data);
// Returns true if any of the queried tags is contained
bool hasTag(const TurnLaneType::Mask tag, const LaneDataVector &data);
} // namespace lane_data_generation
@@ -5,6 +5,7 @@
#include "extractor/guidance/toolkit.hpp"
#include "extractor/guidance/turn_analysis.hpp"
#include "extractor/guidance/turn_lane_data.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/query_node.hpp"
#include "util/guidance/turn_lanes.hpp"
@@ -12,6 +13,7 @@
#include "util/node_based_graph.hpp"
#include "util/typedefs.hpp"
#include <cstdint>
#include <map>
#include <string>
#include <utility>
@@ -34,7 +36,8 @@ class TurnLaneHandler
typedef std::vector<TurnLaneData> LaneDataVector;
TurnLaneHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const util::NameTable &turn_lane_strings,
const std::vector<std::uint32_t> &turn_lane_offsets,
const std::vector<TurnLaneType::Mask> &turn_lane_masks,
const std::vector<QueryNode> &node_info_list,
const TurnAnalysis &turn_analysis);
@@ -47,7 +50,8 @@ class TurnLaneHandler
// we need to be able to look at previous intersections to, in some cases, find the correct turn
// lanes for a turn
const util::NodeBasedDynamicGraph &node_based_graph;
const util::NameTable &turn_lane_strings;
const std::vector<std::uint32_t> &turn_lane_offsets;
const std::vector<TurnLaneType::Mask> &turn_lane_masks;
const std::vector<QueryNode> &node_info_list;
const TurnAnalysis &turn_analysis;
@@ -58,7 +62,7 @@ class TurnLaneHandler
// in case of a simple intersection, assign the lane entries
Intersection simpleMatchTuplesToTurns(Intersection intersection,
const LaneDataVector &lane_data,
const LaneStringID lane_string_id,
const LaneDescriptionID lane_string_id,
LaneDataIdMap &id_map) const;
// partition lane data into lane data relevant at current turn and at next turn
@@ -21,24 +21,16 @@ namespace lanes
{
// Translate Turn Lane Tags into a matching modifier
DirectionModifier::Enum getMatchingModifier(const std::string &tag);
DirectionModifier::Enum getMatchingModifier(const TurnLaneType::Mask &tag);
// check whether a match of a given tag and a turn instruction can be seen as valid
bool isValidMatch(const std::string &tag, const TurnInstruction instruction);
bool isValidMatch(const TurnLaneType::Mask &tag, const TurnInstruction instruction);
// Every tag is somewhat idealized in form of the expected angle. A through lane should go straight
// (or follow a 180 degree turn angle between in/out segments.) The following function tries to find
// the best possible match for every tag in a given intersection, considering a few corner cases
// introduced to OSRM handling u-turns
typename Intersection::const_iterator findBestMatch(const std::string &tag,
// localisation of the best possible match for a tag
typename Intersection::const_iterator findBestMatch(const TurnLaneType::Mask &tag,
const Intersection &intersection);
// Reverse is a special case, because it requires access to the leftmost tag. It has its own
// matching function as a result of that. The leftmost tag is required, since u-turns are disabled
// by default in OSRM. Therefor we cannot check whether a turn is allowed, since it could be
// possible that it is forbidden. In addition, the best u-turn angle does not necessarily represent
// the u-turn, since it could be a sharp-left turn instead on a road with a middle island.
typename Intersection::const_iterator findBestMatchForReverse(const std::string &leftmost_tag,
const Intersection &intersection);
typename Intersection::const_iterator
findBestMatchForReverse(const TurnLaneType::Mask &leftmost_tag, const Intersection &intersection);
// a match is trivial if all turns can be associated with their best match in a valid way and the
// matches occur in order
@@ -48,7 +40,7 @@ bool canMatchTrivially(const Intersection &intersection, const LaneDataVector &l
Intersection triviallyMatchLanesToTurns(Intersection intersection,
const LaneDataVector &lane_data,
const util::NodeBasedDynamicGraph &node_based_graph,
const LaneStringID lane_string_id,
const LaneDescriptionID lane_string_id,
LaneDataIdMap &lane_data_to_id);
} // namespace lanes
@@ -0,0 +1,102 @@
#ifndef OSRM_GUIDANCE_TURN_LANE_TYPES_HPP_
#define OSRM_GUIDANCE_TURN_LANE_TYPES_HPP_
#include <bitset>
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
#include <boost/assert.hpp>
#include <boost/functional/hash_fwd.hpp>
#include "util/simple_logger.hpp"
#include "util/typedefs.hpp"
#include "util/json_container.hpp"
namespace osrm
{
namespace extractor
{
namespace guidance
{
namespace TurnLaneType
{
namespace detail
{
const constexpr std::size_t num_supported_lane_types = 11;
const constexpr char *translations[detail::num_supported_lane_types] = {"none",
"straight",
"sharp left",
"left",
"slight left",
"slight right",
"right",
"sharp right",
"uturn",
"merge to left",
"merge to right"};
} // namespace detail
typedef std::uint16_t Mask;
const constexpr Mask empty = 0u;
const constexpr Mask none = 1u << 0u;
const constexpr Mask straight = 1u << 1u;
const constexpr Mask sharp_left = 1u << 2u;
const constexpr Mask left = 1u << 3u;
const constexpr Mask slight_left = 1u << 4u;
const constexpr Mask slight_right = 1u << 5u;
const constexpr Mask right = 1u << 6u;
const constexpr Mask sharp_right = 1u << 7u;
const constexpr Mask uturn = 1u << 8u;
const constexpr Mask merge_to_left = 1u << 9u;
const constexpr Mask merge_to_right = 1u << 10u;
inline std::string toString(const Mask lane_type)
{
if (lane_type == 0)
return "none";
std::bitset<8 * sizeof(Mask)> mask(lane_type);
std::string result = "";
for (std::size_t lane_id_nr = 0; lane_id_nr < detail::num_supported_lane_types; ++lane_id_nr)
if (mask[lane_id_nr])
result += (result.empty() ? detail::translations[lane_id_nr]
: (std::string(";") + detail::translations[lane_id_nr]));
return result;
}
inline util::json::Array toJsonArray(const Mask lane_type)
{
util::json::Array result;
std::bitset<8 * sizeof(Mask)> mask(lane_type);
for (std::size_t lane_id_nr = 0; lane_id_nr < detail::num_supported_lane_types; ++lane_id_nr)
if (mask[lane_id_nr])
result.values.push_back(detail::translations[lane_id_nr]);
return result;
}
} // TurnLaneType
typedef std::vector<TurnLaneType::Mask> TurnLaneDescription;
// hash function for TurnLaneDescription
struct TurnLaneDescription_hash
{
std::size_t operator()(const TurnLaneDescription &lane_description) const
{
std::size_t seed = 0;
for (auto val : lane_description)
boost::hash_combine(seed, val);
return seed;
}
};
} // guidance
} // extractor
} // osrm
#endif /* OSRM_GUIDANCE_TURN_LANE_TYPES_HPP_ */
@@ -50,7 +50,7 @@ struct InternalExtractorEdge
true,
TRAVEL_MODE_INACCESSIBLE,
false,
INVALID_LANE_STRINGID,
guidance::TurnLaneType::empty,
guidance::RoadClassificationData())
{
}
@@ -66,7 +66,7 @@ struct InternalExtractorEdge
bool startpoint,
TravelMode travel_mode,
bool is_split,
const LaneStringID lane_id,
LaneDescriptionID lane_description,
guidance::RoadClassificationData road_classification)
: result(OSMNodeID(source),
OSMNodeID(target),
@@ -79,7 +79,7 @@ struct InternalExtractorEdge
startpoint,
travel_mode,
is_split,
lane_id,
lane_description,
std::move(road_classification)),
weight_data(std::move(weight_data))
{
@@ -106,7 +106,7 @@ struct InternalExtractorEdge
true,
TRAVEL_MODE_INACCESSIBLE,
false,
INVALID_LANE_STRINGID,
INVALID_LANE_DESCRIPTIONID,
guidance::RoadClassificationData());
}
static InternalExtractorEdge max_osm_value()
@@ -122,7 +122,7 @@ struct InternalExtractorEdge
true,
TRAVEL_MODE_INACCESSIBLE,
false,
INVALID_LANE_STRINGID,
INVALID_LANE_DESCRIPTIONID,
guidance::RoadClassificationData());
}
+8 -8
View File
@@ -26,7 +26,7 @@ struct NodeBasedEdge
bool startpoint,
TravelMode travel_mode,
bool is_split,
const LaneStringID lane_id,
const LaneDescriptionID lane_description_id,
guidance::RoadClassificationData road_classification);
bool operator<(const NodeBasedEdge &other) const;
@@ -42,7 +42,7 @@ struct NodeBasedEdge
bool startpoint : 1;
bool is_split : 1;
TravelMode travel_mode : 4;
LaneStringID lane_string_id;
LaneDescriptionID lane_description_id;
guidance::RoadClassificationData road_classification;
};
@@ -59,7 +59,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge
bool startpoint,
TravelMode travel_mode,
bool is_split,
const LaneStringID lane_string_id,
const LaneDescriptionID lane_description_id,
guidance::RoadClassificationData road_classification);
OSMNodeID osm_source_id;
@@ -71,7 +71,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge
inline NodeBasedEdge::NodeBasedEdge()
: source(SPECIAL_NODEID), target(SPECIAL_NODEID), name_id(0), weight(0), forward(false),
backward(false), roundabout(false), access_restricted(false), startpoint(true),
is_split(false), travel_mode(false), lane_string_id(0)
is_split(false), travel_mode(false), lane_description_id(INVALID_LANE_DESCRIPTIONID)
{
}
@@ -86,12 +86,12 @@ inline NodeBasedEdge::NodeBasedEdge(NodeID source,
bool startpoint,
TravelMode travel_mode,
bool is_split,
const LaneStringID lane_string_id,
const LaneDescriptionID lane_description_id,
guidance::RoadClassificationData road_classification)
: source(source), target(target), name_id(name_id), weight(weight), forward(forward),
backward(backward), roundabout(roundabout), access_restricted(access_restricted),
startpoint(startpoint), is_split(is_split), travel_mode(travel_mode),
lane_string_id(lane_string_id), road_classification(std::move(road_classification))
lane_description_id(lane_description_id), road_classification(std::move(road_classification))
{
}
@@ -124,7 +124,7 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(
bool startpoint,
TravelMode travel_mode,
bool is_split,
const LaneStringID lane_string_id,
const LaneDescriptionID lane_description_id,
guidance::RoadClassificationData road_classification)
: NodeBasedEdge(SPECIAL_NODEID,
SPECIAL_NODEID,
@@ -137,7 +137,7 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(
startpoint,
travel_mode,
is_split,
lane_string_id,
lane_description_id,
std::move(road_classification)),
osm_source_id(std::move(source)), osm_target_id(std::move(target))
{