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 > >, PointListAdaptor< Point >, LIBMESH_DIM >
 

Public Member Functions

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

Protected Attributes

PointListAdaptor< Point > _point_list_adaptor
 
std::unique_ptr< KdTreeT_kd_tree
 

Detailed Description

Definition at line 20 of file KDTree.h.

Member Typedef Documentation

◆ KdTreeT

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

Definition at line 43 of file KDTree.h.

Constructor & Destructor Documentation

◆ KDTree()

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

Definition at line 16 of file KDTree.C.

17  : _point_list_adaptor(master_points.begin(), master_points.end()),
18  _kd_tree(libmesh_make_unique<KdTreeT>(
19  LIBMESH_DIM, _point_list_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(max_leaf_size)))
20 {
21  mooseAssert(_kd_tree != nullptr, "KDTree was not properly initalized.");
22 
23  _kd_tree->buildIndex();
24 }
std::unique_ptr< KdTreeT > _kd_tree
Definition: KDTree.h:47
PointListAdaptor< Point > _point_list_adaptor
Definition: KDTree.h:46

◆ ~KDTree()

virtual KDTree::~KDTree ( )
virtualdefault

Member Function Documentation

◆ neighborSearch() [1/2]

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

Definition at line 27 of file KDTree.C.

Referenced by SlaveNeighborhoodThread::operator()().

30 {
31  std::vector<Real> return_dist_sqr(patch_size);
32  neighborSearch(query_point, patch_size, return_index, return_dist_sqr);
33 }
void neighborSearch(Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index)
Definition: KDTree.C:27

◆ neighborSearch() [2/2]

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

Definition at line 36 of file KDTree.C.

40 {
41  return_index.resize(patch_size);
42 
43  std::size_t n_result =
44  _kd_tree->knnSearch(&query_point(0), patch_size, return_index.data(), return_dist_sqr.data());
45 
46  if (n_result == 0)
47  mooseError("Unable to find closest node!");
48 
49  return_index.resize(n_result);
50  return_dist_sqr.resize(n_result);
51 }
std::unique_ptr< KdTreeT > _kd_tree
Definition: KDTree.h:47
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208

◆ radiusSearch()

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

Definition at line 54 of file KDTree.C.

57 {
58  nanoflann::SearchParams sp;
59  _kd_tree->radiusSearch(&query_point(0), radius * radius, indices_dist, sp);
60 }
std::unique_ptr< KdTreeT > _kd_tree
Definition: KDTree.h:47

Member Data Documentation

◆ _kd_tree

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

Definition at line 47 of file KDTree.h.

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

◆ _point_list_adaptor

PointListAdaptor<Point> KDTree::_point_list_adaptor
protected

Definition at line 46 of file KDTree.h.


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