我在带有Boost Library的R-Tree中插入了一些2d点。问题是我不知道如何从顶级节点到叶子进行深度优先搜索(DFS)。我想要实现的是使用分支和界限为天际(BBS)算法计算点的天际线。什么是包含,重叠和封面等功能似乎不起作用,甚至不编译。只有"相交"功能有效。以下是代码:
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/index/rtree.hpp>
// to store queries results
#include <vector>
// just for output
#include <iostream>
#include <boost/foreach.hpp>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
int main() {
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef std::pair<point, unsigned> value;
// create the rtree using default constructor
bgi::rtree< value, bgi::quadratic<16> > rtree;
// create some values
rtree.insert(std::make_pair(point(1, 12), 1));
rtree.insert(std::make_pair(point(2, 7), 2));
rtree.insert(std::make_pair(point(4, 22), 3));
rtree.insert(std::make_pair(point(5, 14), 4));
rtree.insert(std::make_pair(point(6, 5), 5));
rtree.insert(std::make_pair(point(8, 19), 6));
rtree.insert(std::make_pair(point(9, 9), 7));
rtree.insert(std::make_pair(point(10, 4), 8));
rtree.insert(std::make_pair(point(12, 13), 9));
rtree.insert(std::make_pair(point(15, 22), 10));
rtree.insert(std::make_pair(point(16, 6), 11));
rtree.insert(std::make_pair(point(17, 10), 12));
rtree.insert(std::make_pair(point(17, 20), 13));
rtree.insert(std::make_pair(point(21, 3), 14));
rtree.insert(std::make_pair(point(22, 14), 15));
// find values intersecting some area defined by a box
box query_box(point(5, 4), point(17, 12));
std::vector<value> result_s;
bgi::query(rtree, bgi::intersects(query_box), std::back_inserter(result_s));
// display results
std::cout << "spatial query box:" << std::endl;
std::cout << bg::wkt<box>(query_box) << std::endl;
std::cout << "spatial query result:" << std::endl;
BOOST_FOREACH(value const& v, result_s)
std::cout << bg::wkt<point>(v.first) << " - " << v.second << std::endl;
getchar();
}
代码似乎有用,但是我怎么能做DFS,或者如果不能这样做以另一种方式计算Skyline?