1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/****************************************************************************
* *
* OpenNI 1.x Alpha *
* Copyright (C) 2011 PrimeSense Ltd. *
* *
* This file is part of OpenNI. *
* *
* OpenNI is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* OpenNI is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
* *
****************************************************************************/
#include "MockDepthGenerator.h"
#include <XnPropNames.h>
#include <XnOS.h>
#include <XnLog.h>
MockDepthGenerator::MockDepthGenerator(xn::Context& context, const XnChar* strName) :
MockMapGenerator(context, strName),
m_nDeviceMaxDepth(0),
m_nSupportedUserPositionsCount(0),
m_bSupportedUserPositionsCountReceived(FALSE),
m_pUserPositions(NULL)
{
xnOSMemSet(&m_FOV, 0, sizeof(m_FOV));
}
MockDepthGenerator::~MockDepthGenerator()
{
XN_DELETE_ARR(m_pUserPositions);
}
XnBool MockDepthGenerator::IsCapabilitySupported(const XnChar* strCapabilityName)
{
//TODO: Support user position interface
return MockMapGenerator::IsCapabilitySupported(strCapabilityName);
}
XnStatus MockDepthGenerator::SetIntProperty(const XnChar* strName, XnUInt64 nValue)
{
XnStatus nRetVal = XN_STATUS_OK;
if (strcmp(strName, XN_PROP_DEVICE_MAX_DEPTH) == 0)
{
m_nDeviceMaxDepth = (XnDepthPixel)nValue;
}
else if (strcmp(strName, XN_PROP_SUPPORTED_USER_POSITIONS_COUNT) == 0)
{
m_nSupportedUserPositionsCount = (XnUInt32)nValue;
m_bSupportedUserPositionsCountReceived = TRUE;
}
else
{
nRetVal = MockMapGenerator::SetIntProperty(strName, nValue);
XN_IS_STATUS_OK(nRetVal);
}
return XN_STATUS_OK;
}
XnStatus MockDepthGenerator::SetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, const void* pBuffer)
{
XN_VALIDATE_INPUT_PTR(strName);
XN_VALIDATE_INPUT_PTR(pBuffer);
XnStatus nRetVal = XN_STATUS_OK;
if (strcmp(strName, XN_PROP_FIELD_OF_VIEW) == 0)
{
if (nBufferSize != sizeof(XnFieldOfView))
{
XN_LOG_ERROR_RETURN(XN_STATUS_INVALID_BUFFER_SIZE, XN_MASK_OPEN_NI, "Cannot set XN_PROP_FIELD_OF_VIEW - buffer size is incorrect");
}
const XnFieldOfView* pFOV = (const XnFieldOfView*)pBuffer;
nRetVal = SetFieldOfView(*pFOV);
XN_IS_STATUS_OK(nRetVal);
}
else if (strcmp(strName, XN_PROP_USER_POSITIONS) == 0)
{
if (m_bSupportedUserPositionsCountReceived)
{
m_bSupportedUserPositionsCountReceived = FALSE;
if (nBufferSize != m_nSupportedUserPositionsCount * sizeof(XnBoundingBox3D))
{
XN_LOG_ERROR_RETURN(XN_STATUS_INVALID_BUFFER_SIZE, XN_MASK_OPEN_NI, "Cannot set XN_PROP_USER_POSITIONS - buffer size is incorrect");
}
XN_DELETE_ARR(m_pUserPositions);
m_pUserPositions = XN_NEW_ARR(XnBoundingBox3D, m_nSupportedUserPositionsCount);
XN_VALIDATE_ALLOC_PTR(m_pUserPositions);
xnOSMemCopy(m_pUserPositions, pBuffer, nBufferSize);
}
else
{
/*We got XN_PROP_USER_POSITIONS without
XN_PROP_SUPPORTED_USER_POSITIONS_COUNT before it - that's an error*/
XN_ASSERT(FALSE);
XN_LOG_ERROR_RETURN(XN_STATUS_ERROR, XN_MASK_OPEN_NI, "got XN_PROP_USER_POSITIONS without XN_PROP_SUPPORTED_USER_POSITIONS_COUNT before it.")
}
}
else
{
nRetVal = MockMapGenerator::SetGeneralProperty(strName, nBufferSize, pBuffer);
XN_IS_STATUS_OK(nRetVal);
}
return XN_STATUS_OK;
}
XnDepthPixel* MockDepthGenerator::GetDepthMap()
{
return (XnDepthPixel*)GetData();
}
XnDepthPixel MockDepthGenerator::GetDeviceMaxDepth()
{
return m_nDeviceMaxDepth;
}
void MockDepthGenerator::GetFieldOfView(XnFieldOfView& FOV)
{
FOV = m_FOV;
}
XnStatus MockDepthGenerator::RegisterToFieldOfViewChange(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
{
return m_fieldOfViewChangeEvent.Register(handler, pCookie, hCallback);
}
void MockDepthGenerator::UnregisterFromFieldOfViewChange(XnCallbackHandle hCallback)
{
m_fieldOfViewChangeEvent.Unregister(hCallback);
}
xn::ModuleUserPositionInterface* MockDepthGenerator::GetUserPositionInterface()
{
//TODO: Support user position
return NULL;
}
XnStatus MockDepthGenerator::SetFieldOfView(const XnFieldOfView& FOV)
{
XnStatus nRetVal = XN_STATUS_OK;
if (xnOSMemCmp(&m_FOV, &FOV, sizeof(m_FOV)) != 0)
{
m_FOV = FOV;
nRetVal = m_fieldOfViewChangeEvent.Raise();
XN_IS_STATUS_OK(nRetVal);
}
return XN_STATUS_OK;
}
|