1 // Boost.Geometry Index
3 // R-tree OpenGL drawing visitor implementation
5 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
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
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)
15 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP
16 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP
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>
27 #include <boost/geometry/index/detail/rtree/node/node_elements.hpp>
29 namespace boost { namespace geometry { namespace index { namespace detail {
35 template <typename Point, size_t Dimension>
39 template <typename Point>
40 struct gl_draw_point<Point, 2>
42 static inline void apply(Point const& p, typename coordinate_type<Point>::type z)
44 typename coordinate_type<Point>::type const& x = geometry::get<0>(p);
45 typename coordinate_type<Point>::type const& y = geometry::get<1>(p);
50 glVertex3f(x+1, y, z);
51 glVertex3f(x, y+1, z);
52 glVertex3f(x-1, y, z);
53 glVertex3f(x, y-1, z);
58 template <typename Box, size_t Dimension>
62 template <typename Box>
63 struct gl_draw_box<Box, 2>
65 static inline void apply(Box const& b, typename coordinate_type<Box>::type z)
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);
76 template <typename Segment, size_t Dimension>
77 struct gl_draw_segment
80 template <typename Segment>
81 struct gl_draw_segment<Segment, 2>
83 static inline void apply(Segment const& s, typename coordinate_type<Segment>::type z)
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);
92 template <typename Indexable, typename Tag>
93 struct gl_draw_indexable
95 BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
96 "Not implemented for this Indexable type.",
100 template <typename Box>
101 struct gl_draw_indexable<Box, box_tag>
102 : gl_draw_box<Box, geometry::dimension<Box>::value>
105 template <typename Point>
106 struct gl_draw_indexable<Point, point_tag>
107 : gl_draw_point<Point, geometry::dimension<Point>::value>
110 template <typename Segment>
111 struct gl_draw_indexable<Segment, segment_tag>
112 : gl_draw_segment<Segment, geometry::dimension<Segment>::value>
115 } // namespace dispatch
117 template <typename Indexable> inline
118 void gl_draw_indexable(Indexable const& i, typename coordinate_type<Indexable>::type z)
120 dispatch::gl_draw_indexable<
122 typename tag<Indexable>::type
126 } // namespace utilities
128 namespace rtree { namespace utilities {
132 template <typename MembersHolder>
134 : public MembersHolder::visitor_const
136 typedef typename MembersHolder::box_type box_type;
137 typedef typename MembersHolder::translator_type translator_type;
139 typedef typename MembersHolder::internal_node internal_node;
140 typedef typename MembersHolder::leaf leaf;
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
148 , level_f(level_first)
149 , level_l(level_last)
150 , z_mul(z_coord_level_multiplier)
154 inline void operator()(internal_node const& n)
156 typedef typename rtree::elements_type<internal_node>::type elements_type;
157 elements_type const& elements = rtree::elements(n);
159 if ( level_f <= level )
161 size_t level_rel = level - level_f;
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);
176 glColor3f(0.5f, 0.5f, 0.5f);
178 for (typename elements_type::const_iterator it = elements.begin();
179 it != elements.end(); ++it)
181 detail::utilities::gl_draw_indexable(it->first, level_rel * z_mul);
185 size_t level_backup = level;
188 if ( level < level_l )
190 for (typename elements_type::const_iterator it = elements.begin();
191 it != elements.end(); ++it)
193 rtree::apply_visitor(*this, *it->second);
197 level = level_backup;
200 inline void operator()(leaf const& n)
202 typedef typename rtree::elements_type<leaf>::type elements_type;
203 elements_type const& elements = rtree::elements(n);
205 if ( level_f <= level )
207 size_t level_rel = level - level_f;
209 glColor3f(0.25f, 0.25f, 0.25f);
211 for (typename elements_type::const_iterator it = elements.begin();
212 it != elements.end(); ++it)
214 detail::utilities::gl_draw_indexable(tr(*it), level_rel * z_mul);
219 translator_type const& tr;
222 typename coordinate_type<box_type>::type z_mul;
227 } // namespace visitors
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
238 typedef utilities::view<Rtree> RTV;
243 glColor3f(0.75f, 0.75f, 0.75f);
244 detail::utilities::gl_draw_indexable(tree.bounds(), 0);
248 typename RTV::members_holder
249 > gl_draw_v(rtv.translator(), level_first, level_last, z_coord_level_multiplier);
251 rtv.apply_visitor(gl_draw_v);
254 }} // namespace rtree::utilities
256 }}}} // namespace boost::geometry::index::detail
258 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP