123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- #pragma once
- #include <Mathematics/Math.h>
- namespace WwiseGTE
- {
- template <typename T>
- class FastGaussianBlur3
- {
- public:
- void Execute(int xBound, int yBound, int zBound, T const* input, T* output,
- double scale, double logBase)
- {
- mXBound = xBound;
- mYBound = yBound;
- mZBound = zBound;
- mInput = input;
- mOutput = output;
- int xBoundM1 = xBound - 1, yBoundM1 = yBound - 1, zBoundM1 = zBound - 1;
- for (int z = 0; z < zBound; ++z)
- {
- double rzps = static_cast<double>(z) + scale;
- double rzms = static_cast<double>(z) - scale;
- int zp1 = static_cast<int>(std::floor(rzps));
- int zm1 = static_cast<int>(std::ceil(rzms));
- for (int y = 0; y < yBound; ++y)
- {
- double ryps = static_cast<double>(y) + scale;
- double ryms = static_cast<double>(y) - scale;
- int yp1 = static_cast<int>(std::floor(ryps));
- int ym1 = static_cast<int>(std::ceil(ryms));
- for (int x = 0; x < xBound; ++x)
- {
- double rxps = static_cast<double>(x) + scale;
- double rxms = static_cast<double>(x) - scale;
- int xp1 = static_cast<int>(std::floor(rxps));
- int xm1 = static_cast<int>(std::ceil(rxms));
- double center = Input(x, y, z);
- double xsum = -2.0 * center, ysum = xsum, zsum = xsum;
-
- if (xp1 >= xBoundM1)
- {
- xsum += Input(xBoundM1, y, z);
- }
- else
- {
- double imgXp1 = Input(xp1, y, z);
- double imgXp2 = Input(xp1 + 1, y, z);
- double delta = rxps - static_cast<double>(xp1);
- xsum += imgXp1 + delta * (imgXp2 - imgXp1);
- }
- if (xm1 <= 0)
- {
- xsum += Input(0, y, z);
- }
- else
- {
- double imgXm1 = Input(xm1, y, z);
- double imgXm2 = Input(xm1 - 1, y, z);
- double delta = rxms - static_cast<double>(xm1);
- xsum += imgXm1 + delta * (imgXm1 - imgXm2);
- }
-
- if (yp1 >= yBoundM1)
- {
- ysum += Input(x, yBoundM1, z);
- }
- else
- {
- double imgYp1 = Input(x, yp1, z);
- double imgYp2 = Input(x, yp1 + 1, z);
- double delta = ryps - static_cast<double>(yp1);
- ysum += imgYp1 + delta * (imgYp2 - imgYp1);
- }
- if (ym1 <= 0)
- {
- ysum += Input(x, 0, z);
- }
- else
- {
- double imgYm1 = Input(x, ym1, z);
- double imgYm2 = Input(x, ym1 - 1, z);
- double delta = ryms - static_cast<double>(ym1);
- ysum += imgYm1 + delta * (imgYm1 - imgYm2);
- }
-
- if (zp1 >= zBoundM1)
- {
- zsum += Input(x, y, zBoundM1);
- }
- else
- {
- double imgZp1 = Input(x, y, zp1);
- double imgZp2 = Input(x, y, zp1 + 1);
- double delta = rzps - static_cast<double>(zp1);
- zsum += imgZp1 + delta * (imgZp2 - imgZp1);
- }
- if (zm1 <= 0)
- {
- zsum += Input(x, y, 0);
- }
- else
- {
- double imgZm1 = Input(x, y, zm1);
- double imgZm2 = Input(x, y, zm1 - 1);
- double delta = rzms - static_cast<double>(zm1);
- zsum += imgZm1 + delta * (imgZm1 - imgZm2);
- }
- Output(x, y, z) = static_cast<T>(center + logBase * (xsum + ysum + zsum));
- }
- }
- }
- }
- private:
- inline double Input(int x, int y, int z) const
- {
- return static_cast<double>(mInput[x + mXBound * (y + mYBound * z)]);
- }
- inline T& Output(int x, int y, int z)
- {
- return mOutput[x + mXBound * (y + mYBound * z)];
- }
- int mXBound, mYBound, mZBound;
- T const* mInput;
- T* mOutput;
- };
- }
|