Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@16
|
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
Chris@16
|
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
Chris@16
|
6
|
Chris@16
|
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
9
|
Chris@16
|
10 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
12 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
13
|
Chris@16
|
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_ENVELOPE_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_ALGORITHMS_ENVELOPE_HPP
|
Chris@16
|
16
|
Chris@101
|
17 #include <vector>
|
Chris@101
|
18
|
Chris@101
|
19 #include <boost/numeric/conversion/cast.hpp>
|
Chris@16
|
20 #include <boost/range.hpp>
|
Chris@16
|
21
|
Chris@101
|
22 #include <boost/variant/apply_visitor.hpp>
|
Chris@101
|
23 #include <boost/variant/static_visitor.hpp>
|
Chris@101
|
24 #include <boost/variant/variant_fwd.hpp>
|
Chris@16
|
25
|
Chris@16
|
26 #include <boost/geometry/algorithms/assign.hpp>
|
Chris@16
|
27 #include <boost/geometry/algorithms/expand.hpp>
|
Chris@16
|
28 #include <boost/geometry/algorithms/not_implemented.hpp>
|
Chris@16
|
29 #include <boost/geometry/core/cs.hpp>
|
Chris@16
|
30 #include <boost/geometry/core/exterior_ring.hpp>
|
Chris@101
|
31 #include <boost/geometry/core/point_type.hpp>
|
Chris@101
|
32 #include <boost/geometry/core/tags.hpp>
|
Chris@101
|
33
|
Chris@16
|
34 #include <boost/geometry/geometries/concepts/check.hpp>
|
Chris@16
|
35
|
Chris@16
|
36
|
Chris@16
|
37 namespace boost { namespace geometry
|
Chris@16
|
38 {
|
Chris@16
|
39
|
Chris@16
|
40 #ifndef DOXYGEN_NO_DETAIL
|
Chris@16
|
41 namespace detail { namespace envelope
|
Chris@16
|
42 {
|
Chris@16
|
43
|
Chris@16
|
44
|
Chris@16
|
45 /// Calculate envelope of an 2D or 3D segment
|
Chris@16
|
46 struct envelope_expand_one
|
Chris@16
|
47 {
|
Chris@16
|
48 template<typename Geometry, typename Box>
|
Chris@16
|
49 static inline void apply(Geometry const& geometry, Box& mbr)
|
Chris@16
|
50 {
|
Chris@16
|
51 assign_inverse(mbr);
|
Chris@16
|
52 geometry::expand(mbr, geometry);
|
Chris@16
|
53 }
|
Chris@16
|
54 };
|
Chris@16
|
55
|
Chris@16
|
56
|
Chris@16
|
57 /// Iterate through range (also used in multi*)
|
Chris@16
|
58 template<typename Range, typename Box>
|
Chris@16
|
59 inline void envelope_range_additional(Range const& range, Box& mbr)
|
Chris@16
|
60 {
|
Chris@16
|
61 typedef typename boost::range_iterator<Range const>::type iterator_type;
|
Chris@16
|
62
|
Chris@16
|
63 for (iterator_type it = boost::begin(range);
|
Chris@16
|
64 it != boost::end(range);
|
Chris@16
|
65 ++it)
|
Chris@16
|
66 {
|
Chris@16
|
67 geometry::expand(mbr, *it);
|
Chris@16
|
68 }
|
Chris@16
|
69 }
|
Chris@16
|
70
|
Chris@16
|
71
|
Chris@16
|
72
|
Chris@16
|
73 /// Generic range dispatching struct
|
Chris@16
|
74 struct envelope_range
|
Chris@16
|
75 {
|
Chris@16
|
76 /// Calculate envelope of range using a strategy
|
Chris@16
|
77 template <typename Range, typename Box>
|
Chris@16
|
78 static inline void apply(Range const& range, Box& mbr)
|
Chris@16
|
79 {
|
Chris@16
|
80 assign_inverse(mbr);
|
Chris@16
|
81 envelope_range_additional(range, mbr);
|
Chris@16
|
82 }
|
Chris@16
|
83 };
|
Chris@16
|
84
|
Chris@101
|
85
|
Chris@101
|
86 struct envelope_multi_linestring
|
Chris@101
|
87 {
|
Chris@101
|
88 template<typename MultiLinestring, typename Box>
|
Chris@101
|
89 static inline void apply(MultiLinestring const& mp, Box& mbr)
|
Chris@101
|
90 {
|
Chris@101
|
91 assign_inverse(mbr);
|
Chris@101
|
92 for (typename boost::range_iterator<MultiLinestring const>::type
|
Chris@101
|
93 it = mp.begin();
|
Chris@101
|
94 it != mp.end();
|
Chris@101
|
95 ++it)
|
Chris@101
|
96 {
|
Chris@101
|
97 envelope_range_additional(*it, mbr);
|
Chris@101
|
98 }
|
Chris@101
|
99 }
|
Chris@101
|
100 };
|
Chris@101
|
101
|
Chris@101
|
102
|
Chris@101
|
103 // version for multi_polygon: outer ring's of all polygons
|
Chris@101
|
104 struct envelope_multi_polygon
|
Chris@101
|
105 {
|
Chris@101
|
106 template<typename MultiPolygon, typename Box>
|
Chris@101
|
107 static inline void apply(MultiPolygon const& mp, Box& mbr)
|
Chris@101
|
108 {
|
Chris@101
|
109 assign_inverse(mbr);
|
Chris@101
|
110 for (typename boost::range_const_iterator<MultiPolygon>::type
|
Chris@101
|
111 it = mp.begin();
|
Chris@101
|
112 it != mp.end();
|
Chris@101
|
113 ++it)
|
Chris@101
|
114 {
|
Chris@101
|
115 envelope_range_additional(exterior_ring(*it), mbr);
|
Chris@101
|
116 }
|
Chris@101
|
117 }
|
Chris@101
|
118 };
|
Chris@101
|
119
|
Chris@101
|
120
|
Chris@16
|
121 }} // namespace detail::envelope
|
Chris@16
|
122 #endif // DOXYGEN_NO_DETAIL
|
Chris@16
|
123
|
Chris@16
|
124 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@16
|
125 namespace dispatch
|
Chris@16
|
126 {
|
Chris@16
|
127
|
Chris@16
|
128
|
Chris@16
|
129 template
|
Chris@16
|
130 <
|
Chris@16
|
131 typename Geometry,
|
Chris@16
|
132 typename Tag = typename tag<Geometry>::type
|
Chris@16
|
133 >
|
Chris@16
|
134 struct envelope: not_implemented<Tag>
|
Chris@16
|
135 {};
|
Chris@16
|
136
|
Chris@16
|
137
|
Chris@16
|
138 template <typename Point>
|
Chris@16
|
139 struct envelope<Point, point_tag>
|
Chris@16
|
140 : detail::envelope::envelope_expand_one
|
Chris@16
|
141 {};
|
Chris@16
|
142
|
Chris@16
|
143
|
Chris@16
|
144 template <typename Box>
|
Chris@16
|
145 struct envelope<Box, box_tag>
|
Chris@16
|
146 : detail::envelope::envelope_expand_one
|
Chris@16
|
147 {};
|
Chris@16
|
148
|
Chris@16
|
149
|
Chris@16
|
150 template <typename Segment>
|
Chris@16
|
151 struct envelope<Segment, segment_tag>
|
Chris@16
|
152 : detail::envelope::envelope_expand_one
|
Chris@16
|
153 {};
|
Chris@16
|
154
|
Chris@16
|
155
|
Chris@16
|
156 template <typename Linestring>
|
Chris@16
|
157 struct envelope<Linestring, linestring_tag>
|
Chris@16
|
158 : detail::envelope::envelope_range
|
Chris@16
|
159 {};
|
Chris@16
|
160
|
Chris@16
|
161
|
Chris@16
|
162 template <typename Ring>
|
Chris@16
|
163 struct envelope<Ring, ring_tag>
|
Chris@16
|
164 : detail::envelope::envelope_range
|
Chris@16
|
165 {};
|
Chris@16
|
166
|
Chris@16
|
167
|
Chris@16
|
168 template <typename Polygon>
|
Chris@16
|
169 struct envelope<Polygon, polygon_tag>
|
Chris@16
|
170 : detail::envelope::envelope_range
|
Chris@16
|
171 {
|
Chris@16
|
172 template <typename Box>
|
Chris@16
|
173 static inline void apply(Polygon const& poly, Box& mbr)
|
Chris@16
|
174 {
|
Chris@16
|
175 // For polygon, inspecting outer ring is sufficient
|
Chris@16
|
176 detail::envelope::envelope_range::apply(exterior_ring(poly), mbr);
|
Chris@16
|
177 }
|
Chris@16
|
178
|
Chris@16
|
179 };
|
Chris@16
|
180
|
Chris@16
|
181
|
Chris@101
|
182 template <typename Multi>
|
Chris@101
|
183 struct envelope<Multi, multi_point_tag>
|
Chris@101
|
184 : detail::envelope::envelope_range
|
Chris@101
|
185 {};
|
Chris@101
|
186
|
Chris@101
|
187
|
Chris@101
|
188 template <typename Multi>
|
Chris@101
|
189 struct envelope<Multi, multi_linestring_tag>
|
Chris@101
|
190 : detail::envelope::envelope_multi_linestring
|
Chris@101
|
191 {};
|
Chris@101
|
192
|
Chris@101
|
193
|
Chris@101
|
194 template <typename Multi>
|
Chris@101
|
195 struct envelope<Multi, multi_polygon_tag>
|
Chris@101
|
196 : detail::envelope::envelope_multi_polygon
|
Chris@101
|
197 {};
|
Chris@101
|
198
|
Chris@101
|
199
|
Chris@16
|
200 } // namespace dispatch
|
Chris@16
|
201 #endif
|
Chris@16
|
202
|
Chris@16
|
203
|
Chris@101
|
204 namespace resolve_variant {
|
Chris@101
|
205
|
Chris@101
|
206 template <typename Geometry>
|
Chris@101
|
207 struct envelope
|
Chris@101
|
208 {
|
Chris@101
|
209 template <typename Box>
|
Chris@101
|
210 static inline void apply(Geometry const& geometry, Box& box)
|
Chris@101
|
211 {
|
Chris@101
|
212 concept::check<Geometry const>();
|
Chris@101
|
213 concept::check<Box>();
|
Chris@101
|
214
|
Chris@101
|
215 dispatch::envelope<Geometry>::apply(geometry, box);
|
Chris@101
|
216 }
|
Chris@101
|
217 };
|
Chris@101
|
218
|
Chris@101
|
219 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
|
Chris@101
|
220 struct envelope<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
|
Chris@101
|
221 {
|
Chris@101
|
222 template <typename Box>
|
Chris@101
|
223 struct visitor: boost::static_visitor<void>
|
Chris@101
|
224 {
|
Chris@101
|
225 Box& m_box;
|
Chris@101
|
226
|
Chris@101
|
227 visitor(Box& box): m_box(box) {}
|
Chris@101
|
228
|
Chris@101
|
229 template <typename Geometry>
|
Chris@101
|
230 void operator()(Geometry const& geometry) const
|
Chris@101
|
231 {
|
Chris@101
|
232 envelope<Geometry>::apply(geometry, m_box);
|
Chris@101
|
233 }
|
Chris@101
|
234 };
|
Chris@101
|
235
|
Chris@101
|
236 template <typename Box>
|
Chris@101
|
237 static inline void
|
Chris@101
|
238 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
|
Chris@101
|
239 Box& box)
|
Chris@101
|
240 {
|
Chris@101
|
241 boost::apply_visitor(visitor<Box>(box), geometry);
|
Chris@101
|
242 }
|
Chris@101
|
243 };
|
Chris@101
|
244
|
Chris@101
|
245 } // namespace resolve_variant
|
Chris@101
|
246
|
Chris@101
|
247
|
Chris@16
|
248 /*!
|
Chris@16
|
249 \brief \brief_calc{envelope}
|
Chris@16
|
250 \ingroup envelope
|
Chris@16
|
251 \details \details_calc{envelope,\det_envelope}.
|
Chris@16
|
252 \tparam Geometry \tparam_geometry
|
Chris@16
|
253 \tparam Box \tparam_box
|
Chris@16
|
254 \param geometry \param_geometry
|
Chris@16
|
255 \param mbr \param_box \param_set{envelope}
|
Chris@16
|
256
|
Chris@16
|
257 \qbk{[include reference/algorithms/envelope.qbk]}
|
Chris@16
|
258 \qbk{
|
Chris@16
|
259 [heading Example]
|
Chris@16
|
260 [envelope] [envelope_output]
|
Chris@16
|
261 }
|
Chris@16
|
262 */
|
Chris@16
|
263 template<typename Geometry, typename Box>
|
Chris@16
|
264 inline void envelope(Geometry const& geometry, Box& mbr)
|
Chris@16
|
265 {
|
Chris@101
|
266 resolve_variant::envelope<Geometry>::apply(geometry, mbr);
|
Chris@16
|
267 }
|
Chris@16
|
268
|
Chris@16
|
269
|
Chris@16
|
270 /*!
|
Chris@16
|
271 \brief \brief_calc{envelope}
|
Chris@16
|
272 \ingroup envelope
|
Chris@16
|
273 \details \details_calc{return_envelope,\det_envelope}. \details_return{envelope}
|
Chris@16
|
274 \tparam Box \tparam_box
|
Chris@16
|
275 \tparam Geometry \tparam_geometry
|
Chris@16
|
276 \param geometry \param_geometry
|
Chris@16
|
277 \return \return_calc{envelope}
|
Chris@16
|
278
|
Chris@16
|
279 \qbk{[include reference/algorithms/envelope.qbk]}
|
Chris@16
|
280 \qbk{
|
Chris@16
|
281 [heading Example]
|
Chris@16
|
282 [return_envelope] [return_envelope_output]
|
Chris@16
|
283 }
|
Chris@16
|
284 */
|
Chris@16
|
285 template<typename Box, typename Geometry>
|
Chris@16
|
286 inline Box return_envelope(Geometry const& geometry)
|
Chris@16
|
287 {
|
Chris@16
|
288 Box mbr;
|
Chris@101
|
289 resolve_variant::envelope<Geometry>::apply(geometry, mbr);
|
Chris@16
|
290 return mbr;
|
Chris@16
|
291 }
|
Chris@16
|
292
|
Chris@16
|
293 }} // namespace boost::geometry
|
Chris@16
|
294
|
Chris@16
|
295 #endif // BOOST_GEOMETRY_ALGORITHMS_ENVELOPE_HPP
|