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)
 

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 39 of file KDTree.h.

Constructor & Destructor Documentation

◆ KDTree()

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

Definition at line 15 of file KDTree.C.

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

◆ ~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 26 of file KDTree.C.

Referenced by SlaveNeighborhoodThread::operator()().

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

◆ 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 35 of file KDTree.C.

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

Member Data Documentation

◆ _kd_tree

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

Definition at line 43 of file KDTree.h.

Referenced by KDTree(), and neighborSearch().

◆ _point_list_adaptor

PointListAdaptor<Point> KDTree::_point_list_adaptor
protected

Definition at line 42 of file KDTree.h.


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