diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index 846ed41d7..666aad9cf 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -99,7 +99,7 @@ class TarjanSCC using EmanatingRestrictionsVector = std::vector; using RestrictionMap = std::unordered_map; - std::vector m_coordinate_list; + std::vector m_coordinate_list; std::vector m_restriction_bucket_list; std::shared_ptr m_node_based_graph; std::unordered_set barrier_node_list; @@ -113,7 +113,7 @@ class TarjanSCC std::vector &bn, std::vector &tl, std::vector &irs, - std::vector &nI) + std::vector &nI) : m_coordinate_list(nI), m_restriction_counter(irs.size()) { TIMER_START(SCC_LOAD); diff --git a/Benchmarks/StaticRTreeBench.cpp b/Benchmarks/StaticRTreeBench.cpp index 4e6b2da89..e6e4f2225 100644 --- a/Benchmarks/StaticRTreeBench.cpp +++ b/Benchmarks/StaticRTreeBench.cpp @@ -24,13 +24,13 @@ FixedPointCoordinateListPtr LoadCoordinates(const boost::filesystem::path &nodes { boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary); - NodeInfo current_node; + QueryNode current_node; unsigned number_of_coordinates = 0; nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned)); auto coords = std::make_shared>(number_of_coordinates); for (unsigned i = 0; i < number_of_coordinates; ++i) { - nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); + nodes_input_stream.read((char *)¤t_node, sizeof(QueryNode)); coords->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon); BOOST_ASSERT((std::abs(coords->at(i).lat) >> 30) == 0); BOOST_ASSERT((std::abs(coords->at(i).lon) >> 30) == 0); diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index be35a199c..65aef649d 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -63,7 +63,7 @@ class EdgeBasedGraphFactory std::unique_ptr restricion_map, std::vector &barrier_node_list, std::vector &traffic_light_node_list, - std::vector &m_node_info_list, + std::vector &m_node_info_list, SpeedProfileProperties &speed_profile); void Run(const std::string &original_edge_data_filename, @@ -97,7 +97,7 @@ class EdgeBasedGraphFactory unsigned m_number_of_edge_based_nodes; - std::vector m_node_info_list; + std::vector m_node_info_list; std::vector m_edge_based_node_list; DeallocatingVector m_edge_based_edge_list; diff --git a/Contractor/Prepare.cpp b/Contractor/Prepare.cpp index 75daf4b39..386dc101e 100644 --- a/Contractor/Prepare.cpp +++ b/Contractor/Prepare.cpp @@ -554,7 +554,7 @@ void Prepare::WriteNodeMapping() if (size_of_mapping > 0) { node_stream.write((char *)&(internal_to_external_node_map[0]), - size_of_mapping * sizeof(NodeInfo)); + size_of_mapping * sizeof(QueryNode)); } node_stream.close(); internal_to_external_node_map.clear(); diff --git a/Contractor/Prepare.h b/Contractor/Prepare.h index 9facbb57d..3731e129a 100644 --- a/Contractor/Prepare.h +++ b/Contractor/Prepare.h @@ -42,7 +42,7 @@ class Prepare void BuildRTree(std::vector &node_based_edge_list); private: - std::vector internal_to_external_node_map; + std::vector internal_to_external_node_map; std::vector restriction_list; std::vector barrier_node_list; std::vector traffic_light_list; diff --git a/DataStructures/ExternalMemoryNode.cpp b/DataStructures/ExternalMemoryNode.cpp index 653e421af..5f22220fb 100644 --- a/DataStructures/ExternalMemoryNode.cpp +++ b/DataStructures/ExternalMemoryNode.cpp @@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ExternalMemoryNode::ExternalMemoryNode( int lat, int lon, unsigned int node_id, bool barrier, bool traffic_lights) - : NodeInfo(lat, lon, node_id), barrier(barrier), traffic_lights(traffic_lights) + : QueryNode(lat, lon, node_id), barrier(barrier), traffic_lights(traffic_lights) { } diff --git a/DataStructures/ExternalMemoryNode.h b/DataStructures/ExternalMemoryNode.h index a641a6d8c..c65b40a1f 100644 --- a/DataStructures/ExternalMemoryNode.h +++ b/DataStructures/ExternalMemoryNode.h @@ -32,7 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -struct ExternalMemoryNode : NodeInfo +struct ExternalMemoryNode : QueryNode { ExternalMemoryNode(int lat, int lon, NodeID id, bool barrier, bool traffic_light); diff --git a/DataStructures/QueryNode.h b/DataStructures/QueryNode.h index 6ebbce46d..0d9c6ad9c 100644 --- a/DataStructures/QueryNode.h +++ b/DataStructures/QueryNode.h @@ -36,13 +36,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -struct NodeInfo +struct QueryNode { using key_type = NodeID; // type of NodeID using value_type = int; // type of lat,lons - explicit NodeInfo(int lat, int lon, NodeID node_id) : lat(lat), lon(lon), node_id(node_id) {} - NodeInfo() + explicit QueryNode(int lat, int lon, NodeID node_id) : lat(lat), lon(lon), node_id(node_id) {} + QueryNode() : lat(std::numeric_limits::max()), lon(std::numeric_limits::max()), node_id(std::numeric_limits::max()) { @@ -52,18 +52,18 @@ struct NodeInfo int lon; NodeID node_id; - static NodeInfo min_value() + static QueryNode min_value() { - return NodeInfo(static_cast(-90 * COORDINATE_PRECISION), - static_cast(-180 * COORDINATE_PRECISION), - std::numeric_limits::min()); + return QueryNode(static_cast(-90 * COORDINATE_PRECISION), + static_cast(-180 * COORDINATE_PRECISION), + std::numeric_limits::min()); } - static NodeInfo max_value() + static QueryNode max_value() { - return NodeInfo(static_cast(90 * COORDINATE_PRECISION), - static_cast(180 * COORDINATE_PRECISION), - std::numeric_limits::max()); + return QueryNode(static_cast(90 * COORDINATE_PRECISION), + static_cast(180 * COORDINATE_PRECISION), + std::numeric_limits::max()); } value_type operator[](const std::size_t n) const diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 6805ff4af..aa5bce540 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -72,6 +72,190 @@ template &objects, + const uint32_t element_count, + const std::vector &coordinate_list) + { + for (uint32_t i = 0; i < element_count; ++i) + { + min_lon = std::min(min_lon, + std::min(coordinate_list.at(objects[i].u).lon, + coordinate_list.at(objects[i].v).lon)); + max_lon = std::max(max_lon, + std::max(coordinate_list.at(objects[i].u).lon, + coordinate_list.at(objects[i].v).lon)); + + min_lat = std::min(min_lat, + std::min(coordinate_list.at(objects[i].u).lat, + coordinate_list.at(objects[i].v).lat)); + max_lat = std::max(max_lat, + std::max(coordinate_list.at(objects[i].u).lat, + coordinate_list.at(objects[i].v).lat)); + } + BOOST_ASSERT(min_lat != std::numeric_limits::min()); + BOOST_ASSERT(min_lon != std::numeric_limits::min()); + BOOST_ASSERT(max_lat != std::numeric_limits::min()); + BOOST_ASSERT(max_lon != std::numeric_limits::min()); + } + + inline void MergeBoundingBoxes(const RectangleInt2D &other) + { + min_lon = std::min(min_lon, other.min_lon); + max_lon = std::max(max_lon, other.max_lon); + min_lat = std::min(min_lat, other.min_lat); + max_lat = std::max(max_lat, other.max_lat); + BOOST_ASSERT(min_lat != std::numeric_limits::min()); + BOOST_ASSERT(min_lon != std::numeric_limits::min()); + BOOST_ASSERT(max_lat != std::numeric_limits::min()); + BOOST_ASSERT(max_lon != std::numeric_limits::min()); + } + + inline FixedPointCoordinate Centroid() const + { + FixedPointCoordinate centroid; + // The coordinates of the midpoints are given by: + // x = (x1 + x2) /2 and y = (y1 + y2) /2. + centroid.lon = (min_lon + max_lon) / 2; + centroid.lat = (min_lat + max_lat) / 2; + return centroid; + } + + inline bool Intersects(const RectangleInt2D &other) const + { + FixedPointCoordinate upper_left(other.max_lat, other.min_lon); + FixedPointCoordinate upper_right(other.max_lat, other.max_lon); + FixedPointCoordinate lower_right(other.min_lat, other.max_lon); + FixedPointCoordinate lower_left(other.min_lat, other.min_lon); + + return (Contains(upper_left) || Contains(upper_right) || Contains(lower_right) || + Contains(lower_left)); + } + + inline float GetMinDist(const FixedPointCoordinate &location) const + { + const bool is_contained = Contains(location); + if (is_contained) + { + return 0.; + } + + enum Direction + { + INVALID = 0, + NORTH = 1, + SOUTH = 2, + EAST = 4, + NORTH_EAST = 5, + SOUTH_EAST = 6, + WEST = 8, + NORTH_WEST = 9, + SOUTH_WEST = 10 + }; + + Direction d = INVALID; + if (location.lat > max_lat) + d = (Direction) (d | NORTH); + else if (location.lat < min_lat) + d = (Direction) (d | SOUTH); + if (location.lon > max_lon) + d = (Direction) (d | EAST); + else if (location.lon < min_lon) + d = (Direction) (d | WEST); + + BOOST_ASSERT(d != INVALID); + + float min_dist = std::numeric_limits::max(); + switch (d) + { + case NORTH: + min_dist = FixedPointCoordinate::ApproximateEuclideanDistance(location, FixedPointCoordinate(max_lat, location.lon)); + break; + case SOUTH: + min_dist = FixedPointCoordinate::ApproximateEuclideanDistance(location, FixedPointCoordinate(min_lat, location.lon)); + break; + case WEST: + min_dist = FixedPointCoordinate::ApproximateEuclideanDistance(location, FixedPointCoordinate(location.lat, min_lon)); + break; + case EAST: + min_dist = FixedPointCoordinate::ApproximateEuclideanDistance(location, FixedPointCoordinate(location.lat, max_lon)); + break; + case NORTH_EAST: + min_dist = FixedPointCoordinate::ApproximateEuclideanDistance(location, FixedPointCoordinate(max_lat, max_lon)); + break; + case NORTH_WEST: + min_dist = FixedPointCoordinate::ApproximateEuclideanDistance(location, FixedPointCoordinate(max_lat, min_lon)); + break; + case SOUTH_EAST: + min_dist = FixedPointCoordinate::ApproximateEuclideanDistance(location, FixedPointCoordinate(min_lat, max_lon)); + break; + case SOUTH_WEST: + min_dist = FixedPointCoordinate::ApproximateEuclideanDistance(location, FixedPointCoordinate(min_lat, min_lon)); + break; + default: + break; + } + + BOOST_ASSERT(min_dist != std::numeric_limits::max()); + + return min_dist; + } + + inline float GetMinMaxDist(const FixedPointCoordinate &location) const + { + float min_max_dist = std::numeric_limits::max(); + // Get minmax distance to each of the four sides + const FixedPointCoordinate upper_left(max_lat, min_lon); + const FixedPointCoordinate upper_right(max_lat, max_lon); + const FixedPointCoordinate lower_right(min_lat, max_lon); + const FixedPointCoordinate lower_left(min_lat, min_lon); + + min_max_dist = std::min( + min_max_dist, + std::max( + FixedPointCoordinate::ApproximateEuclideanDistance(location, upper_left), + FixedPointCoordinate::ApproximateEuclideanDistance(location, upper_right))); + + min_max_dist = std::min( + min_max_dist, + std::max( + FixedPointCoordinate::ApproximateEuclideanDistance(location, upper_right), + FixedPointCoordinate::ApproximateEuclideanDistance(location, lower_right))); + + min_max_dist = std::min( + min_max_dist, + std::max(FixedPointCoordinate::ApproximateEuclideanDistance(location, lower_right), + FixedPointCoordinate::ApproximateEuclideanDistance(location, lower_left))); + + min_max_dist = std::min( + min_max_dist, + std::max(FixedPointCoordinate::ApproximateEuclideanDistance(location, lower_left), + FixedPointCoordinate::ApproximateEuclideanDistance(location, upper_left))); + return min_max_dist; + } + + inline bool Contains(const FixedPointCoordinate &location) const + { + const bool lats_contained = (location.lat >= min_lat) && (location.lat <= max_lat); + const bool lons_contained = (location.lon >= min_lon) && (location.lon <= max_lon); + return lats_contained && lons_contained; + } + + inline friend std::ostream &operator<<(std::ostream &out, const RectangleInt2D &rect) + { + out << rect.min_lat / COORDINATE_PRECISION << "," << rect.min_lon / COORDINATE_PRECISION + << " " << rect.max_lat / COORDINATE_PRECISION << "," + << rect.max_lon / COORDINATE_PRECISION; + return out; + } + }; + using RectangleT = RectangleInt2D; struct TreeNode @@ -159,7 +343,7 @@ class StaticRTree explicit StaticRTree(std::vector &input_data_vector, const std::string tree_node_filename, const std::string leaf_node_filename, - const std::vector &coordinate_list) + const std::vector &coordinate_list) : m_element_count(input_data_vector.size()), m_leaf_node_filename(leaf_node_filename) { SimpleLogger().Write() << "constructing r-tree of " << m_element_count @@ -1021,7 +1205,7 @@ class StaticRTree inline void InitializeMBRectangle(RectangleT& rectangle, const std::array &objects, const uint32_t element_count, - const std::vector &coordinate_list) + const std::vector &coordinate_list) { for (uint32_t i = 0; i < element_count; ++i) { diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 77432d33d..9f2019e32 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -126,14 +126,14 @@ template class InternalDataFacade : public BaseDataFacade>(number_of_coordinates); for (unsigned i = 0; i < number_of_coordinates; ++i) { - nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); + nodes_input_stream.read((char *)¤t_node, sizeof(QueryNode)); m_coordinate_list->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon); BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lat) >> 30) == 0); BOOST_ASSERT((std::abs(m_coordinate_list->at(i).lon) >> 30) == 0); diff --git a/Tools/components.cpp b/Tools/components.cpp index b60077bd0..b2b59a31f 100644 --- a/Tools/components.cpp +++ b/Tools/components.cpp @@ -37,7 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -std::vector coordinate_list; +std::vector coordinate_list; std::vector restrictions_vector; std::vector bollard_ID_list; std::vector trafficlight_ID_list; diff --git a/Util/FingerPrint.h b/Util/FingerPrint.h index c61fe360e..5fd04b60e 100644 --- a/Util/FingerPrint.h +++ b/Util/FingerPrint.h @@ -42,7 +42,6 @@ class FingerPrint bool TestGraphUtil(const FingerPrint &other) const; bool TestPrepare(const FingerPrint &other) const; bool TestRTree(const FingerPrint &other) const; - bool TestNodeInfo(const FingerPrint &other) const; bool TestQueryObjects(const FingerPrint &other) const; private: diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index a7eab64f0..44c466cc9 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -57,7 +57,7 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream, std::vector &edge_list, std::vector &barrier_node_list, std::vector &traffic_light_node_list, - std::vector *int_to_ext_node_id_map, + std::vector *int_to_ext_node_id_map, std::vector &restriction_list) { const FingerPrint fingerprint_orig; diff --git a/datastore.cpp b/datastore.cpp index e26ab4b8a..7a376b4ff 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -481,10 +481,10 @@ int main(const int argc, const char *argv[]) shared_layout_ptr->GetBlockPtr( shared_memory_ptr, SharedDataLayout::COORDINATE_LIST); - NodeInfo current_node; + QueryNode current_node; for (unsigned i = 0; i < coordinate_list_size; ++i) { - nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo)); + nodes_input_stream.read((char *)¤t_node, sizeof(QueryNode)); coordinates_ptr[i] = FixedPointCoordinate(current_node.lat, current_node.lon); } nodes_input_stream.close();