mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-09 23:24:02 +00:00
[doc][index] Docs upgrade (mostly related to Range adaptors).
Add a tip about usage of Boost.Range adaptors with the rtree. Add an example of usage of Boost.Range adaptors. Replace invalid main(void) with main() in examples. Fix MSVC type conversion warnings in examples.
This commit is contained in:
parent
38a5bffb05
commit
7b1e4bd601
@ -14,6 +14,7 @@
|
||||
[import src/examples/rtree/variants_map.cpp]
|
||||
[import src/examples/rtree/value_shared_ptr.cpp]
|
||||
[import src/examples/rtree/value_index.cpp]
|
||||
[import src/examples/rtree/range_adaptors.cpp]
|
||||
[import src/examples/rtree/iterative_query.cpp]
|
||||
[import src/examples/rtree/interprocess.cpp]
|
||||
[import src/examples/rtree/mapped_file.cpp]
|
||||
|
@ -164,7 +164,7 @@ stored in another container.
|
||||
[h4 Additional interface]
|
||||
|
||||
The __rtree__ allows creation, inserting and removing of Values from a range. The range may be passed as
|
||||
[first, last) Iterators pair or as a Range.
|
||||
`[first, last)` Iterators pair or as a Range adapted to one of the Boost.Range Concepts.
|
||||
|
||||
namespace bgi = boost::geometry::index;
|
||||
typedef std::pair<Box, int> __value__;
|
||||
@ -184,13 +184,13 @@ The __rtree__ allows creation, inserting and removing of Values from a range. Th
|
||||
|
||||
// create R-tree with default constructor and insert values with insert(Range)
|
||||
RTree rt3;
|
||||
rt3.insert(values);
|
||||
rt3.insert(values_range);
|
||||
|
||||
// create R-tree with constructor taking Iterators
|
||||
RTree rt4(values.begin(), values.end());
|
||||
|
||||
// create R-tree with constructor taking Range
|
||||
RTree rt5(values);
|
||||
RTree rt5(values_range);
|
||||
|
||||
// remove values with remove(Value const&)
|
||||
BOOST_FOREACH(__value__ const& v, values)
|
||||
@ -200,7 +200,13 @@ The __rtree__ allows creation, inserting and removing of Values from a range. Th
|
||||
rt2.remove(values.begin(), values.end());
|
||||
|
||||
// remove values with remove(Range)
|
||||
rt3.remove(values);
|
||||
rt3.remove(values_range);
|
||||
|
||||
Furthermore, it's possible to pass a Range adapted by one of the Boost.Range adaptors into the rtree (more complete example can be found in the *Examples* section).
|
||||
|
||||
// create Rtree containing `std::pair<Box, int>` from a container of Boxes on the fly.
|
||||
RTree rt6(boxes | boost::adaptors::indexed()
|
||||
| boost::adaptors::transformed(pair_maker()));
|
||||
|
||||
[h4 Insert iterator]
|
||||
|
||||
|
@ -46,10 +46,16 @@
|
||||
[include ../src/examples/rtree/value_index_results.qbk]
|
||||
[endsect]
|
||||
|
||||
[section Range adaptors]
|
||||
[rtree_range_adaptors]
|
||||
[h4 Expected results]
|
||||
[include ../src/examples/rtree/range_adaptors_results.qbk]
|
||||
[endsect]
|
||||
|
||||
[section Iterative query]
|
||||
[rtree_iterative_query]
|
||||
[h4 Expected results]
|
||||
[include ../src/examples/rtree/iterative_query.qbk]
|
||||
[include ../src/examples/rtree/iterative_query_results.qbk]
|
||||
[endsect]
|
||||
|
||||
[section Index stored in shared memory using Boost.Interprocess]
|
||||
|
@ -10,6 +10,7 @@ exe iterative_query : iterative_query.cpp ;
|
||||
exe polygons_shared_ptr : polygons_shared_ptr.cpp ;
|
||||
exe polygons_vector : polygons_vector.cpp ;
|
||||
exe quick_start : quick_start.cpp ;
|
||||
exe range_adaptors : range_adaptors.cpp ;
|
||||
exe value_index : value_index.cpp ;
|
||||
exe value_shared_ptr : value_shared_ptr.cpp ;
|
||||
exe variants_map : variants_map.cpp ;
|
||||
|
@ -22,7 +22,7 @@
|
||||
namespace bg = boost::geometry;
|
||||
namespace bgi = boost::geometry::index;
|
||||
|
||||
int main(void)
|
||||
int main()
|
||||
{
|
||||
typedef bg::model::point<double, 2, bg::cs::cartesian> point;
|
||||
typedef point value;
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace bg = boost::geometry;
|
||||
namespace bgi = boost::geometry::index;
|
||||
|
||||
int main(void)
|
||||
int main()
|
||||
{
|
||||
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
|
||||
typedef bg::model::box<point> box;
|
||||
|
@ -25,7 +25,7 @@
|
||||
namespace bg = boost::geometry;
|
||||
namespace bgi = boost::geometry::index;
|
||||
|
||||
int main(void)
|
||||
int main()
|
||||
{
|
||||
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
|
||||
typedef bg::model::box<point> box;
|
||||
|
@ -29,7 +29,7 @@ namespace bg = boost::geometry;
|
||||
namespace bgi = boost::geometry::index;
|
||||
//]
|
||||
|
||||
int main(void)
|
||||
int main()
|
||||
{
|
||||
//[rtree_quickstart_valuetype
|
||||
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
|
||||
@ -47,7 +47,7 @@ int main(void)
|
||||
for ( unsigned i = 0 ; i < 10 ; ++i )
|
||||
{
|
||||
// create a box
|
||||
box b(point(i, i), point(i + 0.5f, i + 0.5f));
|
||||
box b(point(i + 0.0f, i + 0.0f), point(i + 0.5f, i + 0.5f));
|
||||
// insert new value
|
||||
rtree.insert(std::make_pair(b, i));
|
||||
}
|
||||
|
79
doc/index/src/examples/rtree/range_adaptors.cpp
Normal file
79
doc/index/src/examples/rtree/range_adaptors.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
// 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 <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>
|
||||
|
||||
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 <typename First, typename Second>
|
||||
struct pair_maker
|
||||
{
|
||||
typedef std::pair<First, Second> result_type;
|
||||
template<typename T>
|
||||
inline result_type operator()(T const& v) const
|
||||
{
|
||||
return result_type(v.value(), v.index());
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
|
||||
typedef bg::model::box<point> box;
|
||||
|
||||
typedef std::vector<box> container;
|
||||
typedef container::size_type size_type;
|
||||
|
||||
typedef std::pair<box, size_type> 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 using default constructor
|
||||
bgi::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 indexable
|
||||
std::cout << rtree.count(boxes[0]) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//]
|
11
doc/index/src/examples/rtree/range_adaptors_results.qbk
Normal file
11
doc/index/src/examples/rtree/range_adaptors_results.qbk
Normal file
@ -0,0 +1,11 @@
|
||||
[/============================================================================
|
||||
Boost.Geometry Index
|
||||
|
||||
Copyright (c) 2011-2014 Adam Wulkiewicz.
|
||||
|
||||
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)
|
||||
=============================================================================/]
|
||||
|
||||
1
|
@ -37,7 +37,7 @@ public:
|
||||
result_type operator()(size_t i) const { return container[i]; }
|
||||
};
|
||||
|
||||
int main(void)
|
||||
int main()
|
||||
{
|
||||
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
|
||||
typedef bg::model::box<point> box;
|
||||
@ -52,7 +52,7 @@ int main(void)
|
||||
for ( unsigned i = 0 ; i < 10 ; ++i )
|
||||
{
|
||||
// add a box
|
||||
boxes.push_back(box(point(i, i), point(i+0.5f, i+0.5f)));
|
||||
boxes.push_back(box(point(i+0.0f, i+0.0f), point(i+0.5f, i+0.5f)));
|
||||
}
|
||||
|
||||
// display boxes
|
||||
|
@ -38,7 +38,7 @@ struct indexable< boost::shared_ptr<Box> >
|
||||
|
||||
}}} // namespace boost::geometry::index
|
||||
|
||||
int main(void)
|
||||
int main()
|
||||
{
|
||||
typedef bg::model::point<float, 2, bg::cs::cartesian> point;
|
||||
typedef bg::model::box<point> box;
|
||||
@ -54,7 +54,7 @@ int main(void)
|
||||
for ( unsigned i = 0 ; i < 10 ; ++i )
|
||||
{
|
||||
// create a box
|
||||
shp b(new box(point(i, i), point(i+0.5f, i+0.5f)));
|
||||
shp b(new box(point(i+0.0f, i+0.0f), point(i+0.5f, i+0.5f)));
|
||||
|
||||
// display new box
|
||||
std::cout << bg::wkt<box>(*b) << std::endl;
|
||||
|
@ -65,7 +65,7 @@ struct envelope_visitor : public boost::static_visitor<box>
|
||||
};
|
||||
|
||||
|
||||
int main(void)
|
||||
int main()
|
||||
{
|
||||
// geometries container
|
||||
map geometries;
|
||||
|
Loading…
x
Reference in New Issue
Block a user