有没有人知道在生产代码R-tree
实施中使用的好和简单? (实际上,任何实现 - R*, R+
或PR-tree
都会很棒)
如果它是模板或库实现无关紧要,但谷歌发现的一些实现看起来非常令人失望......
答案 0 :(得分:24)
您还可以查看Boost.Geometry库提供的rtree变体:
http://www.boost.org/doc/libs/release/libs/geometry/doc/html/geometry/spatial_indexes.html
Boost.Geometry rtree实现允许在空间索引中存储任意类型的值并执行复杂查询。像最大节点元素这样的参数可以作为编译或运行时参数传递。由于Boost.Move,它支持在C ++ 11之前的编译器上模拟的C ++ 11移动语义。它还支持有状态分配器,它允许例如使用Boost.Interprocess将rtree存储在共享内存中。它很快。
在缺点方面,目前尚不支持当前持久性存储,因此如果您需要的不仅仅是内存空间索引,您应该检查其中一个提到的库。
简单示例:
最常见的用例可能是将一些几何对象存储在容器中,并且它们的边界框中包含空间索引中的一些ID。在Boost.Geometry rtree的情况下,这可能如下所示:
#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <vector>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
/* The definition of my_object type goes here */
int main()
{
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef std::pair<box, size_t> value;
std::vector<my_object> objects;
/* Fill objects */
// create the R* variant of the rtree
bgi::rtree< value, bgi::rstar<16> > rtree;
// insert some values to the rtree
for ( size_t i = 0 ; i < objects.size() ; ++i )
{
// create a box
box b = objects[i].calculate_bounding_box();
// insert new value
rtree.insert(std::make_pair(b, i));
}
// find values intersecting some area defined by a box
box query_box(point(0, 0), point(5, 5));
std::vector<value> result_s;
rtree.query(bgi::intersects(query_box), std::back_inserter(result_s));
// find 5 nearest values to a point
std::vector<value> result_n;
rtree.query(bgi::nearest(point(0, 0), 5), std::back_inserter(result_n));
return 0;
}
答案 1 :(得分:16)
检查http://www.superliminal.com/sources/sources.htm
上的R-Trees代码同时检查
http://www.virtualroadside.com/blog/index.php/2008/10/04/r-tree-implementation-for-cpp/
答案 2 :(得分:8)
我更新了http://www.superliminal.com/sources/sources.htm中的实现,以支持更广泛的数据类型。
您可以在github上找到我的版本:https://github.com/nushoin/RTree
原始版本是公共领域,我的也是。
答案 3 :(得分:4)
spatialindex为不同类型的空间(和时空)索引结构提供了一个很好的接口,包括http://libspatialindex.github.com/处的R,R *,TPR树