Boost logo

Geometry :

Subject: Re: [geometry] Querying index using intersection with custom geometry
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2014-03-31 09:32:53


Hi,

Michael Nett wrote:
> Hi again,
>
> sorry for the confusion. I tried your example at work (with Boost
> 1.48) and now at home (using 1.54) and both produce the same errors.
>

I tested it using VS. To compile under GCC the overloaded
bg::intersects() must be defined before the rtree is included. Otherwise
the compiler tries to use the original version. Let me know if this works:

#include <boost/geometry.hpp>

struct MyFrustum
{
     MyFrustum(int d) : dummy(d) {}
     int dummy;
};

namespace boost { namespace geometry {

// This will be called for Nodes and Values!
template <typename Box> inline
bool intersects(Box const& b, MyFrustum const& f)
{
     std::cout << "checking the intersection with " << f.dummy << std::endl;
     return true;
}

}}

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

int main()
{
     namespace bg = boost::geometry;
     namespace bgi = bg::index;
     namespace bgm = bg::model;
     typedef bgm::point<float, 2, bg::cs::cartesian> pt;
     typedef bgm::box<pt> box;

     // check your implementation
     bool ok = bg::intersects(box(pt(0, 0), pt(1, 1)), MyFrustum(5));

     std::cout << "-------------------" << std::endl;

     // now use the rtree
     bgi::rtree<box, bgi::rstar<8> > rt;
     // insert some values
     rt.insert(box(pt(0, 0), pt(1, 1)));
     rt.insert(box(pt(2, 2), pt(3, 3)));

     // performa a query
     std::vector<box> vec;
     rt.query(bgi::intersects(MyFrustum(10)), std::back_inserter(vec));

     std::cout << vec.size() << std::endl;
}

Regards,
Adam


Geometry list run by mateusz at loskot.net