deal.II version GIT relicensing-6759-gba22b5843e 2026-09-18 10:10:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor > Struct Template Reference

#include <deal.II/numerics/rtree.h>

Detailed Description

template<typename RTreeType, typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
struct RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >

A depth-first visitor for RTree that invokes user-provided lambdas.

For every RTree object, we distinguish between the root node, the internal nodes (i.e., nodes that have other nodes as children) and leaf nodes (i.e., nodes that store the actual leaf values). During the traversal of the tree, we may want to hook into the traversal at different levels of the hierarchy. For example, we may want to print the bounding box of each internal node, then print the bounding box of each leaf node, and then finally print each element stored in the leaf nodes.

This is a convenience visitor for the RTree data structure that forwards each traversal event to four (optional) independent callables:

The traversal is depth-first: starting from the root, internal nodes are visited, their children are recursed immediately, and leaf elements are delivered in the order stored inside each leaf node. This allows users to plug lambdas directly without defining a specific visitor class.

Example (taken from one of the tests): build a tree from 8 random points, then hook all four callbacks:

std::vector<Point<2>> pts(8); for (auto &p : pts) p = random_point<2>();
auto tree = pack_rtree_of_indices<bgi::linear<2>>(pts);
// internal node visitor auto internal = [](std::size_t level, auto &parent,
const BoundingBox<2> &box, auto &child) { std::cout << "Internal node (level
" << level << ") box " <<
Patterns::Tools::to_string(box.get_boundary_points()) << std::endl;
};
// leaf visitor auto leaf = [](std::size_t level, auto &, const
BoundingBox<2> &box, auto &) { std::cout << " Leaf (level " << level
<< ") box " << Patterns::Tools::to_string(box.get_boundary_points()) <<
std::endl;
};
// element visitor (receives the stored value) auto element = [](auto &,
const auto &value) { std::cout << " element " << value;
};
// indexable visitor (receives the indexable geometry) auto indexable =
[](auto &, const auto &indexable) { std::cout << ", indexable " << indexable
<< std::endl;
};
std::cout << "Visiting R-tree with " << pts.size() << " points, and " <<
n_levels(tree) << " levels." << std::endl;
visit_rtree(tree, internal, leaf, element, indexable);
unsigned int level
Definition grid_out.cc:4642
std::string to_string(const T &t)
Definition patterns.h:2450
void visit_rtree(const RTreeType &tree, InternalVisitor internal_node_visitor={}, LeafVisitor leaf_visitor={}, ElementVisitor element_visitor={}, IndexableVisitor indexable_visitor={})

A possible output (indices and boxes depend on the random points) is:

Internal node (level 0) box 0.277775, 0.197551 : 0.911647, 0.55397 Leaf
(level 1) box 0.277775, 0.513401 : 0.364784, 0.55397 element 4, indexable
0.277775 0.55397 element 6, indexable 0.364784 0.513401 Leaf (level 1)
box 0.840188, 0.197551 : 0.911647, 0.394383 element 0, indexable 0.840188
0.394383 element 2, indexable 0.911647 0.197551 Internal node (level 0)
box 0.335223, 0.628871 : 0.95223, 0.916195 Leaf (level 1) box 0.335223,
0.628871 : 0.477397, 0.76823 element 3, indexable 0.335223 0.76823
element 5, indexable 0.477397 0.628871 Leaf (level 1) box 0.783099,
0.79844 : 0.95223, 0.916195 element 1, indexable 0.783099 0.79844
element 7, indexable 0.95223 0.916195

This structure exists to make it easy to instrument or analyze an rtree (bounding boxes, counts, aggregations, debug prints, etc.) without writing the boilerplate of a custom visitor type every time.

Users can call directly the function visit_rtree() (see below) instead of instantiating this class.

Definition at line 422 of file rtree.h.

Inheritance diagram for RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >:
[legend]

Public Types

using internal_node_type = typename boost::geometry::index::detail::rtree::internal_node< typename RTreeView< RTreeType >::value_type, typename RTreeView< RTreeType >::options_type::parameters_type, typename RTreeView< RTreeType >::box_type, typename RTreeView< RTreeType >::allocators_type, typename RTreeView< RTreeType >::options_type::node_tag >::type
 
using leaf_type = typename boost::geometry::index::detail::rtree::leaf< typename RTreeView< RTreeType >::value_type, typename RTreeView< RTreeType >::options_type::parameters_type, typename RTreeView< RTreeType >::box_type, typename RTreeView< RTreeType >::allocators_type, typename RTreeView< RTreeType >::options_type::node_tag >::type
 
using value_type = typename RTreeType::value_type
 
using indexable_type = typename RTreeType::indexable_type
 
using translator_type = typename RTreeView< RTreeType >::translator_type
 
using empty_visitor = internal::RTreeImplementation::EmptyVisitor
 

Public Member Functions

void operator() (internal_node_type &node)
 
void operator() (leaf_type &leaf)
 
 RTreeFunctionalVisitor (const RTreeType &tree, InternalVisitor internal_node_visitor={}, LeafVisitor leaf_visitor={}, ElementVisitor element_visitor={}, IndexableVisitor indexable_visitor={})
 

Public Attributes

InternalVisitor internal_node_visitor
 
LeafVisitor leaf_visitor
 
ElementVisitor element_visitor
 
IndexableVisitor indexable_visitor
 
std::size_t current_level
 
translator_type translator
 

Static Public Attributes

static constexpr unsigned int dim
 
static constexpr bool has_internal_visitor
 
static constexpr bool has_leaf_visitor
 
static constexpr bool has_element_visitor
 
static constexpr bool has_indexable_visitor
 

Member Typedef Documentation

◆ internal_node_type

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
using RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::internal_node_type = typename boost::geometry::index::detail::rtree::internal_node< typename RTreeView<RTreeType>::value_type, typename RTreeView<RTreeType>::options_type::parameters_type, typename RTreeView<RTreeType>::box_type, typename RTreeView<RTreeType>::allocators_type, typename RTreeView<RTreeType>::options_type::node_tag>::type

Internal node type exposed by Boost for this R-tree configuration.

Definition at line 440 of file rtree.h.

◆ leaf_type

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
using RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::leaf_type = typename boost::geometry::index::detail::rtree::leaf< typename RTreeView<RTreeType>::value_type, typename RTreeView<RTreeType>::options_type::parameters_type, typename RTreeView<RTreeType>::box_type, typename RTreeView<RTreeType>::allocators_type, typename RTreeView<RTreeType>::options_type::node_tag>::type

Leaf type exposed by Boost for this R-tree configuration

Definition at line 451 of file rtree.h.

◆ value_type

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
using RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::value_type = typename RTreeType::value_type

Value stored in leaves (matches RTreeType::value_type).

Definition at line 461 of file rtree.h.

◆ indexable_type

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
using RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::indexable_type = typename RTreeType::indexable_type

Indexable geometry obtained from a value via the tree's getter.

Definition at line 466 of file rtree.h.

◆ translator_type

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
using RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::translator_type = typename RTreeView<RTreeType>::translator_type

Translator (indexable getter) associated with the tree view.

Definition at line 471 of file rtree.h.

◆ empty_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
using RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::empty_visitor = internal::RTreeImplementation::EmptyVisitor

Sentinel type used to detect empty visitors.

Definition at line 476 of file rtree.h.

Constructor & Destructor Documentation

◆ RTreeFunctionalVisitor()

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::RTreeFunctionalVisitor ( const RTreeType &  tree,
InternalVisitor  internal_node_visitor = {},
LeafVisitor  leaf_visitor = {},
ElementVisitor  element_visitor = {},
IndexableVisitor  indexable_visitor = {} 
)

Constructor wiring optional callbacks and starting a traversal of the provided rtree through apply_visitor().

You may call this constructor directly, but the preferred way is to use the visit_rtree() function below.

Member Function Documentation

◆ operator()() [1/2]

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
void RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::operator() ( internal_node_type node)

Implements the internal-node branch of the boost::geometry::index::detail::rtree::visitor interface so this functor can be passed to apply_visitor() when traversing an rtree.

◆ operator()() [2/2]

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
void RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::operator() ( leaf_type leaf)

Implements the leaf branch of the boost::geometry::index::detail::rtree::visitor interface so this functor can be passed to apply_visitor() when traversing an rtree.

Member Data Documentation

◆ dim

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
constexpr unsigned int RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::dim
staticconstexpr
Initial value:
=
boost::geometry::dimension<typename RTreeType::indexable_type>::value

Spatial dimension of the indexable geometry stored in the tree.

Definition at line 434 of file rtree.h.

◆ has_internal_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
constexpr bool RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::has_internal_visitor
staticconstexpr
Initial value:
=
!std::is_same_v<InternalVisitor, empty_visitor>

Compile-time flags indicating if internal visitor was provided.

Definition at line 481 of file rtree.h.

◆ has_leaf_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
constexpr bool RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::has_leaf_visitor
staticconstexpr
Initial value:
=
!std::is_same_v<LeafVisitor, empty_visitor>

Compile-time flags indicating if leaf visitor was provided.

Definition at line 487 of file rtree.h.

◆ has_element_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
constexpr bool RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::has_element_visitor
staticconstexpr
Initial value:
=
!std::is_same_v<ElementVisitor, empty_visitor>

Compile-time flags indicating if element visitor was provided.

Definition at line 493 of file rtree.h.

◆ has_indexable_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
constexpr bool RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::has_indexable_visitor
staticconstexpr
Initial value:
=
!std::is_same_v<IndexableVisitor, empty_visitor>

Compile-time flags indicating if indexable visitor was provided.

Definition at line 499 of file rtree.h.

◆ internal_node_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
InternalVisitor RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::internal_node_visitor

Optional callback invoked once per internal node, before descending into its children.

This function is only called when the child is an internal_node_type. If the child is a leaf_type, the leaf_visitor is called instead.

Arguments:

  • level: depth excluding the root (root's children are at level 0; the maximum value is n_levels(tree)-1),
  • parent_node: the internal node being visited (the current parent),
  • node_bounding_box: bounding box of the child about to be traversed,
  • node: the child internal node

Definition at line 516 of file rtree.h.

◆ leaf_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
LeafVisitor RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::leaf_visitor

Optional callback invoked once per leaf node, before iterating its elements.

Arguments mirror the internal callback, but the last argument is the child leaf node.

Definition at line 525 of file rtree.h.

◆ element_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
ElementVisitor RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::element_visitor

Optional callback invoked for each value stored in a leaf.

Arguments:

  • leaf: the leaf holding the value,
  • value: the stored value_type.

Definition at line 534 of file rtree.h.

◆ indexable_visitor

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
IndexableVisitor RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::indexable_visitor

Optional callback invoked for each value after translating it to the corresponding indexable type via the tree's indexable getter. If the tree is built without an indexable getter, this function is in fact identical to the element_visitor, and therefore both can be used interchangeably.

Arguments:

  • leaf: the leaf holding the value,
  • indexable: the Indexable associated with the value.

Definition at line 546 of file rtree.h.

◆ current_level

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
std::size_t RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::current_level

Definition at line 577 of file rtree.h.

◆ translator

template<typename RTreeType , typename InternalVisitor = internal::RTreeImplementation::EmptyVisitor, typename LeafVisitor = internal::RTreeImplementation::EmptyVisitor, typename ElementVisitor = internal::RTreeImplementation::EmptyVisitor, typename IndexableVisitor = internal::RTreeImplementation::EmptyVisitor>
translator_type RTreeFunctionalVisitor< RTreeType, InternalVisitor, LeafVisitor, ElementVisitor, IndexableVisitor >::translator

Definition at line 578 of file rtree.h.


The documentation for this struct was generated from the following file: