KinectSpecialCases.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. using RootSystem = System;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. namespace Windows.Kinect
  6. {
  7. [RootSystem.Runtime.InteropServices.StructLayout(RootSystem.Runtime.InteropServices.LayoutKind.Sequential)]
  8. public struct PointF
  9. {
  10. public float X { get; set; }
  11. public float Y { get; set; }
  12. public override int GetHashCode()
  13. {
  14. return X.GetHashCode() ^ Y.GetHashCode();
  15. }
  16. public override bool Equals(object obj)
  17. {
  18. if (!(obj is PointF))
  19. {
  20. return false;
  21. }
  22. return this.Equals((ColorSpacePoint)obj);
  23. }
  24. public bool Equals(ColorSpacePoint obj)
  25. {
  26. return (X == obj.X) && (Y == obj.Y);
  27. }
  28. public static bool operator ==(PointF a, PointF b)
  29. {
  30. return a.Equals(b);
  31. }
  32. public static bool operator !=(PointF a, PointF b)
  33. {
  34. return !(a.Equals(b));
  35. }
  36. }
  37. public sealed partial class AudioBeamSubFrame
  38. {
  39. [RootSystem.Runtime.InteropServices.DllImport(
  40. "KinectUnityAddin",
  41. EntryPoint = "Windows_Kinect_AudioBeamSubFrame_CopyFrameDataToArray",
  42. CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl,
  43. SetLastError = true)]
  44. private static extern void Windows_Kinect_AudioBeamSubFrame_CopyFrameDataToIntPtr(RootSystem.IntPtr pNative, RootSystem.IntPtr frameData, uint frameDataSize);
  45. public void CopyFrameDataToIntPtr(RootSystem.IntPtr frameData, uint size)
  46. {
  47. if (_pNative == RootSystem.IntPtr.Zero)
  48. {
  49. throw new RootSystem.ObjectDisposedException("AudioBeamSubFrame");
  50. }
  51. Windows_Kinect_AudioBeamSubFrame_CopyFrameDataToIntPtr(_pNative, frameData, size);
  52. Helper.ExceptionHelper.CheckLastError();
  53. }
  54. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  55. private static extern RootSystem.IntPtr Windows_Kinect_AudioBeamSubFrame_LockAudioBuffer(RootSystem.IntPtr pNative);
  56. public Windows.Kinect.KinectBuffer LockAudioBuffer()
  57. {
  58. if (_pNative == RootSystem.IntPtr.Zero)
  59. {
  60. throw new RootSystem.ObjectDisposedException("AudioBeamSubFrame");
  61. }
  62. RootSystem.IntPtr objectPointer = Windows_Kinect_AudioBeamSubFrame_LockAudioBuffer(_pNative);
  63. Helper.ExceptionHelper.CheckLastError();
  64. if (objectPointer == RootSystem.IntPtr.Zero)
  65. {
  66. return null;
  67. }
  68. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectBuffer>(objectPointer, n => new Windows.Kinect.KinectBuffer(n));
  69. }
  70. }
  71. public sealed partial class AudioBeamFrame
  72. {
  73. private Windows.Kinect.AudioBeamSubFrame[] _subFrames = null;
  74. private void Dispose(bool disposing)
  75. {
  76. if (_pNative == RootSystem.IntPtr.Zero)
  77. {
  78. return;
  79. }
  80. if (_subFrames != null)
  81. {
  82. foreach (var subFrame in _subFrames)
  83. {
  84. subFrame.Dispose();
  85. }
  86. _subFrames = null;
  87. }
  88. __EventCleanup();
  89. Helper.NativeObjectCache.RemoveObject<AudioBeamFrame>(_pNative);
  90. Windows_Kinect_AudioBeamFrame_ReleaseObject(ref _pNative);
  91. if (disposing)
  92. {
  93. Windows_Kinect_AudioBeamFrame_Dispose(_pNative);
  94. }
  95. _pNative = RootSystem.IntPtr.Zero;
  96. }
  97. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  98. private static extern void Windows_Kinect_AudioBeamFrame_Dispose(RootSystem.IntPtr pNative);
  99. public void Dispose()
  100. {
  101. if (_pNative == RootSystem.IntPtr.Zero)
  102. {
  103. return;
  104. }
  105. Dispose(true);
  106. RootSystem.GC.SuppressFinalize(this);
  107. }
  108. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  109. private static extern int Windows_Kinect_AudioBeamFrame_get_SubFrames(RootSystem.IntPtr pNative, [RootSystem.Runtime.InteropServices.Out] RootSystem.IntPtr[] outCollection, int outCollectionSize);
  110. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  111. private static extern int Windows_Kinect_AudioBeamFrame_get_SubFrames_Length(RootSystem.IntPtr pNative);
  112. public RootSystem.Collections.Generic.IList<Windows.Kinect.AudioBeamSubFrame> SubFrames
  113. {
  114. get
  115. {
  116. if (_pNative == RootSystem.IntPtr.Zero)
  117. {
  118. throw new RootSystem.ObjectDisposedException("AudioBeamFrame");
  119. }
  120. if (_subFrames == null)
  121. {
  122. int collectionSize = Windows_Kinect_AudioBeamFrame_get_SubFrames_Length(_pNative);
  123. var outCollection = new RootSystem.IntPtr[collectionSize];
  124. _subFrames = new Windows.Kinect.AudioBeamSubFrame[collectionSize];
  125. collectionSize = Windows_Kinect_AudioBeamFrame_get_SubFrames(_pNative, outCollection, collectionSize);
  126. Helper.ExceptionHelper.CheckLastError();
  127. for (int i = 0; i < collectionSize; i++)
  128. {
  129. if (outCollection[i] == RootSystem.IntPtr.Zero)
  130. {
  131. continue;
  132. }
  133. var obj = Helper.NativeObjectCache.GetObject<Windows.Kinect.AudioBeamSubFrame>(outCollection[i]);
  134. if (obj == null)
  135. {
  136. obj = new Windows.Kinect.AudioBeamSubFrame(outCollection[i]);
  137. Helper.NativeObjectCache.AddObject<Windows.Kinect.AudioBeamSubFrame>(outCollection[i], obj);
  138. }
  139. _subFrames[i] = obj;
  140. }
  141. }
  142. return _subFrames;
  143. }
  144. }
  145. }
  146. public sealed partial class BodyFrame
  147. {
  148. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  149. private static extern void Windows_Kinect_BodyFrame_GetAndRefreshBodyData(RootSystem.IntPtr pNative, [RootSystem.Runtime.InteropServices.Out] RootSystem.IntPtr[] bodies, int bodiesSize);
  150. public void GetAndRefreshBodyData(RootSystem.Collections.Generic.IList<Windows.Kinect.Body> bodies)
  151. {
  152. if (_pNative == RootSystem.IntPtr.Zero)
  153. {
  154. throw new RootSystem.ObjectDisposedException("BodyFrame");
  155. }
  156. int _bodies_idx = 0;
  157. var _bodies = new RootSystem.IntPtr[bodies.Count];
  158. for (int i = 0; i < bodies.Count; i++)
  159. {
  160. if (bodies[i] == null)
  161. {
  162. bodies[i] = new Body();
  163. }
  164. _bodies[_bodies_idx] = bodies[i].GetIntPtr();
  165. _bodies_idx++;
  166. }
  167. Windows_Kinect_BodyFrame_GetAndRefreshBodyData(_pNative, _bodies, bodies.Count);
  168. Helper.ExceptionHelper.CheckLastError();
  169. for (int i = 0; i < bodies.Count; i++)
  170. {
  171. bodies[i].SetIntPtr(_bodies[i]);
  172. }
  173. }
  174. }
  175. public sealed partial class Body
  176. {
  177. internal void SetIntPtr(RootSystem.IntPtr value) { _pNative = value; }
  178. internal RootSystem.IntPtr GetIntPtr() { return _pNative; }
  179. internal Body() { }
  180. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  181. private static extern RootSystem.IntPtr Windows_Kinect_Body_get_Lean(RootSystem.IntPtr pNative);
  182. public Windows.Kinect.PointF Lean
  183. {
  184. get
  185. {
  186. if (_pNative == RootSystem.IntPtr.Zero)
  187. {
  188. throw new RootSystem.ObjectDisposedException("Body");
  189. }
  190. var objectPointer = Windows_Kinect_Body_get_Lean(_pNative);
  191. Helper.ExceptionHelper.CheckLastError();
  192. var obj = (Windows.Kinect.PointF)RootSystem.Runtime.InteropServices.Marshal.PtrToStructure(objectPointer, typeof(Windows.Kinect.PointF));
  193. RootSystem.Runtime.InteropServices.Marshal.FreeHGlobal(objectPointer);
  194. return obj;
  195. }
  196. }
  197. }
  198. public sealed partial class ColorFrame
  199. {
  200. [RootSystem.Runtime.InteropServices.DllImport(
  201. "KinectUnityAddin",
  202. EntryPoint = "Windows_Kinect_ColorFrame_CopyRawFrameDataToArray",
  203. CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl,
  204. SetLastError = true)]
  205. private static extern void Windows_Kinect_ColorFrame_CopyRawFrameDataToIntPtr(RootSystem.IntPtr pNative, IntPtr frameData, uint frameDataSize);
  206. public void CopyRawFrameDataToIntPtr(RootSystem.IntPtr frameData, uint size)
  207. {
  208. if (_pNative == RootSystem.IntPtr.Zero)
  209. {
  210. throw new RootSystem.ObjectDisposedException("ColorFrame");
  211. }
  212. Windows_Kinect_ColorFrame_CopyRawFrameDataToIntPtr(_pNative, frameData, size);
  213. Helper.ExceptionHelper.CheckLastError();
  214. }
  215. [RootSystem.Runtime.InteropServices.DllImport(
  216. "KinectUnityAddin",
  217. EntryPoint = "Windows_Kinect_ColorFrame_CopyConvertedFrameDataToArray",
  218. CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl,
  219. SetLastError = true)]
  220. private static extern void Windows_Kinect_ColorFrame_CopyConvertedFrameDataToIntPtr(RootSystem.IntPtr pNative, IntPtr frameData, uint frameDataSize, Windows.Kinect.ColorImageFormat colorFormat);
  221. public void CopyConvertedFrameDataToIntPtr(RootSystem.IntPtr frameData, uint size, Windows.Kinect.ColorImageFormat colorFormat)
  222. {
  223. if (_pNative == RootSystem.IntPtr.Zero)
  224. {
  225. throw new RootSystem.ObjectDisposedException("ColorFrame");
  226. }
  227. Windows_Kinect_ColorFrame_CopyConvertedFrameDataToIntPtr(_pNative, frameData, size, colorFormat);
  228. Helper.ExceptionHelper.CheckLastError();
  229. }
  230. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  231. private static extern RootSystem.IntPtr Windows_Kinect_ColorFrame_LockRawImageBuffer(RootSystem.IntPtr pNative);
  232. public Windows.Kinect.KinectBuffer LockRawImageBuffer()
  233. {
  234. if (_pNative == RootSystem.IntPtr.Zero)
  235. {
  236. throw new RootSystem.ObjectDisposedException("ColorFrame");
  237. }
  238. RootSystem.IntPtr objectPointer = Windows_Kinect_ColorFrame_LockRawImageBuffer(_pNative);
  239. Helper.ExceptionHelper.CheckLastError();
  240. if (objectPointer == RootSystem.IntPtr.Zero)
  241. {
  242. return null;
  243. }
  244. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectBuffer>(objectPointer, n => new Windows.Kinect.KinectBuffer(n));
  245. }
  246. }
  247. public sealed partial class DepthFrame
  248. {
  249. [RootSystem.Runtime.InteropServices.DllImport(
  250. "KinectUnityAddin",
  251. EntryPoint = "Windows_Kinect_DepthFrame_CopyFrameDataToArray",
  252. CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl,
  253. SetLastError = true)]
  254. private static extern void Windows_Kinect_DepthFrame_CopyFrameDataToIntPtr(RootSystem.IntPtr pNative, IntPtr frameData, uint frameDataSize);
  255. public void CopyFrameDataToIntPtr(RootSystem.IntPtr frameData, uint size)
  256. {
  257. if (_pNative == RootSystem.IntPtr.Zero)
  258. {
  259. throw new RootSystem.ObjectDisposedException("DepthFrame");
  260. }
  261. Windows_Kinect_DepthFrame_CopyFrameDataToIntPtr(_pNative, frameData, size / sizeof(ushort));
  262. Helper.ExceptionHelper.CheckLastError();
  263. }
  264. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  265. private static extern RootSystem.IntPtr Windows_Kinect_DepthFrame_LockImageBuffer(RootSystem.IntPtr pNative);
  266. public Windows.Kinect.KinectBuffer LockImageBuffer()
  267. {
  268. if (_pNative == RootSystem.IntPtr.Zero)
  269. {
  270. throw new RootSystem.ObjectDisposedException("DepthFrame");
  271. }
  272. RootSystem.IntPtr objectPointer = Windows_Kinect_DepthFrame_LockImageBuffer(_pNative);
  273. Helper.ExceptionHelper.CheckLastError();
  274. if (objectPointer == RootSystem.IntPtr.Zero)
  275. {
  276. return null;
  277. }
  278. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectBuffer>(objectPointer, n => new Windows.Kinect.KinectBuffer(n));
  279. }
  280. }
  281. public sealed partial class BodyIndexFrame
  282. {
  283. [RootSystem.Runtime.InteropServices.DllImport(
  284. "KinectUnityAddin",
  285. EntryPoint = "Windows_Kinect_BodyIndexFrame_CopyFrameDataToArray",
  286. CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl,
  287. SetLastError = true)]
  288. private static extern void Windows_Kinect_BodyIndexFrame_CopyFrameDataToIntPtr(RootSystem.IntPtr pNative, IntPtr frameData, uint frameDataSize);
  289. public void CopyFrameDataToIntPtr(RootSystem.IntPtr frameData, uint size)
  290. {
  291. if (_pNative == RootSystem.IntPtr.Zero)
  292. {
  293. throw new RootSystem.ObjectDisposedException("BodyIndexFrame");
  294. }
  295. Windows_Kinect_BodyIndexFrame_CopyFrameDataToIntPtr(_pNative, frameData, size);
  296. Helper.ExceptionHelper.CheckLastError();
  297. }
  298. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  299. private static extern RootSystem.IntPtr Windows_Kinect_BodyIndexFrame_LockImageBuffer(RootSystem.IntPtr pNative);
  300. public Windows.Kinect.KinectBuffer LockImageBuffer()
  301. {
  302. if (_pNative == RootSystem.IntPtr.Zero)
  303. {
  304. throw new RootSystem.ObjectDisposedException("BodyIndexFrame");
  305. }
  306. RootSystem.IntPtr objectPointer = Windows_Kinect_BodyIndexFrame_LockImageBuffer(_pNative);
  307. Helper.ExceptionHelper.CheckLastError();
  308. if (objectPointer == RootSystem.IntPtr.Zero)
  309. {
  310. return null;
  311. }
  312. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectBuffer>(objectPointer, n => new Windows.Kinect.KinectBuffer(n));
  313. }
  314. }
  315. public sealed partial class InfraredFrame
  316. {
  317. [RootSystem.Runtime.InteropServices.DllImport(
  318. "KinectUnityAddin",
  319. EntryPoint = "Windows_Kinect_InfraredFrame_CopyFrameDataToArray",
  320. CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl,
  321. SetLastError = true)]
  322. private static extern void Windows_Kinect_InfraredFrame_CopyFrameDataToIntPtr(RootSystem.IntPtr pNative, IntPtr frameData, uint frameDataSize);
  323. public void CopyFrameDataToIntPtr(RootSystem.IntPtr frameData, uint size)
  324. {
  325. if (_pNative == RootSystem.IntPtr.Zero)
  326. {
  327. throw new RootSystem.ObjectDisposedException("InfraredFrame");
  328. }
  329. Windows_Kinect_InfraredFrame_CopyFrameDataToIntPtr(_pNative, frameData, size / sizeof(ushort));
  330. Helper.ExceptionHelper.CheckLastError();
  331. }
  332. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  333. private static extern RootSystem.IntPtr Windows_Kinect_InfraredFrame_LockImageBuffer(RootSystem.IntPtr pNative);
  334. public Windows.Kinect.KinectBuffer LockImageBuffer()
  335. {
  336. if (_pNative == RootSystem.IntPtr.Zero)
  337. {
  338. throw new RootSystem.ObjectDisposedException("InfraredFrame");
  339. }
  340. RootSystem.IntPtr objectPointer = Windows_Kinect_InfraredFrame_LockImageBuffer(_pNative);
  341. Helper.ExceptionHelper.CheckLastError();
  342. if (objectPointer == RootSystem.IntPtr.Zero)
  343. {
  344. return null;
  345. }
  346. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectBuffer>(objectPointer, n => new Windows.Kinect.KinectBuffer(n));
  347. }
  348. }
  349. public sealed partial class KinectSensor
  350. {
  351. private void Dispose(bool disposing)
  352. {
  353. if (_pNative == RootSystem.IntPtr.Zero)
  354. {
  355. return;
  356. }
  357. if (IsOpen)
  358. {
  359. Close();
  360. }
  361. __EventCleanup();
  362. Helper.NativeObjectCache.RemoveObject<KinectSensor>(_pNative);
  363. Windows_Kinect_KinectSensor_ReleaseObject(ref _pNative);
  364. _pNative = RootSystem.IntPtr.Zero;
  365. }
  366. }
  367. public sealed partial class LongExposureInfraredFrame
  368. {
  369. [RootSystem.Runtime.InteropServices.DllImport(
  370. "KinectUnityAddin",
  371. EntryPoint = "Windows_Kinect_LongExposureInfraredFrame_CopyFrameDataToArray",
  372. CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl,
  373. SetLastError = true)]
  374. private static extern void Windows_Kinect_LongExposureInfraredFrame_CopyFrameDataToIntPtr(RootSystem.IntPtr pNative, IntPtr frameData, uint frameDataSize);
  375. public void CopyFrameDataToIntPtr(RootSystem.IntPtr frameData, uint size)
  376. {
  377. if (_pNative == RootSystem.IntPtr.Zero)
  378. {
  379. throw new RootSystem.ObjectDisposedException("LongExposureInfraredFrame");
  380. }
  381. Windows_Kinect_LongExposureInfraredFrame_CopyFrameDataToIntPtr(_pNative, frameData, size / sizeof(ushort));
  382. Helper.ExceptionHelper.CheckLastError();
  383. }
  384. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  385. private static extern RootSystem.IntPtr Windows_Kinect_LongExposureInfraredFrame_LockImageBuffer(RootSystem.IntPtr pNative);
  386. public Windows.Kinect.KinectBuffer LockImageBuffer()
  387. {
  388. if (_pNative == RootSystem.IntPtr.Zero)
  389. {
  390. throw new RootSystem.ObjectDisposedException("LongExposureInfraredFrame");
  391. }
  392. RootSystem.IntPtr objectPointer = Windows_Kinect_LongExposureInfraredFrame_LockImageBuffer(_pNative);
  393. Helper.ExceptionHelper.CheckLastError();
  394. if (objectPointer == RootSystem.IntPtr.Zero)
  395. {
  396. return null;
  397. }
  398. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectBuffer>(objectPointer, n => new Windows.Kinect.KinectBuffer(n));
  399. }
  400. }
  401. public sealed partial class CoordinateMapper
  402. {
  403. private PointF[] _DepthFrameToCameraSpaceTable = null;
  404. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  405. private static extern RootSystem.IntPtr Windows_Kinect_CoordinateMapper_GetDepthCameraIntrinsics(RootSystem.IntPtr pNative);
  406. public Windows.Kinect.CameraIntrinsics GetDepthCameraIntrinsics()
  407. {
  408. if (_pNative == RootSystem.IntPtr.Zero)
  409. {
  410. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  411. }
  412. var objectPointer = Windows_Kinect_CoordinateMapper_GetDepthCameraIntrinsics(_pNative);
  413. Helper.ExceptionHelper.CheckLastError();
  414. var obj = (Windows.Kinect.CameraIntrinsics)RootSystem.Runtime.InteropServices.Marshal.PtrToStructure(objectPointer, typeof(Windows.Kinect.CameraIntrinsics));
  415. RootSystem.Runtime.InteropServices.Marshal.FreeHGlobal(objectPointer);
  416. return obj;
  417. }
  418. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  419. private static extern int Windows_Kinect_CoordinateMapper_GetDepthFrameToCameraSpaceTable(RootSystem.IntPtr pNative, RootSystem.IntPtr outCollection, uint outCollectionSize);
  420. public Windows.Kinect.PointF[] GetDepthFrameToCameraSpaceTable()
  421. {
  422. if (_pNative == RootSystem.IntPtr.Zero)
  423. {
  424. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  425. }
  426. if (_DepthFrameToCameraSpaceTable == null)
  427. {
  428. var desc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;
  429. _DepthFrameToCameraSpaceTable = new PointF[desc.Width * desc.Height];
  430. var pointsSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(_DepthFrameToCameraSpaceTable, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  431. var _points = pointsSmartGCHandle.AddrOfPinnedObject();
  432. Windows_Kinect_CoordinateMapper_GetDepthFrameToCameraSpaceTable(_pNative, _points, (uint)_DepthFrameToCameraSpaceTable.Length);
  433. Helper.ExceptionHelper.CheckLastError();
  434. }
  435. return _DepthFrameToCameraSpaceTable;
  436. }
  437. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  438. private static extern void Windows_Kinect_CoordinateMapper_MapColorFrameToDepthSpace(
  439. RootSystem.IntPtr pNative,
  440. RootSystem.IntPtr depthFrameData,
  441. uint depthFrameDataSize,
  442. RootSystem.IntPtr depthSpacePoints,
  443. uint depthSpacePointsSize);
  444. public void MapColorFrameToDepthSpaceUsingIntPtr(RootSystem.IntPtr depthFrameData, uint depthFrameSize, RootSystem.IntPtr depthSpacePoints, uint depthSpacePointsSize)
  445. {
  446. if (_pNative == RootSystem.IntPtr.Zero)
  447. {
  448. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  449. }
  450. uint length = depthFrameSize / sizeof(UInt16);
  451. Windows_Kinect_CoordinateMapper_MapColorFrameToDepthSpace(_pNative, depthFrameData, length, depthSpacePoints, depthSpacePointsSize);
  452. Helper.ExceptionHelper.CheckLastError();
  453. }
  454. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  455. private static extern void Windows_Kinect_CoordinateMapper_MapColorFrameToCameraSpace(
  456. RootSystem.IntPtr pNative,
  457. RootSystem.IntPtr depthFrameData,
  458. uint depthFrameDataSize,
  459. RootSystem.IntPtr cameraSpacePoints,
  460. uint cameraSpacePointsSize);
  461. public void MapColorFrameToCameraSpaceUsingIntPtr(RootSystem.IntPtr depthFrameData, int depthFrameSize, RootSystem.IntPtr cameraSpacePoints, uint cameraSpacePointsSize)
  462. {
  463. if (_pNative == RootSystem.IntPtr.Zero)
  464. {
  465. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  466. }
  467. uint length = (uint)depthFrameSize / sizeof(UInt16);
  468. Windows_Kinect_CoordinateMapper_MapColorFrameToCameraSpace(_pNative, depthFrameData, length, cameraSpacePoints, cameraSpacePointsSize);
  469. Helper.ExceptionHelper.CheckLastError();
  470. }
  471. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  472. private static extern void Windows_Kinect_CoordinateMapper_MapDepthFrameToColorSpace(
  473. RootSystem.IntPtr pNative,
  474. RootSystem.IntPtr depthFrameData,
  475. uint depthFrameDataSize,
  476. RootSystem.IntPtr colorSpacePoints,
  477. uint colorSpacePointsSize);
  478. public void MapDepthFrameToColorSpaceUsingIntPtr(RootSystem.IntPtr depthFrameData, int depthFrameSize, RootSystem.IntPtr colorSpacePoints, uint colorSpacePointsSize)
  479. {
  480. if (_pNative == RootSystem.IntPtr.Zero)
  481. {
  482. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  483. }
  484. uint length = (uint)depthFrameSize / sizeof(UInt16);
  485. Windows_Kinect_CoordinateMapper_MapDepthFrameToColorSpace(_pNative, depthFrameData, length, colorSpacePoints, colorSpacePointsSize);
  486. Helper.ExceptionHelper.CheckLastError();
  487. }
  488. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  489. private static extern void Windows_Kinect_CoordinateMapper_MapDepthFrameToCameraSpace(
  490. RootSystem.IntPtr pNative,
  491. IntPtr depthFrameData,
  492. uint depthFrameDataSize,
  493. RootSystem.IntPtr cameraSpacePoints,
  494. uint cameraSpacePointsSize);
  495. public void MapDepthFrameToCameraSpaceUsingIntPtr(RootSystem.IntPtr depthFrameData, int depthFrameSize, RootSystem.IntPtr cameraSpacePoints, uint cameraSpacePointsSize)
  496. {
  497. if (_pNative == RootSystem.IntPtr.Zero)
  498. {
  499. throw new RootSystem.ObjectDisposedException("CoordinateMapper");
  500. }
  501. uint length = (uint)depthFrameSize / sizeof(UInt16);
  502. Windows_Kinect_CoordinateMapper_MapDepthFrameToCameraSpace(_pNative, depthFrameData, length, cameraSpacePoints, cameraSpacePointsSize);
  503. Helper.ExceptionHelper.CheckLastError();
  504. }
  505. }
  506. }