78 : spacing(spacing), origin(origin), nPoints(nPoints), data(data), interpolationStrategy(interpolationStrategy)
80 if (nPoints[0] * nPoints[1] * nPoints[2] != data.size())
81 throw std::runtime_error(
"number of values does not match number of points.");
85 return applyTrilinearInterpolation(
point);
90 T applyTrilinearInterpolation(
const real3&
point)
const
92 if (isOutOfBounds(
point))
93 throw std::runtime_error(
"Point is out of bounds!");
95 const auto [ix, iy, iz] = getIndexMMM(
point);
98 const bool endOfX = ix == nPoints[0] - 1;
99 const bool endOfY = iy == nPoints[1] - 1;
100 const bool endOfZ = iz == nPoints[2] - 1;
114 return ub_math::lerp2(data[getIndex(ix, iy, iz)], data[getIndex(ix, iy + 1, iz)], data[getIndex(ix, iy, iz + 1)],
117 return ub_math::lerp2(data[getIndex(ix, iy, iz)], data[getIndex(ix + 1, iy, iz)], data[getIndex(ix, iy, iz + 1)],
120 return ub_math::lerp2(data[getIndex(ix, iy, iz)], data[getIndex(ix + 1, iy + 1, iz)],
121 data[getIndex(ix, iy + 1, iz)], data[getIndex(ix + 1, iy + 1, iz)],
distances.x,
124 return ub_math::lerp3(data[getIndex(ix, iy, iz)], data[getIndex(ix + 1, iy, iz)], data[getIndex(ix, iy + 1, iz)],
125 data[getIndex(ix + 1, iy + 1, iz)], data[getIndex(ix, iy, iz + 1)],
126 data[getIndex(ix + 1, iy, iz + 1)], data[getIndex(ix, iy + 1, iz + 1)],
129 bool isBelowLowerX(
real x)
const
131 if (spacing.
x == vf::basics::constant::c0o1 || nPoints[0] == 1)
135 bool isBelowLowerY(
real y)
const
137 if (spacing.
y == vf::basics::constant::c0o1 || nPoints[1] == 1)
141 bool isBelowLowerZ(
real z)
const
143 if (spacing.
z == vf::basics::constant::c0o1 || nPoints[2] == 1)
148 bool isAboveUpperX(
real x)
const
150 if (spacing.
x == vf::basics::constant::c0o1 || nPoints[0] == 1)
152 return x > origin.
x + spacing.
x * nPoints[0];
154 bool isAboveUpperY(
real y)
const
156 if (spacing.
y == vf::basics::constant::c0o1 || nPoints[1] == 1)
158 return y > origin.
y + spacing.
y * nPoints[1];
160 bool isAboveUpperZ(
real z)
const
162 if (spacing.
z == vf::basics::constant::c0o1 || nPoints[2] == 1)
164 return z > origin.
z + spacing.
z * nPoints[2];
169 return isBelowLowerX(
point.x) || isBelowLowerY(
point.y) || isBelowLowerZ(
point.z) || isAboveUpperX(
point.x) ||
170 isAboveUpperY(
point.y) || isAboveUpperZ(
point.z);
174 if (spacing == vf::basics::constant::c0o1 || numberOfPoints == 1)
182 if (spacing == vf::basics::constant::c0o1 || numberOfPoints == 1)
184 const uint index = (
coord - origin) / spacing + 1;
185 if (index > numberOfPoints)
191 return getNextLowerPoint(
point.x, origin.x, spacing.x, nPoints[0]);
195 return getNextLowerPoint(
point.y, origin.y, spacing.y, nPoints[1]);
199 return getNextLowerPoint(
point.z, origin.z, spacing.z, nPoints[2]);
203 return getNextHigherPoint(
point.x, origin.x, spacing.x, nPoints[0]);
207 return getNextHigherPoint(
point.y, origin.y, spacing.y, nPoints[1]);
211 return getNextHigherPoint(
point.z, origin.z, spacing.z, nPoints[2]);
217 std::array<uint, 3> getIndexMMM(
const real3&
point)
const
219 return { getNextLowerPointX(
point), getNextLowerPointY(
point), getNextLowerPointZ(
point) };
222 real getCoordinateX(
const uint index)
const
224 return origin.x + index * spacing.x;
226 real getCoordinateY(
const uint index)
const
228 return origin.y + index * spacing.y;
230 real getCoordinateZ(
const uint index)
const
232 return origin.z + index * spacing.z;
238 const real3 spacing, origin;
239 const std::array<uint, 3> nPoints;