From 593ab6d9fbcd331892a5f380ebd1b216e23d45cf Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Wed, 14 Nov 2012 21:59:37 +0000 Subject: [PATCH] Names changed query to spatial_query, nearest to nearest_query, query_filtered to adaptors::spatial_queried, nearest_filtered to adaptors::nearest_queried. [SVN r81349] --- doc/src/examples/rtree/quick_start.cpp | 8 +-- .../index/filters/nearest_filter.hpp | 37 +++++++---- .../extensions/index/filters/query_filter.hpp | 28 +++++---- .../extensions/index/rtree/filters.hpp | 16 +++-- .../extensions/index/rtree/rstar/insert.hpp | 2 +- .../geometry/extensions/index/rtree/rtree.hpp | 34 +++++----- .../extensions/index/rtree/visitors/query.hpp | 2 + test/rtree/test_rtree.hpp | 62 ++++++++++--------- 8 files changed, 109 insertions(+), 80 deletions(-) diff --git a/doc/src/examples/rtree/quick_start.cpp b/doc/src/examples/rtree/quick_start.cpp index 25523f8b4..99f9fdd39 100644 --- a/doc/src/examples/rtree/quick_start.cpp +++ b/doc/src/examples/rtree/quick_start.cpp @@ -42,15 +42,15 @@ int main(void) rtree.insert(std::make_pair(b, 0)); //] - //[rtree_quickstart_query + //[rtree_quickstart_spatial_query // find values intersecting a box std::vector result; - rtree.query(b, std::back_inserter(result)); + rtree.spatial_query(b, std::back_inserter(result)); //] - //[rtree_quickstart_nearest + //[rtree_quickstart_nearest_query // find 5 nearest values to a point - rtree.nearest(point(0, 0), 5, std::back_inserter(result)); + rtree.nearest_query(point(0, 0), 5, std::back_inserter(result)); //] return 0; diff --git a/include/boost/geometry/extensions/index/filters/nearest_filter.hpp b/include/boost/geometry/extensions/index/filters/nearest_filter.hpp index 49afbb18a..8e1ecb1f1 100644 --- a/include/boost/geometry/extensions/index/filters/nearest_filter.hpp +++ b/include/boost/geometry/extensions/index/filters/nearest_filter.hpp @@ -13,19 +13,21 @@ namespace boost { namespace geometry { namespace index { +namespace adaptors { + template -class nearest_filter +class nearest_query_range { BOOST_MPL_ASSERT_MSG( (false), NOT_IMPLEMENTED_FOR_THIS_INDEX, - (nearest_filter)); + (nearest_query_range)); typedef int* iterator; typedef const int* const_iterator; template - inline nearest_filter( + inline nearest_query_range( Index const&, DistancesPredicates const&, size_t, @@ -44,9 +46,9 @@ namespace detail { // TODO: awulkiew - consider removing references from predicates template -struct nearest_filtered +struct nearest_query { - inline nearest_filtered( + inline nearest_query( DistancesPredicates const& dpred, size_t k, Predicates const& pred @@ -64,21 +66,34 @@ struct nearest_filtered } // namespace detail template -detail::nearest_filtered nearest_filtered( +detail::nearest_query +nearest_queried( DistancesPredicates const& dpred, size_t k, - Predicates const& pred = detail::empty()) + Predicates const& pred) { - return detail::nearest_filtered(dpred, k, pred); + return detail::nearest_query(dpred, k, pred); } +template +detail::nearest_query +nearest_queried( + DistancesPredicates const& dpred, + size_t k) +{ + return detail::nearest_query(dpred, k, index::detail::empty()); +} + +} // namespace adaptors + template -index::nearest_filter +index::adaptors::nearest_query_range operator|( Index const& si, - detail::nearest_filtered const& f) + index::adaptors::detail::nearest_query const& f) { - return index::nearest_filter(si, f.distances_predicates, f.count, f.predicates); + return index::adaptors::nearest_query_range( + si, f.distances_predicates, f.count, f.predicates); } }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/extensions/index/filters/query_filter.hpp b/include/boost/geometry/extensions/index/filters/query_filter.hpp index 025cfa069..4d30b4ea9 100644 --- a/include/boost/geometry/extensions/index/filters/query_filter.hpp +++ b/include/boost/geometry/extensions/index/filters/query_filter.hpp @@ -13,22 +13,23 @@ namespace boost { namespace geometry { namespace index { +namespace adaptors { + template -class query_filter +class spatial_query_range { BOOST_MPL_ASSERT_MSG( (false), NOT_IMPLEMENTED_FOR_THIS_INDEX, - (query_filter)); + (spatial_query_range)); typedef int* iterator; typedef const int* const_iterator; template - inline query_filter( + inline spatial_query_range( Index const&, - Predicates const& - ) + Predicates const&) {} inline iterator begin() { return 0; } @@ -42,9 +43,9 @@ namespace detail { // TODO: awulkiew - consider removing reference from predicates template -struct query_filtered +struct spatial_query { - inline explicit query_filtered(Predicates const& pred) + inline explicit spatial_query(Predicates const& pred) : predicates(pred) {} @@ -54,18 +55,21 @@ struct query_filtered } // namespace detail template -detail::query_filtered query_filtered(Predicates const& pred) +detail::spatial_query +spatial_queried(Predicates const& pred) { - return detail::query_filtered(pred); + return detail::spatial_query(pred); } +} // namespace adaptors + template -index::query_filter +index::adaptors::spatial_query_range operator|( Index const& si, - index::detail::query_filtered const& f) + index::adaptors::detail::spatial_query const& f) { - return index::query_filter(si, f.predicates); + return index::adaptors::spatial_query_range(si, f.predicates); } }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/extensions/index/rtree/filters.hpp b/include/boost/geometry/extensions/index/rtree/filters.hpp index 6cda2401d..44f56dd2f 100644 --- a/include/boost/geometry/extensions/index/rtree/filters.hpp +++ b/include/boost/geometry/extensions/index/rtree/filters.hpp @@ -22,8 +22,10 @@ namespace boost { namespace geometry { namespace index { template class rtree; +namespace adaptors { + template -class query_filter< index::rtree > +class spatial_query_range< index::rtree > { public: typedef std::vector result_type; @@ -31,12 +33,12 @@ public: typedef typename result_type::const_iterator const_iterator; template - inline query_filter( + inline spatial_query_range( index::rtree const& rtree, Predicates const& pred ) { - rtree.query(pred, std::back_inserter(m_result)); + rtree.spatial_query(pred, std::back_inserter(m_result)); } inline iterator begin() { return m_result.begin(); } @@ -49,7 +51,7 @@ private: }; template -class nearest_filter< index::rtree > +class nearest_query_range< index::rtree > { public: typedef std::vector result_type; @@ -57,14 +59,14 @@ public: typedef typename result_type::const_iterator const_iterator; template - inline nearest_filter( + inline nearest_query_range( index::rtree const& rtree, DistancesPredicates const& dpred, size_t k, Predicates const& pred ) { - rtree.nearest(dpred, k, pred, std::back_inserter(m_result)); + rtree.nearest_query(dpred, k, pred, std::back_inserter(m_result)); } inline iterator begin() { return m_result.begin(); } @@ -76,6 +78,8 @@ private: result_type m_result; }; +} // namespace adaptors + }}} // namespace boost::geometry::index #endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_FILTERS_HPP diff --git a/include/boost/geometry/extensions/index/rtree/rstar/insert.hpp b/include/boost/geometry/extensions/index/rtree/rstar/insert.hpp index faa08f01d..1368689f8 100644 --- a/include/boost/geometry/extensions/index/rtree/rstar/insert.hpp +++ b/include/boost/geometry/extensions/index/rtree/rstar/insert.hpp @@ -34,7 +34,7 @@ public: template static inline void apply(typename rtree::elements_type::type & result_elements, Node & n, - internal_node *parent, + internal_node *parent, size_t current_child_index, parameters_type const& parameters, Translator const& translator, diff --git a/include/boost/geometry/extensions/index/rtree/rtree.hpp b/include/boost/geometry/extensions/index/rtree/rtree.hpp index 355fae991..0943f519c 100644 --- a/include/boost/geometry/extensions/index/rtree/rtree.hpp +++ b/include/boost/geometry/extensions/index/rtree/rtree.hpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -45,6 +45,8 @@ #include //#include +// TODO change the name to bounding_tree + namespace boost { namespace geometry { namespace index { /*! @@ -335,7 +337,7 @@ public: \return The number of values found. */ template - inline size_type query(Predicates const& pred, OutIter out_it) const + inline size_type spatial_query(Predicates const& pred, OutIter out_it) const { detail::rtree::visitors::query find_v(m_translator, pred, out_it); @@ -365,7 +367,7 @@ public: \return The number of values found. */ template - inline size_type nearest(DistancesPredicates const& dpred, value_type & v) const + inline size_type nearest_query(DistancesPredicates const& dpred, value_type & v) const { return raw_nearest_one(dpred, detail::empty(), v); } @@ -397,7 +399,7 @@ public: \return The number of values found. */ template - inline size_type nearest(DistancesPredicates const& dpred, Predicates const& pred, value_type & v) const + inline size_type nearest_query(DistancesPredicates const& dpred, Predicates const& pred, value_type & v) const { return raw_nearest_one(dpred, pred, v); } @@ -422,7 +424,7 @@ public: \return The number of values found. */ template - inline size_type nearest(DistancesPredicates const& dpred, size_t k, OutIter out_it) const + inline size_type nearest_query(DistancesPredicates const& dpred, size_t k, OutIter out_it) const { return raw_nearest_k(dpred, k, detail::empty(), out_it); } @@ -455,7 +457,7 @@ public: \return The number of values found. */ template - inline size_type nearest(DistancesPredicates const& dpred, size_t k, Predicates const& pred, OutIter out_it) const + inline size_type nearest_query(DistancesPredicates const& dpred, size_t k, Predicates const& pred, OutIter out_it) const { return raw_nearest_k(dpred, k, pred, out_it); } @@ -853,9 +855,9 @@ Find values meeting spatial predicates. \return The number of found values. */ template -inline size_t query(rtree const& tree, Predicates const& pred, OutIter out_it) +inline size_t spatial_query(rtree const& tree, Predicates const& pred, OutIter out_it) { - return tree.query(pred, out_it); + return tree.spatial_query(pred, out_it); } /*! @@ -868,9 +870,9 @@ Find the value meeting distances predicates. \return The number of found values. */ template -inline size_t nearest(rtree const& tree, DistancesPredicates const& dpred, Value & v) +inline size_t nearest_query(rtree const& tree, DistancesPredicates const& dpred, Value & v) { - return tree.nearest(dpred, v); + return tree.nearest_query(dpred, v); } /*! @@ -884,9 +886,9 @@ Find the value meeting distances and spatial predicates. \return The number of found values. */ template -inline size_t nearest(rtree const& tree, DistancesPredicates const& dpred, Predicates const& pred, Value & v) +inline size_t nearest_query(rtree const& tree, DistancesPredicates const& dpred, Predicates const& pred, Value & v) { - return tree.nearest(dpred, pred, v); + return tree.nearest_query(dpred, pred, v); } /*! @@ -900,9 +902,9 @@ Find k values meeting distances predicates. \return The number of found values. */ template -inline size_t nearest(rtree const& tree, DistancesPredicates const& dpred, size_t k, OutIter out_it) +inline size_t nearest_query(rtree const& tree, DistancesPredicates const& dpred, size_t k, OutIter out_it) { - return tree.nearest(dpred, k, out_it); + return tree.nearest_query(dpred, k, out_it); } /*! @@ -917,9 +919,9 @@ Find k values meeting distances and spatial predicates. \return The number of found values. */ template -inline size_t nearest(rtree const& tree, DistancesPredicates const& dpred, size_t k, Predicates const& pred, OutIter out_it) +inline size_t nearest_query(rtree const& tree, DistancesPredicates const& dpred, size_t k, Predicates const& pred, OutIter out_it) { - return tree.nearest(dpred, k, pred, out_it); + return tree.nearest_query(dpred, k, pred, out_it); } /*! diff --git a/include/boost/geometry/extensions/index/rtree/visitors/query.hpp b/include/boost/geometry/extensions/index/rtree/visitors/query.hpp index b7aa9643d..689e525aa 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/query.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/query.hpp @@ -11,6 +11,8 @@ #ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_VISITORS_QUERY_HPP #define BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_VISITORS_QUERY_HPP +#include + #include namespace boost { namespace geometry { namespace index { diff --git a/test/rtree/test_rtree.hpp b/test/rtree/test_rtree.hpp index 72b0a1c7d..7b68cfb31 100644 --- a/test/rtree/test_rtree.hpp +++ b/test/rtree/test_rtree.hpp @@ -253,24 +253,24 @@ void test_exactly_the_same_outputs(Rtree const& rtree, Range1 const& output, Ran // spatial query template -void test_query(Rtree & rtree, Predicates const& pred, std::vector const& expected_output) +void test_spatial_query(Rtree & rtree, Predicates const& pred, std::vector const& expected_output) { BOOST_CHECK( bgi::are_levels_ok(rtree) ); BOOST_CHECK( bgi::are_boxes_ok(rtree) ); std::vector output; - size_t n = rtree.query(pred, std::back_inserter(output)); + size_t n = rtree.spatial_query(pred, std::back_inserter(output)); BOOST_CHECK( expected_output.size() == n ); test_compare_outputs(rtree, output, expected_output); std::vector output2; - size_t n2 = query(rtree, pred, std::back_inserter(output2)); + size_t n2 = spatial_query(rtree, pred, std::back_inserter(output2)); BOOST_CHECK( n == n2 ); test_exactly_the_same_outputs(rtree, output, output2); - test_exactly_the_same_outputs(rtree, output, rtree | bgi::query_filtered(pred)); + test_exactly_the_same_outputs(rtree, output, rtree | bgi::adaptors::spatial_queried(pred)); } // rtree specific queries tests @@ -284,11 +284,11 @@ void test_intersects_and_disjoint(bgi::rtree const& tree, std::vect if ( bg::intersects(tree.translator()(v), qbox) ) expected_output.push_back(v); - test_query(tree, qbox, expected_output); - test_query(tree, bgi::intersects(qbox), expected_output); - test_query(tree, !bgi::not_intersects(qbox), expected_output); - test_query(tree, !bgi::disjoint(qbox), expected_output); - test_query(tree, bgi::not_disjoint(qbox), expected_output); + test_spatial_query(tree, qbox, expected_output); + test_spatial_query(tree, bgi::intersects(qbox), expected_output); + test_spatial_query(tree, !bgi::not_intersects(qbox), expected_output); + test_spatial_query(tree, !bgi::disjoint(qbox), expected_output); + test_spatial_query(tree, bgi::not_disjoint(qbox), expected_output); } template @@ -300,7 +300,7 @@ void test_covered_by(bgi::rtree const& tree, std::vector con if ( bg::covered_by(tree.translator()(v), qbox) ) expected_output.push_back(v); - test_query(tree, bgi::covered_by(qbox), expected_output); + test_spatial_query(tree, bgi::covered_by(qbox), expected_output); } template @@ -315,7 +315,7 @@ struct test_overlap_impl if ( bg::overlaps(tree.translator()(v), qbox) ) expected_output.push_back(v); - test_query(tree, bgi::overlaps(qbox), expected_output); + test_spatial_query(tree, bgi::overlaps(qbox), expected_output); } }; @@ -357,7 +357,7 @@ void test_overlaps(bgi::rtree const& tree, std::vector const // if ( bg::touches(tree.translator()(v), qbox) ) // expected_output.push_back(v); // -// test_query(tree, bgi::touches(qbox), expected_output); +// test_spatial_query(tree, bgi::touches(qbox), expected_output); // } //}; // @@ -383,13 +383,13 @@ void test_within(bgi::rtree const& tree, std::vector const& if ( bg::within(tree.translator()(v), qbox) ) expected_output.push_back(v); - test_query(tree, bgi::within(qbox), expected_output); + test_spatial_query(tree, bgi::within(qbox), expected_output); } // rtree nearest queries template -void test_nearest(Rtree const& rtree, std::vector const& input, Point const& pt) +void test_nearest_query(Rtree const& rtree, std::vector const& input, Point const& pt) { // TODO: Nearest object may not be the same as found by the rtree if distances are equal // Should all objects with the same closest distance be picked? @@ -409,7 +409,7 @@ void test_nearest(Rtree const& rtree, std::vector const& input, Point con size_t n = ( (std::numeric_limits::max)() == smallest_d ) ? 0 : 1; Value output; - size_t n_res = rtree.nearest(pt, output); + size_t n_res = rtree.nearest_query(pt, output); BOOST_CHECK(n == n_res); if ( n == n_res && 0 < n ) @@ -451,7 +451,7 @@ struct TestNearestKTransform }; template -void test_nearest_k(Rtree const& rtree, std::vector const& input, Point const& pt, size_t k) +void test_nearest_query_k(Rtree const& rtree, std::vector const& input, Point const& pt, size_t k) { // TODO: Nearest object may not be the same as found by the rtree if distances are equal // All objects with the same closest distance should be picked @@ -485,7 +485,7 @@ void test_nearest_k(Rtree const& rtree, std::vector const& input, Point c // calculate output using rtree std::vector output; - rtree.nearest(pt, k, std::back_inserter(output)); + rtree.nearest_query(pt, k, std::back_inserter(output)); // check output bool are_sizes_ok = (expected_output.size() == output.size()); @@ -504,19 +504,21 @@ void test_nearest_k(Rtree const& rtree, std::vector const& input, Point c } } } + + test_exactly_the_same_outputs(rtree, output, rtree | bgi::adaptors::nearest_queried(pt, k)); } // rtree nearest not found template -void test_nearest_not_found(Rtree const& rtree, Point const& pt, CoordinateType max_distance_1, CoordinateType max_distance_k) +void test_nearest_query_not_found(Rtree const& rtree, Point const& pt, CoordinateType max_distance_1, CoordinateType max_distance_k) { typename Rtree::value_type output; - size_t n_res = rtree.nearest(bgi::max_bounded(pt, max_distance_1), output); + size_t n_res = rtree.nearest_query(bgi::max_bounded(pt, max_distance_1), output); BOOST_CHECK(0 == n_res); std::vector output_v; - n_res = rtree.nearest(bgi::max_bounded(pt, max_distance_k), 5, std::back_inserter(output_v)); + n_res = rtree.nearest_query(bgi::max_bounded(pt, max_distance_k), 5, std::back_inserter(output_v)); BOOST_CHECK(output_v.size() == n_res); BOOST_CHECK(n_res < 5); } @@ -531,7 +533,7 @@ void test_copy_assignment_move(bgi::rtree const& tree, Box const& q BOOST_CHECK(s); std::vector expected_output; - tree.query(qbox, std::back_inserter(expected_output)); + tree.spatial_query(qbox, std::back_inserter(expected_output)); // copy constructor bgi::rtree t1(tree); @@ -539,7 +541,7 @@ void test_copy_assignment_move(bgi::rtree const& tree, Box const& q BOOST_CHECK(tree.size() == t1.size()); std::vector output; - t1.query(qbox, std::back_inserter(output)); + t1.spatial_query(qbox, std::back_inserter(output)); test_exactly_the_same_outputs(t1, output, expected_output); // copying assignment operator @@ -548,7 +550,7 @@ void test_copy_assignment_move(bgi::rtree const& tree, Box const& q BOOST_CHECK(tree.size() == t1.size()); output.clear(); - t1.query(qbox, std::back_inserter(output)); + t1.spatial_query(qbox, std::back_inserter(output)); test_exactly_the_same_outputs(t1, output, expected_output); // moving constructor @@ -558,7 +560,7 @@ void test_copy_assignment_move(bgi::rtree const& tree, Box const& q BOOST_CHECK(t1.size() == 0); output.clear(); - t2.query(qbox, std::back_inserter(output)); + t2.spatial_query(qbox, std::back_inserter(output)); test_exactly_the_same_outputs(t2, output, expected_output); // moving assignment operator @@ -568,7 +570,7 @@ void test_copy_assignment_move(bgi::rtree const& tree, Box const& q BOOST_CHECK(t2.size() == 0); output.clear(); - t1.query(qbox, std::back_inserter(output)); + t1.spatial_query(qbox, std::back_inserter(output)); test_exactly_the_same_outputs(t1, output, expected_output); } @@ -580,7 +582,7 @@ void test_remove(bgi::rtree & tree, Box const& qbox) size_t prev_size = tree.size(); std::vector output; - tree.query(qbox, std::back_inserter(output)); + tree.spatial_query(qbox, std::back_inserter(output)); BOOST_CHECK(0 < output.size()); @@ -589,7 +591,7 @@ void test_remove(bgi::rtree & tree, Box const& qbox) BOOST_CHECK(tree.size() == prev_size - output.size()); output.clear(); - tree.query(qbox, std::back_inserter(output)); + tree.spatial_query(qbox, std::back_inserter(output)); BOOST_CHECK(0 == output.size()); } @@ -619,9 +621,9 @@ void test_rtree_by_value(Parameters const& parameters) P pt; bg::centroid(qbox, pt); - test_nearest(tree, input, pt); - test_nearest_k(tree, input, pt, 10); - test_nearest_not_found(tree, generate_outside_point

::apply(), 1, 3); + test_nearest_query(tree, input, pt); + test_nearest_query_k(tree, input, pt, 10); + test_nearest_query_not_found(tree, generate_outside_point

::apply(), 1, 3); test_copy_assignment_move(tree, qbox);