Example #1
0
void XnVPointDenoiser::OnPointUpdate(const XnVHandPointContext* pContext)
{
	XnVDenoisingLocalContext* pLocalContext = GetLocalContext(pContext->nID);
	if (pLocalContext == NULL)
	{
		return;
	}
	XnVHandPointContext* pDenoisedContext = m_DenoisedHands.GetContext(pContext->nID);

	pDenoisedContext->fTime = pContext->fTime;
	pLocalContext->ptBuffer[pLocalContext->nNextIndex] = pContext->ptPosition;
	pLocalContext->nNextIndex = (pLocalContext->nNextIndex+1)%XNV_SMOOTHER_AVERAGE_SIZE;
	pLocalContext->nCount++;

	XnUInt32 nAverageCount = XN_MIN(XNV_SMOOTHER_AVERAGE_SIZE, pLocalContext->nCount);
	XnV3DVector ptAveragePoint(0, 0, 0);

	for (XnUInt32 i = 0; i < nAverageCount; ++i)
	{
		ptAveragePoint += pLocalContext->ptBuffer[i];
	}
	if (nAverageCount > 0)
	{
		ptAveragePoint /= XnFloat(nAverageCount);
	}

	UpdatePointDenoise(pDenoisedContext->ptPosition, ptAveragePoint);

	m_DenoisedHands.MarkActive(pContext->nID);
} // XnVPointDenoiser::OnPointUpdate
Example #2
0
XnNode* XnNodeManager::Allocate()
{
    XnNode* pResult = NULL;

    xnOSEnterCriticalSection(&m_hCriticalSection);

    if (m_eInitializationState == XN_NM_INIT_STATE_CREATE_INTERNAL_LIST)
    {
        pResult = &(m_InitialNodes[0]);
    }
    else if (m_eInitializationState == XN_NM_INIT_STATE_CREATE_FIRST_LINK)
    {
        pResult = &(m_InitialNodes[1]);
    }

    if (pResult != NULL)
    {
        xnOSLeaveCriticalSection(&m_hCriticalSection);
        return pResult;
    }

    // Check if resize is in order
    if (m_nCurrentAvailability == 1 ||
            XnFloat(m_nCurrentOccupancy)/m_nCurrentCapacity > 0.75)
    {
        XnStatus rc = Resize((XnUInt32)(m_nCurrentCapacity*0.5));
        if (rc != XN_STATUS_OK && m_nCurrentAvailability == 1)
        {
            // Couldn't resize, and there is only one node available
            // We'll need that one node to add to the list, to contain all new nodes
            // So there are actually no available nodes....
            xnOSLeaveCriticalSection(&m_hCriticalSection);
            return NULL;
        }
    }

    m_nCurrentOccupancy++;
    m_nCurrentAvailability--;

    // Return the first available
    XnNode* pOut = m_pFirstAvailable;
    m_pFirstAvailable = m_pFirstAvailable->Next();
    pOut->Next() = NULL;

    xnOSLeaveCriticalSection(&m_hCriticalSection);

    return pOut;
}
Example #3
0
static XnFloat SoftThreshold(XnFloat x, XnFloat fThreshold)
{
	XnFloat fRes = XN_MAX(XnFloat(fabs(x) - fThreshold), 0.0f);
	return x > 0 ? fRes : -fRes;
}