8#ifndef TRILINEAR_INTERPOLATION_H
9#define TRILINEAR_INTERPOLATION_H
23template <
typename Real>
29 Real xSpacing, Real yMin, Real ySpacing, Real zMin, Real zSpacing,
37 inline Real
const*
GetF()
const;
56 Real
operator()(
int xOrder,
int yOrder,
int zOrder, Real x, Real y,
60 int mXBound, mYBound, mZBound, mQuantity;
61 Real mXMin, mXMax, mXSpacing, mInvXSpacing;
62 Real mYMin, mYMax, mYSpacing, mInvYSpacing;
63 Real mZMin, mZMax, mZSpacing, mInvZSpacing;
69template <
typename Real>
71 Real xMin, Real xSpacing, Real yMin, Real ySpacing, Real zMin,
72 Real zSpacing, Real
const* F)
77 mQuantity(xBound * yBound * zBound),
88 Assert(mXBound >= 2 && mYBound >= 2 && mZBound >= 2 && mF,
90 Assert(mXSpacing > (Real)0 && mYSpacing > (Real)0 &&
91 mZSpacing > (Real)0,
"Invalid input.");
93 mXMax = mXMin + mXSpacing *
static_cast<Real
>(mXBound - 1);
94 mInvXSpacing = ((Real)1) / mXSpacing;
95 mYMax = mYMin + mYSpacing *
static_cast<Real
>(mYBound - 1);
96 mInvYSpacing = ((Real)1) / mYSpacing;
97 mZMax = mZMin + mZSpacing *
static_cast<Real
>(mZBound - 1);
98 mInvZSpacing = ((Real)1) / mZSpacing;
100 mBlend[0][0] = (Real)1;
101 mBlend[0][1] = (Real)-1;
102 mBlend[1][0] = (Real)0;
103 mBlend[1][1] = (Real)1;
106template <
typename Real>
inline
112template <
typename Real>
inline
118template <
typename Real>
inline
124template <
typename Real>
inline
130template <
typename Real>
inline
136template <
typename Real>
inline
142template <
typename Real>
inline
148template <
typename Real>
inline
154template <
typename Real>
inline
160template <
typename Real>
inline
166template <
typename Real>
inline
172template <
typename Real>
inline
178template <
typename Real>
inline
184template <
typename Real>
inline
190template <
typename Real>
194 Real xIndex = (x - mXMin) * mInvXSpacing;
195 int ix =
static_cast<int>(xIndex);
200 else if (ix >= mXBound)
206 Real yIndex = (y - mYMin) * mInvYSpacing;
207 int iy =
static_cast<int>(yIndex);
212 else if (iy >= mYBound)
218 Real zIndex = (z - mZMin) * mInvZSpacing;
219 int iz =
static_cast<int>(zIndex);
224 else if (iz >= mZBound)
242 Real P[2], Q[2], R[2];
243 for (
int row = 0; row < 2; ++row)
248 for (
int col = 0; col < 2; ++col)
250 P[row] += mBlend[row][col] * U[col];
251 Q[row] += mBlend[row][col] * V[col];
252 R[row] += mBlend[row][col] * W[col];
258 Real result = (Real)0;
259 for (
int slice = 0; slice < 2; ++slice)
261 int zClamp = iz + slice;
262 if (zClamp >= mZBound)
264 zClamp = mZBound - 1;
267 for (
int row = 0; row < 2; ++row)
269 int yClamp = iy + row;
270 if (yClamp >= mYBound)
272 yClamp = mYBound - 1;
275 for (
int col = 0; col < 2; ++col)
277 int xClamp = ix + col;
278 if (xClamp >= mXBound)
280 xClamp = mXBound - 1;
283 result += P[col] * Q[row] * R[slice] *
284 mF[xClamp + mXBound * (yClamp + mYBound * zClamp)];
292template <
typename Real>
294 Real x, Real y, Real z)
const
297 Real xIndex = (x - mXMin) * mInvXSpacing;
298 int ix =
static_cast<int>(xIndex);
303 else if (ix >= mXBound)
309 Real yIndex = (y - mYMin) * mInvYSpacing;
310 int iy =
static_cast<int>(yIndex);
315 else if (iy >= mYBound)
321 Real zIndex = (z - mZMin) * mInvZSpacing;
322 int iz =
static_cast<int>(zIndex);
327 else if (iz >= mZBound)
332 Real U[2], dx, xMult;
345 xMult = mInvXSpacing;
351 Real V[2], dy, yMult;
364 yMult = mInvYSpacing;
370 Real W[2], dz, zMult;
383 zMult = mInvZSpacing;
390 Real P[2], Q[2], R[2];
391 for (
int row = 0; row < 2; ++row)
396 for (
int col = 0; col < 2; ++col)
398 P[row] += mBlend[row][col] * U[col];
399 Q[row] += mBlend[row][col] * V[col];
400 R[row] += mBlend[row][col] * W[col];
406 Real result = (Real)0;
407 for (
int slice = 0; slice < 2; ++slice)
409 int zClamp = iz + slice;
410 if (zClamp >= mZBound)
412 zClamp = mZBound - 1;
415 for (
int row = 0; row < 2; ++row)
417 int yClamp = iy + row;
418 if (yClamp >= mYBound)
420 yClamp = mYBound - 1;
423 for (
int col = 0; col < 2; ++col)
425 int xClamp = ix + col;
426 if (xClamp >= mXBound)
428 xClamp = mXBound - 1;
431 result += P[col] * Q[row] * R[slice] *
432 mF[xClamp + mXBound * (yClamp + mYBound * zClamp)];
436 result *= xMult * yMult * zMult;
#define Assert(condition, message)
Definition Exception.hpp:10
Definition TrilinearInterpolation.hpp:25
Real GetXMax() const
Definition TrilinearInterpolation.hpp:143
int GetZBound() const
Definition TrilinearInterpolation.hpp:119
Real GetXMin() const
Definition TrilinearInterpolation.hpp:137
int GetYBound() const
Definition TrilinearInterpolation.hpp:113
Real GetXSpacing() const
Definition TrilinearInterpolation.hpp:149
int GetXBound() const
Definition TrilinearInterpolation.hpp:107
Real GetZMax() const
Definition TrilinearInterpolation.hpp:179
Real GetYMin() const
Definition TrilinearInterpolation.hpp:155
Real GetZMin() const
Definition TrilinearInterpolation.hpp:173
Real operator()(Real x, Real y, Real z) const
Definition TrilinearInterpolation.hpp:191
int GetQuantity() const
Definition TrilinearInterpolation.hpp:125
Real const * GetF() const
Definition TrilinearInterpolation.hpp:131
Real GetZSpacing() const
Definition TrilinearInterpolation.hpp:185
IntpTrilinear3(int xBound, int yBound, int zBound, Real xMin, Real xSpacing, Real yMin, Real ySpacing, Real zMin, Real zSpacing, Real const *F)
Definition TrilinearInterpolation.hpp:70
Real GetYMax() const
Definition TrilinearInterpolation.hpp:161
Real GetYSpacing() const
Definition TrilinearInterpolation.hpp:167
Definition TricubicInterpolation.hpp:25