// Boost.Geometry Index // // Quickbook Examples // // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland. // // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //[rtree_range_adaptors #include #include #include #include // Boost.Range #include // adaptors #include #include // a container #include // just for output #include namespace bg = boost::geometry; namespace bgi = 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 struct pair_maker { typedef std::pair result_type; template inline result_type operator()(T const& v) const { return result_type(v.value(), v.index()); } }; int main() { typedef bg::model::point point; typedef bg::model::box box; typedef std::vector container; typedef container::size_type size_type; typedef std::pair value; // create a container of boxes container boxes; for ( size_type i = 0 ; i < 10 ; ++i ) { // add a box into the container box b(point(i + 0.0f, i + 0.0f), point(i + 0.5f, i + 0.5f)); boxes.push_back(b); } // create the rtree passing a Range bgi::rtree< value, bgi::quadratic<16> > rtree(boxes | boost::adaptors::indexed() | boost::adaptors::transformed(pair_maker())); // print the number of values using boxes[0] as indexable std::cout << rtree.count(boxes[0]) << std::endl; return 0; } //]