Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <boost/geometry.hpp>
- #include <boost/geometry/geometries/point.hpp>
- #include <boost/geometry/geometries/box.hpp>
- #include <boost/geometry/index/rtree.hpp>
- typedef boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> point;
- typedef boost::geometry::model::box<point> box;
- typedef std::pair<box, uint64_t> value;
- bgi::rtree< value, bgi::linear<16> > m_rt_linear;
- bgi::rtree< value, bgi::quadratic<16> > m_rt_quad;
- bgi::rtree< value, bgi::rstar<16> > m_rt_rstar;
- c_random<double> rand(-10000,10000);
- c_stopwatch sw;
- uint64_t count = 100000;
- uint64_t querycount = 100000;
- double sz = 2;
- uint64_t obj = 0;
- c_console::out("----------------------------------");
- c_console::out("--------------------");
- sw.start("start box linear<16>");
- for(uint64_t i=0;i<count;i++)
- {
- double x = rand.rand();
- double y = rand.rand();
- box b(point(x-sz, y-sz), point(x+sz,y+sz));
- m_rt_linear.insert(std::make_pair(b, i));
- }
- sw.ms("insert %d msec");
- for(uint64_t i=0;i<querycount;i++)
- {
- double x = rand.rand();
- double y = rand.rand();
- std::vector<value> result_n;
- box query_box(point(x-sz, y-sz), point(x+sz,y+sz));
- m_rt_linear.query(boost::geometry::index::intersects(query_box), std::back_inserter(result_n));
- }
- sw.ms("query %d msec");
- c_console::out("--------------------");
- sw.start("start box quad<16>");
- for(uint64_t i=0;i<count;i++)
- {
- double x = rand.rand();
- double y = rand.rand();
- box b(point(x-sz, y-sz), point(x+sz,y+sz));
- m_rt_quad.insert(std::make_pair(b, i));
- }
- sw.ms("insert %d msec");
- for(uint64_t i=0;i<querycount;i++)
- {
- double x = rand.rand();
- double y = rand.rand();
- std::vector<value> result_n;
- box query_box(point(x-sz, y-sz), point(x+sz,y+sz));
- m_rt_quad.query(boost::geometry::index::intersects(query_box), std::back_inserter(result_n));
- }
- sw.ms("query %d msec");
- c_console::out("--------------------");
- sw.start("start box rstar<16>");
- for(uint64_t i=0;i<count;i++)
- {
- double x = rand.rand();
- double y = rand.rand();
- box b(point(x-sz, y-sz), point(x+sz,y+sz));
- m_rt_rstar.insert(std::make_pair(b, i));
- }
- sw.ms("insert %d msec");
- for(uint64_t i=0;i<querycount;i++)
- {
- double x = rand.rand();
- double y = rand.rand();
- std::vector<value> result_n;
- box query_box(point(x-sz, y-sz), point(x+sz,y+sz));
- m_rt_rstar.query(boost::geometry::index::intersects(query_box), std::back_inserter(result_n));
- }
- sw.ms("query %d msec");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement