CurvatureFlow3.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2020.01.11
  7. #pragma once
  8. #include <Mathematics/PdeFilter3.h>
  9. namespace WwiseGTE
  10. {
  11. template <typename Real>
  12. class CurvatureFlow3 : public PdeFilter3<Real>
  13. {
  14. public:
  15. CurvatureFlow3(int xBound, int yBound, int zBound, Real xSpacing,
  16. Real ySpacing, Real zSpacing, Real const* data, bool const* mask,
  17. Real borderValue, typename PdeFilter<Real>::ScaleType scaleType)
  18. :
  19. PdeFilter3<Real>(xBound, yBound, zBound, xSpacing, ySpacing,
  20. zSpacing, data, mask, borderValue, scaleType)
  21. {
  22. }
  23. virtual ~CurvatureFlow3()
  24. {
  25. }
  26. protected:
  27. virtual void OnUpdateSingle(int x, int y, int z) override
  28. {
  29. this->LookUp27(x, y, z);
  30. Real ux = this->mHalfInvDx * (this->mUpzz - this->mUmzz);
  31. Real uy = this->mHalfInvDy * (this->mUzpz - this->mUzmz);
  32. Real uz = this->mHalfInvDz * (this->mUzzp - this->mUzzm);
  33. Real uxx = this->mInvDxDx * (this->mUpzz - (Real)2 * this->mUzzz + this->mUmzz);
  34. Real uxy = this->mFourthInvDxDy * (this->mUmmz + this->mUppz - this->mUpmz - this->mUmpz);
  35. Real uxz = this->mFourthInvDxDz * (this->mUmzm + this->mUpzp - this->mUpzm - this->mUmzp);
  36. Real uyy = this->mInvDyDy * (this->mUzpz - (Real)2 * this->mUzzz + this->mUzmz);
  37. Real uyz = this->mFourthInvDyDz * (this->mUzmm + this->mUzpp - this->mUzpm - this->mUzmp);
  38. Real uzz = this->mInvDzDz * (this->mUzzp - (Real)2 * this->mUzzz + this->mUzzm);
  39. Real denom = ux * ux + uy * uy + uz * uz;
  40. if (denom > (Real)0)
  41. {
  42. Real numer0 = uy * (uxx*uy - uxy * ux) + ux * (uyy*ux - uxy * uy);
  43. Real numer1 = uz * (uxx*uz - uxz * ux) + ux * (uzz*ux - uxz * uz);
  44. Real numer2 = uz * (uyy*uz - uyz * uy) + uy * (uzz*uy - uyz * uz);
  45. Real numer = numer0 + numer1 + numer2;
  46. this->mBuffer[this->mDst][z][y][x] = this->mUzzz + this->mTimeStep * numer / denom;
  47. }
  48. else
  49. {
  50. this->mBuffer[this->mDst][z][y][x] = this->mUzzz;
  51. }
  52. }
  53. };
  54. }