25 #ifndef SHKZ_ARRAY_INTERPOLATOR3_H
26 #define SHKZ_ARRAY_INTERPOLATOR3_H
50 static void interpolate_coef(
const shape3 &shape,
const vec3d &p,
vec3i indices[8],
double coef[8] ) {
51 double x = std::max(0.0,std::min(shape.
w-1.,p[0]));
52 double y = std::max(0.0,std::min(shape.
h-1.,p[1]));
53 double z = std::max(0.0,std::min(shape.
d-1.,p[2]));
54 int i = std::min(x,shape.
w-2.);
55 int j = std::min(y,shape.
h-2.);
56 int k = std::min(z,shape.
d-2.);
57 indices[0] =
vec3i(i,j,k);
58 indices[1] =
vec3i(i+1,j,k);
59 indices[2] =
vec3i(i,j+1,k);
60 indices[3] =
vec3i(i+1,j+1,k);
61 indices[4] =
vec3i(i,j,k+1);
62 indices[5] =
vec3i(i+1,j,k+1);
63 indices[6] =
vec3i(i,j+1,k+1);
64 indices[7] =
vec3i(i+1,j+1,k+1);
65 coef[0] = (k+1-z)*(i+1-x)*(j+1-y);
66 coef[1] = (k+1-z)*(x-i)*(j+1-y);
67 coef[2] = (k+1-z)*(i+1-x)*(y-j);
68 coef[3] = (k+1-z)*(x-i)*(y-j);
69 coef[4] = (z-k)*(i+1-x)*(j+1-y);
70 coef[5] = (z-k)*(x-i)*(j+1-y);
71 coef[6] = (z-k)*(i+1-x)*(y-j);
72 coef[7] = (z-k)*(x-i)*(y-j);
86 template<
class T>
static T interpolate(
const array3<T> &array,
const vec3d &p,
bool only_actives=
false ) {
87 T values[8];
vec3i indices[8];
double coef[8];
88 interpolate_coef(array.
shape(),p,indices,coef);
93 for(
int n=0; n<8; ++n ) w[n] = array.
active(indices[n]) ? coef[n] : 0.0;
94 for(
int n=0; n<8; ++n ) sum += w[n];
96 for(
int n=0; n<8; ++n ) w[n] /= sum;
97 for(
unsigned n=0; n<8; ++n )
if( w[n] ) value += array(indices[n]) * w[n];
100 for(
unsigned n=0; n<8; ++n )
if( coef[n] ) value += array(indices[n]) * coef[n];
120 template<
class T>
static T interpolate(
const array3<T> &array,
const vec3d &origin,
double dx,
const vec3d &p,
bool only_actives=
false ) {
121 return interpolate<T>(array,(p-origin)/dx,only_actives);