www.mooseframework.org
Public Types | Public Member Functions | Protected Attributes | List of all members
KDTree Class Reference

#include <KDTree.h>

Public Types

using KdTreeT = nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< Real, PointListAdaptor< Point >, Real, std::size_t >, PointListAdaptor< Point >, LIBMESH_DIM, std::size_t >
 

Public Member Functions

 KDTree (std::vector< Point > &master_points, unsigned int max_leaf_size)
 
virtual ~KDTree ()=default
 
void neighborSearch (const Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index)
 
void neighborSearch (const Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index, std::vector< Real > &return_dist_sqr)
 
void radiusSearch (const Point &query_point, Real radius, std::vector< nanoflann::ResultItem< std::size_t, Real >> &indices_dist)
 
std::size_t numberCandidatePoints ()
 

Protected Attributes

PointListAdaptor< Point > _point_list_adaptor
 
std::unique_ptr< KdTreeT_kd_tree
 

Detailed Description

Definition at line 28 of file KDTree.h.

Member Typedef Documentation

◆ KdTreeT

using KDTree::KdTreeT = nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor<Real, PointListAdaptor<Point>, Real, std::size_t>, PointListAdaptor<Point>, LIBMESH_DIM, std::size_t>

Definition at line 57 of file KDTree.h.

Constructor & Destructor Documentation

◆ KDTree()

KDTree::KDTree ( std::vector< Point > &  master_points,
unsigned int  max_leaf_size 
)

Definition at line 27 of file KDTree.C.

28  : _point_list_adaptor(master_points.begin(), master_points.end()),
29  _kd_tree(std::make_unique<KdTreeT>(
30  LIBMESH_DIM, _point_list_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(max_leaf_size)))
31 {
32  mooseAssert(_kd_tree != nullptr, "KDTree was not properly initialized.");
33 
34  _kd_tree->buildIndex();
35 }
std::unique_ptr< KdTreeT > _kd_tree
Definition: KDTree.h:61
PointListAdaptor< Point > _point_list_adaptor
Definition: KDTree.h:60

◆ ~KDTree()

virtual KDTree::~KDTree ( )
virtualdefault

Member Function Documentation

◆ neighborSearch() [1/2]

void KDTree::neighborSearch ( const Point &  query_point,
unsigned int  patch_size,
std::vector< std::size_t > &  return_index 
)

Definition at line 38 of file KDTree.C.

Referenced by SecondaryNeighborhoodThread::operator()().

41 {
42  std::vector<Real> return_dist_sqr(patch_size);
43  neighborSearch(query_point, patch_size, return_index, return_dist_sqr);
44 }
void neighborSearch(const Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index)
Definition: KDTree.C:38

◆ neighborSearch() [2/2]

void KDTree::neighborSearch ( const Point &  query_point,
unsigned int  patch_size,
std::vector< std::size_t > &  return_index,
std::vector< Real > &  return_dist_sqr 
)

Definition at line 47 of file KDTree.C.

51 {
52  return_index.resize(patch_size);
53 
54  std::size_t n_result =
55  _kd_tree->knnSearch(&query_point(0), patch_size, return_index.data(), return_dist_sqr.data());
56 
57  if (n_result == 0)
58  mooseError("Unable to find closest node!");
59 
60  return_index.resize(n_result);
61  return_dist_sqr.resize(n_result);
62 }
std::unique_ptr< KdTreeT > _kd_tree
Definition: KDTree.h:61
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284

◆ numberCandidatePoints()

std::size_t KDTree::numberCandidatePoints ( )

Definition at line 74 of file KDTree.C.

75 {
77 }
PointListAdaptor< Point > _point_list_adaptor
Definition: KDTree.h:60
size_t kdtree_get_point_count() const
Must return the number of data points.

◆ radiusSearch()

void KDTree::radiusSearch ( const Point &  query_point,
Real  radius,
std::vector< nanoflann::ResultItem< std::size_t, Real >> &  indices_dist 
)

Definition at line 65 of file KDTree.C.

68 {
70  _kd_tree->radiusSearch(&query_point(0), radius * radius, indices_dist, sp);
71 }
std::unique_ptr< KdTreeT > _kd_tree
Definition: KDTree.h:61
SearchParams SearchParameters

Member Data Documentation

◆ _kd_tree

std::unique_ptr<KdTreeT> KDTree::_kd_tree
protected

Definition at line 61 of file KDTree.h.

Referenced by KDTree(), neighborSearch(), and radiusSearch().

◆ _point_list_adaptor

PointListAdaptor<Point> KDTree::_point_list_adaptor
protected

Definition at line 60 of file KDTree.h.

Referenced by numberCandidatePoints().


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