58 const uint nx = array2d.nx();
59 const uint ny = array2d.ny();
61 int i0 = (int)floor(x);
62 int j0 = (int)floor(y);
67 const float fx = x - i0;
68 const float fy = y - j0;
70 i0 = mode ==
LerpMode::REPEAT ? i0 % nx : (i0 < 0 ? 0 : (i0 >= nx ? nx - 1 : nx));
71 j0 = mode ==
LerpMode::REPEAT ? j0 % ny : (j0 < 0 ? 0 : (j0 >= ny ? ny - 1 : ny));
73 i1 = mode ==
LerpMode::REPEAT ? i1 % nx : (i1 < 0 ? 0 : (i1 >= nx ? nx - 1 : nx));
74 j1 = mode ==
LerpMode::REPEAT ? j1 % ny : (j1 < 0 ? 0 : (j1 >= ny ? ny - 1 : ny));
76 const float w00 = (1.0f - fx) * (1.0f - fy);
77 const float w10 = fx * (1.0f - fy);
78 const float w01 = (1.0f - fx) * fy;
79 const float w11 = fx * fy;
81 return w00 * array2d(i0, j0) + w01 * array2d(i0, j1) + w10 * array2d(i1, j0) + w11 * array2d(i1, j1);
87 const uint nx = array3d.nx();
88 const uint ny = array3d.ny();
89 const uint nz = array3d.nz();
91 int i0 = (int)floor(x);
92 int j0 = (int)floor(y);
93 int k0 = (int)floor(z);
99 const float fx = x - i0;
100 const float fy = y - j0;
101 const float fz = z - k0;
103 i0 = mode ==
LerpMode::REPEAT ? i0 % nx : (i0 < 0 ? 0 : (i0 >= nx ? nx - 1 : nx));
104 j0 = mode ==
LerpMode::REPEAT ? j0 % ny : (j0 < 0 ? 0 : (j0 >= ny ? ny - 1 : ny));
105 k0 = mode ==
LerpMode::REPEAT ? k0 % nz : (k0 < 0 ? 0 : (k0 >= nz ? nz - 1 : nz));
107 i1 = mode ==
LerpMode::REPEAT ? i1 % nx : (i1 < 0 ? 0 : (i1 >= nx ? nx - 1 : nx));
108 j1 = mode ==
LerpMode::REPEAT ? j1 % ny : (j1 < 0 ? 0 : (j1 >= ny ? ny - 1 : ny));
109 k1 = mode ==
LerpMode::REPEAT ? k1 % nz : (k1 < 0 ? 0 : (k1 >= nz ? nz - 1 : nz));
111 const float w000 = (1.0f - fx) * (1.0f - fy) * (1.0f - fz);
112 const float w100 = fx * (1.0f - fy) * (1.0f - fz);
113 const float w010 = (1.0f - fx) * fy * (1.0f - fz);
114 const float w001 = (1.0f - fx) * (1.0f - fy) * fz;
115 const float w111 = fx * fy * fz;
116 const float w011 = (1.0f - fx) * fy * fz;
117 const float w101 = fx * (1.0f - fy) * fz;
118 const float w110 = fx * fy * (1.0f - fz);
120 return w000 * array3d(i0, j0, k0) + w100 * array3d(i1, j0, k0) + w010 * array3d(i0, j1, k0) + w001 * array3d(i0, j0, k1)
121 + w111 * array3d(i1, j1, k1) + w011 * array3d(i0, j1, k1) + w101 * array3d(i1, j0, k1) + w110 * array3d(i1, j1, k0);
DYN_FUNC T bilinear(Array2D< T, deviceType > &array2d, float x, float y, LerpMode mode=LerpMode::REPEAT)
DYN_FUNC T trilinear(Array3D< T, deviceType > &array3d, float x, float y, float z, LerpMode mode=LerpMode::REPEAT)