www.mooseframework.org
KDTree.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // Moose includes
13 #include "MooseMesh.h"
14 #include "PointListAdaptor.h"
15 
16 #include "libmesh/nanoflann.hpp"
17 #include "libmesh/utility.h"
18 
19 // Make newer nanoflann API compatible with older nanoflann versions
20 #if NANOFLANN_VERSION < 0x150
21 namespace nanoflann
22 {
23 template <typename T, typename U>
24 using ResultItem = std::pair<T, U>;
25 }
26 #endif
27 
28 class KDTree
29 {
30 public:
31  KDTree(std::vector<Point> & master_points, unsigned int max_leaf_size);
32 
33  virtual ~KDTree() = default;
34 
35  void neighborSearch(const Point & query_point,
36  unsigned int patch_size,
37  std::vector<std::size_t> & return_index);
38 
39  void neighborSearch(const Point & query_point,
40  unsigned int patch_size,
41  std::vector<std::size_t> & return_index,
42  std::vector<Real> & return_dist_sqr);
43 
44  void radiusSearch(const Point & query_point,
45  Real radius,
46  std::vector<nanoflann::ResultItem<std::size_t, Real>> & indices_dist);
47 
48  std::size_t numberCandidatePoints();
49 
50  using KdTreeT = nanoflann::KDTreeSingleIndexAdaptor<
51  nanoflann::L2_Simple_Adaptor<Real,
52  /* DataSource = */ PointListAdaptor<Point>,
53  /* DistanceType = */ Real,
54  /* AccessorType = */ std::size_t>,
56  LIBMESH_DIM,
57  std::size_t>;
58 
59 protected:
61  std::unique_ptr<KdTreeT> _kd_tree;
62 };
KDTree(std::vector< Point > &master_points, unsigned int max_leaf_size)
Definition: KDTree.C:27
const Real radius
std::unique_ptr< KdTreeT > _kd_tree
Definition: KDTree.h:61
Definition: KDTree.h:28
virtual ~KDTree()=default
void neighborSearch(const Point &query_point, unsigned int patch_size, std::vector< std::size_t > &return_index)
Definition: KDTree.C:38
PointListAdaptor< Point > _point_list_adaptor
Definition: KDTree.h:60
nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< Real, PointListAdaptor< Point >, Real, std::size_t >, PointListAdaptor< Point >, LIBMESH_DIM, std::size_t > KdTreeT
Definition: KDTree.h:57
std::size_t numberCandidatePoints()
Definition: KDTree.C:74
std::pair< T, U > ResultItem
Definition: KDTree.h:24
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void radiusSearch(const Point &query_point, Real radius, std::vector< nanoflann::ResultItem< std::size_t, Real >> &indices_dist)
Definition: KDTree.C:65