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

#include <KDTree.h>

Classes

class  PointListAdaptor
 PointListAdaptor is required to use libMesh Point coordinate type with nanoflann KDTree library. More...
 

Public Types

using KdTreeT = nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< Real, PointListAdaptor< LIBMESH_DIM >>, PointListAdaptor< LIBMESH_DIM >, 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)
 

Protected Attributes

PointListAdaptor< LIBMESH_DIM > _point_list_adaptor
 
UniquePtr< KdTreeT_kd_tree
 

Detailed Description

Definition at line 23 of file KDTree.h.

Member Typedef Documentation

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

Definition at line 113 of file KDTree.h.

Constructor & Destructor Documentation

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

Definition at line 20 of file KDTree.C.

21  : _point_list_adaptor(master_points),
22  _kd_tree(libmesh_make_unique<KdTreeT>(
23  LIBMESH_DIM, _point_list_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(max_leaf_size)))
24 {
25  mooseAssert(_kd_tree != nullptr, "KDTree was not properly initalized.");
26 
27  _kd_tree->buildIndex();
28 }
UniquePtr< KdTreeT > _kd_tree
Definition: KDTree.h:117
PointListAdaptor< LIBMESH_DIM > _point_list_adaptor
Definition: KDTree.h:116
virtual KDTree::~KDTree ( )
virtualdefault

Member Function Documentation

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

Definition at line 31 of file KDTree.C.

Referenced by SlaveNeighborhoodThread::operator()().

34 {
35  // The query point has to be converted from a C++ array to a C array because nanoflann library
36  // expects C arrays.
37  const Real query_pt[] = {query_point(0), query_point(1), query_point(2)};
38 
39  return_index.resize(patch_size, std::numeric_limits<std::size_t>::max());
40  std::vector<Real> return_dist_sqr(patch_size, std::numeric_limits<Real>::max());
41 
42  _kd_tree->knnSearch(&query_pt[0], patch_size, &return_index[0], &return_dist_sqr[0]);
43 
44  if (return_dist_sqr[0] == std::numeric_limits<Real>::max() ||
45  return_index[0] == std::numeric_limits<std::size_t>::max())
46  mooseError("Unable to find closest node!");
47 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
UniquePtr< KdTreeT > _kd_tree
Definition: KDTree.h:117

Member Data Documentation

UniquePtr<KdTreeT> KDTree::_kd_tree
protected

Definition at line 117 of file KDTree.h.

Referenced by KDTree(), and neighborSearch().

PointListAdaptor<LIBMESH_DIM> KDTree::_point_list_adaptor
protected

Definition at line 116 of file KDTree.h.


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