Use mmap instead of read - it's a lot faster here.

Also clean up construction of STRONG_TYPEDEF so that it can be
packed properly in structs (this explains all the () -> {}) changes
here.
This commit is contained in:
Daniel Patterson
2016-06-23 22:01:37 -07:00
parent 5905708111
commit ec02cdc4cc
34 changed files with 463 additions and 423 deletions
+91 -78
View File
@@ -3,6 +3,7 @@
#include "contractor/graph_contractor.hpp"
#include "extractor/compressed_edge_container.hpp"
#include "extractor/edge_based_graph_factory.hpp"
#include "extractor/node_based_edge.hpp"
#include "util/exception.hpp"
@@ -252,7 +253,7 @@ parse_segment_lookup_from_csv_files(const std::vector<std::string> &segment_spee
throw util::exception{"Segment speed file " + filename + " malformed"};
SegmentSpeedSource val{
{static_cast<OSMNodeID>(from_node_id), static_cast<OSMNodeID>(to_node_id)},
{OSMNodeID{from_node_id}, OSMNodeID{to_node_id}},
{speed, static_cast<std::uint8_t>(file_id)}};
local.push_back(std::move(val));
@@ -338,7 +339,7 @@ parse_turn_penalty_lookup_from_csv_files(const std::vector<std::string> &turn_pe
throw util::exception{"Turn penalty file " + filename + " malformed"};
map[std::make_tuple(
OSMNodeID(from_node_id), OSMNodeID(via_node_id), OSMNodeID(to_node_id))] =
OSMNodeID{from_node_id}, OSMNodeID{via_node_id}, OSMNodeID{to_node_id})] =
std::make_pair(penalty, file_id);
}
};
@@ -366,39 +367,58 @@ EdgeID Contractor::LoadEdgeExpandedGraph(
throw util::exception("Limit of 255 segment speed and turn penalty files each reached");
util::SimpleLogger().Write() << "Opening " << edge_based_graph_filename;
boost::filesystem::ifstream input_stream(edge_based_graph_filename, std::ios::binary);
if (!input_stream)
throw util::exception("Could not load edge based graph file");
auto mmap_file = [](const std::string &filename) {
using boost::interprocess::file_mapping;
using boost::interprocess::mapped_region;
using boost::interprocess::read_only;
const file_mapping mapping{ filename.c_str(), read_only };
mapped_region region{mapping, read_only};
region.advise(mapped_region::advice_sequential);
return region;
};
const auto edge_based_graph_region = mmap_file(edge_based_graph_filename);
const bool update_edge_weights = !segment_speed_filenames.empty();
const bool update_turn_penalties = !turn_penalty_filenames.empty();
boost::filesystem::ifstream edge_segment_input_stream;
boost::filesystem::ifstream edge_fixed_penalties_input_stream;
if (update_edge_weights || update_turn_penalties)
{
edge_segment_input_stream.open(edge_segment_lookup_filename, std::ios::binary);
edge_fixed_penalties_input_stream.open(edge_penalty_filename, std::ios::binary);
if (!edge_segment_input_stream || !edge_fixed_penalties_input_stream)
const auto edge_penalty_region = [&] {
if (update_edge_weights || update_turn_penalties)
{
throw util::exception("Could not load .edge_segment_lookup or .edge_penalties, did you "
"run osrm-extract with '--generate-edge-lookup'?");
return mmap_file(edge_penalty_filename);
}
}
return boost::interprocess::mapped_region();
}();
const auto edge_segment_region = [&] {
if (update_edge_weights || update_turn_penalties)
{
return mmap_file(edge_segment_lookup_filename);
}
return boost::interprocess::mapped_region();
}();
// Set the struct packing to 1 byte word sizes. This prevents any padding. We only use
// this struct once, so any alignment penalty is trivial. If this is *not* done, then
// the struct will be padded out by an extra 4 bytes, and sizeof() will mean we read
// too much data from the original file.
#pragma pack(push, r1, 1)
struct EdgeBasedGraphHeader {
util::FingerPrint fingerprint;
std::uint64_t number_of_edges;
EdgeID max_edge_id;
};
#pragma pack(pop, r1)
const EdgeBasedGraphHeader graph_header = *(reinterpret_cast<const EdgeBasedGraphHeader *>(edge_based_graph_region.get_address()));
const util::FingerPrint fingerprint_valid = util::FingerPrint::GetValid();
util::FingerPrint fingerprint_loaded;
input_stream.read((char *)&fingerprint_loaded, sizeof(util::FingerPrint));
fingerprint_loaded.TestContractor(fingerprint_valid);
graph_header.fingerprint.TestContractor(fingerprint_valid);
std::uint64_t number_of_edges = 0;
EdgeID max_edge_id = SPECIAL_EDGEID;
input_stream.read((char *)&number_of_edges, sizeof(number_of_edges));
input_stream.read((char *)&max_edge_id, sizeof(max_edge_id));
edge_based_edge_list.resize(number_of_edges);
util::SimpleLogger().Write() << "Reading " << number_of_edges
edge_based_edge_list.resize(graph_header.number_of_edges);
util::SimpleLogger().Write() << "Reading " << graph_header.number_of_edges
<< " edges from the edge based graph";
SegmentSpeedSourceFlatMap segment_speed_lookup;
@@ -500,12 +520,9 @@ EdgeID Contractor::LoadEdgeExpandedGraph(
// update the RTree itself, we just use the leaf nodes to iterate over all segments)
using LeafNode = util::StaticRTree<extractor::EdgeBasedNode>::LeafNode;
using boost::interprocess::file_mapping;
using boost::interprocess::mapped_region;
using boost::interprocess::read_only;
const file_mapping mapping{rtree_leaf_filename.c_str(), read_only};
mapped_region region{mapping, read_only};
auto region = mmap_file(rtree_leaf_filename.c_str());
region.advise(mapped_region::advice_willneed);
const auto bytes = region.get_size();
@@ -713,43 +730,43 @@ EdgeID Contractor::LoadEdgeExpandedGraph(
tbb::parallel_invoke(maybe_save_geometries, save_datasource_indexes, save_datastore_names);
// TODO: can we read this in bulk? util::DeallocatingVector isn't necessarily
// all stored contiguously
for (; number_of_edges > 0; --number_of_edges)
auto penaltyblock =
reinterpret_cast<const extractor::lookup::PenaltyBlock *>(edge_penalty_region.get_address());
auto edge_segment_byte_ptr = reinterpret_cast<const char *>(edge_segment_region.get_address());
auto edge_based_edge_ptr = reinterpret_cast<extractor::EdgeBasedEdge *>(
reinterpret_cast<char *>(edge_based_graph_region.get_address()) + sizeof(EdgeBasedGraphHeader));
const auto edge_based_edge_last = reinterpret_cast<extractor::EdgeBasedEdge *>(
reinterpret_cast<char *>(edge_based_graph_region.get_address()) + sizeof(EdgeBasedGraphHeader) + sizeof(extractor::EdgeBasedEdge) * graph_header.number_of_edges);
while (edge_based_edge_ptr != edge_based_edge_last)
{
extractor::EdgeBasedEdge inbuffer;
input_stream.read((char *)&inbuffer, sizeof(extractor::EdgeBasedEdge));
// Make a copy of the data from the memory map
extractor::EdgeBasedEdge inbuffer = *edge_based_edge_ptr;
edge_based_edge_ptr++;
if (update_edge_weights || update_turn_penalties)
{
// Processing-time edge updates
unsigned fixed_penalty;
edge_fixed_penalties_input_stream.read(reinterpret_cast<char *>(&fixed_penalty),
sizeof(fixed_penalty));
auto header = reinterpret_cast<const extractor::lookup::SegmentHeaderBlock *>(
edge_segment_byte_ptr);
edge_segment_byte_ptr += sizeof(extractor::lookup::SegmentHeaderBlock);
auto previous_osm_node_id = header->previous_osm_node_id;
int new_weight = 0;
int compressed_edge_nodes = static_cast<int>(header->num_osm_nodes);
unsigned num_osm_nodes = 0;
edge_segment_input_stream.read(reinterpret_cast<char *>(&num_osm_nodes),
sizeof(num_osm_nodes));
OSMNodeID previous_osm_node_id;
edge_segment_input_stream.read(reinterpret_cast<char *>(&previous_osm_node_id),
sizeof(previous_osm_node_id));
OSMNodeID this_osm_node_id;
double segment_length;
int segment_weight;
int compressed_edge_nodes = static_cast<int>(num_osm_nodes);
--num_osm_nodes;
for (; num_osm_nodes != 0; --num_osm_nodes)
auto segmentblocks =
reinterpret_cast<const extractor::lookup::SegmentBlock *>(edge_segment_byte_ptr);
edge_segment_byte_ptr +=
sizeof(extractor::lookup::SegmentBlock) * (header->num_osm_nodes - 1);
const auto num_segments = header->num_osm_nodes - 1;
for (auto i : util::irange<std::size_t>(0, num_segments))
{
edge_segment_input_stream.read(reinterpret_cast<char *>(&this_osm_node_id),
sizeof(this_osm_node_id));
edge_segment_input_stream.read(reinterpret_cast<char *>(&segment_length),
sizeof(segment_length));
edge_segment_input_stream.read(reinterpret_cast<char *>(&segment_weight),
sizeof(segment_weight));
auto speed_iter =
find(segment_speed_lookup, Segment{previous_osm_node_id, this_osm_node_id});
find(segment_speed_lookup,
Segment{previous_osm_node_id, segmentblocks[i].this_osm_node_id});
if (speed_iter != segment_speed_lookup.end())
{
// This sets the segment weight using the same formula as the
@@ -757,30 +774,22 @@ EdgeID Contractor::LoadEdgeExpandedGraph(
// is lost in the annals of time.
int new_segment_weight = std::max(
1,
static_cast<int>(std::floor(
(segment_length * 10.) / (speed_iter->speed_source.speed / 3.6) + .5)));
static_cast<int>(std::floor((segmentblocks[i].segment_length * 10.) /
(speed_iter->speed_source.speed / 3.6) +
.5)));
new_weight += new_segment_weight;
}
else
{
// If no lookup found, use the original weight value for this segment
new_weight += segment_weight;
new_weight += segmentblocks[i].segment_weight;
}
previous_osm_node_id = this_osm_node_id;
previous_osm_node_id = segmentblocks[i].this_osm_node_id;
}
OSMNodeID from_id;
OSMNodeID via_id;
OSMNodeID to_id;
edge_fixed_penalties_input_stream.read(reinterpret_cast<char *>(&from_id),
sizeof(from_id));
edge_fixed_penalties_input_stream.read(reinterpret_cast<char *>(&via_id),
sizeof(via_id));
edge_fixed_penalties_input_stream.read(reinterpret_cast<char *>(&to_id), sizeof(to_id));
const auto turn_iter =
turn_penalty_lookup.find(std::make_tuple(from_id, via_id, to_id));
const auto turn_iter = turn_penalty_lookup.find(
std::make_tuple(penaltyblock->from_id, penaltyblock->via_id, penaltyblock->to_id));
if (turn_iter != turn_penalty_lookup.end())
{
int new_turn_weight = static_cast<int>(turn_iter->second.first * 10);
@@ -788,24 +797,28 @@ EdgeID Contractor::LoadEdgeExpandedGraph(
if (new_turn_weight + new_weight < compressed_edge_nodes)
{
util::SimpleLogger().Write(logWARNING)
<< "turn penalty " << turn_iter->second.first << " for turn " << from_id
<< ", " << via_id << ", " << to_id
<< " is too negative: clamping turn weight to " << compressed_edge_nodes;
<< "turn penalty " << turn_iter->second.first << " for turn "
<< penaltyblock->from_id << ", " << penaltyblock->via_id << ", "
<< penaltyblock->to_id << " is too negative: clamping turn weight to "
<< compressed_edge_nodes;
}
inbuffer.weight = std::max(new_turn_weight + new_weight, compressed_edge_nodes);
}
else
{
inbuffer.weight = fixed_penalty + new_weight;
inbuffer.weight = penaltyblock->fixed_penalty + new_weight;
}
// Increment the pointer
penaltyblock++;
}
edge_based_edge_list.emplace_back(std::move(inbuffer));
}
util::SimpleLogger().Write() << "Done reading edges";
return max_edge_id;
return graph_header.max_edge_id;
}
void Contractor::ReadNodeLevels(std::vector<float> &node_levels) const
+3 -3
View File
@@ -128,7 +128,7 @@ FixedLine coordinatesToTileLine(const util::Coordinate start,
for (auto const &pt : geo_line)
{
double px_merc = pt.x * util::web_mercator::DEGREE_TO_PX;
double py_merc = util::web_mercator::latToY(util::FloatLatitude(pt.y)) *
double py_merc = util::web_mercator::latToY(util::FloatLatitude{pt.y}) *
util::web_mercator::DEGREE_TO_PX;
// convert lon/lat to tile coordinates
const auto px = std::round(
@@ -174,8 +174,8 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
util::web_mercator::xyzToWGS84(
parameters.x, parameters.y, parameters.z, min_lon, min_lat, max_lon, max_lat);
util::Coordinate southwest{util::FloatLongitude(min_lon), util::FloatLatitude(min_lat)};
util::Coordinate northeast{util::FloatLongitude(max_lon), util::FloatLatitude(max_lat)};
util::Coordinate southwest{util::FloatLongitude{min_lon}, util::FloatLatitude{min_lat}};
util::Coordinate northeast{util::FloatLongitude{max_lon}, util::FloatLatitude{max_lat}};
// Fetch all the segments that are in our bounding box.
// This hits the OSRM StaticRTree
+2 -2
View File
@@ -116,8 +116,8 @@ std::vector<util::Coordinate> decodePolyline(const std::string &geometry_string)
lng += dlng;
util::Coordinate p;
p.lat = util::FixedLatitude(lat * detail::POLYLINE_TO_COORDINATE);
p.lon = util::FixedLongitude(lng * detail::POLYLINE_TO_COORDINATE);
p.lat = util::FixedLatitude{static_cast<std::int32_t>(lat * detail::POLYLINE_TO_COORDINATE)};
p.lon = util::FixedLongitude{static_cast<std::int32_t>(lng * detail::POLYLINE_TO_COORDINATE)};
new_coordinates.push_back(p);
}
+15 -19
View File
@@ -480,19 +480,17 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
// updates to the edge-expanded-edge based directly on its ID.
if (generate_edge_lookup)
{
unsigned fixed_penalty = distance - edge_data1.distance;
edge_penalty_file.write(reinterpret_cast<const char *>(&fixed_penalty),
sizeof(fixed_penalty));
const auto node_based_edges =
m_compressed_edge_container.GetBucketReference(edge_from_u);
NodeID previous = node_u;
const unsigned node_count = node_based_edges.size() + 1;
edge_segment_file.write(reinterpret_cast<const char *>(&node_count),
sizeof(node_count));
const QueryNode &first_node = m_node_info_list[previous];
edge_segment_file.write(reinterpret_cast<const char *>(&first_node.node_id),
sizeof(first_node.node_id));
lookup::SegmentHeaderBlock header = {node_count, first_node.node_id};
edge_segment_file.write(reinterpret_cast<const char *>(&header),
sizeof(header));
for (auto target_node : node_based_edges)
{
@@ -501,12 +499,11 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const double segment_length =
util::coordinate_calculation::greatCircleDistance(from, to);
edge_segment_file.write(reinterpret_cast<const char *>(&to.node_id),
sizeof(to.node_id));
edge_segment_file.write(reinterpret_cast<const char *>(&segment_length),
sizeof(segment_length));
edge_segment_file.write(reinterpret_cast<const char *>(&target_node.weight),
sizeof(target_node.weight));
lookup::SegmentBlock nodeblock = {
to.node_id, segment_length, target_node.weight};
edge_segment_file.write(reinterpret_cast<const char *>(&nodeblock),
sizeof(nodeblock));
previous = target_node.node_id;
}
@@ -533,12 +530,11 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
m_node_info_list[m_compressed_edge_container.GetFirstEdgeTargetID(
turn.eid)];
edge_penalty_file.write(reinterpret_cast<const char *>(&from_node.node_id),
sizeof(from_node.node_id));
edge_penalty_file.write(reinterpret_cast<const char *>(&via_node.node_id),
sizeof(via_node.node_id));
edge_penalty_file.write(reinterpret_cast<const char *>(&to_node.node_id),
sizeof(to_node.node_id));
const unsigned fixed_penalty = distance - edge_data1.distance;
lookup::PenaltyBlock penaltyblock = {
fixed_penalty, from_node.node_id, via_node.node_id, to_node.node_id};
edge_penalty_file.write(reinterpret_cast<const char *>(&penaltyblock),
sizeof(penaltyblock));
}
}
}
+18 -18
View File
@@ -344,9 +344,9 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
BOOST_ASSERT(edge_iterator->result.osm_target_id == node_iterator->node_id);
BOOST_ASSERT(edge_iterator->weight_data.speed >= 0);
BOOST_ASSERT(edge_iterator->source_coordinate.lat !=
util::FixedLatitude(std::numeric_limits<int>::min()));
util::FixedLatitude{std::numeric_limits<std::int32_t>::min()});
BOOST_ASSERT(edge_iterator->source_coordinate.lon !=
util::FixedLongitude(std::numeric_limits<int>::min()));
util::FixedLongitude{std::numeric_limits<std::int32_t>::min()});
const double distance = util::coordinate_calculation::greatCircleDistance(
edge_iterator->source_coordinate,
@@ -652,14 +652,14 @@ void ExtractionContainers::PrepareRestrictions()
restrictions_iterator != restrictions_list_end)
{
if (way_start_and_end_iterator->way_id <
OSMWayID(restrictions_iterator->restriction.from.way))
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.from.way)})
{
++way_start_and_end_iterator;
continue;
}
if (way_start_and_end_iterator->way_id >
OSMWayID(restrictions_iterator->restriction.from.way))
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.from.way)})
{
util::SimpleLogger().Write(LogLevel::logWARNING)
<< "Restriction references invalid way: "
@@ -670,9 +670,9 @@ void ExtractionContainers::PrepareRestrictions()
}
BOOST_ASSERT(way_start_and_end_iterator->way_id ==
OSMWayID(restrictions_iterator->restriction.from.way));
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.from.way)});
// we do not remap the via id yet, since we will need it for the to node as well
const OSMNodeID via_node_id = OSMNodeID(restrictions_iterator->restriction.via.node);
const OSMNodeID via_node_id = OSMNodeID{restrictions_iterator->restriction.via.node};
// check if via is actually valid, if not invalidate
auto via_id_iter = external_to_internal_node_id_map.find(via_node_id);
@@ -686,11 +686,11 @@ void ExtractionContainers::PrepareRestrictions()
continue;
}
if (OSMNodeID(way_start_and_end_iterator->first_segment_source_id) == via_node_id)
if (way_start_and_end_iterator->first_segment_source_id == via_node_id)
{
// assign new from node id
auto id_iter = external_to_internal_node_id_map.find(
OSMNodeID(way_start_and_end_iterator->first_segment_target_id));
way_start_and_end_iterator->first_segment_target_id);
if (id_iter == external_to_internal_node_id_map.end())
{
util::SimpleLogger().Write(LogLevel::logWARNING)
@@ -703,11 +703,11 @@ void ExtractionContainers::PrepareRestrictions()
}
restrictions_iterator->restriction.from.node = id_iter->second;
}
else if (OSMNodeID(way_start_and_end_iterator->last_segment_target_id) == via_node_id)
else if (way_start_and_end_iterator->last_segment_target_id == via_node_id)
{
// assign new from node id
auto id_iter = external_to_internal_node_id_map.find(
OSMNodeID(way_start_and_end_iterator->last_segment_source_id));
way_start_and_end_iterator->last_segment_source_id);
if (id_iter == external_to_internal_node_id_map.end())
{
util::SimpleLogger().Write(LogLevel::logWARNING)
@@ -746,7 +746,7 @@ void ExtractionContainers::PrepareRestrictions()
restrictions_iterator != restrictions_list_end_)
{
if (way_start_and_end_iterator->way_id <
OSMWayID(restrictions_iterator->restriction.to.way))
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.to.way)})
{
++way_start_and_end_iterator;
continue;
@@ -758,7 +758,7 @@ void ExtractionContainers::PrepareRestrictions()
continue;
}
if (way_start_and_end_iterator->way_id >
OSMWayID(restrictions_iterator->restriction.to.way))
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.to.way)})
{
util::SimpleLogger().Write(LogLevel::logDEBUG)
<< "Restriction references invalid way: "
@@ -768,18 +768,18 @@ void ExtractionContainers::PrepareRestrictions()
continue;
}
BOOST_ASSERT(way_start_and_end_iterator->way_id ==
OSMWayID(restrictions_iterator->restriction.to.way));
const OSMNodeID via_node_id = OSMNodeID(restrictions_iterator->restriction.via.node);
OSMWayID{static_cast<std::uint32_t>(restrictions_iterator->restriction.to.way)});
const OSMNodeID via_node_id = OSMNodeID{restrictions_iterator->restriction.via.node};
// assign new via node id
auto via_id_iter = external_to_internal_node_id_map.find(via_node_id);
BOOST_ASSERT(via_id_iter != external_to_internal_node_id_map.end());
restrictions_iterator->restriction.via.node = via_id_iter->second;
if (OSMNodeID(way_start_and_end_iterator->first_segment_source_id) == via_node_id)
if (way_start_and_end_iterator->first_segment_source_id == via_node_id)
{
auto to_id_iter = external_to_internal_node_id_map.find(
OSMNodeID(way_start_and_end_iterator->first_segment_target_id));
way_start_and_end_iterator->first_segment_target_id);
if (to_id_iter == external_to_internal_node_id_map.end())
{
util::SimpleLogger().Write(LogLevel::logWARNING)
@@ -792,10 +792,10 @@ void ExtractionContainers::PrepareRestrictions()
}
restrictions_iterator->restriction.to.node = to_id_iter->second;
}
else if (OSMNodeID(way_start_and_end_iterator->last_segment_target_id) == via_node_id)
else if (way_start_and_end_iterator->last_segment_target_id == via_node_id)
{
auto to_id_iter = external_to_internal_node_id_map.find(
OSMNodeID(way_start_and_end_iterator->last_segment_source_id));
way_start_and_end_iterator->last_segment_source_id);
if (to_id_iter == external_to_internal_node_id_map.end())
{
util::SimpleLogger().Write(LogLevel::logWARNING)
+20 -20
View File
@@ -48,9 +48,9 @@ void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node,
const ExtractionNode &result_node)
{
external_memory.all_nodes_list.push_back(
{util::toFixed(util::FloatLongitude(input_node.location().lon())),
util::toFixed(util::FloatLatitude(input_node.location().lat())),
OSMNodeID(input_node.id()),
{util::toFixed(util::FloatLongitude{input_node.location().lon()}),
util::toFixed(util::FloatLatitude{input_node.location().lat()}),
OSMNodeID{static_cast<std::uint64_t>(input_node.id())},
result_node.barrier,
result_node.traffic_lights});
}
@@ -304,7 +304,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
std::transform(input_way.nodes().begin(),
input_way.nodes().end(),
std::back_inserter(external_memory.used_node_id_list),
[](const osmium::NodeRef &ref) { return OSMNodeID(ref.ref()); });
[](const osmium::NodeRef &ref) { return OSMNodeID{static_cast<std::uint64_t>(ref.ref())}; });
const bool is_opposite_way = TRAVEL_MODE_INACCESSIBLE == parsed_way.forward_travel_mode;
@@ -318,8 +318,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
input_way.nodes().crend(),
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) {
external_memory.all_edges_list.push_back(
InternalExtractorEdge(OSMNodeID(first_node.ref()),
OSMNodeID(last_node.ref()),
InternalExtractorEdge(OSMNodeID{static_cast<std::uint64_t>(first_node.ref())},
OSMNodeID{static_cast<std::uint64_t>(last_node.ref())},
name_id,
backward_weight_data,
true,
@@ -334,11 +334,11 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
});
external_memory.way_start_end_id_list.push_back(
{OSMWayID(input_way.id()),
OSMNodeID(input_way.nodes().back().ref()),
OSMNodeID(input_way.nodes()[input_way.nodes().size() - 2].ref()),
OSMNodeID(input_way.nodes()[1].ref()),
OSMNodeID(input_way.nodes()[0].ref())});
{OSMWayID{static_cast<std::uint32_t>(input_way.id())},
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes().back().ref())},
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[input_way.nodes().size() - 2].ref())},
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[1].ref())},
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[0].ref())}});
}
else
{
@@ -349,8 +349,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
input_way.nodes().cend(),
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) {
external_memory.all_edges_list.push_back(
InternalExtractorEdge(OSMNodeID(first_node.ref()),
OSMNodeID(last_node.ref()),
InternalExtractorEdge(OSMNodeID{static_cast<std::uint64_t>(first_node.ref())},
OSMNodeID{static_cast<std::uint64_t>(last_node.ref())},
name_id,
forward_weight_data,
true,
@@ -371,8 +371,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
input_way.nodes().cend(),
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) {
external_memory.all_edges_list.push_back(
InternalExtractorEdge(OSMNodeID(first_node.ref()),
OSMNodeID(last_node.ref()),
InternalExtractorEdge(OSMNodeID{static_cast<std::uint64_t>(first_node.ref())},
OSMNodeID{static_cast<std::uint64_t>(last_node.ref())},
name_id,
backward_weight_data,
false,
@@ -388,11 +388,11 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
}
external_memory.way_start_end_id_list.push_back(
{OSMWayID(input_way.id()),
OSMNodeID(input_way.nodes().back().ref()),
OSMNodeID(input_way.nodes()[input_way.nodes().size() - 2].ref()),
OSMNodeID(input_way.nodes()[1].ref()),
OSMNodeID(input_way.nodes()[0].ref())});
{OSMWayID{static_cast<std::uint32_t>(input_way.id())},
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes().back().ref())},
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[input_way.nodes().size() - 2].ref())},
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[1].ref())},
OSMNodeID{static_cast<std::uint64_t>(input_way.nodes()[0].ref())}});
}
}
}
+8 -8
View File
@@ -84,10 +84,10 @@ int SourceContainer::LoadRasterSource(const std::string &path_string,
std::size_t nrows,
std::size_t ncols)
{
const auto _xmin = static_cast<int>(util::toFixed(util::FloatLongitude(xmin)));
const auto _xmax = static_cast<int>(util::toFixed(util::FloatLongitude(xmax)));
const auto _ymin = static_cast<int>(util::toFixed(util::FloatLatitude(ymin)));
const auto _ymax = static_cast<int>(util::toFixed(util::FloatLatitude(ymax)));
const auto _xmin = static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{xmin}));
const auto _xmax = static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{xmax}));
const auto _ymin = static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{ymin}));
const auto _ymax = static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{ymax}));
const auto itr = LoadedSourcePaths.find(path_string);
if (itr != LoadedSourcePaths.end())
@@ -135,8 +135,8 @@ RasterDatum SourceContainer::GetRasterDataFromSource(unsigned int source_id, dou
BOOST_ASSERT(lon > -180);
const auto &found = LoadedSources[source_id];
return found.GetRasterData(static_cast<int>(util::toFixed(util::FloatLongitude(lon))),
static_cast<int>(util::toFixed(util::FloatLatitude(lat))));
return found.GetRasterData(static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{lon})),
static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{lat})));
}
// External function for looking up interpolated data from a specified source
@@ -154,8 +154,8 @@ SourceContainer::GetRasterInterpolateFromSource(unsigned int source_id, double l
BOOST_ASSERT(lon > -180);
const auto &found = LoadedSources[source_id];
return found.GetRasterInterpolate(static_cast<int>(util::toFixed(util::FloatLongitude(lon))),
static_cast<int>(util::toFixed(util::FloatLatitude(lat))));
return found.GetRasterInterpolate(static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{lon})),
static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{lat})));
}
}
}
+1 -1
View File
@@ -613,7 +613,7 @@ int Storage::Run()
{
nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode));
coordinates_ptr[i] = util::Coordinate(current_node.lon, current_node.lat);
osmnodeid_list.push_back(OSMNodeID(current_node.node_id));
osmnodeid_list.push_back(current_node.node_id);
}
nodes_input_stream.close();
+6 -6
View File
@@ -19,16 +19,16 @@ namespace util
bool Coordinate::IsValid() const
{
return !(lat > FixedLatitude(90 * COORDINATE_PRECISION) ||
lat < FixedLatitude(-90 * COORDINATE_PRECISION) ||
lon > FixedLongitude(180 * COORDINATE_PRECISION) ||
lon < FixedLongitude(-180 * COORDINATE_PRECISION));
return !(lat > FixedLatitude{static_cast<std::int32_t>(90 * COORDINATE_PRECISION)} ||
lat < FixedLatitude{static_cast<std::int32_t>(-90 * COORDINATE_PRECISION)} ||
lon > FixedLongitude{static_cast<std::int32_t>(180 * COORDINATE_PRECISION)} ||
lon < FixedLongitude{static_cast<std::int32_t>(-180 * COORDINATE_PRECISION)});
}
bool FloatCoordinate::IsValid() const
{
return !(lat > FloatLatitude(90) || lat < FloatLatitude(-90) || lon > FloatLongitude(180) ||
lon < FloatLongitude(-180));
return !(lat > FloatLatitude{90} || lat < FloatLatitude{-90} || lon > FloatLongitude{180} ||
lon < FloatLongitude{-180});
}
bool operator==(const Coordinate lhs, const Coordinate rhs)
+5 -5
View File
@@ -115,8 +115,8 @@ Coordinate centroid(const Coordinate lhs, const Coordinate rhs)
Coordinate centroid;
// The coordinates of the midpoints are given by:
// x = (x1 + x2) /2 and y = (y1 + y2) /2.
centroid.lon = (lhs.lon + rhs.lon) / FixedLongitude(2);
centroid.lat = (lhs.lat + rhs.lat) / FixedLatitude(2);
centroid.lon = (lhs.lon + rhs.lon) / FixedLongitude{2};
centroid.lat = (lhs.lat + rhs.lat) / FixedLatitude{2};
return centroid;
}
@@ -261,7 +261,7 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3)
if (lon < -180.0 || lon > 180.0 || lat < -90.0 || lat > 90.0)
return boost::none;
else
return Coordinate(FloatLongitude(lon), FloatLatitude(lat));
return Coordinate(FloatLongitude{lon}, FloatLatitude{lat});
}
}
@@ -284,8 +284,8 @@ Coordinate interpolateLinear(double factor, const Coordinate from, const Coordin
const auto to_lon = static_cast<std::int32_t>(to.lon);
const auto to_lat = static_cast<std::int32_t>(to.lat);
FixedLongitude interpolated_lon(from_lon + factor * (to_lon - from_lon));
FixedLatitude interpolated_lat(from_lat + factor * (to_lat - from_lat));
FixedLongitude interpolated_lon{static_cast<std::int32_t>(from_lon + factor * (to_lon - from_lon))};
FixedLatitude interpolated_lat{static_cast<std::int32_t>(from_lat + factor * (to_lat - from_lat))};
return {std::move(interpolated_lon), std::move(interpolated_lat)};
}