IntpVectorField2.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.2019.08.13
  7. #pragma once
  8. #include <Mathematics/Delaunay2Mesh.h>
  9. #include <Mathematics/IntpQuadraticNonuniform2.h>
  10. #include <memory>
  11. // Given points (x0[i],y0[i]) which are mapped to (x1[i],y1[i]) for
  12. // 0 <= i < N, interpolate positions (xIn,yIn) to (xOut,yOut).
  13. namespace WwiseGTE
  14. {
  15. template <typename InputType, typename ComputeType, typename RationalType>
  16. class IntpVectorField2
  17. {
  18. public:
  19. // Construction and destruction.
  20. ~IntpVectorField2() = default;
  21. IntpVectorField2(int numPoints, Vector2<InputType> const* domain,
  22. Vector2<InputType> const* range)
  23. :
  24. mMesh(mDelaunay)
  25. {
  26. // Repackage the output vectors into individual components. This
  27. // is required because of the format that the quadratic
  28. // interpolator expects for its input data.
  29. mXRange.resize(numPoints);
  30. mYRange.resize(numPoints);
  31. for (int i = 0; i < numPoints; ++i)
  32. {
  33. mXRange[i] = range[i][0];
  34. mYRange[i] = range[i][1];
  35. }
  36. // Common triangulator for the interpolators.
  37. mDelaunay(numPoints, &domain[0], (ComputeType)0);
  38. // Create interpolator for x-coordinate of vector field.
  39. mXInterp = std::make_unique<IntpQuadraticNonuniform2<InputType, TriangleMesh>>(
  40. mMesh, &mXRange[0], (InputType)1);
  41. // Create interpolator for y-coordinate of vector field, but share the
  42. // already created triangulation for the x-interpolator.
  43. mYInterp = std::make_unique<IntpQuadraticNonuniform2<InputType, TriangleMesh>>(
  44. mMesh, &mYRange[0], (InputType)1);
  45. }
  46. // The return value is 'true' if and only if (xIn,yIn) is in the
  47. // convex hull of the input domain points, in which case the
  48. // interpolation is valid.
  49. bool operator()(Vector2<InputType> const& input, Vector2<InputType>& output) const
  50. {
  51. InputType xDeriv, yDeriv;
  52. return (*mXInterp)(input, output[0], xDeriv, yDeriv)
  53. && (*mYInterp)(input, output[1], xDeriv, yDeriv);
  54. }
  55. protected:
  56. typedef Delaunay2Mesh<InputType, ComputeType, RationalType> TriangleMesh;
  57. Delaunay2<InputType, ComputeType> mDelaunay;
  58. TriangleMesh mMesh;
  59. std::vector<InputType> mXRange;
  60. std::vector<InputType> mYRange;
  61. std::unique_ptr<IntpQuadraticNonuniform2<InputType, TriangleMesh>> mXInterp;
  62. std::unique_ptr<IntpQuadraticNonuniform2<InputType, TriangleMesh>> mYInterp;
  63. };
  64. }