btMiniSDF.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef MINISDF_H
  2. #define MINISDF_H
  3. #include "LinearMath/btVector3.h"
  4. #include "LinearMath/btAabbUtil2.h"
  5. #include "LinearMath/btAlignedObjectArray.h"
  6. struct btMultiIndex
  7. {
  8. unsigned int ijk[3];
  9. };
  10. struct btAlignedBox3d
  11. {
  12. btVector3 m_min;
  13. btVector3 m_max;
  14. const btVector3& min() const
  15. {
  16. return m_min;
  17. }
  18. const btVector3& max() const
  19. {
  20. return m_max;
  21. }
  22. bool contains(const btVector3& x) const
  23. {
  24. return TestPointAgainstAabb2(m_min, m_max, x);
  25. }
  26. btAlignedBox3d(const btVector3& mn, const btVector3& mx)
  27. : m_min(mn),
  28. m_max(mx)
  29. {
  30. }
  31. btAlignedBox3d()
  32. {
  33. }
  34. };
  35. struct btShapeMatrix
  36. {
  37. double m_vec[32];
  38. inline double& operator[](int i)
  39. {
  40. return m_vec[i];
  41. }
  42. inline const double& operator[](int i) const
  43. {
  44. return m_vec[i];
  45. }
  46. };
  47. struct btShapeGradients
  48. {
  49. btVector3 m_vec[32];
  50. void topRowsDivide(int row, double denom)
  51. {
  52. for (int i = 0; i < row; i++)
  53. {
  54. m_vec[i] /= denom;
  55. }
  56. }
  57. void bottomRowsMul(int row, double val)
  58. {
  59. for (int i = 32 - row; i < 32; i++)
  60. {
  61. m_vec[i] *= val;
  62. }
  63. }
  64. inline btScalar& operator()(int i, int j)
  65. {
  66. return m_vec[i][j];
  67. }
  68. };
  69. struct btCell32
  70. {
  71. unsigned int m_cells[32];
  72. };
  73. struct btMiniSDF
  74. {
  75. btAlignedBox3d m_domain;
  76. unsigned int m_resolution[3];
  77. btVector3 m_cell_size;
  78. btVector3 m_inv_cell_size;
  79. std::size_t m_n_cells;
  80. std::size_t m_n_fields;
  81. bool m_isValid;
  82. btAlignedObjectArray<btAlignedObjectArray<double> > m_nodes;
  83. btAlignedObjectArray<btAlignedObjectArray<btCell32> > m_cells;
  84. btAlignedObjectArray<btAlignedObjectArray<unsigned int> > m_cell_map;
  85. btMiniSDF()
  86. : m_isValid(false)
  87. {
  88. }
  89. bool load(const char* data, int size);
  90. bool isValid() const
  91. {
  92. return m_isValid;
  93. }
  94. unsigned int multiToSingleIndex(btMultiIndex const& ijk) const;
  95. btAlignedBox3d subdomain(btMultiIndex const& ijk) const;
  96. btMultiIndex singleToMultiIndex(unsigned int l) const;
  97. btAlignedBox3d subdomain(unsigned int l) const;
  98. btShapeMatrix
  99. shape_function_(btVector3 const& xi, btShapeGradients* gradient = 0) const;
  100. bool interpolate(unsigned int field_id, double& dist, btVector3 const& x, btVector3* gradient) const;
  101. };
  102. #endif //MINISDF_H