#include <mil.h>
#include <Windows.h>
#include "KinectCameraStandalone.h"
CKinectCameraStandalone::CKinectCameraStandalone(MIL_ID MilSystem)
: CKinectCameraInterface(MilSystem, FALSE),
m_SimulatedGrabActive(false),
m_ColorEventTimer(0),
m_DepthEventTimer(0),
m_AviNbImages(0),
m_AviIndex(0),
m_MilKinectDepthImage(M_NULL),
m_MilKinectColorImage(M_NULL)
{
MbufDiskInquire(COLOR_AVI, M_NUMBER_OF_IMAGES, &m_AviNbImages);
}
MIL_INT CKinectCameraStandalone::GetCameraStatus() const
{
return KINECT_CAMERA_OK;
}
CKinectCameraStandalone::~CKinectCameraStandalone()
{
CloseDown();
if(m_MilKinectColorImage)
MbufFree(m_MilKinectColorImage);
if(m_MilKinectDepthImage)
MbufFree(m_MilKinectDepthImage);
}
void CKinectCameraStandalone::ShutdownCamera()
{
timeKillEvent(m_ColorEventTimer);
timeKillEvent(m_DepthEventTimer);
m_SimulatedGrabActive = false;
MbufImportSequence(COLOR_AVI, M_DEFAULT, M_NULL, M_NULL, M_NULL, 0, M_NULL, M_CLOSE);
MbufImportSequence(DEPTH_AVI, M_DEFAULT, M_NULL, M_NULL, M_NULL, 0, M_NULL, M_CLOSE);
}
MIL_INT CKinectCameraStandalone::InitCamera(ColorStreamTypeEnum ColorStreamType, bool UseDepth)
{
if(!m_SimulatedGrabActive)
{
MbufImportSequence(COLOR_AVI, M_DEFAULT, M_NULL, M_NULL, M_NULL, 0, M_NULL, M_OPEN);
MbufImportSequence(DEPTH_AVI, M_DEFAULT, M_NULL, M_NULL, M_NULL, 0, M_NULL, M_OPEN);
MbufImportSequence(COLOR_AVI, M_DEFAULT, M_RESTORE, GetMilSystem(), &m_MilKinectColorImage, 0, 1, M_READ);
MbufImportSequence(DEPTH_AVI, M_DEFAULT, M_RESTORE, GetMilSystem(), &m_MilKinectDepthImage, 0, 1, M_READ);
m_ColorEventTimer = timeSetEvent((UINT)(1.0/GRAB_FPS * 1000), 1, (LPTIMECALLBACK)m_NextColorFrameEvent,
NULL, TIME_PERIODIC + TIME_CALLBACK_EVENT_SET);
m_DepthEventTimer = timeSetEvent((UINT)(1.0/GRAB_FPS * 1000), 1, (LPTIMECALLBACK)m_NextDepthFrameEvent,
NULL, TIME_PERIODIC + TIME_CALLBACK_EVENT_SET);
m_SimulatedGrabActive = true;
}
return KINECT_CAMERA_OK;
}
void CKinectCameraStandalone::ProcessKinectBufferColor(MIL_DIG_HOOK_FUNCTION_PTR HookHandlerPtr, void* UserDataPtr)
{
ProcessKinectBuffer(COLOR_AVI, m_MilKinectColorImage, HookHandlerPtr, UserDataPtr);
m_AviIndex = (m_AviIndex == m_AviNbImages-1) ? 0 : m_AviIndex + 1;
}
void CKinectCameraStandalone::ProcessKinectBufferDepth(MIL_DIG_HOOK_FUNCTION_PTR HookHandlerPtr, void* UserDataPtr)
{
ProcessKinectBuffer(DEPTH_AVI, m_MilKinectDepthImage, HookHandlerPtr, UserDataPtr);
}
void CKinectCameraStandalone::ProcessKinectBuffer(MIL_CONST_TEXT_PTR AviPath,
MIL_ID MilKinectImage,
MIL_DIG_HOOK_FUNCTION_PTR HookHandlerPtr,
void* UserDataPtr)
{
MbufImportSequence(AviPath, M_DEFAULT, M_LOAD, M_NULL, &MilKinectImage, m_AviIndex, 1, M_READ);
(*HookHandlerPtr)(0, MilKinectImage, UserDataPtr);
}