Fieol

KinectV2Device.h

Mar 31st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.29 KB | None | 0 0
  1. //
  2. // Copyright 2018 Adam Horvath - MIRROR.UPLUGINS.COM - info@uplugins.com - All Rights Reserved.
  3. //
  4.  
  5. #pragma once
  6. #include "VirtualMirrorFunctionLibrary.h"
  7. #include "MotionSensorDevice.h"
  8. #include "BoneOrientationDoubleExponentialFilter.h"
  9.  
  10. #include <map>
  11.  
  12. //KinectV2 log
  13. DECLARE_LOG_CATEGORY_EXTERN(KinectV2, Log, All);
  14.  
  15. #define MAX_DEPTH 10000
  16.  
  17. // Safe release for interfaces
  18. template<class Interface>
  19. inline void SafeRelease(Interface *& pInterfaceToRelease)
  20. {
  21.     if (pInterfaceToRelease != NULL)
  22.     {
  23.         pInterfaceToRelease->Release();
  24.         pInterfaceToRelease = NULL;
  25.     }
  26. }
  27.  
  28. class FKinectV2Device: public FMotionSensorDevice, public FRunnable
  29. {
  30.    
  31. public:
  32.     FKinectV2Device();
  33.     virtual ~FKinectV2Device();
  34.  
  35.     /** Startup the device, and do any initialization that may be needed */
  36.     bool StartupDevice();
  37.  
  38.     /** Tear down the device */
  39.     void ShutdownDevice();
  40.    
  41.     /** Update device on each Tick */
  42.     void UpdateDevice(float DeltaTime);
  43.    
  44.     UTexture2D* GetTextureRGB();
  45.     UTexture2D* GetTextureDEPTH();
  46.     UTexture2D* GetTextureUSER();
  47.    
  48.     FString GetDeviceName();
  49.  
  50.     //Experimental RGB without the user
  51.     void UpdateTextureCLEANRGB();
  52.  
  53.     bool Init(bool playOni=false);
  54.     void Cleanup(void);
  55.  
  56.     //Sensor control
  57.     bool SensorInit(bool playOni=false);
  58.     bool SensorShutdown();
  59.    
  60.  
  61.     //Tracking control
  62.     void AbortTracking();
  63.     bool IsTracking();
  64.  
  65.     //Threading
  66.     void StartThread();
  67.     void StopThread();
  68.    
  69.     virtual uint32 Run() override;
  70.     virtual void Stop() override;
  71.  
  72.  
  73.     //Skeleton data
  74.     FVector GetBonePosition(EJointType skelJoint, bool flip = false);
  75.     FVector2D GetBonePosition2D(EJointType skelJoint);
  76.     FRotator GetBoneRotation(EJointType skelJoint, bool flip = false);
  77.  
  78.     EJointType GetClosestBodyJoint(EJointType HandJoint);
  79.    
  80.  
  81.     float                       SensorHeight;
  82.     float                       SensorAngle;
  83.    
  84.    
  85.  
  86.    
  87.    
  88.  
  89. protected:
  90.     void UpdateTextureRGB();
  91.     void UpdateTextureDEPTH();
  92.     void UpdateTextureUSER();
  93.    
  94.    
  95.  
  96.     bool UpdateMultiFrame();
  97.     void MultiSourceFrameArrived(IMultiSourceFrameArrivedEventArgs* pArgs);
  98.     bool UpdateColorFrame();
  99.  
  100.     virtual void ProcessFrames(
  101.         const UINT16* pDepthBuffer, int nDepthHeight, int nDepthWidth,
  102.         const BYTE* pBodyIndexBuffer, int nBodyIndexWidth, int nBodyIndexHeight
  103.         );
  104.  
  105.     virtual void ProcessDepth(INT64 nTime, const UINT16* pBuffer, int nWidth, int nHeight, USHORT nMinDepth, USHORT nMaxDepth);
  106.     virtual void ProcessInfrared(INT64 nTime, const UINT16* pBuffer, int nHeight, int nWidth);
  107.     virtual void ProcessBody(int nBodyCount, IBody** ppBodies);
  108.     virtual void ProcessFaces(IBody** ppBodies);
  109.    
  110.  
  111.     JointType ConvertJoint(EJointType Joint);
  112.  
  113.     // Current Kinect
  114.     IKinectSensor*              KinectSensor;
  115.     ICoordinateMapper*          CoordinateMapper;
  116.     DepthSpacePoint*            DepthCoordinates;
  117.     CameraSpacePoint*           CameraCoordinates;
  118.     ColorSpacePoint*            ColorCoordinates;
  119.     _Vector4                    FloorClippingPlane;
  120.  
  121.     // Multiframe reader except color becasue of 15 FPS framedrop
  122.     IMultiSourceFrameReader*    MultiSourceFrameReader;
  123.     WAITABLE_HANDLE             MultiSourceEventHandle;
  124.  
  125.    
  126.     //Color
  127.     IColorFrameReader*          ColorFrameReader;
  128.  
  129.     bool                        MultiFrameReady;
  130.     bool                        UpdateTexturesReady;
  131.     bool                        bIsTracking;
  132.    
  133.     //Joints
  134.     Joint                       Joints[JointType_Count];
  135.     Joint                       JointsFiltered[JointType_Count];
  136.     JointOrientation            JointOrientationsFiltered[JointType_Count];
  137.     JointOrientation            JointOrientations[JointType_Count];
  138.    
  139.     std::map<uint64, Vector4>   FaceOrientations;
  140.     FString                     FaceText;
  141.    
  142.  
  143.     // Face readers
  144.     IFaceFrameReader*           FaceFrameReaders[BODY_COUNT];
  145.  
  146.     // Face sources
  147.     IFaceFrameSource*           FaceFrameSources[BODY_COUNT];
  148.  
  149.     //Kinect
  150.     int                         NumberOfUsers;
  151.    
  152.     ColorSpacePoint             JointsColorSpace[JointType_Count];
  153.     bool                        IsOutOfFrame;
  154.  
  155.  
  156.     bool                        initiated;
  157.     FString                     DeviceName;
  158.     float                       RefreshTimer;
  159.     bool                        FloorFound;
  160.     UINT64                      PlayerTrackingID;
  161.     bool                        Calibrating;
  162.  
  163.    
  164.     //Textures
  165.     UTexture2D*                 TextureRGB;
  166.     UTexture2D*                 TextureDEPTH;
  167.     UTexture2D*                 TextureUSER;
  168.     UTexture2D*                 DummyTexture;
  169.    
  170.     RGBQUAD*                    QuadRGB;
  171.     RGBQUAD*                    QuadBACKGROUND;
  172.     RGBQUAD*                    QuadDEPTH;
  173.     RGBQUAD*                    QuadUSER;
  174.  
  175.    
  176.  
  177.     //Filters
  178.     BoneOrientationDoubleExponentialFilter* BoneOrientationFilter;
  179.  
  180.     //Unreal thread
  181.     FRunnableThread*        KinectThread;
  182.     FCriticalSection        ColorCriticalSection;
  183.     bool                    bStop;
  184.  
  185.    
  186.  
  187.    
  188.  
  189. };
Add Comment
Please, Sign In to add comment