diff main.cc @ 0:1478aad947a6

init
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Mon, 31 Jan 2011 03:46:10 +0900
parents
children 2afd5c6cc8d2
line wrap: on
line diff
--- /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 <stdio.h>
+#include <XnOpenNI.h>
+#include <XnCppWrapper.h>
+#include <XnVNite.h>
+
+#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;
+}