#include<boost/geometry.hpp>#include<boost/geometry/geometries/point.hpp>#include<boost/geometry/geometries/box.hpp>#include<boost/geometry/index/rtree.hpp>// Boost.Range#include<boost/range.hpp>// adaptors#include<boost/range/adaptor/indexed.hpp>#include<boost/range/adaptor/transformed.hpp>// a container#include<vector>// just for output#include<iostream>namespacebg=boost::geometry;namespacebgi=boost::geometry::index;// Define a function object converting a value_type of indexed Range into std::pair<>.// This is a generic implementation but of course it'd be possible to use some// specific types. One could also take Value as template parameter and access// first_type and second_type members, etc.template<typenameFirst,typenameSecond>structpair_maker{typedefstd::pair<First,Second>result_type;template<typenameT>inlineresult_typeoperator()(Tconst&v)const{returnresult_type(v.value(),v.index());}};intmain(){typedefbg::model::point<float,2,bg::cs::cartesian>point;typedefbg::model::box<point>box;typedefstd::vector<box>container;typedefcontainer::size_typesize_type;typedefstd::pair<box,size_type>value;// create a container of boxescontainerboxes;for(size_typei=0;i<10;++i){// add a box into the containerboxb(point(i+0.0f,i+0.0f),point(i+0.5f,i+0.5f));boxes.push_back(b);}// create the rtree passing a Rangebgi::rtree<value,bgi::quadratic<16>>rtree(boxes|boost::adaptors::indexed()|boost::adaptors::transformed(pair_maker<box,size_type>()));// print the number of values using boxes[0] as indexablestd::cout<<rtree.count(boxes[0])<<std::endl;return0;}
Статья Range adaptors раздела Chapter 1. Geometry Examples может быть полезна для разработчиков на c++ и boost.
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.