Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
// Boost.Geometry Index
//
// R-tree boxes validating visitor implementation
//
// Copyright (c) 2011-2015 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)
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_BOXES_OK_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_BOXES_OK_HPP
#include <boost/geometry/algorithms/equals.hpp>
#include <boost/geometry/index/detail/rtree/node/node.hpp>
namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace utilities {
namespace visitors {
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
class are_boxes_ok
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
{
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
public:
are_boxes_ok(Translator const& tr, bool exact_match)
: result(false), m_tr(tr), m_is_root(true), m_exact_match(exact_match)
{}
void operator()(internal_node const& n)
{
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements(n);
if (elements.empty())
{
result = false;
return;
}
Box box_bckup = m_box;
bool is_root_bckup = m_is_root;
m_is_root = false;
for ( typename elements_type::const_iterator it = elements.begin();
it != elements.end() ; ++it)
{
m_box = it->first;
rtree::apply_visitor(*this, *it->second);
if ( result == false )
return;
}
m_box = box_bckup;
m_is_root = is_root_bckup;
Box box_exp = rtree::elements_box<Box>(elements.begin(), elements.end(), m_tr);
if ( m_exact_match )
result = m_is_root || geometry::equals(box_exp, m_box);
else
result = m_is_root || geometry::covered_by(box_exp, m_box);
}
void operator()(leaf const& n)
{
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements(n);
// non-root node
if (!m_is_root)
{
if ( elements.empty() )
{
result = false;
return;
}
Box box_exp = rtree::values_box<Box>(elements.begin(), elements.end(), m_tr);
if ( m_exact_match )
result = geometry::equals(box_exp, m_box);
else
result = geometry::covered_by(box_exp, m_box);
}
else
result = true;
}
bool result;
private:
Translator const& m_tr;
Box m_box;
bool m_is_root;
bool m_exact_match;
};
} // namespace visitors
template <typename Rtree> inline
bool are_boxes_ok(Rtree const& tree, bool exact_match = true)
{
typedef utilities::view<Rtree> RTV;
RTV rtv(tree);
visitors::are_boxes_ok<
typename RTV::value_type,
typename RTV::options_type,
typename RTV::translator_type,
typename RTV::box_type,
typename RTV::allocators_type
> v(rtv.translator(), exact_match);
rtv.apply_visitor(v);
return v.result;
}
}}}}}} // namespace boost::geometry::index::detail::rtree::utilities
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_BOXES_OK_HPP

View File

@@ -0,0 +1,110 @@
// Boost.Geometry Index
//
// R-tree nodes elements numbers validating visitor implementation
//
// Copyright (c) 2011-2015 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)
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_COUNTS_OK_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_COUNTS_OK_HPP
#include <boost/geometry/index/detail/rtree/node/node.hpp>
namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace utilities {
namespace visitors {
template <typename Value, typename Options, typename Box, typename Allocators>
class are_counts_ok
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
{
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
typedef typename Options::parameters_type parameters_type;
public:
inline are_counts_ok(parameters_type const& parameters)
: result(true), m_current_level(0), m_parameters(parameters)
{}
inline void operator()(internal_node const& n)
{
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements(n);
// root internal node shouldn't contain 0 elements
if ( elements.empty()
|| !check_count(elements) )
{
result = false;
return;
}
size_t current_level_backup = m_current_level;
++m_current_level;
for ( typename elements_type::const_iterator it = elements.begin();
it != elements.end() && result == true ;
++it)
{
rtree::apply_visitor(*this, *it->second);
}
m_current_level = current_level_backup;
}
inline void operator()(leaf const& n)
{
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements(n);
// empty leaf in non-root node
if ( ( m_current_level > 0 && elements.empty() )
|| !check_count(elements) )
{
result = false;
}
}
bool result;
private:
template <typename Elements>
bool check_count(Elements const& elements)
{
// root may contain count < min but should never contain count > max
return elements.size() <= m_parameters.get_max_elements()
&& ( elements.size() >= m_parameters.get_min_elements()
|| m_current_level == 0 );
}
size_t m_current_level;
parameters_type const& m_parameters;
};
} // namespace visitors
template <typename Rtree> inline
bool are_counts_ok(Rtree const& tree)
{
typedef utilities::view<Rtree> RTV;
RTV rtv(tree);
visitors::are_counts_ok<
typename RTV::value_type,
typename RTV::options_type,
typename RTV::box_type,
typename RTV::allocators_type
> v(tree.parameters());
rtv.apply_visitor(v);
return v.result;
}
}}}}}} // namespace boost::geometry::index::detail::rtree::utilities
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_COUNTS_OK_HPP

View File

@@ -0,0 +1,109 @@
// Boost.Geometry Index
//
// R-tree levels validating visitor implementation
//
// Copyright (c) 2011-2013 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)
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_LEVELS_OK_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_LEVELS_OK_HPP
#include <boost/geometry/index/detail/rtree/node/node.hpp>
namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace utilities {
namespace visitors {
template <typename Value, typename Options, typename Box, typename Allocators>
class are_levels_ok
: public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
{
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
public:
inline are_levels_ok()
: result(true), m_leafs_level((std::numeric_limits<size_t>::max)()), m_current_level(0)
{}
inline void operator()(internal_node const& n)
{
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements(n);
if (elements.empty())
{
result = false;
return;
}
size_t current_level_backup = m_current_level;
++m_current_level;
for ( typename elements_type::const_iterator it = elements.begin();
it != elements.end() ; ++it)
{
rtree::apply_visitor(*this, *it->second);
if ( result == false )
return;
}
m_current_level = current_level_backup;
}
inline void operator()(leaf const& n)
{
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements(n);
// empty leaf in non-root node
if (0 < m_current_level && elements.empty())
{
result = false;
return;
}
if ( m_leafs_level == (std::numeric_limits<size_t>::max)() )
{
m_leafs_level = m_current_level;
}
else if ( m_leafs_level != m_current_level )
{
result = false;
}
}
bool result;
private:
size_t m_leafs_level;
size_t m_current_level;
};
} // namespace visitors
template <typename Rtree> inline
bool are_levels_ok(Rtree const& tree)
{
typedef utilities::view<Rtree> RTV;
RTV rtv(tree);
visitors::are_levels_ok<
typename RTV::value_type,
typename RTV::options_type,
typename RTV::box_type,
typename RTV::allocators_type
> v;
rtv.apply_visitor(v);
return v.result;
}
}}}}}} // namespace boost::geometry::index::detail::rtree::utilities
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_LEVELS_OK_HPP

View File

@@ -0,0 +1,243 @@
// Boost.Geometry Index
//
// R-tree OpenGL drawing visitor implementation
//
// Copyright (c) 2011-2013 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)
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP
#include <boost/mpl/assert.hpp>
namespace boost { namespace geometry { namespace index { namespace detail {
namespace utilities {
namespace dispatch {
template <typename Point, size_t Dimension>
struct gl_draw_point
{};
template <typename Point>
struct gl_draw_point<Point, 2>
{
static inline void apply(Point const& p, typename coordinate_type<Point>::type z)
{
typename coordinate_type<Point>::type const& x = geometry::get<0>(p);
typename coordinate_type<Point>::type const& y = geometry::get<1>(p);
/*glBegin(GL_POINT);
glVertex3f(x, y, z);
glEnd();*/
glBegin(GL_QUADS);
glVertex3f(x+1, y, z);
glVertex3f(x, y+1, z);
glVertex3f(x-1, y, z);
glVertex3f(x, y-1, z);
glEnd();
}
};
template <typename Box, size_t Dimension>
struct gl_draw_box
{};
template <typename Box>
struct gl_draw_box<Box, 2>
{
static inline void apply(Box const& b, typename coordinate_type<Box>::type z)
{
glBegin(GL_LINE_LOOP);
glVertex3f(geometry::get<min_corner, 0>(b), geometry::get<min_corner, 1>(b), z);
glVertex3f(geometry::get<max_corner, 0>(b), geometry::get<min_corner, 1>(b), z);
glVertex3f(geometry::get<max_corner, 0>(b), geometry::get<max_corner, 1>(b), z);
glVertex3f(geometry::get<min_corner, 0>(b), geometry::get<max_corner, 1>(b), z);
glEnd();
}
};
template <typename Segment, size_t Dimension>
struct gl_draw_segment
{};
template <typename Segment>
struct gl_draw_segment<Segment, 2>
{
static inline void apply(Segment const& s, typename coordinate_type<Segment>::type z)
{
glBegin(GL_LINES);
glVertex3f(geometry::get<0, 0>(s), geometry::get<0, 1>(s), z);
glVertex3f(geometry::get<1, 0>(s), geometry::get<1, 1>(s), z);
glEnd();
}
};
template <typename Indexable, typename Tag>
struct gl_draw_indexable
{
BOOST_MPL_ASSERT_MSG((false), NOT_IMPLEMENTED_FOR_THIS_TAG, (Tag));
};
template <typename Box>
struct gl_draw_indexable<Box, box_tag>
: gl_draw_box<Box, geometry::dimension<Box>::value>
{};
template <typename Point>
struct gl_draw_indexable<Point, point_tag>
: gl_draw_point<Point, geometry::dimension<Point>::value>
{};
template <typename Segment>
struct gl_draw_indexable<Segment, segment_tag>
: gl_draw_segment<Segment, geometry::dimension<Segment>::value>
{};
} // namespace dispatch
template <typename Indexable> inline
void gl_draw_indexable(Indexable const& i, typename coordinate_type<Indexable>::type z)
{
dispatch::gl_draw_indexable<
Indexable,
typename tag<Indexable>::type
>::apply(i, z);
}
} // namespace utilities
namespace rtree { namespace utilities {
namespace visitors {
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
struct gl_draw : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
{
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
inline gl_draw(Translator const& t,
size_t level_first = 0,
size_t level_last = (std::numeric_limits<size_t>::max)(),
typename coordinate_type<Box>::type z_coord_level_multiplier = 1
)
: tr(t)
, level_f(level_first)
, level_l(level_last)
, z_mul(z_coord_level_multiplier)
, level(0)
{}
inline void operator()(internal_node const& n)
{
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements(n);
if ( level_f <= level )
{
size_t level_rel = level - level_f;
if ( level_rel == 0 )
glColor3f(0.75f, 0.0f, 0.0f);
else if ( level_rel == 1 )
glColor3f(0.0f, 0.75f, 0.0f);
else if ( level_rel == 2 )
glColor3f(0.0f, 0.0f, 0.75f);
else if ( level_rel == 3 )
glColor3f(0.75f, 0.75f, 0.0f);
else if ( level_rel == 4 )
glColor3f(0.75f, 0.0f, 0.75f);
else if ( level_rel == 5 )
glColor3f(0.0f, 0.75f, 0.75f);
else
glColor3f(0.5f, 0.5f, 0.5f);
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
detail::utilities::gl_draw_indexable(it->first, level_rel * z_mul);
}
}
size_t level_backup = level;
++level;
if ( level < level_l )
{
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
rtree::apply_visitor(*this, *it->second);
}
}
level = level_backup;
}
inline void operator()(leaf const& n)
{
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements(n);
if ( level_f <= level )
{
size_t level_rel = level - level_f;
glColor3f(0.25f, 0.25f, 0.25f);
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
detail::utilities::gl_draw_indexable(tr(*it), level_rel * z_mul);
}
}
}
Translator const& tr;
size_t level_f;
size_t level_l;
typename coordinate_type<Box>::type z_mul;
size_t level;
};
} // namespace visitors
template <typename Rtree> inline
void gl_draw(Rtree const& tree,
size_t level_first = 0,
size_t level_last = (std::numeric_limits<size_t>::max)(),
typename coordinate_type<
typename Rtree::bounds_type
>::type z_coord_level_multiplier = 1
)
{
typedef utilities::view<Rtree> RTV;
RTV rtv(tree);
if ( !tree.empty() )
{
glColor3f(0.75f, 0.75f, 0.75f);
detail::utilities::gl_draw_indexable(tree.bounds(), 0);
}
visitors::gl_draw<
typename RTV::value_type,
typename RTV::options_type,
typename RTV::translator_type,
typename RTV::box_type,
typename RTV::allocators_type
> gl_draw_v(rtv.translator(), level_first, level_last, z_coord_level_multiplier);
rtv.apply_visitor(gl_draw_v);
}
}} // namespace rtree::utilities
}}}} // namespace boost::geometry::index::detail
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_GL_DRAW_HPP

View File

@@ -0,0 +1,219 @@
// Boost.Geometry Index
//
// R-tree ostreaming visitor implementation
//
// Copyright (c) 2011-2013 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)
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_PRINT_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_PRINT_HPP
#include <iostream>
namespace boost { namespace geometry { namespace index { namespace detail {
namespace utilities {
namespace dispatch {
template <typename Point, size_t Dimension>
struct print_point
{
BOOST_STATIC_ASSERT(0 < Dimension);
static inline void apply(std::ostream & os, Point const& p)
{
print_point<Point, Dimension - 1>::apply(os, p);
os << ", " << geometry::get<Dimension - 1>(p);
}
};
template <typename Point>
struct print_point<Point, 1>
{
static inline void apply(std::ostream & os, Point const& p)
{
os << geometry::get<0>(p);
}
};
template <typename Box, size_t Corner, size_t Dimension>
struct print_corner
{
BOOST_STATIC_ASSERT(0 < Dimension);
static inline void apply(std::ostream & os, Box const& b)
{
print_corner<Box, Corner, Dimension - 1>::apply(os, b);
os << ", " << geometry::get<Corner, Dimension - 1>(b);
}
};
template <typename Box, size_t Corner>
struct print_corner<Box, Corner, 1>
{
static inline void apply(std::ostream & os, Box const& b)
{
os << geometry::get<Corner, 0>(b);
}
};
template <typename Indexable, typename Tag>
struct print_indexable
{
BOOST_MPL_ASSERT_MSG((false), NOT_IMPLEMENTED_FOR_THIS_TAG, (Tag));
};
template <typename Indexable>
struct print_indexable<Indexable, box_tag>
{
static const size_t dimension = geometry::dimension<Indexable>::value;
static inline void apply(std::ostream &os, Indexable const& i)
{
os << '(';
print_corner<Indexable, min_corner, dimension>::apply(os, i);
os << ")x(";
print_corner<Indexable, max_corner, dimension>::apply(os, i);
os << ')';
}
};
template <typename Indexable>
struct print_indexable<Indexable, point_tag>
{
static const size_t dimension = geometry::dimension<Indexable>::value;
static inline void apply(std::ostream &os, Indexable const& i)
{
os << '(';
print_point<Indexable, dimension>::apply(os, i);
os << ')';
}
};
template <typename Indexable>
struct print_indexable<Indexable, segment_tag>
{
static const size_t dimension = geometry::dimension<Indexable>::value;
static inline void apply(std::ostream &os, Indexable const& i)
{
os << '(';
print_corner<Indexable, 0, dimension>::apply(os, i);
os << ")-(";
print_corner<Indexable, 1, dimension>::apply(os, i);
os << ')';
}
};
} // namespace dispatch
template <typename Indexable> inline
void print_indexable(std::ostream & os, Indexable const& i)
{
dispatch::print_indexable<
Indexable,
typename tag<Indexable>::type
>::apply(os, i);
}
} // namespace utilities
namespace rtree { namespace utilities {
namespace visitors {
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
struct print : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
{
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
inline print(std::ostream & o, Translator const& t)
: os(o), tr(t), level(0)
{}
inline void operator()(internal_node const& n)
{
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements(n);
spaces(level) << "INTERNAL NODE - L:" << level << " Ch:" << elements.size() << " @:" << &n << '\n';
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
spaces(level);
detail::utilities::print_indexable(os, it->first);
os << " ->" << it->second << '\n';
}
size_t level_backup = level;
++level;
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
rtree::apply_visitor(*this, *it->second);
}
level = level_backup;
}
inline void operator()(leaf const& n)
{
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements(n);
spaces(level) << "LEAF - L:" << level << " V:" << elements.size() << " @:" << &n << '\n';
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
spaces(level);
detail::utilities::print_indexable(os, tr(*it));
os << '\n';
}
}
inline std::ostream & spaces(size_t level)
{
for ( size_t i = 0 ; i < 2 * level ; ++i )
os << ' ';
return os;
}
std::ostream & os;
Translator const& tr;
size_t level;
};
} // namespace visitors
template <typename Rtree> inline
void print(std::ostream & os, Rtree const& tree)
{
typedef utilities::view<Rtree> RTV;
RTV rtv(tree);
visitors::print<
typename RTV::value_type,
typename RTV::options_type,
typename RTV::translator_type,
typename RTV::box_type,
typename RTV::allocators_type
> print_v(os, rtv.translator());
rtv.apply_visitor(print_v);
}
}} // namespace rtree::utilities
}}}} // namespace boost::geometry::index::detail
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_PRINT_HPP

View File

@@ -0,0 +1,105 @@
// Boost.Geometry Index
//
// R-tree visitor collecting basic statistics
//
// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2013 Mateusz Loskot, London, UK.
//
// 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)
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_STATISTICS_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_STATISTICS_HPP
#include <algorithm>
#include <boost/tuple/tuple.hpp>
namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace utilities {
namespace visitors {
template <typename Value, typename Options, typename Box, typename Allocators>
struct statistics : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
{
typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
inline statistics()
: level(0)
, levels(1) // count root
, nodes(0)
, leaves(0)
, values(0)
, values_min(0)
, values_max(0)
{}
inline void operator()(internal_node const& n)
{
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements(n);
++nodes; // count node
size_t const level_backup = level;
++level;
levels += level++ > levels ? 1 : 0; // count level (root already counted)
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
rtree::apply_visitor(*this, *it->second);
}
level = level_backup;
}
inline void operator()(leaf const& n)
{
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements(n);
++leaves; // count leaves
std::size_t const v = elements.size();
// count values spread per node and total
values_min = (std::min)(values_min == 0 ? v : values_min, v);
values_max = (std::max)(values_max, v);
values += v;
}
std::size_t level;
std::size_t levels;
std::size_t nodes;
std::size_t leaves;
std::size_t values;
std::size_t values_min;
std::size_t values_max;
};
} // namespace visitors
template <typename Rtree> inline
boost::tuple<std::size_t, std::size_t, std::size_t, std::size_t, std::size_t, std::size_t>
statistics(Rtree const& tree)
{
typedef utilities::view<Rtree> RTV;
RTV rtv(tree);
visitors::statistics<
typename RTV::value_type,
typename RTV::options_type,
typename RTV::box_type,
typename RTV::allocators_type
> stats_v;
rtv.apply_visitor(stats_v);
return boost::make_tuple(stats_v.levels, stats_v.nodes, stats_v.leaves, stats_v.values, stats_v.values_min, stats_v.values_max);
}
}}}}}} // namespace boost::geometry::index::detail::rtree::utilities
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_STATISTICS_HPP

View File

@@ -0,0 +1,61 @@
// Boost.Geometry Index
//
// Rtree utilities view
//
// Copyright (c) 2011-2013 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)
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_VIEW_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_VIEW_HPP
namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree { namespace utilities {
template <typename Rtree>
class view
{
public:
typedef typename Rtree::size_type size_type;
typedef typename Rtree::translator_type translator_type;
typedef typename Rtree::value_type value_type;
typedef typename Rtree::options_type options_type;
typedef typename Rtree::box_type box_type;
typedef typename Rtree::allocators_type allocators_type;
view(Rtree const& rt) : m_rtree(rt) {}
template <typename Visitor>
void apply_visitor(Visitor & vis) const
{
m_rtree.apply_visitor(vis);
}
// This will most certainly be removed in the future
translator_type translator() const
{
return m_rtree.translator();
}
// This will probably be removed in the future
size_type depth() const
{
return m_rtree.depth();
}
private:
view(view const&);
view & operator=(view const&);
Rtree const& m_rtree;
};
}}} // namespace detail::rtree::utilities
}}} // namespace boost::geometry::index
#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_VIEW_HPP