CoordinateMapper.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. using RootSystem = System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Windows.Kinect
  5. {
  6. //
  7. // Windows.Kinect.CoordinateMapper
  8. //
  9. public sealed partial class CoordinateMapper : Helper.INativeWrapper
  10. {
  11. internal RootSystem.IntPtr _pNative;
  12. RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
  13. // Constructors and Finalizers
  14. internal CoordinateMapper(RootSystem.IntPtr pNative)
  15. {
  16. _pNative = pNative;
  17. Windows_Kinect_CoordinateMapper_AddRefObject(ref _pNative);
  18. }
  19. ~CoordinateMapper()
  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_CoordinateMapper_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_CoordinateMapper_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<CoordinateMapper>(_pNative);
  35. Windows_Kinect_CoordinateMapper_ReleaseObject(ref _pNative);
  36. _pNative = RootSystem.IntPtr.Zero;
  37. }
  38. // Events
  39. private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_Handle;
  40. [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  41. private delegate void _Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
  42. private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.CoordinateMappingChangedEventArgs>>> Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.CoordinateMappingChangedEventArgs>>>();
  43. [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate))]
  44. private static void Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
  45. {
  46. List<RootSystem.EventHandler<Windows.Kinect.CoordinateMappingChangedEventArgs>> callbackList = null;
  47. Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
  48. lock(callbackList)
  49. {
  50. var objThis = Helper.NativeObjectCache.GetObject<CoordinateMapper>(pNative);
  51. var args = new Windows.Kinect.CoordinateMappingChangedEventArgs(result);
  52. foreach(var func in callbackList)
  53. {
  54. Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
  55. }
  56. }
  57. }
  58. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  59. private static extern void Windows_Kinect_CoordinateMapper_add_CoordinateMappingChanged(RootSystem.IntPtr pNative, _Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate eventCallback, bool unsubscribe);
  60. public event RootSystem.EventHandler<Windows.Kinect.CoordinateMappingChangedEventArgs> CoordinateMappingChanged
  61. {
  62. add
  63. {
  64. Helper.EventPump.EnsureInitialized();
  65. Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  66. var callbackList = Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_callbacks[_pNative];
  67. lock (callbackList)
  68. {
  69. callbackList.Add(value);
  70. if(callbackList.Count == 1)
  71. {
  72. var del = new _Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate(Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_Handler);
  73. _Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
  74. Windows_Kinect_CoordinateMapper_add_CoordinateMappingChanged(_pNative, del, false);
  75. }
  76. }
  77. }
  78. remove
  79. {
  80. if (_pNative == RootSystem.IntPtr.Zero)
  81. {
  82. return;
  83. }
  84. Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  85. var callbackList = Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_callbacks[_pNative];
  86. lock (callbackList)
  87. {
  88. callbackList.Remove(value);
  89. if(callbackList.Count == 0)
  90. {
  91. Windows_Kinect_CoordinateMapper_add_CoordinateMappingChanged(_pNative, Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_Handler, true);
  92. _Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_Handle.Free();
  93. }
  94. }
  95. }
  96. }
  97. // Public Methods
  98. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  99. private static extern RootSystem.IntPtr Windows_Kinect_CoordinateMapper_MapCameraPointToDepthSpace(RootSystem.IntPtr pNative, Windows.Kinect.CameraSpacePoint cameraPoint);
  100. public Windows.Kinect.DepthSpacePoint MapCameraPointToDepthSpace(Windows.Kinect.CameraSpacePoint cameraPoint)
  101. {
  102. if (_pNative == RootSystem.IntPtr.Zero)
  103. {
  104. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  105. }
  106. var objectPointer = Windows_Kinect_CoordinateMapper_MapCameraPointToDepthSpace(_pNative, cameraPoint);
  107. Helper.ExceptionHelper.CheckLastError();
  108. var obj = (Windows.Kinect.DepthSpacePoint)RootSystem.Runtime.InteropServices.Marshal.PtrToStructure(objectPointer, typeof(Windows.Kinect.DepthSpacePoint));
  109. RootSystem.Runtime.InteropServices.Marshal.FreeHGlobal(objectPointer);
  110. return obj;
  111. }
  112. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  113. private static extern RootSystem.IntPtr Windows_Kinect_CoordinateMapper_MapCameraPointToColorSpace(RootSystem.IntPtr pNative, Windows.Kinect.CameraSpacePoint cameraPoint);
  114. public Windows.Kinect.ColorSpacePoint MapCameraPointToColorSpace(Windows.Kinect.CameraSpacePoint cameraPoint)
  115. {
  116. if (_pNative == RootSystem.IntPtr.Zero)
  117. {
  118. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  119. }
  120. var objectPointer = Windows_Kinect_CoordinateMapper_MapCameraPointToColorSpace(_pNative, cameraPoint);
  121. Helper.ExceptionHelper.CheckLastError();
  122. var obj = (Windows.Kinect.ColorSpacePoint)RootSystem.Runtime.InteropServices.Marshal.PtrToStructure(objectPointer, typeof(Windows.Kinect.ColorSpacePoint));
  123. RootSystem.Runtime.InteropServices.Marshal.FreeHGlobal(objectPointer);
  124. return obj;
  125. }
  126. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  127. private static extern RootSystem.IntPtr Windows_Kinect_CoordinateMapper_MapDepthPointToCameraSpace(RootSystem.IntPtr pNative, Windows.Kinect.DepthSpacePoint depthPoint, ushort depth);
  128. public Windows.Kinect.CameraSpacePoint MapDepthPointToCameraSpace(Windows.Kinect.DepthSpacePoint depthPoint, ushort depth)
  129. {
  130. if (_pNative == RootSystem.IntPtr.Zero)
  131. {
  132. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  133. }
  134. var objectPointer = Windows_Kinect_CoordinateMapper_MapDepthPointToCameraSpace(_pNative, depthPoint, depth);
  135. Helper.ExceptionHelper.CheckLastError();
  136. var obj = (Windows.Kinect.CameraSpacePoint)RootSystem.Runtime.InteropServices.Marshal.PtrToStructure(objectPointer, typeof(Windows.Kinect.CameraSpacePoint));
  137. RootSystem.Runtime.InteropServices.Marshal.FreeHGlobal(objectPointer);
  138. return obj;
  139. }
  140. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  141. private static extern RootSystem.IntPtr Windows_Kinect_CoordinateMapper_MapDepthPointToColorSpace(RootSystem.IntPtr pNative, Windows.Kinect.DepthSpacePoint depthPoint, ushort depth);
  142. public Windows.Kinect.ColorSpacePoint MapDepthPointToColorSpace(Windows.Kinect.DepthSpacePoint depthPoint, ushort depth)
  143. {
  144. if (_pNative == RootSystem.IntPtr.Zero)
  145. {
  146. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  147. }
  148. var objectPointer = Windows_Kinect_CoordinateMapper_MapDepthPointToColorSpace(_pNative, depthPoint, depth);
  149. Helper.ExceptionHelper.CheckLastError();
  150. var obj = (Windows.Kinect.ColorSpacePoint)RootSystem.Runtime.InteropServices.Marshal.PtrToStructure(objectPointer, typeof(Windows.Kinect.ColorSpacePoint));
  151. RootSystem.Runtime.InteropServices.Marshal.FreeHGlobal(objectPointer);
  152. return obj;
  153. }
  154. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  155. private static extern void Windows_Kinect_CoordinateMapper_MapCameraPointsToDepthSpace(RootSystem.IntPtr pNative, RootSystem.IntPtr cameraPoints, int cameraPointsSize, RootSystem.IntPtr depthPoints, int depthPointsSize);
  156. public void MapCameraPointsToDepthSpace(Windows.Kinect.CameraSpacePoint[] cameraPoints, Windows.Kinect.DepthSpacePoint[] depthPoints)
  157. {
  158. if (_pNative == RootSystem.IntPtr.Zero)
  159. {
  160. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  161. }
  162. var cameraPointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(cameraPoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  163. var _cameraPoints = cameraPointsSmartGCHandle.AddrOfPinnedObject();
  164. var depthPointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depthPoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  165. var _depthPoints = depthPointsSmartGCHandle.AddrOfPinnedObject();
  166. Windows_Kinect_CoordinateMapper_MapCameraPointsToDepthSpace(_pNative, _cameraPoints, cameraPoints.Length, _depthPoints, depthPoints.Length);
  167. Helper.ExceptionHelper.CheckLastError();
  168. }
  169. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  170. private static extern void Windows_Kinect_CoordinateMapper_MapCameraPointsToColorSpace(RootSystem.IntPtr pNative, RootSystem.IntPtr cameraPoints, int cameraPointsSize, RootSystem.IntPtr colorPoints, int colorPointsSize);
  171. public void MapCameraPointsToColorSpace(Windows.Kinect.CameraSpacePoint[] cameraPoints, Windows.Kinect.ColorSpacePoint[] colorPoints)
  172. {
  173. if (_pNative == RootSystem.IntPtr.Zero)
  174. {
  175. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  176. }
  177. var cameraPointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(cameraPoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  178. var _cameraPoints = cameraPointsSmartGCHandle.AddrOfPinnedObject();
  179. var colorPointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(colorPoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  180. var _colorPoints = colorPointsSmartGCHandle.AddrOfPinnedObject();
  181. Windows_Kinect_CoordinateMapper_MapCameraPointsToColorSpace(_pNative, _cameraPoints, cameraPoints.Length, _colorPoints, colorPoints.Length);
  182. Helper.ExceptionHelper.CheckLastError();
  183. }
  184. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  185. private static extern void Windows_Kinect_CoordinateMapper_MapDepthPointsToCameraSpace(RootSystem.IntPtr pNative, RootSystem.IntPtr depthPoints, int depthPointsSize, RootSystem.IntPtr depths, int depthsSize, RootSystem.IntPtr cameraPoints, int cameraPointsSize);
  186. public void MapDepthPointsToCameraSpace(Windows.Kinect.DepthSpacePoint[] depthPoints, ushort[] depths, Windows.Kinect.CameraSpacePoint[] cameraPoints)
  187. {
  188. if (_pNative == RootSystem.IntPtr.Zero)
  189. {
  190. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  191. }
  192. var depthPointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depthPoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  193. var _depthPoints = depthPointsSmartGCHandle.AddrOfPinnedObject();
  194. var depthsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depths, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  195. var _depths = depthsSmartGCHandle.AddrOfPinnedObject();
  196. var cameraPointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(cameraPoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  197. var _cameraPoints = cameraPointsSmartGCHandle.AddrOfPinnedObject();
  198. Windows_Kinect_CoordinateMapper_MapDepthPointsToCameraSpace(_pNative, _depthPoints, depthPoints.Length, _depths, depths.Length, _cameraPoints, cameraPoints.Length);
  199. Helper.ExceptionHelper.CheckLastError();
  200. }
  201. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  202. private static extern void Windows_Kinect_CoordinateMapper_MapDepthPointsToColorSpace(RootSystem.IntPtr pNative, RootSystem.IntPtr depthPoints, int depthPointsSize, RootSystem.IntPtr depths, int depthsSize, RootSystem.IntPtr colorPoints, int colorPointsSize);
  203. public void MapDepthPointsToColorSpace(Windows.Kinect.DepthSpacePoint[] depthPoints, ushort[] depths, Windows.Kinect.ColorSpacePoint[] colorPoints)
  204. {
  205. if (_pNative == RootSystem.IntPtr.Zero)
  206. {
  207. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  208. }
  209. var depthPointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depthPoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  210. var _depthPoints = depthPointsSmartGCHandle.AddrOfPinnedObject();
  211. var depthsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depths, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  212. var _depths = depthsSmartGCHandle.AddrOfPinnedObject();
  213. var colorPointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(colorPoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  214. var _colorPoints = colorPointsSmartGCHandle.AddrOfPinnedObject();
  215. Windows_Kinect_CoordinateMapper_MapDepthPointsToColorSpace(_pNative, _depthPoints, depthPoints.Length, _depths, depths.Length, _colorPoints, colorPoints.Length);
  216. Helper.ExceptionHelper.CheckLastError();
  217. }
  218. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  219. private static extern void Windows_Kinect_CoordinateMapper_MapDepthFrameToCameraSpace(RootSystem.IntPtr pNative, RootSystem.IntPtr depthFrameData, int depthFrameDataSize, RootSystem.IntPtr cameraSpacePoints, int cameraSpacePointsSize);
  220. public void MapDepthFrameToCameraSpace(ushort[] depthFrameData, Windows.Kinect.CameraSpacePoint[] cameraSpacePoints)
  221. {
  222. if (_pNative == RootSystem.IntPtr.Zero)
  223. {
  224. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  225. }
  226. var depthFrameDataSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depthFrameData, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  227. var _depthFrameData = depthFrameDataSmartGCHandle.AddrOfPinnedObject();
  228. var cameraSpacePointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(cameraSpacePoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  229. var _cameraSpacePoints = cameraSpacePointsSmartGCHandle.AddrOfPinnedObject();
  230. Windows_Kinect_CoordinateMapper_MapDepthFrameToCameraSpace(_pNative, _depthFrameData, depthFrameData.Length, _cameraSpacePoints, cameraSpacePoints.Length);
  231. Helper.ExceptionHelper.CheckLastError();
  232. }
  233. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  234. private static extern void Windows_Kinect_CoordinateMapper_MapDepthFrameToColorSpace(RootSystem.IntPtr pNative, RootSystem.IntPtr depthFrameData, int depthFrameDataSize, RootSystem.IntPtr colorSpacePoints, int colorSpacePointsSize);
  235. public void MapDepthFrameToColorSpace(ushort[] depthFrameData, Windows.Kinect.ColorSpacePoint[] colorSpacePoints)
  236. {
  237. if (_pNative == RootSystem.IntPtr.Zero)
  238. {
  239. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  240. }
  241. var depthFrameDataSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depthFrameData, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  242. var _depthFrameData = depthFrameDataSmartGCHandle.AddrOfPinnedObject();
  243. var colorSpacePointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(colorSpacePoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  244. var _colorSpacePoints = colorSpacePointsSmartGCHandle.AddrOfPinnedObject();
  245. Windows_Kinect_CoordinateMapper_MapDepthFrameToColorSpace(_pNative, _depthFrameData, depthFrameData.Length, _colorSpacePoints, colorSpacePoints.Length);
  246. Helper.ExceptionHelper.CheckLastError();
  247. }
  248. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  249. private static extern void Windows_Kinect_CoordinateMapper_MapColorFrameToDepthSpace(RootSystem.IntPtr pNative, RootSystem.IntPtr depthFrameData, int depthFrameDataSize, RootSystem.IntPtr depthSpacePoints, int depthSpacePointsSize);
  250. public void MapColorFrameToDepthSpace(ushort[] depthFrameData, Windows.Kinect.DepthSpacePoint[] depthSpacePoints)
  251. {
  252. if (_pNative == RootSystem.IntPtr.Zero)
  253. {
  254. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  255. }
  256. var depthFrameDataSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depthFrameData, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  257. var _depthFrameData = depthFrameDataSmartGCHandle.AddrOfPinnedObject();
  258. var depthSpacePointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depthSpacePoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  259. var _depthSpacePoints = depthSpacePointsSmartGCHandle.AddrOfPinnedObject();
  260. Windows_Kinect_CoordinateMapper_MapColorFrameToDepthSpace(_pNative, _depthFrameData, depthFrameData.Length, _depthSpacePoints, depthSpacePoints.Length);
  261. Helper.ExceptionHelper.CheckLastError();
  262. }
  263. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  264. private static extern void Windows_Kinect_CoordinateMapper_MapColorFrameToCameraSpace(RootSystem.IntPtr pNative, RootSystem.IntPtr depthFrameData, int depthFrameDataSize, RootSystem.IntPtr cameraSpacePoints, int cameraSpacePointsSize);
  265. public void MapColorFrameToCameraSpace(ushort[] depthFrameData, Windows.Kinect.CameraSpacePoint[] cameraSpacePoints)
  266. {
  267. if (_pNative == RootSystem.IntPtr.Zero)
  268. {
  269. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  270. }
  271. var depthFrameDataSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(depthFrameData, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  272. var _depthFrameData = depthFrameDataSmartGCHandle.AddrOfPinnedObject();
  273. var cameraSpacePointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(cameraSpacePoints, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  274. var _cameraSpacePoints = cameraSpacePointsSmartGCHandle.AddrOfPinnedObject();
  275. Windows_Kinect_CoordinateMapper_MapColorFrameToCameraSpace(_pNative, _depthFrameData, depthFrameData.Length, _cameraSpacePoints, cameraSpacePoints.Length);
  276. Helper.ExceptionHelper.CheckLastError();
  277. }
  278. private void __EventCleanup()
  279. {
  280. {
  281. Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  282. var callbackList = Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_callbacks[_pNative];
  283. lock (callbackList)
  284. {
  285. if (callbackList.Count > 0)
  286. {
  287. callbackList.Clear();
  288. if (_pNative != RootSystem.IntPtr.Zero)
  289. {
  290. Windows_Kinect_CoordinateMapper_add_CoordinateMappingChanged(_pNative, Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_Handler, true);
  291. }
  292. _Windows_Kinect_CoordinateMappingChangedEventArgs_Delegate_Handle.Free();
  293. }
  294. }
  295. }
  296. }
  297. }
  298. }