Hi again,

Li, Richie [Student] wrote:
Thanks for that. But I'm still a bit confused. Could you give me an example code of getting all the MBRs from level2 to the leaf nodes?

I decided to write a simplified version of the visitor. It only prints boxes/values and traverses the R-tree depth-first. Here is complete program:

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <iostream>

namespace bg = boost::geometry;
namespace bgi = bg::index;
namespace bgid = bgi::detail;

template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
class test_visitor
    : public bgid::rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
{
    typedef typename bgid::rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
    typedef typename bgid::rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;

public:
    void operator()(internal_node const& n)
    {
        typedef typename bgid::rtree::elements_type<internal_node>::type elements_type;
        elements_type const& elements = bgid::rtree::elements(n);

        for ( typename elements_type::const_iterator it = elements.begin();
              it != elements.end() ; ++it)
        {
            handle_box_or_value(it->first);

            bgid::rtree::apply_visitor(*this, *(it->second));
        }
    }

    void operator()(leaf const& n)
    {
        typedef typename bgid::rtree::elements_type<leaf>::type elements_type;
        elements_type const& elements = bgid::rtree::elements(n);

        for ( typename elements_type::const_iterator it = elements.begin();
              it != elements.end() ; ++it)
        {
            handle_box_or_value(*it);
        }
    }

    template <typename BoxOrValue>
    void handle_box_or_value(BoxOrValue const& b)
    {
        std::cout << bg::dsv(b) << std::endl;
    }
};

template <typename Rtree>
inline void test(Rtree const& tree)
{
    typedef bgid::rtree::utilities::view<Rtree> RTV;
    RTV rtv(tree);

    test_visitor<
        typename RTV::value_type,
        typename RTV::options_type,
        typename RTV::translator_type,
        typename RTV::box_type,
        typename RTV::allocators_type
    > v;
   
    rtv.apply_visitor(v);
}

int main()
{
    typedef bg::model::point<float, 2, bg::cs::cartesian> point;
    typedef bg::model::box<point> box;
    typedef bgi::rtree<box, bgi::rstar<4> > rtree;

    rtree rt;
    rt.insert(box(point(0, 0), point(1, 1)));
    rt.insert(box(point(1, 1), point(2, 2)));
    rt.insert(box(point(2, 2), point(3, 3)));
    rt.insert(box(point(3, 3), point(4, 4)));
    rt.insert(box(point(4, 4), point(5, 5)));
    rt.insert(box(point(5, 5), point(6, 6)));

    test(rt);
}

Regards,
Adam