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