Mercurial > hg > Game > Kinect
changeset 2:3b5465899da9
add KinectTrack.cc
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Feb 2011 03:01:22 +0900 |
parents | 2afd5c6cc8d2 |
children | 7e112b536f0a |
files | KinectTrack.cc KinectTrack.h Makefile main.cc |
diffstat | 4 files changed, 77 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /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 <XnVNite.h> + +#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<XnUInt32, std::list<XnPoint3D> >::iterator iter; + for (iter = mHistory.begin(); iter != mHistory.end(); ++iter) + { + iter->second.clear(); + } + mHistory.clear(); + + delete []mPFPositionBuffer; +} + +void XnVPointDrawer::setDepthMap(XnBool bDrawDM) { + mBDrawDM = bDrawDM; +} +
--- 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 <map> +#include <list> +#include <XnCppWrapper.h> +#include <XnVPointControl.h> + 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<XnUInt32, std::list<XnPoint3D> > mHistory; + xn::DepthGenerator mDepthGenerator; + XnFloat *mPFPositionBuffer; + XnBool mBDrawDM; + XnBool mBFrameID; +};
--- 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
--- 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; }