在提升包装算法RTREE [英] packing algorithm in rtree in boost

查看:237
本文介绍了在提升包装算法RTREE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我明白,如果RTREE在提升,有范围的值创建它会使用打包算法。我需要使用打包算法的rtree的一个例子。这是我的一个使用二次算法code

Hi all I understand that if rtree is created with range values in boost it would use packing algorithm. I need an example of rtree using packing algorithm. Here is my code that uses quadratic algorithm

    using  point = bg::model::point < int, 2, bg::cs::cartesian >;
    using  pointI = std::pair<point, std::size_t>;
 vector<point> contourCenters // has some value
bgi::rtree< pointI, bgi::quadratic<16> > rtree;
vector< pointI > cloud;

for (size_t i = 0; i < contourCenters.size(); ++i)
{
    int x = contourCenters[i].get < 0 >();
    int y = contourCenters[i].get < 1 >();

    cout << "Contour Centers: (" << x << "," << y << ")";
    cloud.push_back(mp(x, y, i));
    rtree.insert(make_pair(contourCenters[i], i));
}

我想创建RTREE与包装算法,因为它似乎是最快的国家之一,在升压。请指导我如何创建一个RTREE在提升包装算法。

I would like to create rtree with packing algorithm as it seems to be the fastest one in boost. Kindly guide me how to create a rtree with packing algorithm in boost.

推荐答案

你只需要使用<一个href="http://www.boost.org/doc/libs/1_58_0/libs/geometry/doc/html/geometry/reference/spatial_indexes/boost__geometry__index__rtree/rtree_range_const___.html#classboost_1_1geometry_1_1index_1_1rtree_1a7b96b715c52ddc13d7a81db344825848"相对=nofollow>范围内构造。

有关的工作,一定范围内已构建RTREE之前创建的。最简单的方式来实现,在你的例子是,首先要建立自己的载体,然后从它建立索引:

For that to work, the range must have been created before constructing the rtree. The simplest way to achieve that in your example would be to build your cloud vector first, and then construct the index from it:

<大骨节病> 住在Coliru

#include <boost/geometry/index/rtree.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <vector>
#include <iostream>

namespace bg = boost::geometry;
namespace bgi = bg::index;
using  point  = bg::model::point <int, 2, bg::cs::cartesian>;
using  pointI = std::pair<point, std::size_t>;

pointI mp(int x, int y, size_t v) {
    return std::make_pair(point(x,y), v);
}

int main()
{
    std::vector<point> contourCenters; // has some value
    std::vector<pointI> cloud;

    size_t id_gen = 0;
    std::transform(
            contourCenters.begin(), contourCenters.end(),
            back_inserter(cloud), 
            [&](point const& p) { return std::make_pair(p, id_gen++); }
        );

    for(pointI& pi : cloud)
        std::cout << "Contour Centers: (" << bg::get<0>(pi.first) << "," << bg::get<1>(pi.first) << ")";

    bgi::rtree<pointI, bgi::quadratic<16> > rtree(cloud);
}

我换成的std ::变换的好作风循环,但你可以保持环,你有它。

I replaced the loop with std::transform for good style, but you could keep the loop as you had it.

这篇关于在提升包装算法RTREE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆