PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/Assets/Standard Assets/Microsoft/Kinect/Face/FaceModel.cs

https://gitlab.com/IOException/KinectGame
C# | 182 lines | 150 code | 26 blank | 6 comment | 14 complexity | 03ea0f51282c3237f3dfbd0e5fda5ec2 MD5 | raw file
  1. using RootSystem = System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Microsoft.Kinect.Face
  5. {
  6. //
  7. // Microsoft.Kinect.Face.FaceModel
  8. //
  9. public sealed partial class FaceModel : 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 FaceModel(RootSystem.IntPtr pNative)
  15. {
  16. _pNative = pNative;
  17. Microsoft_Kinect_Face_FaceModel_AddRefObject(ref _pNative);
  18. }
  19. ~FaceModel()
  20. {
  21. Dispose(false);
  22. }
  23. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  24. private static extern void Microsoft_Kinect_Face_FaceModel_ReleaseObject(ref RootSystem.IntPtr pNative);
  25. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  26. private static extern void Microsoft_Kinect_Face_FaceModel_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<FaceModel>(_pNative);
  35. if (disposing)
  36. {
  37. Microsoft_Kinect_Face_FaceModel_Dispose(_pNative);
  38. }
  39. Microsoft_Kinect_Face_FaceModel_ReleaseObject(ref _pNative);
  40. _pNative = RootSystem.IntPtr.Zero;
  41. }
  42. // Public Properties
  43. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  44. private static extern int Microsoft_Kinect_Face_FaceModel_get_FaceShapeDeformations(RootSystem.IntPtr pNative, [RootSystem.Runtime.InteropServices.Out] Microsoft.Kinect.Face.FaceShapeDeformations[] outKeys, float[] outValues, int outCollectionSize);
  45. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  46. private static extern int Microsoft_Kinect_Face_FaceModel_get_FaceShapeDeformations_Length(RootSystem.IntPtr pNative);
  47. public RootSystem.Collections.Generic.Dictionary<Microsoft.Kinect.Face.FaceShapeDeformations, float> FaceShapeDeformations
  48. {
  49. get
  50. {
  51. if (_pNative == RootSystem.IntPtr.Zero)
  52. {
  53. throw new RootSystem.ObjectDisposedException("FaceModel");
  54. }
  55. int outCollectionSize = Microsoft_Kinect_Face_FaceModel_get_FaceShapeDeformations_Length(_pNative);
  56. var outKeys = new Microsoft.Kinect.Face.FaceShapeDeformations[outCollectionSize];
  57. var outValues = new float[outCollectionSize];
  58. var managedDictionary = new RootSystem.Collections.Generic.Dictionary<Microsoft.Kinect.Face.FaceShapeDeformations, float>();
  59. outCollectionSize = Microsoft_Kinect_Face_FaceModel_get_FaceShapeDeformations(_pNative, outKeys, outValues, outCollectionSize);
  60. Helper.ExceptionHelper.CheckLastError();
  61. for(int i=0;i<outCollectionSize;i++)
  62. {
  63. managedDictionary.Add(outKeys[i], outValues[i]);
  64. }
  65. return managedDictionary;
  66. }
  67. }
  68. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  69. private static extern float Microsoft_Kinect_Face_FaceModel_get_Scale(RootSystem.IntPtr pNative);
  70. public float Scale
  71. {
  72. get
  73. {
  74. if (_pNative == RootSystem.IntPtr.Zero)
  75. {
  76. throw new RootSystem.ObjectDisposedException("FaceModel");
  77. }
  78. return Microsoft_Kinect_Face_FaceModel_get_Scale(_pNative);
  79. }
  80. }
  81. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  82. private static extern uint Microsoft_Kinect_Face_FaceModel_get_TriangleCount();
  83. public static uint TriangleCount
  84. {
  85. get
  86. {
  87. return Microsoft_Kinect_Face_FaceModel_get_TriangleCount();
  88. }
  89. }
  90. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  91. private static extern int Microsoft_Kinect_Face_FaceModel_get_TriangleIndices(uint[] outCollection, int outCollectionSize);
  92. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  93. private static extern int Microsoft_Kinect_Face_FaceModel_get_TriangleIndices_Length();
  94. public static RootSystem.Collections.Generic.IList<uint> TriangleIndices
  95. {
  96. get
  97. {
  98. int outCollectionSize = Microsoft_Kinect_Face_FaceModel_get_TriangleIndices_Length();
  99. var outCollection = new uint[outCollectionSize];
  100. var managedCollection = new uint[outCollectionSize];
  101. outCollectionSize = Microsoft_Kinect_Face_FaceModel_get_TriangleIndices(outCollection, outCollectionSize);
  102. Helper.ExceptionHelper.CheckLastError();
  103. for(int i=0;i<outCollectionSize;i++)
  104. {
  105. managedCollection[i] = outCollection[i];
  106. }
  107. return managedCollection;
  108. }
  109. }
  110. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  111. private static extern uint Microsoft_Kinect_Face_FaceModel_get_VertexCount();
  112. public static uint VertexCount
  113. {
  114. get
  115. {
  116. return Microsoft_Kinect_Face_FaceModel_get_VertexCount();
  117. }
  118. }
  119. // Public Methods
  120. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  121. private static extern int Microsoft_Kinect_Face_FaceModel_CalculateVerticesForAlignment_Length(RootSystem.IntPtr pNative, RootSystem.IntPtr faceAlignment);
  122. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  123. private static extern int Microsoft_Kinect_Face_FaceModel_CalculateVerticesForAlignment(RootSystem.IntPtr pNative, RootSystem.IntPtr faceAlignment, [RootSystem.Runtime.InteropServices.Out] Windows.Kinect.CameraSpacePoint[] outCollection, int outCollectionSize);
  124. public RootSystem.Collections.Generic.IList<Windows.Kinect.CameraSpacePoint> CalculateVerticesForAlignment(Microsoft.Kinect.Face.FaceAlignment faceAlignment)
  125. {
  126. if (_pNative == RootSystem.IntPtr.Zero)
  127. {
  128. throw new RootSystem.ObjectDisposedException("FaceModel");
  129. }
  130. int outCollectionSize = Microsoft_Kinect_Face_FaceModel_CalculateVerticesForAlignment_Length(_pNative, Helper.NativeWrapper.GetNativePtr(faceAlignment));
  131. var outCollection = new Windows.Kinect.CameraSpacePoint[outCollectionSize];
  132. var managedCollection = new Windows.Kinect.CameraSpacePoint[outCollectionSize];
  133. outCollectionSize = Microsoft_Kinect_Face_FaceModel_CalculateVerticesForAlignment(_pNative, Helper.NativeWrapper.GetNativePtr(faceAlignment), outCollection, outCollectionSize);
  134. Helper.ExceptionHelper.CheckLastError();
  135. for(int i=0;i<outCollectionSize;i++)
  136. {
  137. managedCollection[i] = outCollection[i];
  138. }
  139. return managedCollection;
  140. }
  141. [RootSystem.Runtime.InteropServices.DllImport("KinectFaceUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  142. private static extern void Microsoft_Kinect_Face_FaceModel_Dispose(RootSystem.IntPtr pNative);
  143. public void Dispose()
  144. {
  145. if (_pNative == RootSystem.IntPtr.Zero)
  146. {
  147. return;
  148. }
  149. Dispose(true);
  150. RootSystem.GC.SuppressFinalize(this);
  151. }
  152. private void __EventCleanup()
  153. {
  154. }
  155. }
  156. }