CGAL 4.5.2 - dD Range and Segment Trees
|
#include <CGAL/Segment_tree_k.h>
An object of the class Segment_tree_k
is a \( k\)-dimensional segment tree that can store k-dimensional intervals of type Interval
.
The class allows to perform window queries, enclosing queries, and inverse range queries on the keys. The class Segment_tree_k
is parameterized with a segment tree traits class Traits
that defines, among other things, the type of the Interval
. In order to perform an inverse range query, a range query of \( \epsilon\) width has to be performed. We prefered not to offer an extra function for this sort of query, since the inverse range query is a special case of the range query. Furthermore, offering an inverse range query in the segment tree class implies offering this function also in the range tree class and having an extra item in the traits class that accesses the inverse range query point.
CGAL provides traits class implementations that allow to use the segment tree with point classes from the CGAL kernel as keys. These classes are CGAL::Range_segment_tree_traits_set_2<R>
, CGAL::Range_segment_tree_traits_set_3<R>
, CGAL::Segment_tree_traits_map_2<R>
and CGAL::Segment_tree_traits_map_3<R>
. The concept RangeSegmentTreeTraits_d defines the requirements that segment tree traits classes must fulfill. This allows the advanced user to develop further segment tree traits classes.
Example
This example illustrates the use of the predefined segment tree on 3-dimensional interval data (with no value associated). After the definition of the traits type and tree type, some intervals are constructed and the tree is build according to the intervals. Then, a window query is performed and the query elements are given out.
Types | |
typedef Traits::Key | Key |
typedef Traits::Interval | Interval |
Creation | |
Segment_tree_k () | |
Introduces an empty segment tree S . | |
template<class ForwardIterator > | |
Segment_tree_k (ForwardIterator first, ForwardIterator last) | |
Introduces a segment tree S and initializes it with the data in the range [first, last) . More... | |
Operations | |
template<class ForwardIterator > | |
void | make_tree (ForwardIterator first, ForwardIterator last) |
Introduces a segment tree S and initializes it with the data in the range [first, last) . More... | |
template<class OutputIterator > | |
OutputIterator | window_query (Interval window, OutputIterator out) |
writes all intervals that have non empty intersection with interval window to the container where out points to, and returns an output iterator that points to the last location the function wrote to. More... | |
template<class OutputIterator > | |
OutputIterator | enclosing_query (Interval window, OutputIterator out) |
writes all intervals that enclose in the interval window to the container where out points to, and returns an output iterator that points to the last location the function wrote to. More... | |
CGAL::Segment_tree_k< Traits >::Segment_tree_k | ( | ForwardIterator | first, |
ForwardIterator | last | ||
) |
Introduces a segment tree S
and initializes it with the data in the range [first, last)
.
value_type(first) == Traits::Interval
. OutputIterator CGAL::Segment_tree_k< Traits >::enclosing_query | ( | Interval | window, |
OutputIterator | out | ||
) |
writes all intervals that enclose in the interval window
to the container where out
points to, and returns an output iterator that points to the last location the function wrote to.
value_type(out) == Traits::Interval
. void CGAL::Segment_tree_k< Traits >::make_tree | ( | ForwardIterator | first, |
ForwardIterator | last | ||
) |
Introduces a segment tree S
and initializes it with the data in the range [first, last)
.
This function can only be applied once on an empty segment tree.
value_type(first) == Traits::Interval
. OutputIterator CGAL::Segment_tree_k< Traits >::window_query | ( | Interval | window, |
OutputIterator | out | ||
) |
writes all intervals that have non empty intersection with interval window
to the container where out
points to, and returns an output iterator that points to the last location the function wrote to.
value_type(out) == Traits::Interval
.