A class used to to perform kd-tree based operations. More...
#include <kdtree2.h>

Classes | |
| struct | data_struct |
Public Types | |
| using | Point = std::array< double, NDIM > |
Public Member Functions | |
| void | add (const Point &x, const TYPE &data) |
| Add a point. | |
| std::array< double, 2 *NDIM > | box () const |
| Return the bounding box for the tree. | |
| bool | empty () const |
| Return true if the tree is empty. | |
| std::tuple< Point, TYPE > | findNearest (const Point &x) const |
| Search the tree for the nearest neighbor point. | |
| std::vector< std::tuple< Point, TYPE > > | findNearest (const Point &x, double dist) const |
| Search the tree for the nearest neighbor points. | |
| std::vector< std::tuple< Point, TYPE > > | findNearest (const Point &x, int N) const |
| Search the tree for the nearest neighbor points. | |
| std::vector< std::tuple< Point, TYPE > > | findNearestRay (const Point &x, const Point &dir, double dist) const |
| Search the tree for the nearest points to a ray. | |
| std::vector< Point > | getPoints () const |
| Return the points in the tree. | |
| std::vector< std::pair< Point, TYPE > > | getPointsAndData () const |
| Return the points in the tree. | |
| kdtree2 ()=default | |
| kdtree2 (const kdtree2 &)=delete | |
| kdtree2 (const std::vector< Point > &x, const std::vector< TYPE > &data) | |
| Constructor. | |
| kdtree2 (kdtree2 &&)=default | |
| kdtree2 & | operator= (const kdtree2 &)=delete |
| kdtree2 & | operator= (kdtree2 &&)=default |
| size_t | size () const |
| Return the number of entries stored in the tree. | |
| ~kdtree2 ()=default | |
Private Member Functions | |
| void | checkNearest (const Point &x, size_t N, std::tuple< Point, TYPE > *nearest, double *dist) const |
| void | findNearest (const Point &x, double dist2, std::vector< std::tuple< Point, TYPE > > &nearest) const |
| void | findNearest (const Point &x, size_t N, std::tuple< Point, TYPE > *nearest, double *dist) const |
| void | findNearestRay (const Point &x, const Point &dir, const Point &n_inv, double dist2, std::vector< std::tuple< Point, TYPE > > &nearest) const |
| void | getPoints (std::vector< Point > &x) const |
| void | getPoints (std::vector< std::pair< Point, TYPE > > &x) const |
| void | initialize (size_t N, Point *x, TYPE *data) |
| bool | intersect (const Point &x, double dist2) const |
| kdtree2 (size_t N, Point *x, TYPE *data) | |
| void | splitData (size_t N, Point *x, TYPE *data) |
Private Attributes | |
| std::unique_ptr< data_struct > | d_data |
| Point | d_lb = { 0 } |
| std::unique_ptr< kdtree2 > | d_left |
| size_t | d_N = 0 |
| std::unique_ptr< kdtree2 > | d_right |
| double | d_split = 0 |
| uint8_t | d_split_dim = 0 |
| Point | d_ub = { 0 } |
A class used to to perform kd-tree based operations.
This class provides routines for creating and search a kd-tree. The kdtree allows for log(N) nearest neighbor search. The memory requirements for this class are O(N) on the number of points. The search performance for small dimension data is O(log(N)). For high dimension data, the number of points should be N >> 2^d where d is the dimension. Otherwise the performance will degrade approaching O(N).
| using AMP::kdtree2< NDIM, TYPE >::Point = std::array<double, NDIM> |
| AMP::kdtree2< NDIM, TYPE >::kdtree2 | ( | const std::vector< Point > & | x, |
| const std::vector< TYPE > & | data | ||
| ) |
Constructor.
This is the default constructor for creating the kdtree
| [in] | x | The coordinates of each point in the tree |
| [in] | data | Data to associate with the nodes |
|
default |
|
default |
|
delete |
|
default |
|
private |
| void AMP::kdtree2< NDIM, TYPE >::add | ( | const Point & | x, |
| const TYPE & | data | ||
| ) |
Add a point.
This will add a point to the kdtree. Note that no rebalancing will be performed
| [in] | x | The coordinates of the point |
| [in] | data | The data to add |
| std::array< double, 2 *NDIM > AMP::kdtree2< NDIM, TYPE >::box | ( | ) | const |
Return the bounding box for the tree.
|
private |
|
inline |
Return true if the tree is empty.
Definition at line 48 of file kdtree2.h.
References AMP::kdtree2< NDIM, TYPE >::d_N.
| std::tuple< Point, TYPE > AMP::kdtree2< NDIM, TYPE >::findNearest | ( | const Point & | x | ) | const |
Search the tree for the nearest neighbor point.
This will return the point and data for the nearest neighbor in the tree
| [in] | x | The coordinates of the point to search (NDIM) |
| std::vector< std::tuple< Point, TYPE > > AMP::kdtree2< NDIM, TYPE >::findNearest | ( | const Point & | x, |
| double | dist | ||
| ) | const |
Search the tree for the nearest neighbor points.
This will return the point and data for the all the points within the distance to the point x
| [in] | x | The coordinates of the point to search (NDIM) |
| [in] | dist | The distance to the point |
|
private |
| std::vector< std::tuple< Point, TYPE > > AMP::kdtree2< NDIM, TYPE >::findNearest | ( | const Point & | x, |
| int | N | ||
| ) | const |
Search the tree for the nearest neighbor points.
This will return the point and data for the nearest N neighbors in the tree
| [in] | x | The coordinates of the point to search (NDIM) |
| [in] | N | The number of points to return |
|
private |
|
private |
| std::vector< std::tuple< Point, TYPE > > AMP::kdtree2< NDIM, TYPE >::findNearestRay | ( | const Point & | x, |
| const Point & | dir, | ||
| double | dist | ||
| ) | const |
Search the tree for the nearest points to a ray.
This function will return all points within the given distance to the ray
| [in] | x | The coordinates of the starting point (NDIM) |
| [in] | dir | The direction vector (NDIM) |
| [in] | dist | The distance to search |
| std::vector< Point > AMP::kdtree2< NDIM, TYPE >::getPoints | ( | ) | const |
Return the points in the tree.
|
private |
|
private |
| std::vector< std::pair< Point, TYPE > > AMP::kdtree2< NDIM, TYPE >::getPointsAndData | ( | ) | const |
Return the points in the tree.
|
private |
|
private |
|
delete |
|
default |
|
inline |
Return the number of entries stored in the tree.
Definition at line 45 of file kdtree2.h.
References AMP::kdtree2< NDIM, TYPE >::d_N.
|
private |
|
private |
|
private |
|
private |
|
private |
Definition at line 127 of file kdtree2.h.
Referenced by AMP::kdtree2< NDIM, TYPE >::empty(), and AMP::kdtree2< NDIM, TYPE >::size().
|
private |
|
private |
|
private |
|
private |
|
Advanced Multi-Physics (AMP) Oak Ridge National Laboratory Idaho National Laboratory Los Alamos National Laboratory |
This page automatically produced from the source code by Last updated: Tue Mar 10 2026 13:06:42. Comments on this page |