]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/index/detail/rtree/utilities/gl_draw.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / index / detail / rtree / utilities / gl_draw.hpp
1 // Boost.Geometry Index
2 //
3 // R-tree OpenGL drawing visitor implementation
4 //
5 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
6 //
7 // This file was modified by Oracle on 2019-2021.
8 // Modifications copyright (c) 2019-2021 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 //
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP
16 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP
17
18 #include <limits>
19
20 #include <boost/geometry/core/access.hpp>
21 #include <boost/geometry/core/coordinate_dimension.hpp>
22 #include <boost/geometry/core/coordinate_type.hpp>
23 #include <boost/geometry/core/static_assert.hpp>
24 #include <boost/geometry/core/tag.hpp>
25 #include <boost/geometry/core/tags.hpp>
26
27 #include <boost/geometry/index/detail/rtree/node/node_elements.hpp>
28
29 namespace boost { namespace geometry { namespace index { namespace detail {
30
31 namespace utilities {
32
33 namespace dispatch {
34
35 template <typename Point, size_t Dimension>
36 struct gl_draw_point
37 {};
38
39 template <typename Point>
40 struct gl_draw_point<Point, 2>
41 {
42 static inline void apply(Point const& p, typename coordinate_type<Point>::type z)
43 {
44 typename coordinate_type<Point>::type const& x = geometry::get<0>(p);
45 typename coordinate_type<Point>::type const& y = geometry::get<1>(p);
46 /*glBegin(GL_POINT);
47 glVertex3f(x, y, z);
48 glEnd();*/
49 glBegin(GL_QUADS);
50 glVertex3f(x+1, y, z);
51 glVertex3f(x, y+1, z);
52 glVertex3f(x-1, y, z);
53 glVertex3f(x, y-1, z);
54 glEnd();
55 }
56 };
57
58 template <typename Box, size_t Dimension>
59 struct gl_draw_box
60 {};
61
62 template <typename Box>
63 struct gl_draw_box<Box, 2>
64 {
65 static inline void apply(Box const& b, typename coordinate_type<Box>::type z)
66 {
67 glBegin(GL_LINE_LOOP);
68 glVertex3f(geometry::get<min_corner, 0>(b), geometry::get<min_corner, 1>(b), z);
69 glVertex3f(geometry::get<max_corner, 0>(b), geometry::get<min_corner, 1>(b), z);
70 glVertex3f(geometry::get<max_corner, 0>(b), geometry::get<max_corner, 1>(b), z);
71 glVertex3f(geometry::get<min_corner, 0>(b), geometry::get<max_corner, 1>(b), z);
72 glEnd();
73 }
74 };
75
76 template <typename Segment, size_t Dimension>
77 struct gl_draw_segment
78 {};
79
80 template <typename Segment>
81 struct gl_draw_segment<Segment, 2>
82 {
83 static inline void apply(Segment const& s, typename coordinate_type<Segment>::type z)
84 {
85 glBegin(GL_LINES);
86 glVertex3f(geometry::get<0, 0>(s), geometry::get<0, 1>(s), z);
87 glVertex3f(geometry::get<1, 0>(s), geometry::get<1, 1>(s), z);
88 glEnd();
89 }
90 };
91
92 template <typename Indexable, typename Tag>
93 struct gl_draw_indexable
94 {
95 BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
96 "Not implemented for this Indexable type.",
97 Indexable, Tag);
98 };
99
100 template <typename Box>
101 struct gl_draw_indexable<Box, box_tag>
102 : gl_draw_box<Box, geometry::dimension<Box>::value>
103 {};
104
105 template <typename Point>
106 struct gl_draw_indexable<Point, point_tag>
107 : gl_draw_point<Point, geometry::dimension<Point>::value>
108 {};
109
110 template <typename Segment>
111 struct gl_draw_indexable<Segment, segment_tag>
112 : gl_draw_segment<Segment, geometry::dimension<Segment>::value>
113 {};
114
115 } // namespace dispatch
116
117 template <typename Indexable> inline
118 void gl_draw_indexable(Indexable const& i, typename coordinate_type<Indexable>::type z)
119 {
120 dispatch::gl_draw_indexable<
121 Indexable,
122 typename tag<Indexable>::type
123 >::apply(i, z);
124 }
125
126 } // namespace utilities
127
128 namespace rtree { namespace utilities {
129
130 namespace visitors {
131
132 template <typename MembersHolder>
133 struct gl_draw
134 : public MembersHolder::visitor_const
135 {
136 typedef typename MembersHolder::box_type box_type;
137 typedef typename MembersHolder::translator_type translator_type;
138
139 typedef typename MembersHolder::internal_node internal_node;
140 typedef typename MembersHolder::leaf leaf;
141
142 inline gl_draw(translator_type const& t,
143 size_t level_first = 0,
144 size_t level_last = (std::numeric_limits<size_t>::max)(),
145 typename coordinate_type<box_type>::type z_coord_level_multiplier = 1
146 )
147 : tr(t)
148 , level_f(level_first)
149 , level_l(level_last)
150 , z_mul(z_coord_level_multiplier)
151 , level(0)
152 {}
153
154 inline void operator()(internal_node const& n)
155 {
156 typedef typename rtree::elements_type<internal_node>::type elements_type;
157 elements_type const& elements = rtree::elements(n);
158
159 if ( level_f <= level )
160 {
161 size_t level_rel = level - level_f;
162
163 if ( level_rel == 0 )
164 glColor3f(0.75f, 0.0f, 0.0f);
165 else if ( level_rel == 1 )
166 glColor3f(0.0f, 0.75f, 0.0f);
167 else if ( level_rel == 2 )
168 glColor3f(0.0f, 0.0f, 0.75f);
169 else if ( level_rel == 3 )
170 glColor3f(0.75f, 0.75f, 0.0f);
171 else if ( level_rel == 4 )
172 glColor3f(0.75f, 0.0f, 0.75f);
173 else if ( level_rel == 5 )
174 glColor3f(0.0f, 0.75f, 0.75f);
175 else
176 glColor3f(0.5f, 0.5f, 0.5f);
177
178 for (typename elements_type::const_iterator it = elements.begin();
179 it != elements.end(); ++it)
180 {
181 detail::utilities::gl_draw_indexable(it->first, level_rel * z_mul);
182 }
183 }
184
185 size_t level_backup = level;
186 ++level;
187
188 if ( level < level_l )
189 {
190 for (typename elements_type::const_iterator it = elements.begin();
191 it != elements.end(); ++it)
192 {
193 rtree::apply_visitor(*this, *it->second);
194 }
195 }
196
197 level = level_backup;
198 }
199
200 inline void operator()(leaf const& n)
201 {
202 typedef typename rtree::elements_type<leaf>::type elements_type;
203 elements_type const& elements = rtree::elements(n);
204
205 if ( level_f <= level )
206 {
207 size_t level_rel = level - level_f;
208
209 glColor3f(0.25f, 0.25f, 0.25f);
210
211 for (typename elements_type::const_iterator it = elements.begin();
212 it != elements.end(); ++it)
213 {
214 detail::utilities::gl_draw_indexable(tr(*it), level_rel * z_mul);
215 }
216 }
217 }
218
219 translator_type const& tr;
220 size_t level_f;
221 size_t level_l;
222 typename coordinate_type<box_type>::type z_mul;
223
224 size_t level;
225 };
226
227 } // namespace visitors
228
229 template <typename Rtree> inline
230 void gl_draw(Rtree const& tree,
231 size_t level_first = 0,
232 size_t level_last = (std::numeric_limits<size_t>::max)(),
233 typename coordinate_type<
234 typename Rtree::bounds_type
235 >::type z_coord_level_multiplier = 1
236 )
237 {
238 typedef utilities::view<Rtree> RTV;
239 RTV rtv(tree);
240
241 if ( !tree.empty() )
242 {
243 glColor3f(0.75f, 0.75f, 0.75f);
244 detail::utilities::gl_draw_indexable(tree.bounds(), 0);
245 }
246
247 visitors::gl_draw<
248 typename RTV::members_holder
249 > gl_draw_v(rtv.translator(), level_first, level_last, z_coord_level_multiplier);
250
251 rtv.apply_visitor(gl_draw_v);
252 }
253
254 }} // namespace rtree::utilities
255
256 }}}} // namespace boost::geometry::index::detail
257
258 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP