Delaunay3Mesh.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/Delaunay3.h>
  9. namespace WwiseGTE
  10. {
  11. template <typename InputType, typename ComputeType, typename RationalType>
  12. class Delaunay3Mesh
  13. {
  14. public:
  15. // Construction.
  16. Delaunay3Mesh(Delaunay3<InputType, ComputeType> const& delaunay)
  17. :
  18. mDelaunay(&delaunay)
  19. {
  20. }
  21. // Mesh information.
  22. inline int GetNumVertices() const
  23. {
  24. return mDelaunay->GetNumVertices();
  25. }
  26. inline int GetNumTetrahedra() const
  27. {
  28. return mDelaunay->GetNumTetrahedra();
  29. }
  30. inline Vector3<InputType> const* GetVertices() const
  31. {
  32. return mDelaunay->GetVertices();
  33. }
  34. inline int const* GetIndices() const
  35. {
  36. return &mDelaunay->GetIndices()[0];
  37. }
  38. inline int const* GetAdjacencies() const
  39. {
  40. return &mDelaunay->GetAdjacencies()[0];
  41. }
  42. // Containment queries.
  43. int GetContainingTetrahedron(Vector3<InputType> const& P) const
  44. {
  45. typename Delaunay3<InputType, ComputeType>::SearchInfo info;
  46. return mDelaunay->GetContainingTetrahedron(P, info);
  47. }
  48. bool GetVertices(int t, std::array<Vector3<InputType>, 4>& vertices) const
  49. {
  50. if (mDelaunay->GetDimension() == 3)
  51. {
  52. std::array<int, 4> indices;
  53. if (mDelaunay->GetIndices(t, indices))
  54. {
  55. PrimalQuery3<ComputeType> const& query = mDelaunay->GetQuery();
  56. Vector3<ComputeType> const* ctVertices = query.GetVertices();
  57. for (int i = 0; i < 4; ++i)
  58. {
  59. Vector3<ComputeType> const& V = ctVertices[indices[i]];
  60. for (int j = 0; j < 3; ++j)
  61. {
  62. vertices[i][j] = (InputType)V[j];
  63. }
  64. }
  65. return true;
  66. }
  67. }
  68. return false;
  69. }
  70. bool GetIndices(int t, std::array<int, 4>& indices) const
  71. {
  72. return mDelaunay->GetIndices(t, indices);
  73. }
  74. bool GetAdjacencies(int t, std::array<int, 4>& adjacencies) const
  75. {
  76. return mDelaunay->GetAdjacencies(t, adjacencies);
  77. }
  78. bool GetBarycentrics(int t, Vector3<InputType> const& P, std::array<InputType, 4>& bary) const
  79. {
  80. std::array<int, 4> indices;
  81. if (mDelaunay->GetIndices(t, indices))
  82. {
  83. PrimalQuery3<ComputeType> const& query = mDelaunay->GetQuery();
  84. Vector3<ComputeType> const* vertices = query.GetVertices();
  85. Vector3<RationalType> rtP{ P[0], P[1], P[2] };
  86. std::array<Vector3<RationalType>, 4> rtV;
  87. for (int i = 0; i < 4; ++i)
  88. {
  89. Vector3<ComputeType> const& V = vertices[indices[i]];
  90. for (int j = 0; j < 3; ++j)
  91. {
  92. rtV[i][j] = (RationalType)V[j];
  93. }
  94. };
  95. RationalType rtBary[4];
  96. if (ComputeBarycentrics(rtP, rtV[0], rtV[1], rtV[2], rtV[3], rtBary))
  97. {
  98. for (int i = 0; i < 4; ++i)
  99. {
  100. bary[i] = (InputType)rtBary[i];
  101. }
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. private:
  108. Delaunay3<InputType, ComputeType> const* mDelaunay;
  109. };
  110. }