udQueryContext.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. namespace udSDK
  5. {
  6. public class udQueryFilter
  7. {
  8. public IntPtr pQueryFilter = IntPtr.Zero;
  9. public udQueryFilter()
  10. {
  11. udError error = udQueryFilter_Create(ref pQueryFilter);
  12. if (error != udError.udE_Success)
  13. throw new Exception("Query Creation Failed: " + error.ToString());
  14. }
  15. ~udQueryFilter()
  16. {
  17. udError error = udQueryFilter_Destroy(ref pQueryFilter);
  18. if (error != udError.udE_Success)
  19. throw new Exception("Query Destruction Failed: " + error.ToString());
  20. }
  21. /*
  22. *Invert the result of a udQueryFilter
  23. *
  24. Parameters
  25. inverted: True if the filter should be inverted, False is it should behave as default.
  26. */
  27. public void SetInverted(bool inverted)
  28. {
  29. udError error = udQueryFilter_SetInverted(pQueryFilter, inverted);
  30. if (error != udError.udE_Success)
  31. throw new Exception("Query Inversion Failed: " + error.ToString());
  32. }
  33. /*
  34. *Set the udQueryFilter to find voxels within a box.
  35. *
  36. Note:
  37. When inverted, this filter will return all points outside the box.
  38. Parameters:
  39. pQueryFilter: The udQueryFilter to configure.
  40. centrePoint: The world space {X,Y,Z} array for the center point.
  41. halfSize: The local space {X,Y,Z} half size of the box (the world space axis are defined by yawPitchRoll).
  42. yawPitchRoll: The rotation of the model (in radians). Applied in YPR order.
  43. */
  44. public void SetAsBox(double[] centrePoint, double[] halfSize, double[] yawPitchRoll)
  45. {
  46. udError error = udQueryFilter_SetAsBox(pQueryFilter, centrePoint, halfSize, yawPitchRoll);
  47. if (error != udError.udE_Success)
  48. throw new Exception("Query SetAsBox Failed: " + error.ToString());
  49. }
  50. /*
  51. *Set the udQueryFilter to find voxels within a cylinder.
  52. *
  53. Note
  54. When inverted, this filter will return all points outside the cylinder.
  55. Parameters
  56. pQueryFilter: The udQueryFilter to configure.
  57. centrePoint: The world space {X,Y,Z} array for the center point of the cylinder.
  58. radius: The radius of the cylinder (the world space axis are defined by yawPitchRoll) the circle exists in local axis XY extruded along Z.
  59. halfHeight: The half-height of the cylinder (the world space axis are defined by yawPitchRoll) the circle exists in local axis XY extruded along Z.
  60. yawPitchRoll: The rotation of the cylinder (in radians). Applied in YPR order.
  61. */
  62. public void SetAsCylinder(double[] centrePoint, double radius, double halfHeight, double[] yawPitchRoll)
  63. {
  64. udError error = udQueryFilter_SetAsCylinder(pQueryFilter, centrePoint, radius, halfHeight, yawPitchRoll);
  65. if (error != udError.udE_Success)
  66. throw new Exception("Query SetAsCylinder Failed: " + error.ToString());
  67. }
  68. /*
  69. *Set the udQueryFilter to find voxels within a sphere.
  70. *
  71. *
  72. Note:
  73. When inverted, this filter will return all points outside the sphere.
  74. Parameters:
  75. pQueryFilter: The udQueryFilter to configure.
  76. centrePoint: The world space {X,Y,Z} array for the center point.
  77. radius: The radius from the centerPoint to the edge of the sphere.
  78. */
  79. public void SetAsSphere(double[] centrePoint, double radius)
  80. {
  81. udError error = udQueryFilter_SetAsSphere(pQueryFilter, centrePoint, radius);
  82. if (error != udError.udE_Success)
  83. throw new Exception("Query SetAsSphere Failed: " + error.ToString());
  84. }
  85. [DllImport(UDSDKLibrary.name)]
  86. private static extern udError udQueryFilter_Create(ref IntPtr ppQueryFilter);
  87. [DllImport(UDSDKLibrary.name)]
  88. private static extern udError udQueryFilter_Destroy(ref IntPtr ppQueryFilter);
  89. [DllImport(UDSDKLibrary.name)]
  90. private static extern udError udQueryFilter_SetInverted(IntPtr pQueryFilter, bool inverted);
  91. [DllImport(UDSDKLibrary.name)]
  92. private static extern udError udQueryFilter_SetAsBox(IntPtr pQueryFilter, double[] centrePoint, double[] halfSize, double[] yawPitchRoll);
  93. [DllImport(UDSDKLibrary.name)]
  94. private static extern udError udQueryFilter_SetAsCylinder(IntPtr pQueryFilter, double[] centrePoint, double radius, double halfHeight, double[] yawPitchRoll);
  95. [DllImport(UDSDKLibrary.name)]
  96. private static extern udError udQueryFilter_SetAsSphere(IntPtr pQueryFilter, double[] centrePoint, double radius);
  97. }
  98. }