|
latest version v1.9 - last update 24 Nov 2005 |
|
#include <ltiKdTree.h>
Inheritance diagram for lti::kdTree< T, D, U >:


Public Types | |
| typedef T::value_type | value_type |
| typedef typeInfo< value_type >::accumulation_type | acc_type |
| typedef int | size_type |
Public Member Functions | |
| kdTree () | |
| kdTree (const kdTree &other) | |
| virtual | ~kdTree () |
| virtual const char * | getTypeName () const |
| kdTree & | copy (const kdTree &other) |
| kdTree & | operator= (const kdTree &other) |
| virtual mathObject * | clone () const |
| virtual void | clear () |
| virtual bool | empty () const |
| virtual int | getNumberOfAddedElements () const |
| virtual int | size () const |
| virtual int | getNumberOfLeaves () const |
| virtual int | getLevels () const |
| virtual node * | getRoot () |
| void | add (const T &point, const D &data) |
| bool | build (const int bucketSize=1) |
| bool | rebuild (const int bucketSize=1) |
| virtual bool | read (ioHandler &handler, const bool complete=true) |
| virtual bool | write (ioHandler &handler, const bool complete=true) const |
Search methods | |
| bool | searchExactly (const T &key, element &elem) const |
| bool | searchExactly (const T &key, std::list< element > &elems) const |
| bool | searchNearest (const T &key, element *&elem) const |
| bool | searchNearest (const T &key, element *&elem, acc_type &dist) const |
| bool | searchNearest (const T &key, element &elem) const |
| bool | searchNearest (const T &key, element &elem, acc_type &dist) const |
| bool | searchNearest (const T &key, D &data) const |
| bool | searchNearest (const int k, const T &key, std::list< element * > &neighbors) const |
| bool | searchNearest (const int k, const T &key, std::multimap< acc_type, element * > &neighbors) const |
| bool | searchWithin (const T &key, const acc_type &dist, std::list< element * > &elems) const |
| bool | searchWithin (const T &key, const acc_type &dist, std::multimap< acc_type, element * > &neighbors) const |
| bool | searchBestBinFirst (const int k, const T &key, const int emax, std::list< element * > &neighbors) const |
| bool | searchBestBinFirst (const int k, const T &key, const int emax, std::multimap< acc_type, element * > &neighbors) const |
| bool | searchRange (const T &boxMin, const T &boxMax, std::list< element * > &neighbors) const |
Protected Attributes | |
| node * | root |
| int | levels |
| int | numElements |
| int | numAddedElements |
| int | numLeaves |
| matrix< value_type > | totalBounds |
| std::list< element * > | points |
| U | distantor |
Classes | |
| class | element |
| At the leave nodes, a list of elements of this type will contain the points and their corresponding data. More... | |
| class | node |
| Class of nodes of the kd-tree. More... | |
A k-d tree is a generalization of the simple binary tree used for sorting and searching. At each level of the tree, a n-dimensional subspace is split in two subspaces at a given dimension. The leaves of the tree contain a "bucket" of data within the described subspace.
You can consider data for building with the add() method. Then you can either build() the tree from that data, discarding the old data, or rebuild() the tree, which will then contain the data added since the last call to build() or rebuild() plus the newly added data.
This type allows to search in an efficient way for the more similar neighbors of a given point.
The type T describes a point in an n-dimensional space. Usually, you will use vector<float> or vector<double>, but types like rgbPixel, trgbPixel<float>, tpoint<float> are also supported. The type T MUST provide following methods/operators:
value_type, which describes the type of each element in the container.(lti::vector, lti::tpoint, lti::tpoint3D, lti::trgbpixel and lti::rgbPixel provide this interface)
The type D describes the data contained at each node, which is per default just an integer value. It must provide following methods/operators
The type U specifies a "distantor" policy, i.e. it specifies the distance to be used while computing the nearest neighbors. If not given, the default value will be l2SquareDistantor, which provides, as the name says, the square of the euclidian distance. Only Minkowski distances are allowed. If you need your own distance measure you can create your policy following the interfaces of one of the classes lti::l2Distantor, lti::l1Distantor or l2SquareDistantor.
|
|||||
|
Type used to accumulate data of value_type elements.
|
|
|||||
|
Return type of the size() member.
|
|
|||||
|
Value type at each dimension of the space.
|
|
|||||||||
|
Default constructor.
|
|
||||||||||
|
Copy constructor.
|
|
|||||||||
|
Destructor.
|
|
||||||||||||||||
|
Consider the given element to be inserted in the tree after calling the build(const int) method. The dimensionality of each point MUST be equal than the one first added, otherwise an assertion will be thrown when building the tree.
|
|
||||||||||
|
Build the kd-Tree for all nodes added with the add() method, using the given bucket size as the maximum number of elements a node can contain. The previous tree will be destroyed before the new one is constructed. the
|
|
|||||||||
|
Clear the tree. All elements belonging to the tree will be removed. Also all elements added until now will be deleted. |
|
|||||||||
|
Returns a pointer to a clone of this functor.
Implements lti::mathObject. |
|
||||||||||
|
Copy data of "other" functor.
|
|
|||||||||
|
Check if the tree is empty.
|
|
|||||||||
|
Get the number of levels of the tree. Return zero if the tree hasn't been build yet. |
|
|||||||||
|
Get the number of elements added to the tree with the function add(). Note that these points are not really in the tree until you call build() or rebuild(). After calling either the added points are flushed and the return value of this function is zero.
|
|
|||||||||
|
Get the number of leaves in the tree. Return zero if the tree hasn't been build yet. |
|
|||||||||
|
Get pointer to root node. Return a null pointer if the tree hasn't been build yet. |
|
|||||||||
|
Returns the name of this type ("kdTree").
Reimplemented from lti::mathObject. |
|
||||||||||
|
Alias for copy member.
|
|
||||||||||||||||
|
Read the parameters from the given ioHandler.
Reimplemented from lti::mathObject. |
|
||||||||||
|
Rebuild the kd-Tree for all elements added with the add() method and those already present in the tree, using the given bucket size as the maximum number of elements a node can contain. Although the previous tree will be destroyed before the new one is constructed it will contain all elements contained in the old one. Rebuilding the tree is quite slow since the elements have to be extracted and copied from the existing tree first. This is necessary since a kd-tree needs to know the complete set of data for building.
|
|
||||||||||||||||||||||||
|
Search the best-bin-first algorithm of Beis and Lowe. Use this method only if the dimensionality of your data is high enough. The time savings take effect only if the kd-tree is big enough and the dimensionality of the data too. Make a few tests with your data in order to detect if this approximation is good enough and fast enough for you. Otherwise use the traditional search with searchNearest()
|
|
||||||||||||||||||||||||
|
Search the best-bin-first algorithm of Beis and Lowe. Use this method only if the dimensionality of your data is high enough. The time savings take effect only if the kd-tree is big enough and the dimensionality of the data too. Make a few tests with your data in order to detect if this approximation is good enough and fast enough for you. Otherwise use the traditional search with searchNearest()
|
|
||||||||||||||||
|
Search for all elements with exactly the given position in the hyperspace. This is the classical search in a kd-tree, that assumes that a leaf node contains exactly the given point. If found, the contents of the element will by copied in the elem attributes and true will be returned. Otherwise false will be returned.
|
|
||||||||||||||||
|
Search for an element with exactly the given position in the hyperspace. This is the classical search in a kd-tree, that assumes that a leaf node contains exactly the given point. If found, the contents of the element will by copied in the elem attributes and true will be returned. Otherwise false will be returned. If the key is present more than once, only the "first" one will be returned, which is the first one the list of points at the left-most node containing it.
|
|
||||||||||||||||||||
|
Search for the nearest k elements in the tree to the given key point. If you are looking just for the nearest elements (i.e. k=1) use the searchNearest(const T&,D&) or searchNearest(const T&,element&) methods instead. They are optimized for this case and are much faster.
|
|
||||||||||||||||||||
|
Search for the nearest k elements in the tree to the given key point. If you are looking just for the nearest elements (i.e. k=1) use the searchNearest(const T&,D&) or searchNearest(const T&,element&) methods instead. They are optimized for this case and are much faster.
|
|
||||||||||||||||
|
Search for the nearest element in the tree to the given key point. If found, the contents of the element will by copied in the elem parameters and true will be returned. Otherwise false will be returned.
|
|
||||||||||||||||||||
|
Search for the nearest element in the tree to the given key point. If found, the contents of the element will by copied in the elem parameters and true will be returned. Otherwise false will be returned.
|
|
||||||||||||||||
|
Search for the nearest element in the tree to the given key point. If found, the contents of the element will by copied in the elem parameters and true will be returned. Otherwise false will be returned.
|
|
||||||||||||||||||||
|
Search for the nearest element in the tree to the given key point. If found, a pointer to the element will be written in the elem parameters and true will be returned. Otherwise false will be returned and the pointer will be set to zero. The pointer is not const to allow you to change the data of the element, but if you also change the point the tree will be corrupted and will not work appropriately. There is no way to change the search keys dynamically in a kd-tree without a heavy load of computation. If that is what you are looking for, you should consider rebuilding the entire tree (expensive!).
|
|
||||||||||||||||
|
Search for the nearest element in the tree to the given key point. If found, a pointer to the element will be written in the elem parameters and true will be returned. Otherwise false will be returned and the pointer will be set to zero. The pointer is not const to allow you to change the data of the element, but if you also change the point, the tree will be corrupted and will not work appropriately. There is no way to change the search keys dynamically in a kd-tree without a heavy load of computation. If that is what you are looking for, you should consider rebuilding the entire tree (expensive!).
|
|
||||||||||||||||||||
|
Search for all points lying within the given hyperbox.
|
|
||||||||||||||||||||
|
Search for elements in an hyper-spheric neighbourhood of a given key point, i.e. search for all elements that reside within a hypersphere with the given radius centered at the given key. Note that the hypersphere is always defined using an Euclidean distance, no matter of the specified distanctor policy. The returned multimap is always sorted in ascending order of the distances (this is a property of all std::multimaps). If you want to save some time and don't need the sorted data consider using the other searchWithin() method, which stores the result in a std::list.
|
|
||||||||||||||||||||
|
Search for elements in an hyper-spheric neighbourhood of a given key point, i.e. search for all elements that reside within a hypersphere with the given radius centered at the given key. Note that the hypersphere is always defined using an Euclidean distance, no matter of the specified distanctor policy. The returned list of elements is not sorted. If you need it sorted you should use the searchWithin() method with the multimap result.
|
|
|||||||||
|
Get the number of elements in the built tree. Note that this value can differ substantially from the value returned by getNumberOfAddedElements(). The latter don't belong to the tree yet. Thus, adding elements, then calling build and then adding more elements, generally results in two different values. The return value is zero if no tree has been built yet.
|
|
||||||||||||||||
|
Write the parameters in the given ioHandler.
Reimplemented from lti::mathObject. |
|
|||||
|
Instance of the policy class used for computing the distances.
|
|
|||||
|
Number of levels in the tree.
|
|
|||||
|
Number of elements added to the tree (see add()).
|
|
|||||
|
Number of elements contained in the tree.
|
|
|||||
|
Number of leaf nodes in the tree.
|
|
|||||
|
Elements that will be contained in the tree. All nodes contain pointers to the elements objects, that will be transfered to the nodes in the tree with the build method. Thereafter, this list will be empty. |
|
|||||
|
The root node.
|
|
|||||
|
Bounding Box After creating the tree with build(), this matrix will be a 2 x n matrix containing at the first row the minimum possible values for the current type, and the second row the maximum values.
|