Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Garfield::KDTree Class Reference

#include <KDTree.hh>

Public Member Functions

 KDTree ()=delete
 
 KDTree (KDTreeArray &data_in)
 Constructor.
 
 ~KDTree ()
 Destructor.
 
void n_nearest (const std::vector< double > &qv, const unsigned int nn, std::vector< KDTreeResult > &result) const
 
void n_nearest_around_point (const unsigned int idx, const unsigned int ndecorrel, const unsigned int nn, std::vector< KDTreeResult > &result) const
 
void r_nearest (const std::vector< double > &qv, const double r2, std::vector< KDTreeResult > &result) const
 
void r_nearest_around_point (const unsigned int idx, const unsigned int ndecorrel, const double r2, std::vector< KDTreeResult > &result) const
 

Public Attributes

const KDTreeArraym_data
 
size_t m_dim
 
bool sort_results = false
 

Friends

class KDTreeNode
 

Detailed Description

Main k-d tree class. Fast search of points in k-dimensional Euclidean space.

Definition at line 34 of file KDTree.hh.

Constructor & Destructor Documentation

◆ KDTree() [1/2]

Garfield::KDTree::KDTree ( )
delete

◆ KDTree() [2/2]

Garfield::KDTree::KDTree ( KDTreeArray data_in)

Constructor.

Definition at line 35 of file KDTree.cc.

36 : m_data(data_in) {
37
38 const size_t n = data_in.size();
39 if (!data_in.empty()) {
40 m_dim = data_in[0].size();
41 }
42
43 m_ind.resize(n);
44 for (size_t i = 0; i < n; i++) m_ind[i] = i;
45 // Build the tree.
46 m_root = build_tree_for_range(0, n - 1, 0);
47}
const KDTreeArray & m_data
Definition: KDTree.hh:37
size_t m_dim
Definition: KDTree.hh:39

◆ ~KDTree()

Garfield::KDTree::~KDTree ( )

Destructor.

Definition at line 50 of file KDTree.cc.

50 {
51 delete m_root;
52}

Member Function Documentation

◆ n_nearest()

void Garfield::KDTree::n_nearest ( const std::vector< double > &  qv,
const unsigned int  nn,
std::vector< KDTreeResult > &  result 
) const

Search for nn nearest neighbours around a point.

Parameters
qvinput point
nnnumber of nearest neighbours
resultindices and distances of the nearest neighbours

Definition at line 174 of file KDTree.cc.

176 {
177 // Search for n nearest to a given query vector 'qv'.
178 std::priority_queue<KDTreeResult> res;
179 double r2 = std::numeric_limits<double>::max();
180 m_root->search_n(-1, 0, nn, r2, qv, *this, res);
181 result.clear();
182 while (!res.empty()) {
183 result.push_back(res.top());
184 res.pop();
185 }
186 if (sort_results) sort(result.begin(), result.end());
187}
bool sort_results
Definition: KDTree.hh:40

Referenced by Garfield::ComponentComsol::Initialise(), Garfield::ComponentComsol::SetDelayedWeightingPotential(), and Garfield::ComponentComsol::SetWeightingField().

◆ n_nearest_around_point()

void Garfield::KDTree::n_nearest_around_point ( const unsigned int  idx,
const unsigned int  ndecorrel,
const unsigned int  nn,
std::vector< KDTreeResult > &  result 
) const

Search for nn nearest neighbours around a node of the input data, excluding neighbors within a decorrelation interval.

Parameters
idxindex of the input point
ndecorreldecorrelation interval
nnnumber of nearest neighbours
resultindices and distances of the nearest neighbours

Definition at line 189 of file KDTree.cc.

192 {
193
194 std::priority_queue<KDTreeResult> res;
195 double r2 = std::numeric_limits<double>::max();
196 m_root->search_n(idx, ndecorrel, nn, r2, m_data[idx], *this, res);
197 result.clear();
198 while (!res.empty()) {
199 result.push_back(res.top());
200 res.pop();
201 }
202 if (sort_results) sort(result.begin(), result.end());
203}

◆ r_nearest()

void Garfield::KDTree::r_nearest ( const std::vector< double > &  qv,
const double  r2,
std::vector< KDTreeResult > &  result 
) const

Search for all neighbors in a ball of size r2

Parameters
qvinput point
r2ball size (square Euclidean distance)
resultindices and distances of the nearest neighbours

Definition at line 205 of file KDTree.cc.

206 {
207 // Search for all within a ball of a certain radius.
208 result.clear();
209 m_root->search_r(-1, 0, r2, qv, *this, result);
210 if (sort_results) sort(result.begin(), result.end());
211}

◆ r_nearest_around_point()

void Garfield::KDTree::r_nearest_around_point ( const unsigned int  idx,
const unsigned int  ndecorrel,
const double  r2,
std::vector< KDTreeResult > &  result 
) const

Like r_nearest, but around an existing point, with decorrelation interval.

Definition at line 213 of file KDTree.cc.

216 {
217
218 result.clear();
219 m_root->search_r(idx, ndecorrel, r2, m_data[idx], *this, result);
220 if (sort_results) sort(result.begin(), result.end());
221}

Friends And Related Function Documentation

◆ KDTreeNode

friend class KDTreeNode
friend

Definition at line 83 of file KDTree.hh.

Member Data Documentation

◆ m_data

const KDTreeArray& Garfield::KDTree::m_data

Definition at line 37 of file KDTree.hh.

Referenced by n_nearest_around_point(), and r_nearest_around_point().

◆ m_dim

size_t Garfield::KDTree::m_dim

Definition at line 39 of file KDTree.hh.

Referenced by KDTree().

◆ sort_results

bool Garfield::KDTree::sort_results = false

Definition at line 40 of file KDTree.hh.

Referenced by n_nearest(), n_nearest_around_point(), r_nearest(), and r_nearest_around_point().


The documentation for this class was generated from the following files: