25 #ifndef SHKZ_ARRAY_DERIVATIVE3_H
26 #define SHKZ_ARRAY_DERIVATIVE3_H
53 double x = std::max(0.0,std::min(shape.
w-1.,p[0]));
54 double y = std::max(0.0,std::min(shape.
h-1.,p[1]));
55 double z = std::max(0.0,std::min(shape.
d-1.,p[2]));
56 int i = std::min(x,shape.
w-2.);
57 int j = std::min(y,shape.
h-2.);
58 int k = std::min(z,shape.
d-2.);
60 indices[0] =
vec3i(i,j,k);
61 indices[1] =
vec3i(i+1,j,k);
62 indices[2] =
vec3i(i,j+1,k);
63 indices[3] =
vec3i(i+1,j+1,k);
64 indices[4] =
vec3i(i,j,k+1);
65 indices[5] =
vec3i(i+1,j,k+1);
66 indices[6] =
vec3i(i,j+1,k+1);
67 indices[7] =
vec3i(i+1,j+1,k+1);
69 coef[0][0] = -(k+1-z)*(j+1-y);
70 coef[0][1] = (k+1-z)*(j+1-y);
71 coef[0][2] = -(k+1-z)*(y-j);
72 coef[0][3] = (k+1-z)*(y-j);
73 coef[0][4] = -(z-k)*(j+1-y);
74 coef[0][5] = (z-k)*(j+1-y);
75 coef[0][6] = -(z-k)*(y-j);
76 coef[0][7] = (z-k)*(y-j);
78 coef[1][0] = -(k+1-z)*(i+1-x);
79 coef[1][1] = -(k+1-z)*(x-i);
80 coef[1][2] = (k+1-z)*(i+1-x);
81 coef[1][3] = (k+1-z)*(x-i);
82 coef[1][4] = -(z-k)*(i+1-x);
83 coef[1][5] = -(z-k)*(x-i);
84 coef[1][6] = (z-k)*(i+1-x);
85 coef[1][7] = (z-k)*(x-i);
87 coef[2][0] = -(i+1-x)*(j+1-y);
88 coef[2][1] = -(x-i)*(j+1-y);
89 coef[2][2] = -(i+1-x)*(y-j);
90 coef[2][3] = -(x-i)*(y-j);
91 coef[2][4] = (i+1-x)*(j+1-y);
92 coef[2][5] = (x-i)*(j+1-y);
93 coef[2][6] = (i+1-x)*(y-j);
94 coef[2][7] = (x-i)*(y-j);
108 T values[8];
vec3i indices[8];
double coef[DIM3][8];
109 for(
unsigned dim : DIMS3 ) result[dim] = T();
111 for(
unsigned dim : DIMS3 ) {
112 for(
unsigned n=0; n<8; ++n ) {
113 result[dim] += coef[dim][n] * array(indices[n][0],indices[n][1],indices[n][2]);
133 derivative<T>(array,(p-origin)/dx,result.
v);