Refactor turn data into own class
This commit is contained in:
committed by
Patrick Niklaus
parent
865111bca9
commit
d7e1c9c09c
@@ -841,14 +841,14 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
|
||||
return m_entry_class_table.at(entry_class_id);
|
||||
}
|
||||
|
||||
bool hasLaneData(const EdgeID id) const override final
|
||||
bool HasLaneData(const EdgeID id) const override final
|
||||
{
|
||||
return INVALID_LANE_DATAID != m_lane_data_id.at(id);
|
||||
}
|
||||
|
||||
util::guidance::LaneTupleIdPair GetLaneData(const EdgeID id) const override final
|
||||
{
|
||||
BOOST_ASSERT(hasLaneData(id));
|
||||
BOOST_ASSERT(HasLaneData(id));
|
||||
return m_lane_tupel_id_pairs.at(m_lane_data_id.at(id));
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ class BaseDataFacade
|
||||
const int bearing,
|
||||
const int bearing_range) const = 0;
|
||||
|
||||
virtual bool hasLaneData(const EdgeID id) const = 0;
|
||||
virtual bool HasLaneData(const EdgeID id) const = 0;
|
||||
virtual util::guidance::LaneTupleIdPair GetLaneData(const EdgeID id) const = 0;
|
||||
virtual extractor::guidance::TurnLaneDescription
|
||||
GetTurnDescription(const LaneDescriptionID lane_description_id) const = 0;
|
||||
|
||||
@@ -174,7 +174,7 @@ void annotatePath(const FacadeT &facade,
|
||||
util::guidance::TurnBearing(0)});
|
||||
}
|
||||
BOOST_ASSERT(unpacked_path.size() > 0);
|
||||
if (facade.hasLaneData(turn_id))
|
||||
if (facade.HasLaneData(turn_id))
|
||||
unpacked_path.back().lane_data = facade.GetLaneData(turn_id);
|
||||
|
||||
unpacked_path.back().entry_classid = facade.GetEntryClassID(turn_id);
|
||||
|
||||
@@ -65,6 +65,27 @@ inline void writeSegmentData(const boost::filesystem::path &path, const SegmentD
|
||||
|
||||
serialization::write(writer, segment_data);
|
||||
}
|
||||
|
||||
// reads .osrm.edges
|
||||
template<storage::Ownership Ownership>
|
||||
inline void readTurnData(const boost::filesystem::path &path, detail::TurnDataContainerImpl<Ownership> &turn_data)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
|
||||
storage::io::FileReader reader{path, fingerprint};
|
||||
|
||||
serialization::read(reader, turn_data);
|
||||
}
|
||||
|
||||
// writes .osrm.edges
|
||||
template<storage::Ownership Ownership>
|
||||
inline void writeTurnData(const boost::filesystem::path &path, const detail::TurnDataContainerImpl<Ownership> &turn_data)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
|
||||
storage::io::FileWriter writer{path, fingerprint};
|
||||
|
||||
serialization::write(writer, turn_data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,10 +201,10 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
|
||||
|
||||
friend void
|
||||
serialization::read<Ownership>(storage::io::FileReader &reader,
|
||||
detail::SegmentDataContainerImpl<Ownership> &segment_data);
|
||||
friend void
|
||||
serialization::write<Ownership>(storage::io::FileWriter &writer,
|
||||
const detail::SegmentDataContainerImpl<Ownership> &segment_data);
|
||||
detail::SegmentDataContainerImpl<Ownership> &segment_data);
|
||||
friend void serialization::write<Ownership>(
|
||||
storage::io::FileWriter &writer,
|
||||
const detail::SegmentDataContainerImpl<Ownership> &segment_data);
|
||||
|
||||
private:
|
||||
Vector<std::uint32_t> index;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "extractor/datasources.hpp"
|
||||
#include "extractor/nbg_to_ebg.hpp"
|
||||
#include "extractor/segment_data_container.hpp"
|
||||
#include "extractor/turn_data_container.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
|
||||
@@ -36,8 +37,9 @@ inline void write(storage::io::FileWriter &writer, Datasources &sources)
|
||||
writer.WriteFrom(sources);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void read(storage::io::FileReader &reader, SegmentDataContainer &segment_data)
|
||||
template <storage::Ownership Ownership>
|
||||
inline void read(storage::io::FileReader &reader,
|
||||
detail::SegmentDataContainerImpl<Ownership> &segment_data)
|
||||
{
|
||||
auto num_indices = reader.ReadElementCount32();
|
||||
segment_data.index.resize(num_indices);
|
||||
@@ -59,8 +61,9 @@ inline void read(storage::io::FileReader &reader, SegmentDataContainer &segment_
|
||||
reader.ReadInto(segment_data.datasources);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void write(storage::io::FileWriter &writer, const SegmentDataContainer &segment_data)
|
||||
template <storage::Ownership Ownership>
|
||||
inline void write(storage::io::FileWriter &writer,
|
||||
const detail::SegmentDataContainerImpl<Ownership> &segment_data)
|
||||
{
|
||||
writer.WriteElementCount32(segment_data.index.size());
|
||||
writer.WriteFrom(segment_data.index);
|
||||
@@ -78,6 +81,34 @@ inline void write(storage::io::FileWriter &writer, const SegmentDataContainer &s
|
||||
writer.WriteFrom(segment_data.rev_durations);
|
||||
writer.WriteFrom(segment_data.datasources);
|
||||
}
|
||||
|
||||
template <storage::Ownership Ownership>
|
||||
inline void read(storage::io::FileReader &reader,
|
||||
detail::TurnDataContainerImpl<Ownership> &turn_data_container)
|
||||
{
|
||||
reader.DeserializeVector(turn_data_container.geometry_ids);
|
||||
reader.DeserializeVector(turn_data_container.name_ids);
|
||||
reader.DeserializeVector(turn_data_container.turn_instructions);
|
||||
reader.DeserializeVector(turn_data_container.lane_data_ids);
|
||||
reader.DeserializeVector(turn_data_container.travel_modes);
|
||||
reader.DeserializeVector(turn_data_container.entry_class_ids);
|
||||
reader.DeserializeVector(turn_data_container.pre_turn_bearings);
|
||||
reader.DeserializeVector(turn_data_container.post_turn_bearings);
|
||||
}
|
||||
|
||||
template <storage::Ownership Ownership>
|
||||
inline void write(storage::io::FileWriter &writer,
|
||||
const detail::TurnDataContainerImpl<Ownership> &turn_data_container)
|
||||
{
|
||||
writer.SerializeVector(turn_data_container.geometry_ids);
|
||||
writer.SerializeVector(turn_data_container.name_ids);
|
||||
writer.SerializeVector(turn_data_container.turn_instructions);
|
||||
writer.SerializeVector(turn_data_container.lane_data_ids);
|
||||
writer.SerializeVector(turn_data_container.travel_modes);
|
||||
writer.SerializeVector(turn_data_container.entry_class_ids);
|
||||
writer.SerializeVector(turn_data_container.pre_turn_bearings);
|
||||
writer.SerializeVector(turn_data_container.post_turn_bearings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
#ifndef OSRM_EXTRACTOR_TURN_DATA_CONTAINER_HPP
|
||||
#define OSRM_EXTRACTOR_TURN_DATA_CONTAINER_HPP
|
||||
|
||||
#include "extractor/guidance/turn_instruction.hpp"
|
||||
#include "extractor/travel_mode.hpp"
|
||||
|
||||
#include "storage/shared_memory_ownership.hpp"
|
||||
#include "util/guidance/turn_bearing.hpp"
|
||||
#include "util/shared_memory_vector_wrapper.hpp"
|
||||
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
|
||||
namespace storage
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
class FileReader;
|
||||
class FileWriter;
|
||||
}
|
||||
}
|
||||
|
||||
namespace extractor
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <storage::Ownership Ownership> class TurnDataContainerImpl;
|
||||
}
|
||||
|
||||
namespace serialization
|
||||
{
|
||||
template <storage::Ownership Ownership>
|
||||
void read(storage::io::FileReader &reader, detail::TurnDataContainerImpl<Ownership> &turn_data);
|
||||
|
||||
template <storage::Ownership Ownership>
|
||||
void write(storage::io::FileWriter &writer,
|
||||
const detail::TurnDataContainerImpl<Ownership> &turn_data);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <storage::Ownership Ownership> class TurnDataContainerImpl
|
||||
{
|
||||
template <typename T> using Vector = typename util::ShM<T, Ownership>::vector;
|
||||
|
||||
public:
|
||||
TurnDataContainerImpl() = default;
|
||||
|
||||
TurnDataContainerImpl(Vector<GeometryID> geometry_ids_,
|
||||
Vector<NameID> name_ids_,
|
||||
Vector<extractor::guidance::TurnInstruction> turn_instructions_,
|
||||
Vector<LaneDataID> lane_data_ids_,
|
||||
Vector<extractor::TravelMode> travel_modes_,
|
||||
Vector<EntryClassID> entry_class_ids_,
|
||||
Vector<util::guidance::TurnBearing> pre_turn_bearings_,
|
||||
Vector<util::guidance::TurnBearing> post_turn_bearings_)
|
||||
: geometry_ids(std::move(geometry_ids_)), name_ids(std::move(name_ids_)),
|
||||
turn_instructions(std::move(turn_instructions_)),
|
||||
lane_data_ids(std::move(lane_data_ids_)), travel_modes(std::move(travel_modes_)),
|
||||
entry_class_ids(std::move(entry_class_ids_)),
|
||||
pre_turn_bearings(std::move(pre_turn_bearings_)),
|
||||
post_turn_bearings(std::move(post_turn_bearings_))
|
||||
{
|
||||
}
|
||||
|
||||
GeometryID GetGeometryID(const EdgeID id) const { return geometry_ids[id]; }
|
||||
|
||||
EntryClassID GetEntryClassID(const EdgeID id) const { return entry_class_ids[id]; }
|
||||
|
||||
util::guidance::TurnBearing GetPreTurnBearing(const EdgeID id) const
|
||||
{
|
||||
return pre_turn_bearings[id];
|
||||
}
|
||||
|
||||
util::guidance::TurnBearing GetPostTurnBearing(const EdgeID id) const
|
||||
{
|
||||
return post_turn_bearings[id];
|
||||
}
|
||||
|
||||
bool HasLaneData(const EdgeID id) const { return INVALID_LANE_DATAID != lane_data_ids[id]; }
|
||||
|
||||
NameID GetNameID(const EdgeID id) const { return name_ids[id]; }
|
||||
|
||||
extractor::guidance::TurnInstruction GetTurnInstruction(const EdgeID id) const
|
||||
{
|
||||
return turn_instructions[id];
|
||||
}
|
||||
|
||||
// Used by EdgeBasedGraphFactory to fill data structure
|
||||
template <typename = std::enable_if<Ownership == storage::Ownership::Container>>
|
||||
void push_back(GeometryID geometry_id,
|
||||
NameID name_id,
|
||||
extractor::guidance::TurnInstruction turn_instruction,
|
||||
LaneDataID lane_data_id,
|
||||
EntryClassID entry_class_id,
|
||||
extractor::TravelMode travel_mode,
|
||||
util::guidance::TurnBearing pre_turn_bearing,
|
||||
util::guidance::TurnBearing post_turn_bearing)
|
||||
{
|
||||
geometry_ids.push_back(geometry_id);
|
||||
name_ids.push_back(name_id);
|
||||
turn_instructions.push_back(turn_instruction);
|
||||
lane_data_ids.push_back(lane_data_id);
|
||||
travel_modes.push_back(travel_mode);
|
||||
entry_class_ids.push_back(entry_class_id);
|
||||
pre_turn_bearings.push_back(pre_turn_bearing);
|
||||
post_turn_bearings.push_back(post_turn_bearing);
|
||||
}
|
||||
|
||||
friend void serialization::read<Ownership>(storage::io::FileReader &reader,
|
||||
TurnDataContainerImpl &turn_data_container);
|
||||
friend void serialization::write<Ownership>(storage::io::FileWriter &writer,
|
||||
const TurnDataContainerImpl &turn_data_container);
|
||||
|
||||
private:
|
||||
Vector<GeometryID> geometry_ids;
|
||||
Vector<NameID> name_ids;
|
||||
Vector<extractor::guidance::TurnInstruction> turn_instructions;
|
||||
Vector<LaneDataID> lane_data_ids;
|
||||
Vector<extractor::TravelMode> travel_modes;
|
||||
Vector<EntryClassID> entry_class_ids;
|
||||
Vector<util::guidance::TurnBearing> pre_turn_bearings;
|
||||
Vector<util::guidance::TurnBearing> post_turn_bearings;
|
||||
};
|
||||
}
|
||||
|
||||
using TurnDataContainer = detail::TurnDataContainerImpl<storage::Ownership::Container>;
|
||||
using TurnDataView = detail::TurnDataContainerImpl<storage::Ownership::View>;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -128,7 +128,7 @@ class FileReader
|
||||
std::uint32_t ReadElementCount32() { return ReadOne<std::uint32_t>(); }
|
||||
std::uint64_t ReadElementCount64() { return ReadOne<std::uint64_t>(); }
|
||||
|
||||
template <typename T> void DeserializeVector(std::vector<T> &data)
|
||||
template <typename VectorT> void DeserializeVector(VectorT &data)
|
||||
{
|
||||
const auto count = ReadElementCount64();
|
||||
data.resize(count);
|
||||
@@ -296,7 +296,7 @@ class FileWriter
|
||||
void WriteElementCount32(const std::uint32_t count) { WriteOne<std::uint32_t>(count); }
|
||||
void WriteElementCount64(const std::uint64_t count) { WriteOne<std::uint64_t>(count); }
|
||||
|
||||
template <typename T> void SerializeVector(const std::vector<T> &data)
|
||||
template <typename VectorT> void SerializeVector(const VectorT &data)
|
||||
{
|
||||
const auto count = data.size();
|
||||
WriteElementCount64(count);
|
||||
|
||||
@@ -70,42 +70,6 @@ inline void readHSGR(io::FileReader &input_file,
|
||||
input_file.ReadInto(edge_buffer, number_of_edges);
|
||||
}
|
||||
|
||||
// Loads edge data from .edge files into memory which includes its
|
||||
// geometry, name ID, turn instruction, lane data ID, travel mode, entry class ID
|
||||
// Needs to be called after readElementCount() to get the correct offset in the stream
|
||||
inline void readEdges(io::FileReader &edges_input_file,
|
||||
GeometryID *geometry_list,
|
||||
NameID *name_id_list,
|
||||
extractor::guidance::TurnInstruction *turn_instruction_list,
|
||||
LaneDataID *lane_data_id_list,
|
||||
extractor::TravelMode *travel_mode_list,
|
||||
EntryClassID *entry_class_id_list,
|
||||
util::guidance::TurnBearing *pre_turn_bearing_list,
|
||||
util::guidance::TurnBearing *post_turn_bearing_list,
|
||||
const std::uint64_t number_of_edges)
|
||||
{
|
||||
BOOST_ASSERT(geometry_list);
|
||||
BOOST_ASSERT(name_id_list);
|
||||
BOOST_ASSERT(turn_instruction_list);
|
||||
BOOST_ASSERT(lane_data_id_list);
|
||||
BOOST_ASSERT(travel_mode_list);
|
||||
BOOST_ASSERT(entry_class_id_list);
|
||||
extractor::OriginalEdgeData current_edge_data;
|
||||
for (std::uint64_t i = 0; i < number_of_edges; ++i)
|
||||
{
|
||||
edges_input_file.ReadInto(current_edge_data);
|
||||
|
||||
geometry_list[i] = current_edge_data.via_geometry;
|
||||
name_id_list[i] = current_edge_data.name_id;
|
||||
turn_instruction_list[i] = current_edge_data.turn_instruction;
|
||||
lane_data_id_list[i] = current_edge_data.lane_data_id;
|
||||
travel_mode_list[i] = current_edge_data.travel_mode;
|
||||
entry_class_id_list[i] = current_edge_data.entry_classid;
|
||||
pre_turn_bearing_list[i] = current_edge_data.pre_turn_bearing;
|
||||
post_turn_bearing_list[i] = current_edge_data.post_turn_bearing;
|
||||
}
|
||||
}
|
||||
|
||||
// Loads coordinates and OSM node IDs from .nodes files into memory
|
||||
// Needs to be called after readElementCount() to get the correct offset in the stream
|
||||
template <typename OSMNodeIDVectorT>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SHARED_MEMORY_VECTOR_WRAPPER_HPP
|
||||
|
||||
#include "util/log.hpp"
|
||||
#include "util/exception.hpp"
|
||||
|
||||
#include "storage/shared_memory_ownership.hpp"
|
||||
|
||||
@@ -82,6 +83,15 @@ template <typename DataT> class vector_view
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
// for a vector-like interface
|
||||
void resize(std::size_t size) const
|
||||
{
|
||||
if(m_size != size)
|
||||
{
|
||||
throw util::exception("Invalid resize on immutable shared memory vector.");
|
||||
}
|
||||
}
|
||||
|
||||
DataT &at(const std::size_t index) { return m_ptr[index]; }
|
||||
|
||||
const DataT &at(const std::size_t index) const { return m_ptr[index]; }
|
||||
@@ -128,7 +138,8 @@ template <typename DataT> class vector_view
|
||||
|
||||
auto data() const { return m_ptr; }
|
||||
|
||||
template <typename T> friend void swap(vector_view<T> &, vector_view<T> &) noexcept;
|
||||
template <typename T>
|
||||
friend void swap(vector_view<T> &, vector_view<T> &) noexcept;
|
||||
};
|
||||
|
||||
template <> class vector_view<bool>
|
||||
@@ -138,6 +149,8 @@ template <> class vector_view<bool>
|
||||
std::size_t m_size;
|
||||
|
||||
public:
|
||||
using value_type = bool;
|
||||
|
||||
vector_view() : m_ptr(nullptr), m_size(0) {}
|
||||
|
||||
vector_view(unsigned *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
|
||||
@@ -150,12 +163,20 @@ template <> class vector_view<bool>
|
||||
return m_ptr[bucket] & (1u << offset);
|
||||
}
|
||||
|
||||
void reset(unsigned *ptr, std::size_t size)
|
||||
void reset(unsigned *, std::size_t size)
|
||||
{
|
||||
m_ptr = ptr;
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
// for ensuring a vector compatible interface
|
||||
void resize(std::size_t size) const
|
||||
{
|
||||
if(m_size != size)
|
||||
{
|
||||
throw util::exception("Invalid resize on immutable shared memory vector.");
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t size() const { return m_size; }
|
||||
|
||||
bool empty() const { return 0 == size(); }
|
||||
@@ -178,6 +199,7 @@ template <typename DataT, storage::Ownership Ownership> struct ShM
|
||||
vector_view<DataT>,
|
||||
std::vector<DataT>>::type;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user