Implements a vector tileserver so you can see what's going on inside

OSRM.
This commit is contained in:
Daniel Patterson
2016-02-16 10:51:04 -08:00
committed by Patrick Niklaus
parent 33403efc8e
commit 5dc7b79bb6
18 changed files with 709 additions and 14 deletions
+1 -1
View File
@@ -15,13 +15,13 @@ class exception final : public std::exception
public:
explicit exception(const char *message) : message(message) {}
explicit exception(std::string message) : message(std::move(message)) {}
const char *what() const noexcept override { return message.c_str(); }
private:
// This function exists to 'anchor' the class, and stop the compiler from
// copying vtable and RTTI info into every object file that includes
// this header. (Caught by -Wweak-vtables under Clang.)
virtual void anchor() const;
const char *what() const noexcept override { return message.c_str(); }
const std::string message;
};
}
+8 -7
View File
@@ -26,6 +26,10 @@ struct RectangleInt2D
{
}
RectangleInt2D(int32_t min_lon_, int32_t max_lon_, int32_t min_lat_, int32_t max_lat_) :
min_lon(min_lon_), max_lon(max_lon_),
min_lat(min_lat_), max_lat(max_lat_) {}
int32_t min_lon, max_lon;
int32_t min_lat, max_lat;
@@ -53,13 +57,10 @@ struct RectangleInt2D
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));
// Standard box intersection test - check if boxes *don't* overlap,
// and return the negative of that
return ! (max_lon < other.min_lon || min_lon > other.max_lon
|| max_lat < other.min_lat || min_lat > other.max_lat);
}
double GetMinDist(const FixedPointCoordinate location) const
+56
View File
@@ -321,6 +321,62 @@ class StaticRTree
leaves_stream.read((char *)&m_element_count, sizeof(uint64_t));
}
/* Returns all features inside the bounding box */
std::vector<EdgeDataT> SearchInBox(const Rectangle & search_rectangle)
{
std::vector<EdgeDataT> results;
std::queue<TreeNode> traversal_queue;
traversal_queue.push(m_search_tree[0]);
while (!traversal_queue.empty())
{
auto const current_tree_node = traversal_queue.front();
traversal_queue.pop();
if (current_tree_node.child_is_on_disk)
{
LeafNode current_leaf_node;
LoadLeafFromDisk(current_tree_node.children[0], current_leaf_node);
for (const auto i : irange(0u, current_leaf_node.object_count))
{
const auto &current_edge = current_leaf_node.objects[i];
Rectangle bbox =
{std::min((*m_coordinate_list)[current_edge.u].lon, (*m_coordinate_list)[current_edge.v].lon),
std::max((*m_coordinate_list)[current_edge.u].lon, (*m_coordinate_list)[current_edge.v].lon),
std::min((*m_coordinate_list)[current_edge.u].lat, (*m_coordinate_list)[current_edge.v].lat),
std::max((*m_coordinate_list)[current_edge.u].lat, (*m_coordinate_list)[current_edge.v].lat)};
if (bbox.Intersects(search_rectangle))
{
results.push_back(current_edge);
}
}
}
else
{
// If it's a tree node, look at all children and add them
// to the search queue if their bounding boxes intersect
for (uint32_t i = 0; i < current_tree_node.child_count; ++i)
{
const int32_t child_id = current_tree_node.children[i];
const auto &child_tree_node = m_search_tree[child_id];
const auto &child_rectangle = child_tree_node.minimum_bounding_rectangle;
if (child_rectangle.Intersects(search_rectangle))
{
traversal_queue.push(m_search_tree[child_id]);
}
}
}
}
return results;
}
// Override filter and terminator for the desired behaviour.
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate,
const std::size_t max_results)
+32
View File
@@ -0,0 +1,32 @@
#ifndef TILE_BBOX
#define TILE_BBOX
#include "util/rectangle.hpp"
#include <cmath>
namespace osrm
{
namespace util
{
inline RectangleInt2D TileToBBOX(int z, int x, int y)
{
double minx = x / pow(2.0, z) * 360 - 180;
double n = M_PI - 2.0 * M_PI * y / pow(2.0, z);
double miny = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
double maxx = (x + 1) / pow(2.0, z) * 360 - 180;
double mn = M_PI - 2.0 * M_PI * (y + 1) / pow(2.0, z);
double maxy = 180.0 / M_PI * atan(0.5 * (exp(mn) - exp(-mn)));
return {
static_cast<int32_t>(std::min(minx,maxx) * COORDINATE_PRECISION),
static_cast<int32_t>(std::max(minx,maxx) * COORDINATE_PRECISION),
static_cast<int32_t>(std::min(miny,maxy) * COORDINATE_PRECISION),
static_cast<int32_t>(std::min(miny,maxy) * COORDINATE_PRECISION)
};
}
}
}
#endif