JD2022-TU1/main/extern/KinectGesture/Src/RingBuffer.h

172 lines
No EOL
4 KiB
C++

//--------------------------------------------------------------------------------------
// RingBuffer.h
//
// Implementation of a simple ringbuffer that holds NUI skeleton data
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#if defined( GESTURE_TRAINER )
#if defined( TARGET_X360 )
#include <windows.h>
#include <XnaMath.h>
#include <NuiTools.h>
#elif defined( TARGET_DURANGO )
#include <windows.h>
#include <Kinect/Durango/NuiCore.h>
#elif defined( TARGET_ORBIS )
#include "SK_iisu/PS4/include/HumanTrackingCTypes.h"
#include "Kinect/PS4/commontypes.h"
#elif defined( TARGET_WIN32 )
#include <windows.h>
#include <Kinect/Win32/NuiCore.h>
#else
#error unsuported platform
#endif
#else // defined( GESTURE_TRAINER )
#if defined( _XBOX ) || defined( ITF_X360 )
#include <xtl.h>
#include <XnaMath.h>
#include <nuiapi.h>
#elif defined( DURANGO ) || defined( ITF_DURANGO )
#include <windows.h>
#include <Kinect/Durango/NuiCore.h>
#elif defined( __ORBIS__ ) || defined( ITF_ORBIS )
#include "SK_iisu/PS4/include/HumanTrackingCTypes.h"
#include "Kinect/PS4/commontypes.h"
#elif defined ( WIN32 ) ||defined( ITF_WIN32)
#include <windows.h>
#include <NuiApi.h>
#else
#error unsuported platform
#endif
#endif
#include "Common.h"
#include "NuiTypes.h"
namespace KinectGesture
{
#define RING_BUFFER_SIZE NUM_HISTORY_FRAMES
//--------------------------------------------------------------------------------------
// Name: RingBuffer
// Desc: Simple ringbuffer that holds nui skeleton data
//--------------------------------------------------------------------------------------
class RingBuffer
{
public:
RingBuffer()
{
Clear();
}
inline VOID Clear()
{
m_uHead = 0;
m_uTail = RING_BUFFER_SIZE - 1;
#ifdef _XBOX
XMemSet( m_Buffer, 0, RING_BUFFER_SIZE * sizeof( GESTURE_SKELETON_TYPE ) );
#else
memset( m_Buffer, 0, RING_BUFFER_SIZE * sizeof( GESTURE_SKELETON_TYPE ) );
#endif
}
inline VOID AddToFront( const GESTURE_SKELETON_TYPE* pSkeletonData )
{
DecrementIndex( m_uHead );
DecrementIndex( m_uTail );
#ifdef _XBOX
XMemCpy( &m_Buffer[ m_uHead ], pSkeletonData, sizeof( GESTURE_SKELETON_TYPE ) );
#else
memcpy( &m_Buffer[ m_uHead ], pSkeletonData, sizeof( GESTURE_SKELETON_TYPE ) );
#endif
}
inline GESTURE_SKELETON_TYPE* GetCurrentSkeleton()
{
return &m_Buffer[ m_uHead ];
}
inline GESTURE_SKELETON_TYPE* GetAt( const UINT uIndex )
{
return &m_Buffer[ uIndex ];
}
inline UINT GetCurrentFrameIndex() const
{
return m_uHead;
}
inline UINT GetPreviousFrameIndex( const UINT uCurrentIndex )
{
UINT uPreviousFrameIndex = uCurrentIndex;
IncrementIndex( uPreviousFrameIndex );
return uPreviousFrameIndex;
}
VOID Splat( const GESTURE_SKELETON_TYPE* pSkeletonData )
{
for ( UINT i = 0; i < RING_BUFFER_SIZE; i++ )
{
#ifdef _XBOX
XMemCpy( &m_Buffer[ i ], pSkeletonData, sizeof( GESTURE_SKELETON_TYPE ) );
#else
memcpy( &m_Buffer[ i ], pSkeletonData, sizeof( GESTURE_SKELETON_TYPE ) );
#endif
}
}
protected:
UINT m_uHead;
UINT m_uTail;
GESTURE_SKELETON_TYPE m_Buffer[ RING_BUFFER_SIZE ];
inline VOID IncrementIndex( UINT& uIndex )
{
uIndex++;
if ( uIndex >= RING_BUFFER_SIZE )
{
uIndex = 0;
}
}
inline VOID DecrementIndex( UINT& uIndex )
{
uIndex--;
if ( uIndex >= RING_BUFFER_SIZE )
{
uIndex = RING_BUFFER_SIZE - 1;
}
}
};
}