packing algorithm in rtree in boost

后端 未结 1 1311
感情败类
感情败类 2020-12-18 22:38

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

1条回答
  •  执笔经年
    2020-12-18 23:20

    You'd just need to use the range constructor.

    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:

    Live On Coliru

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    namespace bg = boost::geometry;
    namespace bgi = bg::index;
    using  point  = bg::model::point ;
    using  pointI = std::pair;
    
    pointI mp(int x, int y, size_t v) {
        return std::make_pair(point(x,y), v);
    }
    
    int main()
    {
        std::vector contourCenters; // has some value
        std::vector 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 > rtree(cloud);
    }
    

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

    0 讨论(0)
提交回复
热议问题