# HG changeset patch # User kazz # Date 1296496882 -32400 # Node ID 3b5465899da9e0c344066ceb7b1cab9e07500162 # Parent 2afd5c6cc8d23b8e68233a764a9d763d7dee21d5 add KinectTrack.cc diff -r 2afd5c6cc8d2 -r 3b5465899da9 KinectTrack.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KinectTrack.cc Tue Feb 01 03:01:22 2011 +0900 @@ -0,0 +1,25 @@ +#include + +#include "KinectTrack.h" + +XnVPointDrawer::XnVPointDrawer(XnUInt32 nHistory, xn::DepthGenerator depthGenerator) : + XnVPointControl("XnVPointDrawer"), + mNHistorySize(nHistory), mDepthGenerator(depthGenerator), mBDrawDM(false), mBFrameID(false) { + mPFPositionBuffer = new XnFloat[nHistory*3]; +} + +XnVPointDrawer::~XnVPointDrawer() { + std::map >::iterator iter; + for (iter = mHistory.begin(); iter != mHistory.end(); ++iter) + { + iter->second.clear(); + } + mHistory.clear(); + + delete []mPFPositionBuffer; +} + +void XnVPointDrawer::setDepthMap(XnBool bDrawDM) { + mBDrawDM = bDrawDM; +} + diff -r 2afd5c6cc8d2 -r 3b5465899da9 KinectTrack.h --- a/KinectTrack.h Mon Jan 31 03:49:24 2011 +0900 +++ b/KinectTrack.h Tue Feb 01 03:01:22 2011 +0900 @@ -1,3 +1,8 @@ +#include +#include +#include +#include + typedef enum { IN_SESSION, NOT_IN_SESSION, @@ -7,8 +12,30 @@ class NIState { public: static SessionState gSessionState; + static XnBool gBDrawDepthMap; static void XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt); static void XN_CALLBACK_TYPE sessionEnding(void *userCxt); static void XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition, XnFloat fProgress, void *userCxt); + static void XN_CALLBACK_TYPE noHands(void *UserCxt); }; + +class XnVPointDrawer : public XnVPointControl { +public: + XnVPointDrawer(XnUInt32 nHistorySize, xn::DepthGenerator depthGenerator); + virtual ~XnVPointDrawer(); + void update(XnVMessage *pMessage); + void onPointCreate(const XnVHandPointContext *cxt); + void onPointUpdate(const XnVHandPointContext *cxt); + void onPointDestroy(XnUInt32 nID); + void draw() const; + void setDepthMap(XnBool bDrawDM); + void setFrameID(XnBool bFrameID); +protected: + XnUInt32 mNHistorySize; + std::map > mHistory; + xn::DepthGenerator mDepthGenerator; + XnFloat *mPFPositionBuffer; + XnBool mBDrawDM; + XnBool mBFrameID; +}; diff -r 2afd5c6cc8d2 -r 3b5465899da9 Makefile --- a/Makefile Mon Jan 31 03:49:24 2011 +0900 +++ b/Makefile Tue Feb 01 03:01:22 2011 +0900 @@ -2,7 +2,7 @@ CFLAGS = -Wall -g -O2 INCLUDE = -I/usr/include/ni -I/usr/include/nite LIBS = -lOpenNI -lXnVNite -OBJS = main.o +OBJS = main.o KinectTrack.o TARGET = kinect .SUFFIXES: .cc .o diff -r 2afd5c6cc8d2 -r 3b5465899da9 main.cc --- a/main.cc Mon Jan 31 03:49:24 2011 +0900 +++ b/main.cc Tue Feb 01 03:01:22 2011 +0900 @@ -22,6 +22,7 @@ } SessionState NIState::gSessionState = NOT_IN_SESSION; +XnBool NIState::gBDrawDepthMap = true; void NIState::XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt) { printf("Session start: (%f, %f, %f)\n)", ptPosition.X, ptPosition.Y, ptPosition.Z); gSessionState = IN_SESSION; @@ -34,6 +35,12 @@ XnFloat fProgress, void *userCxt) { //printf("Focus progress: %s @(%f, %f, %f): %f\n)", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress); } +void NIState::XN_CALLBACK_TYPE noHands(void *UserCxt) { + if (gSessionState != NOT_IN_SESSION) { + printf("Quick refocus\n"); + gSessionState = QUICK_REFOCUS; + } +} int main(int argc, char *argv[]) { xn::Context gContext; @@ -52,7 +59,24 @@ XnVSessionManager *gPSessionManager = new XnVSessionManager(); rc = gPSessionManager->Initialize(&gContext, "Click,Wave", "RaiseHand"); checkRC(rc, "SessionManager::Initialize"); + gPSessionManager->RegisterSession(NULL, NIState::sessionStarting, NIState::sessionEnding, NIState::focusProgress); + + XnVPointDrawer *gPDrawer = new XnVPointDrawer(20, gDepthGenerator); + XnVFlowRouter *gPFlowRouter = new XnVFlowRouter; + gPFlowRouter->SetActive(gPDrawer); + + gPSessionManager->AddListener(gPFlowRouter); + + gPDrawer->RegisterNoPoints(NULL, NIState::noHands); + gPDrawer->setDepthMap(NIState::gBDrawDepthMap); + rc = gContext.StartGeneratingAll(); + checkRC(rc, "StartGenerating"); + + while (true) { + usleep(100); + } + return 0; }