|
ACTS
Experiment-independent tracking
|
A general k-d tree with fast range search. More...
#include <Acts/Utilities/KDTree.hpp>
Public Types | |
| using | const_iterator_t = typename vector_t::const_iterator |
| Type alias for const iterator over coordinate-value pairs. | |
| using | coordinate_t = Vector<Scalar, Dims> |
| The type of coordinates for points. | |
| using | iterator_t = typename vector_t::iterator |
| The type of iterators in our vectors. | |
| using | pair_t = std::pair<coordinate_t, Type> |
| The type of coordinate-value pairs. | |
| using | range_t = RangeXD<Dims, Scalar> |
| The type describing a multi-dimensional orthogonal range. | |
| using | value_t = Type |
| The type of value contained in this k-d tree. | |
| using | vector_t = std::vector<pair_t> |
| The type of a vector of coordinate-value pairs. | |
Public Member Functions | |
| KDTree ()=delete | |
| KDTree (vector_t &&d) | |
| Construct a k-d tree from a vector of position-value pairs. | |
| const_iterator_t | begin (void) const |
| Get iterator to first element. | |
| const_iterator_t | end (void) const |
| Get iterator to one past the last element. | |
| std::vector< Type > | rangeSearch (const range_t &r) const |
| Perform an orthogonal range search within the k-d tree. | |
| void | rangeSearch (const range_t &r, std::vector< Type > &v) const |
| Perform an in-place orthogonal range search within the k-d tree. | |
| template<typename OutputIt> | |
| void | rangeSearchInserter (const range_t &r, OutputIt i) const |
| Perform an orthogonal range search within the k-d tree, writing the resulting values to an output iterator. | |
| template<typename OutputIt> | |
| void | rangeSearchInserterWithKey (const range_t &r, OutputIt i) const |
| Perform an orthogonal range search within the k-d tree, writing the resulting values to an output iterator, including the keys. | |
| template<typename Result> | |
| std::vector< Result > | rangeSearchMap (const range_t &r, std::function< Result(const coordinate_t &, const Type &)> f) const |
| Perform an orthogonal range search within the k-d tree, applying a mapping function to the values found. | |
| template<typename Callable> | |
| void | rangeSearchMapDiscard (const range_t &r, Callable &&f) const |
| Perform an orthogonal range search within the k-d tree, applying a a void-returning function with side-effects to each key-value pair. | |
| template<typename Result, typename OutputIt> | |
| void | rangeSearchMapInserter (const range_t &r, std::function< Result(const coordinate_t &, const Type &)> f, OutputIt i) const |
| Perform an orthogonal range search within the k-d tree, applying a mapping function to the values found, and inserting them into an inserter. | |
| std::vector< pair_t > | rangeSearchWithKey (const range_t &r) const |
| Perform an orthogonal range search within the k-d tree, returning keys as well as values. | |
| void | rangeSearchWithKey (const range_t &r, std::vector< pair_t > &v) const |
| Perform an in-place orthogonal range search within the k-d tree, including keys in the result. | |
| std::size_t | size (void) const |
| Return the number of elements in the k-d tree. | |
A general k-d tree with fast range search.
This is a generalized k-d tree, with a configurable number of dimension, scalar type, content type, index type, vector type, and leaf size. This class is purposefully generalized to support a wide range of use cases.
A k-d tree is, in essence, a k-dimensional binary search tree. Each internal node splits the content of the tree in half, with the pivot point being an orthogonal hyperplane in one of the k dimensions. This allows us to efficiently look up points within certain k-dimensional ranges.
This particular class is mostly a wrapper class around an underlying node class which does all the actual work.
| Dims | The number of dimensions. |
| Type | The type of value contained in the tree. |
| Scalar | The scalar type used to construct position vectors. |
| Vector | The general vector type used to construct coordinates. |
| LeafSize | The maximum number of elements stored in a leaf node. |
| using Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::const_iterator_t = typename vector_t::const_iterator |
Type alias for const iterator over coordinate-value pairs.
| using Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::coordinate_t = Vector<Scalar, Dims> |
The type of coordinates for points.
| using Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::iterator_t = typename vector_t::iterator |
The type of iterators in our vectors.
| using Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::pair_t = std::pair<coordinate_t, Type> |
The type of coordinate-value pairs.
| using Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::range_t = RangeXD<Dims, Scalar> |
The type describing a multi-dimensional orthogonal range.
| using Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::value_t = Type |
The type of value contained in this k-d tree.
| using Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::vector_t = std::vector<pair_t> |
The type of a vector of coordinate-value pairs.
|
delete |
|
explicit |
Construct a k-d tree from a vector of position-value pairs.
This constructor takes an r-value reference to a vector of position-value pairs and constructs a k-d tree from those pairs.
| d | The vector of position-value pairs to construct the k-d tree from. |
| const_iterator_t Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::begin | ( | void | ) | const |
Get iterator to first element.
| const_iterator_t Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::end | ( | void | ) | const |
Get iterator to one past the last element.
| std::vector< Type > Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearch | ( | const range_t & | r | ) | const |
Perform an orthogonal range search within the k-d tree.
A range search operation is one that takes a k-d tree and an orthogonal range, and returns all values associated with coordinates in the k-d tree that lie within the orthogonal range. k-d trees can do this operation quickly.
| r | The range to search for. |
| void Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearch | ( | const range_t & | r, |
| std::vector< Type > & | v ) const |
Perform an in-place orthogonal range search within the k-d tree.
This range search module operates in place, writing its results to the given output vector.
| r | The range to search for. |
| v | The vector to write the output to. |
| void Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearchInserter | ( | const range_t & | r, |
| OutputIt | i ) const |
Perform an orthogonal range search within the k-d tree, writing the resulting values to an output iterator.
This method allows the user more control in where the result is written to.
| OutputIt | The type of the output iterator. |
| r | The range to search for. |
| i | The iterator to write the output to. |
| void Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearchInserterWithKey | ( | const range_t & | r, |
| OutputIt | i ) const |
Perform an orthogonal range search within the k-d tree, writing the resulting values to an output iterator, including the keys.
Performs the same operation as the keyless version, but includes the key in the output.
| OutputIt | The type of the output iterator. |
| r | The range to search for. |
| i | The iterator to write the output to. |
| std::vector< Result > Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearchMap | ( | const range_t & | r, |
| std::function< Result(const coordinate_t &, const Type &)> | f ) const |
Perform an orthogonal range search within the k-d tree, applying a mapping function to the values found.
In some cases, we may wish to transform the values in some way. This method allows the user to provide a mapping function which takes a set of coordinates and a value and transforms them to a new value, which is returned.
| Result | The return type of the map operation. |
| r | The range to search for. |
| f | The mapping function to apply to key-value pairs. |
| void Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearchMapDiscard | ( | const range_t & | r, |
| Callable && | f ) const |
Perform an orthogonal range search within the k-d tree, applying a a void-returning function with side-effects to each key-value pair.
This is the most general version of range search in this class, and every other operation can be reduced to this operation as long as we allow arbitrary side-effects.
Functional programmers will know this method as mapM_.
| r | The range to search for. |
| f | The mapping function to apply to key-value pairs. |
| void Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearchMapInserter | ( | const range_t & | r, |
| std::function< Result(const coordinate_t &, const Type &)> | f, | ||
| OutputIt | i ) const |
Perform an orthogonal range search within the k-d tree, applying a mapping function to the values found, and inserting them into an inserter.
Performs the same operation as the interter-less version, but allows the user additional control over the insertion process.
| Result | The return type of the map operation. |
| OutputIt | The type of the output iterator. |
| r | The range to search for. |
| f | The mapping function to apply to key-value pairs. |
| i | The inserter to insert the results into. |
| std::vector< pair_t > Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearchWithKey | ( | const range_t & | r | ) | const |
Perform an orthogonal range search within the k-d tree, returning keys as well as values.
Performs the same logic as the keyless version, but includes a copy of the key with each element.
| r | The range to search for. |
| void Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::rangeSearchWithKey | ( | const range_t & | r, |
| std::vector< pair_t > & | v ) const |
Perform an in-place orthogonal range search within the k-d tree, including keys in the result.
Performs the same operation as the keyless version, but includes the keys in the results.
| r | The range to search for. |
| v | The vector to write the output to. |
| std::size_t Acts::KDTree< Dims, Type, Scalar, Vector, LeafSize >::size | ( | void | ) | const |
Return the number of elements in the k-d tree.
We simply defer this method to the root node of the k-d tree.