From 99bfd03b2210de8bfa4307f217bb625cac508565 Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 31 Mar 2016 11:21:57 +0200 Subject: [PATCH] spatial_index - make generic --- include/mapnik/util/spatial_index.hpp | 41 ++++++++++++++------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/include/mapnik/util/spatial_index.hpp b/include/mapnik/util/spatial_index.hpp index d207dbab4..720667768 100644 --- a/include/mapnik/util/spatial_index.hpp +++ b/include/mapnik/util/spatial_index.hpp @@ -47,12 +47,13 @@ bool check_spatial_index(InputStream& in) return (std::strncmp(header, "mapnik-index",12) == 0); } -template +template > class spatial_index { + using bbox_type = BBox; public: static void query(Filter const& filter, InputStream& in,std::vector& pos); - static box2d bounding_box( InputStream& in ); + static bbox_type bounding_box( InputStream& in ); static void query_first_n(Filter const& filter, InputStream & in, std::vector& pos, std::size_t count); private: spatial_index(); @@ -60,25 +61,25 @@ private: spatial_index(spatial_index const&); spatial_index& operator=(spatial_index const&); static int read_ndr_integer(InputStream& in); - static void read_envelope(InputStream& in, box2d& envelope); + static void read_envelope(InputStream& in, bbox_type& envelope); static void query_node(Filter const& filter, InputStream& in, std::vector & results); static void query_first_n_impl(Filter const& filter, InputStream& in, std::vector & results, std::size_t count); }; -template -box2d spatial_index::bounding_box(InputStream& in) +template +BBox spatial_index::bounding_box(InputStream& in) { static_assert(std::is_standard_layout::value, "Values stored in quad-tree must be standard layout type"); if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)"); in.seekg(16 + 4, std::ios::beg); - box2d box; + typename spatial_index::bbox_type box; read_envelope(in, box); in.seekg(0, std::ios::beg); return box; } -template -void spatial_index::query(Filter const& filter, InputStream& in, std::vector& results) +template +void spatial_index::query(Filter const& filter, InputStream& in, std::vector& results) { static_assert(std::is_standard_layout::value, "Values stored in quad-tree must be standard layout type"); if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)"); @@ -86,11 +87,11 @@ void spatial_index::query(Filter const& filter, Inpu query_node(filter, in, results); } -template -void spatial_index::query_node(Filter const& filter, InputStream& in, std::vector& results) +template +void spatial_index::query_node(Filter const& filter, InputStream& in, std::vector& results) { int offset = read_ndr_integer(in); - box2d node_ext; + typename spatial_index::bbox_type node_ext; read_envelope(in, node_ext); int num_shapes = read_ndr_integer(in); if (!filter.pass(node_ext)) @@ -113,8 +114,8 @@ void spatial_index::query_node(Filter const& filter, } } -template -void spatial_index::query_first_n(Filter const& filter, InputStream& in, std::vector& results, std::size_t count) +template +void spatial_index::query_first_n(Filter const& filter, InputStream& in, std::vector& results, std::size_t count) { static_assert(std::is_standard_layout::value, "Values stored in quad-tree must be standard layout type"); if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)"); @@ -122,12 +123,12 @@ void spatial_index::query_first_n(Filter const& filt query_first_n_impl(filter, in, results, count); } -template -void spatial_index::query_first_n_impl(Filter const& filter, InputStream& in, std::vector& results, std::size_t count) +template +void spatial_index::query_first_n_impl(Filter const& filter, InputStream& in, std::vector& results, std::size_t count) { if (results.size() == count) return; int offset = read_ndr_integer(in); - box2d node_ext; + typename spatial_index::bbox_type node_ext; read_envelope(in, node_ext); int num_shapes = read_ndr_integer(in); if (!filter.pass(node_ext)) @@ -149,16 +150,16 @@ void spatial_index::query_first_n_impl(Filter const& } } -template -int spatial_index::read_ndr_integer(InputStream& in) +template +int spatial_index::read_ndr_integer(InputStream& in) { char b[4]; in.read(b, 4); return (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24; } -template -void spatial_index::read_envelope(InputStream& in, box2d& envelope) +template +void spatial_index::read_envelope(InputStream& in, BBox& envelope) { in.read(reinterpret_cast(&envelope), sizeof(envelope)); }