16#ifndef dealii_numerics_rtree_h
17#define dealii_numerics_rtree_h
28#include <boost/geometry/algorithms/distance.hpp>
29#include <boost/geometry/index/rtree.hpp>
30#include <boost/geometry/strategies/strategies.hpp>
139template <
typename LeafType,
140 typename IndexType = boost::geometry::index::linear<16>,
141 typename IndexableGetter =
144 boost::geometry::index::rtree<LeafType, IndexType, IndexableGetter>;
153template <
typename IndexType = boost::geometry::index::linear<16>,
154 typename LeafTypeIterator,
155 typename IndexableGetter = boost::geometry::index::indexable<
156 typename LeafTypeIterator::value_type>>
158pack_rtree(
const LeafTypeIterator &begin,
const LeafTypeIterator &end);
170template <
typename IndexType = boost::geometry::index::linear<16>,
171 typename ContainerType,
172 typename IndexableGetter = boost::geometry::index::indexable<
173 typename ContainerType::value_type>>
195template <
typename Container>
214 using size_t =
typename Container::size_type;
275template <
typename IndexType = boost::geometry::index::linear<16>,
276 typename ContainerType>
277RTree<
typename ContainerType::size_type,
294template <
typename Value,
300 :
public boost::geometry::index::detail::rtree::visitor<
302 typename Options::parameters_type,
305 typename Options::node_tag,
321 typename boost::geometry::index::detail::rtree::internal_node<
323 typename Options::parameters_type,
326 typename Options::node_tag>::type;
331 using Leaf =
typename boost::geometry::index::detail::rtree::leaf<
333 typename Options::parameters_type,
336 typename Options::node_tag>::type;
369 std::vector<BoundingBox<boost::geometry::dimension<Box>::value>> &
boxes;
423template <
typename Rtree>
425 boost::geometry::dimension<typename Rtree::indexable_type>::value>>
433template <
typename IndexType,
434 typename LeafTypeIterator,
435 typename IndexableGetter>
437pack_rtree(
const LeafTypeIterator &begin,
const LeafTypeIterator &end)
439 return RTree<
typename LeafTypeIterator::value_type,
441 IndexableGetter>(begin, end);
446template <
typename IndexType,
typename ContainerType,
typename IndexableGetter>
450 return pack_rtree<IndexType,
decltype(container.begin()), IndexableGetter>(
451 container.begin(), container.end());
456template <
typename IndexType,
typename ContainerType>
457RTree<
typename ContainerType::size_type,
463 typename ContainerType::size_type>
464 indices(0, container.size());
465 return RTree<
typename ContainerType::size_type,
476template <
typename Value,
483 const Translator & translator,
484 const unsigned int target_level,
485 std::vector<
BoundingBox<boost::geometry::dimension<Box>::value>> &boxes)
486 : translator(translator)
488 , target_level(target_level)
494template <
typename Value,
504 typename boost::geometry::index::detail::rtree::elements_type<
507 const auto &elements = boost::geometry::index::detail::rtree::elements(node);
509 if (
level == target_level)
511 const auto offset = boxes.size();
512 boxes.resize(offset + elements.size());
514 unsigned int i = offset;
515 for (
typename ElementsType::const_iterator it = elements.begin();
516 it != elements.end();
519 boost::geometry::convert(it->first, boxes[i]);
525 const size_t level_backup =
level;
528 for (
typename ElementsType::const_iterator it = elements.begin();
529 it != elements.end();
532 boost::geometry::index::detail::rtree::apply_visitor(*
this, *it->second);
535 level = level_backup;
538template <
typename Value,
550template <
typename Rtree>
552 boost::geometry::dimension<typename Rtree::indexable_type>::value>>
555 constexpr unsigned int dim =
556 boost::geometry::dimension<typename Rtree::indexable_type>::value;
559 boost::geometry::index::detail::rtree::utilities::view<Rtree>;
562 std::vector<BoundingBox<dim>> boxes;
564 if (rtv.depth() == 0)
570 boost::geometry::convert(tree.bounds(), boxes[0]);
574 const unsigned int target_level =
575 std::min<unsigned int>(
level, rtv.depth() - 1);
578 typename RtreeView::options_type,
579 typename RtreeView::translator_type,
580 typename RtreeView::box_type,
581 typename RtreeView::allocators_type>
582 extract_level_visitor(rtv.translator(), target_level, boxes);
583 rtv.apply_visitor(extract_level_visitor);
591template <
class Rtree>
593n_levels(
const Rtree &tree)
595 boost::geometry::index::detail::rtree::utilities::view<Rtree> rtv(tree);
result_type operator()(size_t i) const
const Container & container
typename Container::size_type size_t
typename boost::geometry::index::indexable< typename Container::value_type > IndexableGetter
typename IndexableGetter::result_type result_type
IndexableGetterFromIndices(Container const &c)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
boost::integer_range< IncrementableType > iota_view
std::vector< BoundingBox< boost::geometry::dimension< typename Rtree::indexable_type >::value > > extract_rtree_level(const Rtree &tree, const unsigned int level)
boost::geometry::index::rtree< LeafType, IndexType, IndexableGetter > RTree
RTree< typename LeafTypeIterator::value_type, IndexType, IndexableGetter > pack_rtree(const LeafTypeIterator &begin, const LeafTypeIterator &end)
RTree< typename ContainerType::size_type, IndexType, IndexableGetterFromIndices< ContainerType > > pack_rtree_of_indices(const ContainerType &container)