refactor loading code of .nodes and .edges files and move to io.hpp
This commit is contained in:
+73
-5
@@ -63,9 +63,9 @@ inline HSGRHeader readHSGRHeader(boost::filesystem::ifstream &input_stream)
|
||||
// Needs to be called after readHSGRHeader() to get the correct offset in the stream
|
||||
template <typename NodeT, typename EdgeT>
|
||||
void readHSGR(boost::filesystem::ifstream &input_stream,
|
||||
NodeT *node_buffer,
|
||||
NodeT node_buffer[],
|
||||
std::uint32_t number_of_nodes,
|
||||
EdgeT *edge_buffer,
|
||||
EdgeT edge_buffer[],
|
||||
std::uint32_t number_of_edges)
|
||||
{
|
||||
input_stream.read(reinterpret_cast<char *>(node_buffer), number_of_nodes * sizeof(NodeT));
|
||||
@@ -74,20 +74,88 @@ void readHSGR(boost::filesystem::ifstream &input_stream,
|
||||
// Returns the size of the timestamp in a file
|
||||
inline std::uint32_t readTimestampSize(boost::filesystem::ifstream ×tamp_input_stream)
|
||||
{
|
||||
timestamp_input_stream.seekg (0, timestamp_input_stream.end);
|
||||
timestamp_input_stream.seekg(0, timestamp_input_stream.end);
|
||||
auto length = timestamp_input_stream.tellg();
|
||||
timestamp_input_stream.seekg (0, timestamp_input_stream.beg);
|
||||
timestamp_input_stream.seekg(0, timestamp_input_stream.beg);
|
||||
return length;
|
||||
}
|
||||
|
||||
// Reads the timestamp in a file
|
||||
inline void readTimestamp(boost::filesystem::ifstream ×tamp_input_stream,
|
||||
char *timestamp,
|
||||
char timestamp[],
|
||||
std::size_t timestamp_length)
|
||||
{
|
||||
timestamp_input_stream.read(timestamp, timestamp_length * sizeof(char));
|
||||
}
|
||||
|
||||
// Returns the number of edges in a .edges file
|
||||
inline std::uint32_t readEdgesSize(boost::filesystem::ifstream &edges_input_stream)
|
||||
{
|
||||
std::uint32_t number_of_edges;
|
||||
edges_input_stream.read((char *)&number_of_edges, sizeof(std::uint32_t));
|
||||
return number_of_edges;
|
||||
}
|
||||
|
||||
// Reads edge data from .edge files which includes its
|
||||
// geometry, name ID, turn instruction, lane data ID, travel mode, entry class ID
|
||||
template <typename GeometryIDT,
|
||||
typename NameIDT,
|
||||
typename TurnInstructionT,
|
||||
typename LaneDataIDT,
|
||||
typename TravelModeT,
|
||||
typename EntryClassIDT,
|
||||
typename PreTurnBearingT,
|
||||
typename PostTurnBearingT>
|
||||
void readEdgesData(boost::filesystem::ifstream &edges_input_stream,
|
||||
GeometryIDT geometry_list[],
|
||||
NameIDT name_id_list[],
|
||||
TurnInstructionT turn_instruction_list[],
|
||||
LaneDataIDT lane_data_id_list[],
|
||||
TravelModeT travel_mode_list[],
|
||||
EntryClassIDT entry_class_id_list[],
|
||||
PreTurnBearingT pre_turn_bearing_list[],
|
||||
PostTurnBearingT post_turn_bearing_list[],
|
||||
std::uint32_t number_of_edges)
|
||||
{
|
||||
extractor::OriginalEdgeData current_edge_data;
|
||||
for (std::uint32_t i = 0; i < number_of_edges; ++i)
|
||||
{
|
||||
edges_input_stream.read((char *)&(current_edge_data), sizeof(extractor::OriginalEdgeData));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the number of nodes in a .nodes file
|
||||
inline std::uint32_t readNodesSize(boost::filesystem::ifstream &nodes_input_stream)
|
||||
{
|
||||
std::uint32_t number_of_coordinates;
|
||||
nodes_input_stream.read((char *)&number_of_coordinates, sizeof(std::uint32_t));
|
||||
return number_of_coordinates;
|
||||
}
|
||||
|
||||
// Reads coordinates and OSM node IDs from .nodes files
|
||||
template <typename CoordinateT, typename OSMNodeIDVectorT>
|
||||
void readNodesData(boost::filesystem::ifstream &nodes_input_stream,
|
||||
CoordinateT coordinate_list[],
|
||||
OSMNodeIDVectorT &osmnodeid_list,
|
||||
std::uint32_t number_of_coordinates)
|
||||
{
|
||||
extractor::QueryNode current_node;
|
||||
for (std::uint32_t i = 0; i < number_of_coordinates; ++i)
|
||||
{
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(extractor::QueryNode));
|
||||
coordinate_list[i] = CoordinateT(current_node.lon, current_node.lat);
|
||||
osmnodeid_list.push_back(current_node.node_id);
|
||||
BOOST_ASSERT(coordinate_list[i].IsValid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user