[SVN r71775]
This commit is contained in:
Adam Wulkiewicz
2011-05-06 23:59:05 +00:00
parent 9dcca981e2
commit c06e620e28
11 changed files with 90 additions and 93 deletions

View File

@@ -16,9 +16,6 @@ struct linear_tag {};
}}} // namespace boost::geometry::index
//TEST
// TODO
#include <boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp>
#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_LINEAR_LINEAR_HPP

View File

@@ -30,16 +30,16 @@ struct internal_node_def
Box,
typename node<Value, Box, Tag>::type *
>
> children_type;
> elements_type;
children_type children;
elements_type elements;
};
template <typename Value, typename Box, typename Tag>
struct leaf_def
{
typedef std::vector<Value> values_type;
values_type values;
typedef std::vector<Value> elements_type;
elements_type elements;
};
// nodes traits
@@ -73,18 +73,6 @@ struct elements_type
typedef typename Node::elements_type type;
};
template <typename Value, typename Box, typename Tag>
struct elements_type< internal_node_def<Value, Box, Tag> >
{
typedef typename internal_node_def<Value, Box, Tag>::children_type type;
};
template <typename Value, typename Box, typename Tag>
struct elements_type< leaf_def<Value, Box, Tag> >
{
typedef typename leaf_def<Value, Box, Tag>::values_type type;
};
template <typename Node>
typename elements_type<Node>::type &
elements_get(Node & n)
@@ -92,18 +80,11 @@ elements_get(Node & n)
return n.elements;
}
template <typename Value, typename Box, typename Tag>
typename internal_node_def<Value, Box, Tag>::children_type &
elements_get(internal_node_def<Value, Box, Tag> & n)
template <typename Node>
typename elements_type<Node>::type const&
elements_get(Node const& n)
{
return n.children;
}
template <typename Value, typename Box, typename Tag>
typename leaf_def<Value, Box, Tag>::values_type &
elements_get(leaf_def<Value, Box, Tag> & n)
{
return n.values;
return n.elements;
}
//template <typename Node>

View File

@@ -30,7 +30,10 @@ public:
inline bool operator()(internal_node const& n)
{
if (n.children.empty())
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements_get(n);
if (elements.empty())
return false;
Box box_bckup = m_box;
@@ -38,8 +41,8 @@ public:
m_is_root = false;
for ( internal_node::children_type::const_iterator it = n.children.begin();
it != n.children.end() ; ++it)
for ( typename elements_type::const_iterator it = elements.begin();
it != elements.end() ; ++it)
{
m_box = it->first;
@@ -51,9 +54,9 @@ public:
m_is_root = is_root_bckup;
Box result;
geometry::convert(n.children.front().first, result);
for(internal_node::children_type::const_iterator it = n.children.begin() + 1;
it != n.children.end() ; ++it)
geometry::convert(elements.front().first, result);
for( typename elements_type::const_iterator it = elements.begin() + 1;
it != elements.end() ; ++it)
{
geometry::expand(result, it->first);
}
@@ -63,13 +66,16 @@ public:
inline bool operator()(leaf const& n)
{
if (n.values.empty())
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements_get(n);
if (elements.empty())
return false;
Box result;
geometry::convert(m_tr(n.values.front()), result);
for(leaf::values_type::const_iterator it = n.values.begin() + 1;
it != n.values.end() ; ++it)
geometry::convert(m_tr(elements.front()), result);
for(typename elements_type::const_iterator it = elements.begin() + 1;
it != elements.end() ; ++it)
{
geometry::expand(result, m_tr(*it));
}

View File

@@ -24,10 +24,11 @@ struct destroy : public boost::static_visitor<>
inline void operator()(internal_node & n) const
{
typedef typename internal_node::children_type children_type;
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type & elements = rtree::elements_get(n);
for (typename children_type::iterator it = n.children.begin();
it != n.children.end(); ++it)
for (typename elements_type::iterator it = elements.begin();
it != elements.end(); ++it)
{
boost::apply_visitor(*this, *it->second);

View File

@@ -193,10 +193,11 @@ struct find : public boost::static_visitor<>
// }
//}
typedef typename internal_node::children_type children_type;
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements_get(n);
for (typename children_type::const_iterator it = n.children.begin();
it != n.children.end(); ++it)
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
if ( geometry::intersects(it->first, geom) )
boost::apply_visitor(*this, *it->second);
@@ -205,10 +206,11 @@ struct find : public boost::static_visitor<>
inline void operator()(leaf const& n)
{
typedef typename leaf::values_type values_type;
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements_get(n);
for (typename values_type::const_iterator it = n.values.begin();
it != n.values.end(); ++it)
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
if ( geometry::intersects(tr(*it), geom) )
{

View File

@@ -114,7 +114,8 @@ struct gl_draw : public boost::static_visitor<>
inline void operator()(internal_node const& n)
{
typedef typename internal_node::children_type children_type;
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements_get(n);
if ( level_f <= level )
{
@@ -135,8 +136,8 @@ struct gl_draw : public boost::static_visitor<>
else
glColor3f(0.5f, 0.5f, 0.5f);
for (typename children_type::const_iterator it = n.children.begin();
it != n.children.end(); ++it)
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
detail::gl_draw_indexable(it->first, level_rel * z_mul);
}
@@ -147,8 +148,8 @@ struct gl_draw : public boost::static_visitor<>
if ( level < level_l )
{
for (typename children_type::const_iterator it = n.children.begin();
it != n.children.end(); ++it)
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
boost::apply_visitor(*this, *it->second);
}
@@ -159,7 +160,8 @@ struct gl_draw : public boost::static_visitor<>
inline void operator()(leaf const& n)
{
typedef typename leaf::values_type values_type;
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements_get(n);
if ( level_f <= level )
{
@@ -167,8 +169,8 @@ struct gl_draw : public boost::static_visitor<>
glColor3f(1.0f, 1.0f, 1.0f);
for (typename values_type::const_iterator it = n.values.begin();
it != n.values.end(); ++it)
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
detail::gl_draw_indexable(tr(*it), level_rel * z_mul);
}

View File

@@ -111,9 +111,9 @@ struct split
if ( parent != 0 )
{
// update old node's box
parent->children[current_child_index].first = box1;
rtree::elements_get(*parent)[current_child_index].first = box1;
// add new node to the parent's children
parent->children.push_back(std::make_pair(box2, second_node));
rtree::elements_get(*parent).push_back(std::make_pair(box2, second_node));
}
// node is the root
else
@@ -123,8 +123,8 @@ struct split
// create new root and add nodes
node * new_root = rtree::create_node(internal_node());
boost::get<internal_node>(*new_root).children.push_back(std::make_pair(box1, root));
boost::get<internal_node>(*new_root).children.push_back(std::make_pair(box2, second_node));
rtree::elements_get(boost::get<internal_node>(*new_root)).push_back(std::make_pair(box1, root));
rtree::elements_get(boost::get<internal_node>(*new_root)).push_back(std::make_pair(box2, second_node));
root = new_root;
}
@@ -209,7 +209,7 @@ protected:
// expand the node to contain value
geometry::expand(
n.children[choosen_node_index].first,
rtree::elements_get(n)[choosen_node_index].first,
rtree::element_indexable(m_element, m_tr));
// next traversing step

View File

@@ -125,12 +125,13 @@ struct print : public boost::static_visitor<>
inline void operator()(internal_node const& n)
{
typedef typename internal_node::children_type children_type;
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type const& elements = rtree::elements_get(n);
spaces(level) << "INTERNAL NODE - L:" << level << " Ch:" << n.children.size() << " @:" << &n << '\n';
spaces(level) << "INTERNAL NODE - L:" << level << " Ch:" << elements.size() << " @:" << &n << '\n';
for (typename children_type::const_iterator it = n.children.begin();
it != n.children.end(); ++it)
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
spaces(level);
detail::print_indexable(os, it->first);
@@ -140,8 +141,8 @@ struct print : public boost::static_visitor<>
size_t level_backup = level;
++level;
for (typename children_type::const_iterator it = n.children.begin();
it != n.children.end(); ++it)
for (typename elements_type::const_iterator it = elements.begin();
it != elements.end(); ++it)
{
boost::apply_visitor(*this, *it->second);
}
@@ -151,11 +152,12 @@ struct print : public boost::static_visitor<>
inline void operator()(leaf const& n)
{
typedef typename leaf::values_type values_type;
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type const& elements = rtree::elements_get(n);
spaces(level) << "LEAF - L:" << level << " V:" << n.values.size() << " @:" << &n << '\n';
for (typename values_type::const_iterator it = n.values.begin();
it != n.values.end(); ++it)
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::print_indexable(os, tr(*it));

View File

@@ -167,7 +167,7 @@ private:
++m_current_level;
// next traversing step
boost::apply_visitor(*this, *n.children[choosen_node_index].second);
boost::apply_visitor(*this, *rtree::elements_get(n)[choosen_node_index].second);
// restore previous traverse inputs
m_parent = parent_bckup;

View File

@@ -54,35 +54,41 @@ struct save<
inline void operator()(internal_node & n)
{
os << n.children.size() << '\n';
typedef typename rtree::elements_type<internal_node>::type elements_type;
elements_type & elements = rtree::elements_get(n);
for ( size_t i = 0 ; i < n.children.size() ; ++i )
os << elements.size() << '\n';
for ( size_t i = 0 ; i < elements.size() ; ++i )
{
if ( boost::apply_visitor(visitors::is_leaf<value_type, Box, Tag>(), *(n.children[i].second)) )
if ( boost::apply_visitor(visitors::is_leaf<value_type, Box, Tag>(), *(elements[i].second)) )
os << "l ";
else
os << "i ";
os << geometry::get<min_corner, 0>(n.children[i].first) << ' ';
os << geometry::get<min_corner, 1>(n.children[i].first) << ' ';
os << geometry::get<max_corner, 0>(n.children[i].first) << ' ';
os << geometry::get<max_corner, 1>(n.children[i].first) << ' ';
os << geometry::get<min_corner, 0>(elements[i].first) << ' ';
os << geometry::get<min_corner, 1>(elements[i].first) << ' ';
os << geometry::get<max_corner, 0>(elements[i].first) << ' ';
os << geometry::get<max_corner, 1>(elements[i].first) << ' ';
boost::apply_visitor(*this, *(n.children[i].second));
boost::apply_visitor(*this, *(elements[i].second));
}
}
inline void operator()(leaf & n)
{
os << n.values.size() << '\n';
typedef typename rtree::elements_type<leaf>::type elements_type;
elements_type & elements = rtree::elements_get(n);
for ( size_t i = 0 ; i < n.values.size() ; ++i )
os << elements.size() << '\n';
for ( size_t i = 0 ; i < elements.size() ; ++i )
{
os << "v ";
os << geometry::get<min_corner, 0>(n.values[i].first) << ' ';
os << geometry::get<min_corner, 1>(n.values[i].first) << ' ';
os << geometry::get<max_corner, 0>(n.values[i].first) << ' ';
os << geometry::get<max_corner, 1>(n.values[i].first) << ' ';
os << n.values[i].second << '\n';
os << geometry::get<min_corner, 0>(elements[i].first) << ' ';
os << geometry::get<min_corner, 1>(elements[i].first) << ' ';
os << geometry::get<max_corner, 0>(elements[i].first) << ' ';
os << geometry::get<max_corner, 1>(elements[i].first) << ' ';
os << elements[i].second << '\n';
}
}

View File

@@ -8,9 +8,9 @@ int main()
{
tests_translators_hpp();
tests_rtree_native_hpp<boost::geometry::index::linear_tag>();
//tests_rtree_native_hpp<boost::geometry::index::rstar_tag>();
tests_rtree_native_hpp<boost::geometry::index::quadratic_tag>();
tests_rtree_filters_hpp();
/*
{
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
@@ -22,21 +22,21 @@ int main()
const int m = 15;
for ( int i = 0 ; i < m ; ++i )
{
bgi::insert(t, V(B(P(i*2, i*2), P(i*2+1, i*2+1)), i));
bgi::insert(t, V(B(P(i*2.0f, i*2.0f), P(i*2.0f+1, i*2.0f+1)), i));
}
std::cout << t << "\n------------------------------------\n";
std::cin.get();
for ( int i = 0 ; i < m ; ++i )
{
bgi::remove(t, V(B(P(i*2, i*2), P(i*2+1, i*2+1)), i));
bgi::remove(t, V(B(P(i*2.0f, i*2.0f), P(i*2.0f+1, i*2.0f+1)), i));
std::cout << t << '\n';
std::cout << ( boost::geometry::index::are_boxes_ok(t) ? "boxes OK" : "WRONG BOXES!" );
std::cout << "\n------------------------------------\n";
std::cin.get();
}
}
*/
#ifdef _MSC_VER
std::cin.get();
#endif