]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/index/example/serialize.cpp
1 // Boost.Geometry Index
4 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
13 #define BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
15 #include <boost/geometry.hpp>
16 #include <boost/geometry/index/rtree.hpp>
17 #include <boost/geometry/index/detail/rtree/utilities/statistics.hpp>
19 #include <boost/archive/binary_oarchive.hpp>
20 #include <boost/archive/binary_iarchive.hpp>
21 #include <boost/archive/xml_oarchive.hpp>
22 #include <boost/archive/xml_iarchive.hpp>
23 #include <boost/serialization/vector.hpp>
25 #include <boost/foreach.hpp>
26 #include <boost/timer.hpp>
28 template <typename T
, size_t I
= 0, size_t S
= boost::tuples::length
<T
>::value
>
31 template <typename Os
>
32 static inline Os
& apply(Os
& os
, T
const& t
)
34 os
<< boost::get
<I
>(t
) << ", ";
35 return print_tuple
<T
, I
+1>::apply(os
, t
);
39 template <typename T
, size_t S
>
40 struct print_tuple
<T
, S
, S
>
42 template <typename Os
>
43 static inline Os
& apply(Os
& os
, T
const&)
51 namespace bg
= boost::geometry
;
52 namespace bgi
= bg::index
;
54 typedef boost::tuple
<std::size_t, std::size_t, std::size_t, std::size_t, std::size_t, std::size_t> S
;
56 typedef bg::model::point
<double, 2, bg::cs::cartesian
> P
;
57 typedef bg::model::box
<P
> B
;
59 //typedef bgi::rtree<V, bgi::linear<16> > RT;
60 //typedef bgi::rtree<V, bgi::quadratic<8, 3> > RT;
61 //typedef bgi::rtree<V, bgi::rstar<8, 3> > RT;
62 typedef bgi::rtree
<V
, bgi::dynamic_linear
> RT
;
65 RT
tree(bgi::dynamic_linear(16));
72 for ( double x
= 0 ; x
< 1000 ; x
+= 1 )
73 for ( double y
= 0 ; y
< 1000 ; y
+= 1 )
74 vect
.push_back(B(P(x
, y
), P(x
+0.5, y
+0.5)));
75 RT
tmp(vect
, tree
.parameters());
76 tree
= boost::move(tmp
);
78 B
q(P(5, 5), P(6, 6));
81 std::cout
<< "vector and tree created in: " << t
.elapsed() << std::endl
;
83 print_tuple
<S
>::apply(std::cout
, bgi::detail::rtree::utilities::statistics(tree
)) << std::endl
;
84 std::cout
<< boost::get
<0>(s
) << std::endl
;
85 BOOST_FOREACH(V
const& v
, tree
| bgi::adaptors::queried(bgi::intersects(q
)))
86 std::cout
<< bg::wkt
<V
>(v
) << std::endl
;
90 std::ofstream
ofs("serialized_vector.bin", std::ios::binary
| std::ios::trunc
);
91 boost::archive::binary_oarchive
oa(ofs
);
94 std::cout
<< "vector saved to bin in: " << t
.elapsed() << std::endl
;
97 std::ofstream
ofs("serialized_tree.bin", std::ios::binary
| std::ios::trunc
);
98 boost::archive::binary_oarchive
oa(ofs
);
101 std::cout
<< "tree saved to bin in: " << t
.elapsed() << std::endl
;
104 std::ofstream
ofs("serialized_tree.xml", std::ios::trunc
);
105 boost::archive::xml_oarchive
oa(ofs
);
107 oa
<< boost::serialization::make_nvp("rtree", tree
);
108 std::cout
<< "tree saved to xml in: " << t
.elapsed() << std::endl
;
113 std::cout
<< "vector cleared in: " << t
.elapsed() << std::endl
;
117 std::cout
<< "tree cleared in: " << t
.elapsed() << std::endl
;
122 std::ifstream
ifs("serialized_vector.bin", std::ios::binary
);
123 boost::archive::binary_iarchive
ia(ifs
);
126 std::cout
<< "vector loaded from bin in: " << t
.elapsed() << std::endl
;
128 RT
tmp(vect
, tree
.parameters());
129 tree
= boost::move(tmp
);
130 std::cout
<< "tree rebuilt from vector in: " << t
.elapsed() << std::endl
;
135 std::cout
<< "tree cleared in: " << t
.elapsed() << std::endl
;
138 std::ifstream
ifs("serialized_tree.bin", std::ios::binary
);
139 boost::archive::binary_iarchive
ia(ifs
);
142 std::cout
<< "tree loaded from bin in: " << t
.elapsed() << std::endl
;
145 std::cout
<< "loaded from bin" << std::endl
;
146 print_tuple
<S
>::apply(std::cout
, bgi::detail::rtree::utilities::statistics(tree
)) << std::endl
;
147 BOOST_FOREACH(V
const& v
, tree
| bgi::adaptors::queried(bgi::intersects(q
)))
148 std::cout
<< bg::wkt
<V
>(v
) << std::endl
;
152 std::cout
<< "tree cleared in: " << t
.elapsed() << std::endl
;
155 std::ifstream
ifs("serialized_tree.xml");
156 boost::archive::xml_iarchive
ia(ifs
);
158 ia
>> boost::serialization::make_nvp("rtree", tree
);
159 std::cout
<< "tree loaded from xml in: " << t
.elapsed() << std::endl
;
162 std::cout
<< "loaded from xml" << std::endl
;
163 print_tuple
<S
>::apply(std::cout
, bgi::detail::rtree::utilities::statistics(tree
)) << std::endl
;
164 BOOST_FOREACH(V
const& v
, tree
| bgi::adaptors::queried(bgi::intersects(q
)))
165 std::cout
<< bg::wkt
<V
>(v
) << std::endl
;