8#ifndef TRICUBIC_INTERPOLATION_H
9#define TRICUBIC_INTERPOLATION_H
27template <
typename Real>
33 Real xSpacing, Real yMin, Real ySpacing, Real zMin, Real zSpacing,
34 Real
const* F,
bool catmullRom);
41 inline Real
const*
GetF()
const;
60 Real
operator()(
int xOrder,
int yOrder,
int zOrder, Real x, Real y,
64 int mXBound, mYBound, mZBound, mQuantity;
65 Real mXMin, mXMax, mXSpacing, mInvXSpacing;
66 Real mYMin, mYMax, mYSpacing, mInvYSpacing;
67 Real mZMin, mZMax, mZSpacing, mInvZSpacing;
73template <
typename Real>
75 Real xMin, Real xSpacing, Real yMin, Real ySpacing, Real zMin,
76 Real zSpacing, Real
const* F,
bool catmullRom)
81 mQuantity(xBound * yBound * zBound),
92 Assert(mXBound >= 4 && mYBound >= 4 && mZBound >= 4 && mF,
93 "Invalid input Bound.");
94 Assert(mXSpacing > (Real)0 && mYSpacing > (Real)0 &&
95 mZSpacing > (Real)0,
"Invalid input Spacing.");
97 mXMax = mXMin + mXSpacing *
static_cast<Real
>(mXBound - 1);
98 mInvXSpacing = ((Real)1) / mXSpacing;
99 mYMax = mYMin + mYSpacing *
static_cast<Real
>(mYBound - 1);
100 mInvYSpacing = ((Real)1) / mYSpacing;
101 mZMax = mZMin + mZSpacing *
static_cast<Real
>(mZBound - 1);
102 mInvZSpacing = ((Real)1) / mZSpacing;
106 mBlend[0][0] = (Real)0;
107 mBlend[0][1] = (Real)-0.5;
108 mBlend[0][2] = (Real)1;
109 mBlend[0][3] = (Real)-0.5;
110 mBlend[1][0] = (Real)1;
111 mBlend[1][1] = (Real)0;
112 mBlend[1][2] = (Real)-2.5;
113 mBlend[1][3] = (Real)1.5;
114 mBlend[2][0] = (Real)0;
115 mBlend[2][1] = (Real)0.5;
116 mBlend[2][2] = (Real)2;
117 mBlend[2][3] = (Real)-1.5;
118 mBlend[3][0] = (Real)0;
119 mBlend[3][1] = (Real)0;
120 mBlend[3][2] = (Real)-0.5;
121 mBlend[3][3] = (Real)0.5;
125 mBlend[0][0] = (Real)1 / (Real)6;
126 mBlend[0][1] = (Real)-3 / (Real)6;
127 mBlend[0][2] = (Real)3 / (Real)6;
128 mBlend[0][3] = (Real)-1 / (Real)6;;
129 mBlend[1][0] = (Real)4 / (Real)6;
130 mBlend[1][1] = (Real)0 / (Real)6;
131 mBlend[1][2] = (Real)-6 / (Real)6;
132 mBlend[1][3] = (Real)3 / (Real)6;
133 mBlend[2][0] = (Real)1 / (Real)6;
134 mBlend[2][1] = (Real)3 / (Real)6;
135 mBlend[2][2] = (Real)3 / (Real)6;
136 mBlend[2][3] = (Real)-3 / (Real)6;
137 mBlend[3][0] = (Real)0 / (Real)6;
138 mBlend[3][1] = (Real)0 / (Real)6;
139 mBlend[3][2] = (Real)0 / (Real)6;
140 mBlend[3][3] = (Real)1 / (Real)6;
144template <
typename Real>
inline
150template <
typename Real>
inline
156template <
typename Real>
inline
162template <
typename Real>
inline
168template <
typename Real>
inline
174template <
typename Real>
inline
180template <
typename Real>
inline
186template <
typename Real>
inline
192template <
typename Real>
inline
198template <
typename Real>
inline
204template <
typename Real>
inline
210template <
typename Real>
inline
216template <
typename Real>
inline
222template <
typename Real>
inline
228template <
typename Real>
232 Real xIndex = (x - mXMin) * mInvXSpacing;
233 int ix =
static_cast<int>(xIndex);
238 else if (ix >= mXBound)
244 Real yIndex = (y - mYMin) * mInvYSpacing;
245 int iy =
static_cast<int>(yIndex);
250 else if (iy >= mYBound)
256 Real zIndex = (z - mZMin) * mInvZSpacing;
257 int iz =
static_cast<int>(zIndex);
262 else if (iz >= mZBound)
286 Real P[4], Q[4], R[4];
287 for (
int row = 0; row < 4; ++row)
292 for (
int col = 0; col < 4; ++col)
294 P[row] += mBlend[row][col] * U[col];
295 Q[row] += mBlend[row][col] * V[col];
296 R[row] += mBlend[row][col] * W[col];
305 Real result = (Real)0;
306 for (
int slice = 0; slice < 4; ++slice)
308 int zClamp = iz + slice;
313 else if (zClamp > mZBound - 1)
315 zClamp = mZBound - 1;
318 for (
int row = 0; row < 4; ++row)
320 int yClamp = iy + row;
325 else if (yClamp > mYBound - 1)
327 yClamp = mYBound - 1;
330 for (
int col = 0; col < 4; ++col)
332 int xClamp = ix + col;
337 else if (xClamp > mXBound - 1)
339 xClamp = mXBound - 1;
342 result += P[col] * Q[row] * R[slice] *
343 mF[xClamp + mXBound * (yClamp + mYBound * zClamp)];
351template <
typename Real>
353 Real x, Real y, Real z)
const
356 Real xIndex = (x - mXMin) * mInvXSpacing;
357 int ix =
static_cast<int>(xIndex);
362 else if (ix >= mXBound)
368 Real yIndex = (y - mYMin) * mInvYSpacing;
369 int iy =
static_cast<int>(yIndex);
374 else if (iy >= mYBound)
380 Real zIndex = (z - mZMin) * mInvZSpacing;
381 int iz =
static_cast<int>(zIndex);
386 else if (iz >= mZBound)
391 Real U[4], dx, xMult;
406 U[2] = ((Real)2) * dx;
407 U[3] = ((Real)3) * dx * dx;
408 xMult = mInvXSpacing;
415 U[3] = ((Real)6) * dx;
416 xMult = mInvXSpacing * mInvXSpacing;
423 xMult = mInvXSpacing * mInvXSpacing * mInvXSpacing;
429 Real V[4], dy, yMult;
444 V[2] = ((Real)2) * dy;
445 V[3] = ((Real)3) * dy * dy;
446 yMult = mInvYSpacing;
453 V[3] = ((Real)6) * dy;
454 yMult = mInvYSpacing * mInvYSpacing;
461 yMult = mInvYSpacing * mInvYSpacing * mInvYSpacing;
467 Real W[4], dz, zMult;
482 W[2] = ((Real)2) * dz;
483 W[3] = ((Real)3) * dz * dz;
484 zMult = mInvZSpacing;
491 W[3] = ((Real)6) * dz;
492 zMult = mInvZSpacing * mInvZSpacing;
499 zMult = mInvZSpacing * mInvZSpacing * mInvZSpacing;
506 Real P[4], Q[4], R[4];
507 for (
int row = 0; row < 4; ++row)
512 for (
int col = 0; col < 4; ++col)
514 P[row] += mBlend[row][col] * U[col];
515 Q[row] += mBlend[row][col] * V[col];
516 R[row] += mBlend[row][col] * W[col];
525 Real result = (Real)0;
526 for (
int slice = 0; slice < 4; ++slice)
528 int zClamp = iz + slice;
533 else if (zClamp > mZBound - 1)
535 zClamp = mZBound - 1;
538 for (
int row = 0; row < 4; ++row)
540 int yClamp = iy + row;
545 else if (yClamp > mYBound - 1)
547 yClamp = mYBound - 1;
550 for (
int col = 0; col < 4; ++col)
552 int xClamp = ix + col;
557 else if (xClamp > mXBound - 1)
559 xClamp = mXBound - 1;
562 result += P[col] * Q[row] * R[slice] *
563 mF[xClamp + mXBound * (yClamp + mYBound * zClamp)];
567 result *= xMult * yMult * zMult;
#define Assert(condition, message)
Definition Exception.hpp:10
Definition TricubicInterpolation.hpp:29
Real const * GetF() const
Definition TricubicInterpolation.hpp:169
Real GetXMin() const
Definition TricubicInterpolation.hpp:175
Real GetYMax() const
Definition TricubicInterpolation.hpp:199
int GetXBound() const
Definition TricubicInterpolation.hpp:145
Real GetYMin() const
Definition TricubicInterpolation.hpp:193
Real GetYSpacing() const
Definition TricubicInterpolation.hpp:205
Real GetZMax() const
Definition TricubicInterpolation.hpp:217
int GetZBound() const
Definition TricubicInterpolation.hpp:157
Real operator()(Real x, Real y, Real z) const
Definition TricubicInterpolation.hpp:229
Real GetXSpacing() const
Definition TricubicInterpolation.hpp:187
int GetQuantity() const
Definition TricubicInterpolation.hpp:163
Real GetXMax() const
Definition TricubicInterpolation.hpp:181
int GetYBound() const
Definition TricubicInterpolation.hpp:151
Real GetZMin() const
Definition TricubicInterpolation.hpp:211
Real GetZSpacing() const
Definition TricubicInterpolation.hpp:223
IntpTricubic3(int xBound, int yBound, int zBound, Real xMin, Real xSpacing, Real yMin, Real ySpacing, Real zMin, Real zSpacing, Real const *F, bool catmullRom)
Definition TricubicInterpolation.hpp:74
Definition TricubicInterpolation.hpp:25