有没有人知道在生产代码R-tree实现中使用的好和简单?(实际上,任何实现 - R*, R+或者PR-tree会很棒)
它是一个模板或库实现无关紧要,但谷歌发现的一些实现看起来非常令人失望......
Ada*_*icz 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;
}
Run Code Online (Sandbox Code Playgroud)
Lio*_*gan 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/
我更新了http://www.superliminal.com/sources/sources.htm中的实现,以支持更广泛的数据类型.
你可以在github上找到我的版本:https://github.com/nushoin/RTree
原始版本是公共领域,我的也是.
| 归档时间: |
|
| 查看次数: |
23996 次 |
| 最近记录: |