https://mooseframework.inl.gov
Loading...
Searching...
No Matches
include
utils
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
18
template
<
typename
Po
int
Object>
19
class
PointListAdaptor
20
{
21
public
:
22
using
Iterator
=
typename
std::vector<PointObject>::const_iterator;
23
24
PointListAdaptor
(
Iterator
begin,
Iterator
end)
25
:
_begin
(begin),
_end
(end),
_size
(
std
::
distance
(begin, end))
26
{
27
}
28
29
private
:
31
const
Iterator
_begin
;
32
34
const
Iterator
_end
;
35
37
std::size_t
_size
;
38
39
public
:
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)
110
template
<>
111
inline
const
Point &
112
PointListAdaptor<Point>::getPoint
(
const
Point & item)
const
113
{
114
return
item;
115
}
dim
unsigned int dim
PointListAdaptor
Definition
PointListAdaptor.h:20
PointListAdaptor::_begin
const Iterator _begin
begin iterator of the underlying point type vector
Definition
PointListAdaptor.h:31
PointListAdaptor::_size
std::size_t _size
number of elements pointed to
Definition
PointListAdaptor.h:37
PointListAdaptor::coord_t
Real coord_t
libMesh Point coordinate type
Definition
PointListAdaptor.h:43
PointListAdaptor::kdtree_distance
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 ...
Definition
PointListAdaptor.h:59
PointListAdaptor::_end
const Iterator _end
end iterator of the underlying point type vector
Definition
PointListAdaptor.h:34
PointListAdaptor::Iterator
typename std::vector< PointObject >::const_iterator Iterator
Definition
PointListAdaptor.h:22
PointListAdaptor::PointListAdaptor
PointListAdaptor(Iterator begin, Iterator end)
Definition
PointListAdaptor.h:24
PointListAdaptor::kdtree_get_bbox
bool kdtree_get_bbox(BBOX &) const
Optional bounding-box computation.
Definition
PointListAdaptor.h:103
PointListAdaptor::getPoint
const Point & getPoint(const PointObject &item) const
get a Point reference from the PointData object at index idx in the list
PointListAdaptor::kdtree_get_point_count
size_t kdtree_get_point_count() const
Must return the number of data points.
Definition
PointListAdaptor.h:48
PointListAdaptor::kdtree_get_pt
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.
Definition
PointListAdaptor.h:81
Moose::dim
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition
Moose.h:165
std
distance
Real distance(const Point &p)
Generated on Fri Aug 21 2026 13:33:52 for https://mooseframework.inl.gov by
1.9.8