ParametricSurface.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/Vector.h>
  9. namespace WwiseGTE
  10. {
  11. template <int N, typename Real>
  12. class ParametricSurface
  13. {
  14. protected:
  15. // Abstract base class for a parameterized surface X(u,v). The
  16. // parametric domain is either rectangular or triangular. Valid
  17. // (u,v) values for a rectangular domain satisfy
  18. // umin <= u <= umax, vmin <= v <= vmax
  19. // and valid (u,v) values for a triangular domain satisfy
  20. // umin <= u <= umax, vmin <= v <= vmax,
  21. // (vmax-vmin)*(u-umin)+(umax-umin)*(v-vmax) <= 0
  22. ParametricSurface(Real umin, Real umax, Real vmin, Real vmax, bool rectangular)
  23. :
  24. mUMin(umin),
  25. mUMax(umax),
  26. mVMin(vmin),
  27. mVMax(vmax),
  28. mRectangular(rectangular)
  29. {
  30. }
  31. public:
  32. virtual ~ParametricSurface()
  33. {
  34. }
  35. // To validate construction, create an object as shown:
  36. // DerivedClassSurface<Real> surface(parameters);
  37. // if (!surface) { <constructor failed, handle accordingly>; }
  38. inline operator bool() const
  39. {
  40. return mConstructed;
  41. }
  42. // Member access.
  43. inline Real GetUMin() const
  44. {
  45. return mUMin;
  46. }
  47. inline Real GetUMax() const
  48. {
  49. return mUMax;
  50. }
  51. inline Real GetVMin() const
  52. {
  53. return mVMin;
  54. }
  55. inline Real GetVMax() const
  56. {
  57. return mVMax;
  58. }
  59. inline bool IsRectangular() const
  60. {
  61. return mRectangular;
  62. }
  63. // Evaluation of the surface. The function supports derivative
  64. // calculation through order 2; that is, order <= 2 is required. If
  65. // you want only the position, pass in order of 0. If you want the
  66. // position and first-order derivatives, pass in order of 1, and so
  67. // on. The output array 'jet' must have enough storage to support the
  68. // maximum order. The values are ordered as: position X; first-order
  69. // derivatives dX/du, dX/dv; second-order derivatives d2X/du2,
  70. // d2X/dudv, d2X/dv2.
  71. enum { SUP_ORDER = 6 };
  72. virtual void Evaluate(Real u, Real v, unsigned int order, Vector<N, Real>* jet) const = 0;
  73. // Differential geometric quantities.
  74. Vector<N, Real> GetPosition(Real u, Real v) const
  75. {
  76. Vector<N, Real> position;
  77. Evaluate(u, v, 0, &position);
  78. return position;
  79. }
  80. Vector<N, Real> GetUTangent(Real u, Real v) const
  81. {
  82. std::array<Vector<N, Real>, 3> jet;
  83. Evaluate(u, v, 1, jet.data());
  84. Normalize(jet[1]);
  85. return jet[1];
  86. }
  87. Vector<N, Real> GetVTangent(Real u, Real v) const
  88. {
  89. std::array<Vector<N, Real>, 3> jet;
  90. Evaluate(u, v, 1, jet.data());
  91. Normalize(jet[2]);
  92. return jet[2];
  93. }
  94. protected:
  95. Real mUMin, mUMax, mVMin, mVMax;
  96. bool mRectangular;
  97. bool mConstructed;
  98. };
  99. }