view main.cc @ 1:2afd5c6cc8d2

Class definition export to KinectTrack.h
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Mon, 31 Jan 2011 03:49:24 +0900
parents 1478aad947a6
children 3b5465899da9
line wrap: on
line source

#include <stdio.h>
#include <XnOpenNI.h>
#include <XnCppWrapper.h>
#include <XnVNite.h>

#include "KinectTrack.h"

#define INIT_XML_PATH "./kinect.xml"

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);
	}
}

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;
}