CurvatureFlow2.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/PdeFilter2.h>
  9. namespace WwiseGTE
  10. {
  11. template <typename Real>
  12. class CurvatureFlow2 : public PdeFilter2<Real>
  13. {
  14. public:
  15. CurvatureFlow2(int xBound, int yBound, Real xSpacing,
  16. Real ySpacing, Real const* data, bool const* mask,
  17. Real borderValue, typename PdeFilter<Real>::ScaleType scaleType)
  18. :
  19. PdeFilter2<Real>(xBound, yBound, xSpacing, ySpacing, data, mask,
  20. borderValue, scaleType)
  21. {
  22. }
  23. virtual ~CurvatureFlow2()
  24. {
  25. }
  26. protected:
  27. virtual void OnUpdateSingle(int x, int y) override
  28. {
  29. this->LookUp9(x, y);
  30. Real ux = this->mHalfInvDx * (this->mUpz - this->mUmz);
  31. Real uy = this->mHalfInvDy * (this->mUzp - this->mUzm);
  32. Real uxx = this->mInvDxDx * (this->mUpz - (Real)2 * this->mUzz + this->mUmz);
  33. Real uxy = this->mFourthInvDxDy * (this->mUmm + this->mUpp - this->mUmp - this->mUpm);
  34. Real uyy = this->mInvDyDy * (this->mUzp - (Real)2 * this->mUzz + this->mUzm);
  35. Real sqrUx = ux * ux;
  36. Real sqrUy = uy * uy;
  37. Real denom = sqrUx + sqrUy;
  38. if (denom > (Real)0)
  39. {
  40. Real numer = uxx * sqrUy + uyy * sqrUx - (Real)0.5 * uxy * ux * uy;
  41. this->mBuffer[this->mDst][y][x] = this->mUzz + this->mTimeStep * numer / denom;
  42. }
  43. else
  44. {
  45. this->mBuffer[this->mDst][y][x] = this->mUzz;
  46. }
  47. }
  48. };
  49. }