DepthFrame.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using RootSystem = System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Windows.Kinect
  5. {
  6. //
  7. // Windows.Kinect.DepthFrame
  8. //
  9. public sealed partial class DepthFrame : RootSystem.IDisposable, Helper.INativeWrapper
  10. {
  11. internal RootSystem.IntPtr _pNative;
  12. RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
  13. // Constructors and Finalizers
  14. internal DepthFrame(RootSystem.IntPtr pNative)
  15. {
  16. _pNative = pNative;
  17. Windows_Kinect_DepthFrame_AddRefObject(ref _pNative);
  18. }
  19. ~DepthFrame()
  20. {
  21. Dispose(false);
  22. }
  23. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  24. private static extern void Windows_Kinect_DepthFrame_ReleaseObject(ref RootSystem.IntPtr pNative);
  25. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  26. private static extern void Windows_Kinect_DepthFrame_AddRefObject(ref RootSystem.IntPtr pNative);
  27. private void Dispose(bool disposing)
  28. {
  29. if (_pNative == RootSystem.IntPtr.Zero)
  30. {
  31. return;
  32. }
  33. __EventCleanup();
  34. Helper.NativeObjectCache.RemoveObject<DepthFrame>(_pNative);
  35. if (disposing)
  36. {
  37. Windows_Kinect_DepthFrame_Dispose(_pNative);
  38. }
  39. Windows_Kinect_DepthFrame_ReleaseObject(ref _pNative);
  40. _pNative = RootSystem.IntPtr.Zero;
  41. }
  42. // Public Properties
  43. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  44. private static extern RootSystem.IntPtr Windows_Kinect_DepthFrame_get_DepthFrameSource(RootSystem.IntPtr pNative);
  45. public Windows.Kinect.DepthFrameSource DepthFrameSource
  46. {
  47. get
  48. {
  49. if (_pNative == RootSystem.IntPtr.Zero)
  50. {
  51. throw new RootSystem.ObjectDisposedException("DepthFrame");
  52. }
  53. RootSystem.IntPtr objectPointer = Windows_Kinect_DepthFrame_get_DepthFrameSource(_pNative);
  54. Helper.ExceptionHelper.CheckLastError();
  55. if (objectPointer == RootSystem.IntPtr.Zero)
  56. {
  57. return null;
  58. }
  59. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.DepthFrameSource>(objectPointer, n => new Windows.Kinect.DepthFrameSource(n));
  60. }
  61. }
  62. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  63. private static extern ushort Windows_Kinect_DepthFrame_get_DepthMaxReliableDistance(RootSystem.IntPtr pNative);
  64. public ushort DepthMaxReliableDistance
  65. {
  66. get
  67. {
  68. if (_pNative == RootSystem.IntPtr.Zero)
  69. {
  70. throw new RootSystem.ObjectDisposedException("DepthFrame");
  71. }
  72. return Windows_Kinect_DepthFrame_get_DepthMaxReliableDistance(_pNative);
  73. }
  74. }
  75. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  76. private static extern ushort Windows_Kinect_DepthFrame_get_DepthMinReliableDistance(RootSystem.IntPtr pNative);
  77. public ushort DepthMinReliableDistance
  78. {
  79. get
  80. {
  81. if (_pNative == RootSystem.IntPtr.Zero)
  82. {
  83. throw new RootSystem.ObjectDisposedException("DepthFrame");
  84. }
  85. return Windows_Kinect_DepthFrame_get_DepthMinReliableDistance(_pNative);
  86. }
  87. }
  88. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  89. private static extern RootSystem.IntPtr Windows_Kinect_DepthFrame_get_FrameDescription(RootSystem.IntPtr pNative);
  90. public Windows.Kinect.FrameDescription FrameDescription
  91. {
  92. get
  93. {
  94. if (_pNative == RootSystem.IntPtr.Zero)
  95. {
  96. throw new RootSystem.ObjectDisposedException("DepthFrame");
  97. }
  98. RootSystem.IntPtr objectPointer = Windows_Kinect_DepthFrame_get_FrameDescription(_pNative);
  99. Helper.ExceptionHelper.CheckLastError();
  100. if (objectPointer == RootSystem.IntPtr.Zero)
  101. {
  102. return null;
  103. }
  104. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.FrameDescription>(objectPointer, n => new Windows.Kinect.FrameDescription(n));
  105. }
  106. }
  107. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  108. private static extern long Windows_Kinect_DepthFrame_get_RelativeTime(RootSystem.IntPtr pNative);
  109. public RootSystem.TimeSpan RelativeTime
  110. {
  111. get
  112. {
  113. if (_pNative == RootSystem.IntPtr.Zero)
  114. {
  115. throw new RootSystem.ObjectDisposedException("DepthFrame");
  116. }
  117. return RootSystem.TimeSpan.FromMilliseconds(Windows_Kinect_DepthFrame_get_RelativeTime(_pNative));
  118. }
  119. }
  120. // Public Methods
  121. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  122. private static extern void Windows_Kinect_DepthFrame_CopyFrameDataToArray(RootSystem.IntPtr pNative, RootSystem.IntPtr frameData, int frameDataSize);
  123. public void CopyFrameDataToArray(ushort[] frameData)
  124. {
  125. if (_pNative == RootSystem.IntPtr.Zero)
  126. {
  127. throw new RootSystem.ObjectDisposedException("DepthFrame");
  128. }
  129. var frameDataSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(frameData, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  130. var _frameData = frameDataSmartGCHandle.AddrOfPinnedObject();
  131. Windows_Kinect_DepthFrame_CopyFrameDataToArray(_pNative, _frameData, frameData.Length);
  132. Helper.ExceptionHelper.CheckLastError();
  133. }
  134. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  135. private static extern void Windows_Kinect_DepthFrame_Dispose(RootSystem.IntPtr pNative);
  136. public void Dispose()
  137. {
  138. if (_pNative == RootSystem.IntPtr.Zero)
  139. {
  140. return;
  141. }
  142. Dispose(true);
  143. RootSystem.GC.SuppressFinalize(this);
  144. }
  145. private void __EventCleanup()
  146. {
  147. }
  148. }
  149. }