Advanced Multi-Physics (AMP)
On-Line Documentation
kdtree.h
Go to the documentation of this file.
1#ifndef included_AMP_kdtree
2#define included_AMP_kdtree
3
4#include <array>
5#include <cstdint>
6#include <iostream>
7#include <memory>
8#include <string>
9#include <vector>
10
11
12namespace AMP::Mesh {
13template<class TYPE>
14class MeshPoint; // Forward declare MeshPoint
15} // namespace AMP::Mesh
16
17
18namespace AMP {
19
20
32class kdtree
33{
34public:
35 // Empty constructor
36 kdtree() : d_dim( 0 ), d_N( 0 ), d_tree( nullptr ) {}
37
45 kdtree( int ndim, size_t N, const double *const *x );
46
52 kdtree( const std::vector<AMP::Mesh::MeshPoint<double>> &x );
53
56
58 kdtree( const kdtree & ) = delete;
59
62
64 kdtree &operator=( const kdtree & ) = delete;
65
68
69
77 static std::shared_ptr<kdtree> create2d( size_t N, const double *x, const double *y );
78
87 static std::shared_ptr<kdtree>
88 create3d( size_t N, const double *x, const double *y, const double *z );
89
90
92 std::vector<double> box() const;
93
94
101 void add( const double *x );
102
110
118 size_t find_nearest( const double *x, double *dist = nullptr, double *pos = nullptr ) const;
119
129 void find_nearest( int N,
130 const double *x,
131 size_t *index,
132 double *dist = nullptr,
133 double *pos = nullptr ) const;
134
141 size_t find_nearest2d( const double x, const double y ) const;
142
150 size_t find_nearest3d( const double x, const double y, const double z ) const;
151
152
153private: // Internal data
154 uint8_t d_dim;
155 size_t d_N;
156 void *d_tree;
157
158 // Find the nearest point in the tree to x
159 size_t find_nearest2( const double *x, double &dist, double *pos ) const;
160};
161
162
163} // namespace AMP
164
165
166#endif
A class used to to perform kd-tree based operations.
Definition kdtree.h:33
size_t find_nearest(const double *x, double *dist=nullptr, double *pos=nullptr) const
Search the tree for the nearest neighbor point.
kdtree(const std::vector< AMP::Mesh::MeshPoint< double > > &x)
Default constructor.
size_t find_nearest3d(const double x, const double y, const double z) const
Search the tree for the nearest neighbor point.
void * d_tree
Definition kdtree.h:156
uint8_t d_dim
Definition kdtree.h:154
std::vector< double > box() const
Function to return the bounding box for the tree.
static std::shared_ptr< kdtree > create2d(size_t N, const double *x, const double *y)
Constructor for 2d.
kdtree & operator=(const kdtree &)=delete
Assignment operator.
void add(const double *x)
Add a point.
void find_nearest(int N, const double *x, size_t *index, double *dist=nullptr, double *pos=nullptr) const
Search the tree for the nearest neighbor point.
~kdtree()
Destructor.
kdtree(const kdtree &)=delete
Copy constructor.
size_t find_nearest2(const double *x, double &dist, double *pos) const
size_t d_N
Definition kdtree.h:155
kdtree & operator=(kdtree &&)
Move operator.
kdtree(kdtree &&)
Move constructor.
kdtree(int ndim, size_t N, const double *const *x)
Default constructor.
size_t find_nearest2d(const double x, const double y) const
Search the tree for the nearest neighbor point.
static std::shared_ptr< kdtree > create3d(size_t N, const double *x, const double *y, const double *z)
Constructor for 3d.
AMP::Mesh::MeshPoint< double > find_nearest(const AMP::Mesh::MeshPoint< double > &p) const
Search the tree for the nearest neighbor point.



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page