https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PointListAdaptor.h
Go to the documentation of this file.
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#include "libmesh/nanoflann.hpp"
13#include "libmesh/utility.h"
14#include "libmesh/point.h"
15
16#include <iterator>
17
18template <typename PointObject>
20{
21public:
22 using Iterator = typename std::vector<PointObject>::const_iterator;
23
25 : _begin(begin), _end(end), _size(std::distance(begin, end))
26 {
27 }
28
29private:
32
35
37 std::size_t _size;
38
39public:
43 using coord_t = Real;
44
48 inline size_t kdtree_get_point_count() const { return _size; }
49
53 const Point & getPoint(const PointObject & item) const;
54
59 inline coord_t kdtree_distance(const coord_t * p1, const size_t idx_p2, size_t /*size*/) const
60 {
61 mooseAssert(idx_p2 < _size,
62 "The point index should be less than"
63 "total number of points used to build"
64 "the KDTree.");
65
66 auto it = _begin;
67 std::advance(it, idx_p2);
68 const Point & p2 = getPoint(*it);
69
70 coord_t dist = 0.0;
71
72 for (const auto i : make_range(Moose::dim))
73 dist += Utility::pow<2>(p1[i] - p2(i));
74
75 return dist;
76 }
77
81 inline coord_t kdtree_get_pt(const size_t idx, int dim) const
82 {
83 mooseAssert(dim < (int)Moose::dim,
84 "The required component number should be less than the LIBMESH_DIM.");
85 mooseAssert(idx < _size,
86 "The index of the point should be less"
87 "than total number of points used to"
88 "construct the KDTree.");
89
90 auto it = _begin;
91 std::advance(it, idx);
92 const Point & p = getPoint(*it);
93
94 return p(dim);
95 }
96
102 template <class BBOX>
103 bool kdtree_get_bbox(BBOX & /* bb */) const
104 {
105 return false;
106 }
107};
108
109// Specialization for PointListAdaptor<Point> (provide your own for custom types)
110template <>
111inline const Point &
112PointListAdaptor<Point>::getPoint(const Point & item) const
113{
114 return item;
115}
unsigned int dim
const Iterator _begin
begin iterator of the underlying point type vector
std::size_t _size
number of elements pointed to
Real coord_t
libMesh Point coordinate type
coord_t kdtree_distance(const coord_t *p1, const size_t idx_p2, size_t) const
Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored ...
const Iterator _end
end iterator of the underlying point type vector
typename std::vector< PointObject >::const_iterator Iterator
PointListAdaptor(Iterator begin, Iterator end)
bool kdtree_get_bbox(BBOX &) const
Optional bounding-box computation.
const Point & getPoint(const PointObject &item) const
get a Point reference from the PointData object at index idx in the list
size_t kdtree_get_point_count() const
Must return the number of data points.
coord_t kdtree_get_pt(const size_t idx, int dim) const
Returns the dim'th component of the idx'th point in the class.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165
Real distance(const Point &p)