Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 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(const std::vector<Point> & master_points, unsigned int max_leaf_size); 32 : 33 70151 : 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>, 55 : PointListAdaptor<Point>, 56 : LIBMESH_DIM, 57 : std::size_t>; 58 : 59 : protected: 60 : PointListAdaptor<Point> _point_list_adaptor; 61 : std::unique_ptr<KdTreeT> _kd_tree; 62 : };