23 #ifndef O2SCL_INTERPM_IDW_H
24 #define O2SCL_INTERPM_IDW_H
34 #include <gsl/gsl_combination.h>
36 #include <o2scl/err_hnd.h>
37 #include <o2scl/vector.h>
39 #ifndef DOXYGEN_NO_O2NS
77 template<
class vec_vec_t>
78 void set_data(
size_t dim,
size_t n_points, vec_vec_t &vecs) {
81 O2SCL_ERR2(
"Must provide at least three points in ",
87 for(
size_t i=0;i<dim+1;i++) {
97 template<
class vec2_t>
double operator()(vec2_t &x)
const {
103 template<
class vec2_t>
double eval(vec2_t &x)
const {
106 O2SCL_ERR(
"Data not set in interpm_idw::eval_points().",
117 double c1=
dist(i1,x);
118 double c2=
dist(i2,x);
119 double c3=
dist(i3,x);
147 for(
size_t j=3;j<
np;j++) {
149 double c4=
dist(i4,x);
163 double f1=(*(
ptrs[
nd]))[i1];
164 double f2=(*(
ptrs[
nd]))[i2];
165 double f3=(*(
ptrs[
nd]))[i3];
170 }
else if (c2==0.0) {
172 }
else if (c3==0.0) {
177 double norm=1.0/c1+1.0/c2+1.0/c3;
178 return (f1/c1+f2/c2+f3/c3)/norm;
181 #ifndef DOXYGEN_INTERNAL
195 template<
class vec2_t>
double dist(
size_t index, vec2_t &x)
const {
197 size_t nscales=
scales.size();
198 for(
size_t i=0;i<
nd;i++) {
199 ret+=pow((x[i]-(*(
ptrs[i]))[index])/
scales[i%nscales],2.0);
205 int swap(
size_t &index_1,
double &dist_1,
size_t &index_2,
206 double &dist_2)
const {
211 index_temp=index_1; dist_temp=dist_1;
212 index_1=index_2; dist_1=dist_2;
213 index_2=index_temp; dist_2=dist_temp;
222 #ifndef DOXYGEN_NO_O2NS
Multi-dimensional interpolation by inverse distance weighting.
double eval(vec2_t &x) const
Perform the interpolation.
invalid argument supplied by user
std::vector< vec_t * > ptrs
A vector of pointers holding the data.
size_t nd
The number of dimensions.
ubvector scales
Distance scales for each coordinate.
int swap(size_t &index_1, double &dist_1, size_t &index_2, double &dist_2) const
Swap points 1 and 2.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
double operator()(vec2_t &x) const
Perform the interpolation.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
size_t np
The number of points.
bool data_set
True if the data has been specified.
double dist(size_t index, vec2_t &x) const
Compute the distance between x and the point at index index.
void set_data(size_t dim, size_t n_points, vec_vec_t &vecs)
Initialize the data for the interpolation.