# HG changeset patch # User kazz # Date 1296413170 -32400 # Node ID 1478aad947a60d6f2323471b592c05967b42b9bc init diff -r 000000000000 -r 1478aad947a6 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Mon Jan 31 03:46:10 2011 +0900 @@ -0,0 +1,16 @@ +CC = g++ +CFLAGS = -Wall -g -O2 +INCLUDE = -I/usr/include/ni -I/usr/include/nite +LIBS = -lOpenNI -lXnVNite +OBJS = main.o +TARGET = kinect + +.SUFFIXES: .cc .o + +all: $(OBJS) + $(CC) $(CFLAGS) $(INCLUDE) $(LIBS) $(OBJS) -o $(TARGET) +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ +clean: + rm *.o + rm $(TARGET) diff -r 000000000000 -r 1478aad947a6 kinect.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kinect.xml Mon Jan 31 03:46:10 2011 +0900 @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r 1478aad947a6 main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cc Mon Jan 31 03:46:10 2011 +0900 @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +#define INIT_XML_PATH "./kinect.xml" + +typedef enum { + IN_SESSION, + NOT_IN_SESSION, + QUICK_REFOCUS +} SessionState; + +void checkRC(const XnStatus &rc, const char *what) { + if (rc != XN_STATUS_OK) { + printf("%s faild: %s\n", what, xnGetStatusString(rc)); + } +} + +void checkErrors(XnStatus &rc, xn::EnumerationErrors &errors, const char *what) { + if (rc == XN_STATUS_NO_NODE_PRESENT) { + XnChar strError[1024]; + errors.ToString(strError, 1024); + printf("%s\n", strError); + } +} + +class NIState { +public: + static SessionState gSessionState; + 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); +}; +SessionState NIState::gSessionState = NOT_IN_SESSION; +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; +} +void NIState::XN_CALLBACK_TYPE sessionEnding(void *userCxt) { + printf("Session end\n"); + gSessionState = NOT_IN_SESSION; +} +void NIState::XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition, + XnFloat fProgress, void *userCxt) { + //printf("Focus progress: %s @(%f, %f, %f): %f\n)", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress); +} + +int main(int argc, char *argv[]) { + xn::Context gContext; + xn::EnumerationErrors errors; + XnStatus rc = gContext.InitFromXmlFile(INIT_XML_PATH, &errors); + checkErrors(rc, errors, "InitFromXMLFile"); + checkRC(rc, "InitFromXMLFile"); + + xn::DepthGenerator gDepthGenerator; + rc = gContext.FindExistingNode(XN_NODE_TYPE_DEPTH, gDepthGenerator); + checkRC(rc, "Find depth generator"); + + xn::HandsGenerator gHandsGenerator; + rc = gContext.FindExistingNode(XN_NODE_TYPE_HANDS, gHandsGenerator); + checkRC(rc, "Find hands generator"); + XnVSessionManager *gPSessionManager = new XnVSessionManager(); + rc = gPSessionManager->Initialize(&gContext, "Click,Wave", "RaiseHand"); + checkRC(rc, "SessionManager::Initialize"); + gPSessionManager->RegisterSession(NULL, NIState::sessionStarting, NIState::sessionEnding, NIState::focusProgress); + + return 0; +}