renamed: Util/* -> util/*

This commit is contained in:
Dennis Luxen
2015-01-27 17:44:46 +01:00
parent 203e3ef077
commit b20b7e65bf
113 changed files with 4533 additions and 971 deletions
+200 -208
View File
@@ -37,12 +37,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "shared_memory_vector_wrapper.hpp"
#include "upper_bound.hpp"
#include "../Util/floating_point.hpp"
#include "../Util/integer_range.hpp"
#include "../Util/mercator.hpp"
#include "../Util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp"
#include "../Util/timing_util.hpp"
#include "../util/floating_point.hpp"
#include "../util/integer_range.hpp"
#include "../util/mercator.hpp"
#include "../util/osrm_exception.hpp"
#include "../util/simple_logger.hpp"
#include "../util/timing_util.hpp"
#include "../typedefs.h"
#include <osrm/coordinate.hpp>
@@ -69,8 +69,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
template <class EdgeDataT,
class CoordinateListT = std::vector<FixedPointCoordinate>,
bool UseSharedMemory = false,
uint32_t BRANCHING_FACTOR=64,
uint32_t LEAF_NODE_SIZE=1024>
uint32_t BRANCHING_FACTOR = 64,
uint32_t LEAF_NODE_SIZE = 1024>
class StaticRTree
{
public:
@@ -87,19 +87,15 @@ class StaticRTree
{
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_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));
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<int>::min());
BOOST_ASSERT(min_lon != std::numeric_limits<int>::min());
@@ -150,58 +146,66 @@ class StaticRTree
enum Direction
{
INVALID = 0,
NORTH = 1,
SOUTH = 2,
EAST = 4,
INVALID = 0,
NORTH = 1,
SOUTH = 2,
EAST = 4,
NORTH_EAST = 5,
SOUTH_EAST = 6,
WEST = 8,
WEST = 8,
NORTH_WEST = 9,
SOUTH_WEST = 10
};
Direction d = INVALID;
if (location.lat > max_lat)
d = (Direction) (d | NORTH);
d = (Direction)(d | NORTH);
else if (location.lat < min_lat)
d = (Direction) (d | SOUTH);
d = (Direction)(d | SOUTH);
if (location.lon > max_lon)
d = (Direction) (d | EAST);
d = (Direction)(d | EAST);
else if (location.lon < min_lon)
d = (Direction) (d | WEST);
d = (Direction)(d | WEST);
BOOST_ASSERT(d != INVALID);
float min_dist = std::numeric_limits<float>::max();
switch (d)
{
case NORTH:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(max_lat, location.lon));
break;
case SOUTH:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(min_lat, location.lon));
break;
case WEST:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(location.lat, min_lon));
break;
case EAST:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(location.lat, max_lon));
break;
case NORTH_EAST:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(max_lat, max_lon));
break;
case NORTH_WEST:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(max_lat, min_lon));
break;
case SOUTH_EAST:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(min_lat, max_lon));
break;
case SOUTH_WEST:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(min_lat, min_lon));
break;
default:
break;
case NORTH:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(max_lat, location.lon));
break;
case SOUTH:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(min_lat, location.lon));
break;
case WEST:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(location.lat, min_lon));
break;
case EAST:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(location.lat, max_lon));
break;
case NORTH_EAST:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(max_lat, max_lon));
break;
case NORTH_WEST:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(max_lat, min_lon));
break;
case SOUTH_EAST:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(min_lat, max_lon));
break;
case SOUTH_WEST:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(min_lat, min_lon));
break;
default:
break;
}
BOOST_ASSERT(min_dist != std::numeric_limits<float>::max());
@@ -220,15 +224,13 @@ class StaticRTree
min_max_dist = std::min(
min_max_dist,
std::max(
coordinate_calculation::euclidean_distance(location, upper_left),
coordinate_calculation::euclidean_distance(location, upper_right)));
std::max(coordinate_calculation::euclidean_distance(location, upper_left),
coordinate_calculation::euclidean_distance(location, upper_right)));
min_max_dist = std::min(
min_max_dist,
std::max(
coordinate_calculation::euclidean_distance(location, upper_right),
coordinate_calculation::euclidean_distance(location, lower_right)));
std::max(coordinate_calculation::euclidean_distance(location, upper_right),
coordinate_calculation::euclidean_distance(location, lower_right)));
min_max_dist = std::min(
min_max_dist,
@@ -378,7 +380,8 @@ class StaticRTree
FixedPointCoordinate(coordinate_list.at(current_element.v).lat,
coordinate_list.at(current_element.v).lon));
current_centroid.lat =
COORDINATE_PRECISION * mercator::lat2y(current_centroid.lat / COORDINATE_PRECISION);
COORDINATE_PRECISION *
mercator::lat2y(current_centroid.lat / COORDINATE_PRECISION);
current_wrapper.m_hilbert_value = get_hilbert_number(current_centroid);
}
@@ -416,8 +419,8 @@ class StaticRTree
}
// generate tree node that resemble the objects in leaf and store it for next level
InitializeMBRectangle(current_node.minimum_bounding_rectangle,
current_leaf.objects, current_leaf.object_count, coordinate_list);
InitializeMBRectangle(current_node.minimum_bounding_rectangle, current_leaf.objects,
current_leaf.object_count, coordinate_list);
current_node.child_is_on_disk = true;
current_node.children[0] = tree_nodes_in_level.size();
tree_nodes_in_level.emplace_back(current_node);
@@ -440,8 +443,7 @@ class StaticRTree
TreeNode parent_node;
// pack BRANCHING_FACTOR elements into tree_nodes each
for (uint32_t current_child_node_index = 0;
BRANCHING_FACTOR > current_child_node_index;
++current_child_node_index)
BRANCHING_FACTOR > current_child_node_index; ++current_child_node_index)
{
if (processed_tree_nodes_in_level < tree_nodes_in_level.size())
{
@@ -474,17 +476,17 @@ class StaticRTree
tbb::parallel_for(tbb::blocked_range<uint32_t>(0, search_tree_size),
[this, &search_tree_size](const tbb::blocked_range<uint32_t> &range)
{
for (uint32_t i = range.begin(); i != range.end(); ++i)
{
TreeNode &current_tree_node = this->m_search_tree[i];
for (uint32_t j = 0; j < current_tree_node.child_count; ++j)
{
const uint32_t old_id = current_tree_node.children[j];
const uint32_t new_id = search_tree_size - old_id - 1;
current_tree_node.children[j] = new_id;
}
}
});
for (uint32_t i = range.begin(); i != range.end(); ++i)
{
TreeNode &current_tree_node = this->m_search_tree[i];
for (uint32_t j = 0; j < current_tree_node.child_count; ++j)
{
const uint32_t old_id = current_tree_node.children[j];
const uint32_t new_id = search_tree_size - old_id - 1;
current_tree_node.children[j] = new_id;
}
}
});
// open tree file
boost::filesystem::ofstream tree_node_file(tree_node_filename, std::ios::binary);
@@ -606,12 +608,10 @@ class StaticRTree
continue;
}
float current_minimum_distance =
coordinate_calculation::euclidean_distance(
input_coordinate.lat,
input_coordinate.lon,
m_coordinate_list->at(current_edge.u).lat,
m_coordinate_list->at(current_edge.u).lon);
float current_minimum_distance = coordinate_calculation::euclidean_distance(
input_coordinate.lat, input_coordinate.lon,
m_coordinate_list->at(current_edge.u).lat,
m_coordinate_list->at(current_edge.u).lon);
if (current_minimum_distance < min_dist)
{
// found a new minimum
@@ -619,12 +619,10 @@ class StaticRTree
result_coordinate = m_coordinate_list->at(current_edge.u);
}
current_minimum_distance =
coordinate_calculation::euclidean_distance(
input_coordinate.lat,
input_coordinate.lon,
m_coordinate_list->at(current_edge.v).lat,
m_coordinate_list->at(current_edge.v).lon);
current_minimum_distance = coordinate_calculation::euclidean_distance(
input_coordinate.lat, input_coordinate.lon,
m_coordinate_list->at(current_edge.v).lat,
m_coordinate_list->at(current_edge.v).lon);
if (current_minimum_distance < min_dist)
{
@@ -636,27 +634,23 @@ class StaticRTree
}
else
{
min_max_dist = ExploreTreeNode(current_tree_node,
input_coordinate,
min_dist,
min_max_dist,
traversal_queue);
min_max_dist = ExploreTreeNode(current_tree_node, input_coordinate, min_dist,
min_max_dist, traversal_queue);
}
}
}
return result_coordinate.is_valid();
}
// implementation of the Hjaltason/Samet query [3], a BFS traversal of the tree
// - searches for k elements nearest elements
// - continues to find the k+1st element from a big component if k elements
// come from tiny components
bool
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
std::vector<PhantomNode> &result_phantom_node_vector,
const unsigned max_number_of_phantom_nodes,
const unsigned max_checked_elements = 4*LEAF_NODE_SIZE)
bool IncrementalFindPhantomNodeForCoordinate(
const FixedPointCoordinate &input_coordinate,
std::vector<PhantomNode> &result_phantom_node_vector,
const unsigned max_number_of_phantom_nodes,
const unsigned max_checked_elements = 4 * LEAF_NODE_SIZE)
{
unsigned inspected_elements = 0;
unsigned number_of_elements_from_big_cc = 0;
@@ -664,9 +658,9 @@ class StaticRTree
unsigned pruned_elements = 0;
std::pair<double, double> projected_coordinate =
{ mercator::lat2y(input_coordinate.lat / COORDINATE_PRECISION),
input_coordinate.lon / COORDINATE_PRECISION };
std::pair<double, double> projected_coordinate = {
mercator::lat2y(input_coordinate.lat / COORDINATE_PRECISION),
input_coordinate.lon / COORDINATE_PRECISION};
// upper bound pruning technique
upper_bound<float> pruning_bound(max_number_of_phantom_nodes);
@@ -682,7 +676,8 @@ class StaticRTree
if (current_query_node.node.template is<TreeNode>())
{ // current object is a tree node
const TreeNode & current_tree_node = current_query_node.node.template get<TreeNode>();
const TreeNode &current_tree_node =
current_query_node.node.template get<TreeNode>();
if (current_tree_node.child_is_on_disk)
{
LeafNode current_leaf_node;
@@ -692,11 +687,10 @@ class StaticRTree
for (const auto i : osrm::irange(0u, current_leaf_node.object_count))
{
const auto &current_edge = current_leaf_node.objects[i];
const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance_from_projected_coordinate(
const float current_perpendicular_distance = coordinate_calculation::
perpendicular_distance_from_projected_coordinate(
m_coordinate_list->at(current_edge.u),
m_coordinate_list->at(current_edge.v),
input_coordinate,
m_coordinate_list->at(current_edge.v), input_coordinate,
projected_coordinate);
// distance must be non-negative
BOOST_ASSERT(0.f <= current_perpendicular_distance);
@@ -706,7 +700,9 @@ class StaticRTree
{
pruning_bound.insert(current_perpendicular_distance);
traversal_queue.emplace(current_perpendicular_distance, current_edge);
} else {
}
else
{
++pruned_elements;
}
}
@@ -718,8 +714,10 @@ class StaticRTree
{
const int32_t child_id = current_tree_node.children[i];
const TreeNode &child_tree_node = m_search_tree[child_id];
const RectangleT &child_rectangle = child_tree_node.minimum_bounding_rectangle;
const float lower_bound_to_element = child_rectangle.GetMinDist(input_coordinate);
const RectangleT &child_rectangle =
child_tree_node.minimum_bounding_rectangle;
const float lower_bound_to_element =
child_rectangle.GetMinDist(input_coordinate);
BOOST_ASSERT(0.f <= lower_bound_to_element);
traversal_queue.emplace(lower_bound_to_element, child_tree_node);
@@ -730,7 +728,8 @@ class StaticRTree
{ // current object is a leaf node
++inspected_elements;
// inspecting an actual road segment
const EdgeDataT & current_segment = current_query_node.node.template get<EdgeDataT>();
const EdgeDataT &current_segment =
current_query_node.node.template get<EdgeDataT>();
// continue searching for the first segment from a big component
if (number_of_elements_from_big_cc == 0 &&
@@ -744,29 +743,20 @@ class StaticRTree
float current_ratio = 0.f;
FixedPointCoordinate foot_point_coordinate_on_segment;
// const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance_from_projected_coordinate(
m_coordinate_list->at(current_segment.u),
m_coordinate_list->at(current_segment.v),
input_coordinate,
projected_coordinate,
foot_point_coordinate_on_segment,
current_ratio);
coordinate_calculation::perpendicular_distance_from_projected_coordinate(
m_coordinate_list->at(current_segment.u),
m_coordinate_list->at(current_segment.v), input_coordinate,
projected_coordinate, foot_point_coordinate_on_segment, current_ratio);
// store phantom node in result vector
result_phantom_node_vector.emplace_back(
current_segment.forward_edge_based_node_id,
current_segment.reverse_edge_based_node_id,
current_segment.name_id,
current_segment.forward_weight,
current_segment.reverse_weight,
current_segment.forward_offset,
current_segment.reverse_offset,
current_segment.packed_geometry_id,
current_segment.component_id,
foot_point_coordinate_on_segment,
current_segment.fwd_segment_position,
current_segment.forward_travel_mode,
current_segment.backward_travel_mode);
current_segment.reverse_edge_based_node_id, current_segment.name_id,
current_segment.forward_weight, current_segment.reverse_weight,
current_segment.forward_offset, current_segment.reverse_offset,
current_segment.packed_geometry_id, current_segment.component_id,
foot_point_coordinate_on_segment, current_segment.fwd_segment_position,
current_segment.forward_travel_mode, current_segment.backward_travel_mode);
// Hack to fix rounding errors and wandering via nodes.
FixUpRoundingIssue(input_coordinate, result_phantom_node_vector.back());
@@ -787,16 +777,20 @@ class StaticRTree
}
// stop the search by flushing the queue
if ((result_phantom_node_vector.size() >= max_number_of_phantom_nodes && number_of_elements_from_big_cc > 0) ||
if ((result_phantom_node_vector.size() >= max_number_of_phantom_nodes &&
number_of_elements_from_big_cc > 0) ||
inspected_elements >= max_checked_elements)
{
traversal_queue = std::priority_queue<IncrementalQueryCandidate>{};
}
}
// SimpleLogger().Write() << "result_phantom_node_vector.size(): " << result_phantom_node_vector.size();
// SimpleLogger().Write() << "result_phantom_node_vector.size(): " <<
// result_phantom_node_vector.size();
// SimpleLogger().Write() << "max_number_of_phantom_nodes: " << max_number_of_phantom_nodes;
// SimpleLogger().Write() << "number_of_elements_from_big_cc: " << number_of_elements_from_big_cc;
// SimpleLogger().Write() << "number_of_elements_from_tiny_cc: " << number_of_elements_from_tiny_cc;
// SimpleLogger().Write() << "number_of_elements_from_big_cc: " <<
// number_of_elements_from_big_cc;
// SimpleLogger().Write() << "number_of_elements_from_tiny_cc: " <<
// number_of_elements_from_tiny_cc;
// SimpleLogger().Write() << "inspected_elements: " << inspected_elements;
// SimpleLogger().Write() << "max_checked_elements: " << max_checked_elements;
// SimpleLogger().Write() << "pruned_elements: " << pruned_elements;
@@ -805,13 +799,14 @@ class StaticRTree
}
// implementation of the Hjaltason/Samet query [3], a BFS traversal of the tree
bool
IncrementalFindPhantomNodeForCoordinateWithDistance(const FixedPointCoordinate &input_coordinate,
std::vector<std::pair<PhantomNode, double>> &result_phantom_node_vector,
const unsigned number_of_results,
const unsigned max_checked_segments = 4*LEAF_NODE_SIZE)
bool IncrementalFindPhantomNodeForCoordinateWithDistance(
const FixedPointCoordinate &input_coordinate,
std::vector<std::pair<PhantomNode, double>> &result_phantom_node_vector,
const unsigned number_of_results,
const unsigned max_checked_segments = 4 * LEAF_NODE_SIZE)
{
std::vector<float> min_found_distances(number_of_results, std::numeric_limits<float>::max());
std::vector<float> min_found_distances(number_of_results,
std::numeric_limits<float>::max());
unsigned number_of_results_found_in_big_cc = 0;
unsigned number_of_results_found_in_tiny_cc = 0;
@@ -827,7 +822,7 @@ class StaticRTree
const IncrementalQueryCandidate current_query_node = traversal_queue.top();
traversal_queue.pop();
const float current_min_dist = min_found_distances[number_of_results-1];
const float current_min_dist = min_found_distances[number_of_results - 1];
if (current_query_node.min_dist > current_min_dist)
{
@@ -836,7 +831,8 @@ class StaticRTree
if (current_query_node.RepresentsTreeNode())
{
const TreeNode & current_tree_node = current_query_node.node.template get<TreeNode>();
const TreeNode &current_tree_node =
current_query_node.node.template get<TreeNode>();
if (current_tree_node.child_is_on_disk)
{
LeafNode current_leaf_node;
@@ -848,8 +844,7 @@ class StaticRTree
const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance(
m_coordinate_list->at(current_edge.u),
m_coordinate_list->at(current_edge.v),
input_coordinate);
m_coordinate_list->at(current_edge.v), input_coordinate);
// distance must be non-negative
BOOST_ASSERT(0. <= current_perpendicular_distance);
@@ -866,8 +861,10 @@ class StaticRTree
{
const int32_t child_id = current_tree_node.children[i];
const TreeNode &child_tree_node = m_search_tree[child_id];
const RectangleT &child_rectangle = child_tree_node.minimum_bounding_rectangle;
const float lower_bound_to_element = child_rectangle.GetMinDist(input_coordinate);
const RectangleT &child_rectangle =
child_tree_node.minimum_bounding_rectangle;
const float lower_bound_to_element =
child_rectangle.GetMinDist(input_coordinate);
// TODO - enough elements found, i.e. nearest distance > maximum distance?
// ie. some measure of 'confidence of accuracy'
@@ -878,23 +875,27 @@ class StaticRTree
traversal_queue.emplace(lower_bound_to_element, child_tree_node);
}
}
// SimpleLogger().Write(logDEBUG) << "added " << current_tree_node.child_count << " mbrs into queue of " << traversal_queue.size();
// SimpleLogger().Write(logDEBUG) << "added " << current_tree_node.child_count
// << " mbrs into queue of " << traversal_queue.size();
}
}
else
{
++inspected_segments;
// inspecting an actual road segment
const EdgeDataT & current_segment = current_query_node.node.template get<EdgeDataT>();
const EdgeDataT &current_segment =
current_query_node.node.template get<EdgeDataT>();
// don't collect too many results from small components
if (number_of_results_found_in_big_cc == number_of_results && !current_segment.is_in_tiny_cc)
if (number_of_results_found_in_big_cc == number_of_results &&
!current_segment.is_in_tiny_cc)
{
continue;
}
// don't collect too many results from big components
if (number_of_results_found_in_tiny_cc == number_of_results && current_segment.is_in_tiny_cc)
if (number_of_results_found_in_tiny_cc == number_of_results &&
current_segment.is_in_tiny_cc)
{
continue;
}
@@ -905,10 +906,8 @@ class StaticRTree
const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance(
m_coordinate_list->at(current_segment.u),
m_coordinate_list->at(current_segment.v),
input_coordinate,
foot_point_coordinate_on_segment,
current_ratio);
m_coordinate_list->at(current_segment.v), input_coordinate,
foot_point_coordinate_on_segment, current_ratio);
BOOST_ASSERT(0. <= current_perpendicular_distance);
@@ -918,16 +917,11 @@ class StaticRTree
// store phantom node in result vector
result_phantom_node_vector.emplace_back(
current_segment.forward_edge_based_node_id,
current_segment.reverse_edge_based_node_id,
current_segment.name_id,
current_segment.forward_weight,
current_segment.reverse_weight,
current_segment.forward_offset,
current_segment.reverse_offset,
current_segment.packed_geometry_id,
foot_point_coordinate_on_segment,
current_segment.fwd_segment_position,
current_perpendicular_distance);
current_segment.reverse_edge_based_node_id, current_segment.name_id,
current_segment.forward_weight, current_segment.reverse_weight,
current_segment.forward_offset, current_segment.reverse_offset,
current_segment.packed_geometry_id, foot_point_coordinate_on_segment,
current_segment.fwd_segment_position, current_perpendicular_distance);
// Hack to fix rounding errors and wandering via nodes.
FixUpRoundingIssue(input_coordinate, result_phantom_node_vector.back());
@@ -944,17 +938,22 @@ class StaticRTree
else
{
// found an element in a large component
min_found_distances[number_of_results_found_in_big_cc] = current_perpendicular_distance;
min_found_distances[number_of_results_found_in_big_cc] =
current_perpendicular_distance;
++number_of_results_found_in_big_cc;
// SimpleLogger().Write(logDEBUG) << std::setprecision(8) << foot_point_coordinate_on_segment << " at " << current_perpendicular_distance;
// SimpleLogger().Write(logDEBUG) << std::setprecision(8) <<
// foot_point_coordinate_on_segment << " at " <<
// current_perpendicular_distance;
}
}
}
// TODO add indicator to prune if maxdist > threshold
if (number_of_results == number_of_results_found_in_big_cc || inspected_segments >= max_checked_segments)
if (number_of_results == number_of_results_found_in_big_cc ||
inspected_segments >= max_checked_segments)
{
// SimpleLogger().Write(logDEBUG) << "flushing queue of " << traversal_queue.size() << " elements";
// SimpleLogger().Write(logDEBUG) << "flushing queue of " << traversal_queue.size()
// << " elements";
// work-around for traversal_queue.clear();
traversal_queue = std::priority_queue<IncrementalQueryCandidate>{};
}
@@ -963,8 +962,6 @@ class StaticRTree
return !result_phantom_node_vector.empty();
}
bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
PhantomNode &result_phantom_node,
const unsigned zoom_level)
@@ -1005,9 +1002,7 @@ class StaticRTree
const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance(
m_coordinate_list->at(current_edge.u),
m_coordinate_list->at(current_edge.v),
input_coordinate,
nearest,
m_coordinate_list->at(current_edge.v), input_coordinate, nearest,
current_ratio);
BOOST_ASSERT(0. <= current_perpendicular_distance);
@@ -1035,11 +1030,8 @@ class StaticRTree
}
else
{
min_max_dist = ExploreTreeNode(current_tree_node,
input_coordinate,
min_dist,
min_max_dist,
traversal_queue);
min_max_dist = ExploreTreeNode(current_tree_node, input_coordinate, min_dist,
min_max_dist, traversal_queue);
}
}
}
@@ -1056,8 +1048,7 @@ class StaticRTree
}
private:
inline void SetForwardAndReverseWeightsOnPhantomNode(const EdgeDataT & nearest_edge,
inline void SetForwardAndReverseWeightsOnPhantomNode(const EdgeDataT &nearest_edge,
PhantomNode &result_phantom_node) const
{
const float distance_1 = coordinate_calculation::euclidean_distance(
@@ -1069,32 +1060,34 @@ class StaticRTree
using TreeWeightType = decltype(result_phantom_node.forward_weight);
static_assert(std::is_same<decltype(result_phantom_node.forward_weight),
decltype(result_phantom_node.reverse_weight)>::value,
"forward and reverse weight type in tree must be the same");
"forward and reverse weight type in tree must be the same");
if (SPECIAL_NODEID != result_phantom_node.forward_node_id)
{
const auto new_weight = static_cast<TreeWeightType>(result_phantom_node.forward_weight * ratio);
const auto new_weight =
static_cast<TreeWeightType>(result_phantom_node.forward_weight * ratio);
result_phantom_node.forward_weight = new_weight;
}
if (SPECIAL_NODEID != result_phantom_node.reverse_node_id)
{
const auto new_weight = static_cast<TreeWeightType>(result_phantom_node.reverse_weight * (1.f-ratio));
const auto new_weight =
static_cast<TreeWeightType>(result_phantom_node.reverse_weight * (1.f - ratio));
result_phantom_node.reverse_weight = new_weight;
}
}
// fixup locations if too close to inputs
inline void FixUpRoundingIssue(const FixedPointCoordinate &input_coordinate,
PhantomNode &result_phantom_node) const
PhantomNode &result_phantom_node) const
{
if (1 == std::abs(input_coordinate.lon - result_phantom_node.location.lon))
{
result_phantom_node.location.lon = input_coordinate.lon;
}
if (1 == std::abs(input_coordinate.lat - result_phantom_node.location.lat))
{
result_phantom_node.location.lat = input_coordinate.lat;
}
if (1 == std::abs(input_coordinate.lon - result_phantom_node.location.lon))
{
result_phantom_node.location.lon = input_coordinate.lon;
}
if (1 == std::abs(input_coordinate.lat - result_phantom_node.location.lat))
{
result_phantom_node.location.lat = input_coordinate.lat;
}
}
template <class QueueT>
@@ -1140,8 +1133,7 @@ class StaticRTree
}
const uint64_t seek_pos = sizeof(uint64_t) + leaf_id * sizeof(LeafNode);
leaves_stream.seekg(seek_pos);
BOOST_ASSERT_MSG(leaves_stream.good(),
"Seeking to position in leaf file failed.");
BOOST_ASSERT_MSG(leaves_stream.good(), "Seeking to position in leaf file failed.");
leaves_stream.read((char *)&result_node, sizeof(LeafNode));
BOOST_ASSERT_MSG(leaves_stream.good(), "Reading from leaf file failed.");
}
@@ -1154,26 +1146,26 @@ class StaticRTree
return (a == b && c == d) || (a == c && b == d) || (a == d && b == c);
}
inline void InitializeMBRectangle(RectangleT& rectangle,
inline void InitializeMBRectangle(RectangleT &rectangle,
const std::array<EdgeDataT, LEAF_NODE_SIZE> &objects,
const uint32_t element_count,
const std::vector<QueryNode> &coordinate_list)
{
for (uint32_t i = 0; i < element_count; ++i)
{
rectangle.min_lon = std::min(rectangle.min_lon,
std::min(coordinate_list.at(objects[i].u).lon,
coordinate_list.at(objects[i].v).lon));
rectangle.max_lon = std::max(rectangle.max_lon,
std::max(coordinate_list.at(objects[i].u).lon,
coordinate_list.at(objects[i].v).lon));
rectangle.min_lon =
std::min(rectangle.min_lon, std::min(coordinate_list.at(objects[i].u).lon,
coordinate_list.at(objects[i].v).lon));
rectangle.max_lon =
std::max(rectangle.max_lon, std::max(coordinate_list.at(objects[i].u).lon,
coordinate_list.at(objects[i].v).lon));
rectangle.min_lat = std::min(rectangle.min_lat,
std::min(coordinate_list.at(objects[i].u).lat,
coordinate_list.at(objects[i].v).lat));
rectangle.max_lat = std::max(rectangle.max_lat,
std::max(coordinate_list.at(objects[i].u).lat,
coordinate_list.at(objects[i].v).lat));
rectangle.min_lat =
std::min(rectangle.min_lat, std::min(coordinate_list.at(objects[i].u).lat,
coordinate_list.at(objects[i].v).lat));
rectangle.max_lat =
std::max(rectangle.max_lat, std::max(coordinate_list.at(objects[i].u).lat,
coordinate_list.at(objects[i].v).lat));
}
BOOST_ASSERT(rectangle.min_lat != std::numeric_limits<int>::min());
BOOST_ASSERT(rectangle.min_lon != std::numeric_limits<int>::min());