Medusa
1.1
Coordinate Free Mehless Method implementation
Sheppard.hpp
Go to the documentation of this file.
1
#ifndef MEDUSA_BITS_INTERPOLANTS_SHEPPARD_HPP_
2
#define MEDUSA_BITS_INTERPOLANTS_SHEPPARD_HPP_
3
9
#include <
medusa/bits/utils/assert.hpp
>
10
#include <
medusa/bits/utils/numutils.hpp
>
11
12
#include "
Sheppard_fwd.hpp
"
13
14
namespace
mm
{
15
16
template
<
class
vec_t,
class
value_t>
17
value_t
SheppardInterpolant<vec_t, value_t>::operator()
(
const
vec_t& point,
int
num_closest,
18
int
power,
double
reg,
19
double
conf_dist)
const
{
20
int
N = tree.size();
21
int
M = values.size();
22
assert_msg
(N == M && N >= 0,
23
"Missing or wrong number of positions/values. Did you forget to call setValues() or "
24
"setPositions()?"
);
25
assert_msg
(num_closest >= 0,
"Number of closest nodes should be greater than 0, got %d."
,
26
num_closest);
27
assert_msg
(reg >= 0,
"Regularization parameter should be greater than 0, got %e."
, reg);
28
assert_msg
(power >= 0,
"Power should be greater than 0, got %e."
, power);
29
assert_msg
(num_closest <= N,
"You requested %d closest points, but there are only %d in total."
,
30
num_closest, N);
31
32
Range<value_t>
d2
;
// Squares of distances.
33
Range<int>
idx;
// Closest nodes indexes.
34
std::tie(idx,
d2
) = tree.query(point, num_closest);
35
36
int
n = idx.
size
();
37
scalar_t
s = 0.0, r = 0.0;
38
Range<scalar_t>
inv_dist(n);
39
40
if
(
d2
[0] < conf_dist * conf_dist) {
41
// Point is close to the tree point, thus return value in node.
42
return
values[idx[0]];
43
}
44
45
for
(
int
i = 0; i < n; ++i) {
46
inv_dist[i] = 1.0 / (sqrt(
ipow
(
d2
[i], power)) + reg);
47
s += inv_dist[i];
48
}
49
for
(
int
i = 0; i < n; ++i) {
50
inv_dist[i] /= s;
51
}
52
for
(
int
i = 0; i < n; ++i) {
53
r += inv_dist[i] * values[idx[i]];
54
}
55
56
return
r;
57
}
58
}
// namespace mm
59
60
#endif // MEDUSA_BITS_INTERPOLANTS_SHEPPARD_HPP_
mm
Root namespace for the whole library.
Definition:
Gaussian.hpp:14
mm::ipow
double ipow(double base)
Compile time integer power, returns base raised to power exponent.
Definition:
numutils.hpp:40
mm::SheppardInterpolant::operator()
value_t operator()(const vec_t &point, int num_closest, int power=2, double reg=0.0, double conf_dist=1e-12) const
Evaluate the interpolant at the given point.
Definition:
Sheppard.hpp:17
numutils.hpp
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition:
assert.hpp:75
mm::sh::d2
static const shape_flags d2
Indicates to calculate d2 shapes.
Definition:
shape_flags.hpp:25
assert.hpp
mm::SheppardInterpolant::scalar_t
vec_t::scalar_t scalar_t
Scalar data type.
Definition:
Sheppard_fwd.hpp:40
mm::Range::size
int size() const
Returns number of elements.
Definition:
Range_fwd.hpp:185
mm::Range< value_t >
Sheppard_fwd.hpp
include
medusa
bits
interpolants
Sheppard.hpp
Generated on Thu Jun 9 2022 09:42:26 for Medusa by
1.8.17