From 9dbb67ed82adf7335992ef6fd2d84f7ece94302f Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Fri, 13 May 2011 20:23:16 +0000 Subject: [PATCH] intersects changed to within in remove visitor + some comments added [SVN r71927] --- .../extensions/index/algorithms/within.hpp | 131 ++++++++++++++++++ .../index/rtree/rstar/choose_next_node.hpp | 7 +- .../index/rtree/visitors/insert.hpp | 5 + .../index/rtree/visitors/remove.hpp | 6 +- tests/additional_glut_vis.cpp | 9 ++ tests/additional_sizes_and_times.cpp | 9 ++ tests/main.cpp | 9 ++ 7 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 include/boost/geometry/extensions/index/algorithms/within.hpp diff --git a/include/boost/geometry/extensions/index/algorithms/within.hpp b/include/boost/geometry/extensions/index/algorithms/within.hpp new file mode 100644 index 000000000..eec2291c8 --- /dev/null +++ b/include/boost/geometry/extensions/index/algorithms/within.hpp @@ -0,0 +1,131 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Boost.SpatialIndex - n-dimensional within box +// +// Copyright 2011 Adam Wulkiewicz. +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_WITHIN_HPP +#define BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_WITHIN_HPP + +namespace boost { namespace geometry { namespace index { + +namespace dispatch { + +template +struct within_compare +{ + // TODO: awulkiew - static assert? +}; + +template +struct within_compare +{ + template + static inline bool apply(Box const& b1, Indexable const& b2) + { + return index::get(b1) <= index::get(b2); + } +}; + +template +struct within_compare +{ + template + static inline bool apply(Box const& b1, Indexable const& b2) + { + return index::get(b2) <= index::get(b1); + } +}; + +template +struct within_compare +{ + template + static inline bool apply(Box const& b, Indexable const& p) + { + return index::get(b) <= index::get(p); + } +}; + +template +struct within_compare +{ + template + static inline bool apply(Box const& b, Indexable const& p) + { + return index::get(p) <= index::get(b); + } +}; + +} // namespace dispatch + +namespace detail { + +template +struct within_for_each_dimension +{ + BOOST_STATIC_ASSERT(0 < CurrentDimension); + BOOST_STATIC_ASSERT(CurrentDimension <= traits::dimension::value); + BOOST_STATIC_ASSERT(traits::dimension::value == traits::dimension::value); + + static inline bool apply(Box const& b, Indexable const& i) + { + return + within_for_each_dimension< + Box, + Indexable, + CurrentDimension - 1 + >::apply(b, i) && + dispatch::within_compare< + min_corner, + CurrentDimension - 1, + Indexable, + typename traits::tag::type + >::apply(b, i) && + dispatch::within_compare< + max_corner, + CurrentDimension - 1, + Indexable, + typename traits::tag::type + >::apply(b, i); + } +}; + +template +struct within_for_each_dimension +{ + BOOST_STATIC_ASSERT(1 <= traits::dimension::value); + BOOST_STATIC_ASSERT(traits::dimension::value == traits::dimension::value); + + static inline bool apply(Box const& b, Indexable const& i) + { + return + dispatch::within_compare< + min_corner, + 0, + Indexable, + typename traits::tag::type + >::apply(b, i) && + dispatch::within_compare< + max_corner, + 0, + Indexable, + typename traits::tag::type + >::apply(b, i); + } +}; + +} // namespace detail + +template +bool within(Box const& box, Indexable const& i) +{ + return detail::within_for_each_dimension::value>::apply(box, i); +} + +}}} // namespace boost::geometry::index + +#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_WITHIN_HPP diff --git a/include/boost/geometry/extensions/index/rtree/rstar/choose_next_node.hpp b/include/boost/geometry/extensions/index/rtree/rstar/choose_next_node.hpp index a3a1c68ec..9bacd7eb8 100644 --- a/include/boost/geometry/extensions/index/rtree/rstar/choose_next_node.hpp +++ b/include/boost/geometry/extensions/index/rtree/rstar/choose_next_node.hpp @@ -77,7 +77,7 @@ private: child_type const& ch_i = children[i]; Box box_exp(ch_i.first); - // calculate expanded box fo node ch_i + // calculate expanded box of child node ch_i geometry::expand(box_exp, indexable); // calculate area and area diff @@ -126,18 +126,21 @@ private: area_type smallest_area_diff = std::numeric_limits::max(); area_type smallest_area = std::numeric_limits::max(); - // caculate areas and areas of all nodes' boxes + // choose the child which requires smallest box expansion to store the indexable for ( size_t i = 0 ; i < children_count ; ++i ) { typedef typename children_type::value_type child_type; child_type const& ch_i = children[i]; + // expanded child node's box Box box_exp(ch_i.first); geometry::expand(box_exp, indexable); + // areas difference area_type area = index::area(box_exp); area_type area_diff = area - index::area(ch_i.first); + // update the result if ( area_diff < smallest_area_diff || ( area_diff == smallest_area_diff && area < smallest_area ) ) { diff --git a/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp b/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp index a5185cea8..7a5b23da3 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp @@ -52,12 +52,15 @@ struct choose_next_node typedef typename children_type::value_type child_type; child_type const& ch_i = children[i]; + // expanded child node's box Box box_exp(ch_i.first); geometry::expand(box_exp, indexable); + // areas difference area_type area = index::area(box_exp); area_type area_diff = area - index::area(ch_i.first); + // update the result if ( area_diff < smallest_area_diff || ( area_diff == smallest_area_diff && area < smallest_area ) ) { @@ -95,6 +98,7 @@ struct split size_t max_elems, Translator const& tr) { + // create additional node node * second_node = rtree::create_node(Node()); Node & n2 = rtree::get(*second_node); @@ -221,6 +225,7 @@ protected: size_t current_child_index_bckup = m_current_child_index; size_t current_level_bckup = m_current_level; + // calculate new traverse inputs m_parent = &n; m_current_child_index = choosen_node_index; ++m_current_level; diff --git a/include/boost/geometry/extensions/index/rtree/visitors/remove.hpp b/include/boost/geometry/extensions/index/rtree/visitors/remove.hpp index 623132356..fac9efee2 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/remove.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/remove.hpp @@ -14,6 +14,8 @@ #include +#include + namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace visitors { @@ -52,9 +54,7 @@ public: size_t child_node_index = 0; for ( ; child_node_index < children.size() ; ++child_node_index ) { - // TODO: awulkiew - change intersects to within - - if ( geometry::intersects(children[child_node_index].first, m_tr(m_value)) ) + if ( index::within(children[child_node_index].first, m_tr(m_value)) ) { // next traversing step traverse_apply_visitor(n, child_node_index); diff --git a/tests/additional_glut_vis.cpp b/tests/additional_glut_vis.cpp index 8e68e8da2..d9864a7d9 100644 --- a/tests/additional_glut_vis.cpp +++ b/tests/additional_glut_vis.cpp @@ -1,3 +1,12 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Boost.Index - example +// +// Copyright 2011 Adam Wulkiewicz. +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + #include #include diff --git a/tests/additional_sizes_and_times.cpp b/tests/additional_sizes_and_times.cpp index 35a5e14f5..c2c5fb5e6 100644 --- a/tests/additional_sizes_and_times.cpp +++ b/tests/additional_sizes_and_times.cpp @@ -1,3 +1,12 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Boost.Index - example +// +// Copyright 2011 Adam Wulkiewicz. +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + //#define BOOST_GEOMETRY_INDEX_USE_VARIANT_NODES #include diff --git a/tests/main.cpp b/tests/main.cpp index 2af71fd58..d30121b65 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,3 +1,12 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Boost.Index - example +// +// Copyright 2011 Adam Wulkiewicz. +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + #include #include #include