Esempio n. 1
0
BOOL APIENTRY DllMain(HANDLE hModule, 
					  DWORD  dwReason, 
					  LPVOID lpReserved)
{
	if (dwReason == DLL_PROCESS_DETACH)
	{
		xnLogClose();
	}

	BOOL bRes = DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved);

	// init log from local file (if it exists)
	if (dwReason == DLL_PROCESS_ATTACH)
	{
		xnLogInitFromXmlFile("OpenNIConfig.xml");
	}

	return bRes;
}
Esempio n. 2
0
XnStatus openDeviceFromXmlWithChoice(const char* csXmlFile, EnumerationErrors& errors)
{
	XnStatus nRetVal = XN_STATUS_OK;

	xnLogInitFromXmlFile(csXmlFile);

	nRetVal = g_Context.Init();
	XN_IS_STATUS_OK(nRetVal);

	// find devices
	NodeInfoList list;
	nRetVal = g_Context.EnumerateProductionTrees(XN_NODE_TYPE_DEVICE, NULL, list, &errors);
	XN_IS_STATUS_OK(nRetVal);

	printf("The following devices were found:\n");
	int i = 1;
	for (NodeInfoList::Iterator it = list.Begin(); it != list.End(); ++it, ++i)
	{
		NodeInfo deviceNodeInfo = *it;

		Device deviceNode;
		deviceNodeInfo.GetInstance(deviceNode);
		XnBool bExists = deviceNode.IsValid();
		if (!bExists)
		{
			g_Context.CreateProductionTree(deviceNodeInfo, deviceNode);
			// this might fail.
		}

		if (deviceNode.IsValid() && deviceNode.IsCapabilitySupported(XN_CAPABILITY_DEVICE_IDENTIFICATION))
		{
			const XnUInt32 nStringBufferSize = 200;
			XnChar strDeviceName[nStringBufferSize];
			XnChar strSerialNumber[nStringBufferSize];

			XnUInt32 nLength = nStringBufferSize;
			deviceNode.GetIdentificationCap().GetDeviceName(strDeviceName, nLength);
			nLength = nStringBufferSize;
			deviceNode.GetIdentificationCap().GetSerialNumber(strSerialNumber, nLength);
			printf("[%d] %s (%s)\n", i, strDeviceName, strSerialNumber);
		}
		else
		{
			printf("[%d] %s\n", i, deviceNodeInfo.GetCreationInfo());
		}

		// release the device if we created it
		if (!bExists && deviceNode.IsValid())
		{
			deviceNode.Release();
		}
	}
	printf("\n");
	printf("Choose device to open (1): ");

	int chosen = 1;
	scanf("%d", &chosen);

	// create it
	NodeInfoList::Iterator it = list.Begin();
	for (i = 1; i < chosen; ++i)
	{
		it++;
	}

	NodeInfo deviceNode = *it;
	nRetVal = g_Context.CreateProductionTree(deviceNode, g_Device);
	XN_IS_STATUS_OK(nRetVal);

	// now run the rest of the XML
	nRetVal = g_Context.RunXmlScriptFromFile(csXmlFile, g_scriptNode, &errors);
	XN_IS_STATUS_OK(nRetVal);

	openCommon();

	return (XN_STATUS_OK);
}
Esempio n. 3
0
int main(int argc, char* argv[])
{
    
    XnBool bChooseDevice = false;
	const char* csRecordingName = NULL;
    
	if (argc > 1)
	{
		if (strcmp(argv[1], "-devices") == 0)
		{
			bChooseDevice = TRUE;
		}
		else
		{
			csRecordingName = argv[1];
		}
	}
    
	if (csRecordingName != NULL)
	{
		// check if running from a different directory. If so, we need to change directory
		// to the real one, so that path to INI file will be OK (for log initialization, for example)
		if (0 != changeDirectory(argv[0]))
		{
			return(ERR_DEVICE);
		}
	}
    
	// Xiron Init
	XnStatus rc = XN_STATUS_OK;
	EnumerationErrors errors;
    
	if (csRecordingName != NULL)
	{
		xnLogInitFromXmlFile(SAMPLE_XML_PATH);
		rc = openDeviceFile(argv[1]);
	}
	else if (bChooseDevice)
	{
		rc = openDeviceFromXmlWithChoice(SAMPLE_XML_PATH, errors);
	}
	else
	{
		rc = openDeviceFromXml(SAMPLE_XML_PATH, errors);
	}
    
	if (rc == XN_STATUS_NO_NODE_PRESENT)
	{
		XnChar strError[1024];
		errors.ToString(strError, 1024);
		printf("%s\n", strError);
		closeSample(ERR_DEVICE);
		return (rc);
	}
	else if (rc != XN_STATUS_OK)
	{
		printf("Open failed: %s\n", xnGetStatusString(rc));
		closeSample(ERR_DEVICE);
	}
    
	captureInit();
	statisticsInit();
    
	//reshaper.zNear = 1;
	//reshaper.zFar = 100;
	//glut_add_interactor(&reshaper);
    
	//cb.mouse_function = MouseCallback;
	//cb.motion_function = MotionCallback;
	//cb.passive_motion_function = MotionCallback;
	//cb.keyboard_function = KeyboardCallback;
	//cb.reshape_function = ReshapeCallback;
	//glut_add_interactor(&cb);
    
    glutInit(&argc, argv);
	glutInitDisplayString("stencil double rgb");
	glutInitWindowSize(WIN_SIZE_X, WIN_SIZE_Y);
	glutCreateWindow("OpenNI Viewer");
	//glutFullScreen();
	glutSetCursor(GLUT_CURSOR_NONE);
    
    glutMouseFunc(MouseCallback);
    glutMotionFunc(MotionCallback);
    
    init_opengl();
    
    glutIdleFunc(IdleCallback);
	glutDisplayFunc(drawFunctionMain);
    glutPassiveMotionFunc(MotionCallback);
    
	//createKeyboardMap();
	//createMenu();

    atexit(onExit);
    
    //Use built in hand tracker class to handle all hand movements and gestures
    HandTracker mainHandTracker(g_Context);
    m_HandTracker = &mainHandTracker;
    
    drawInit(m_HandTracker);
    
    //mainHandTracker.Init();
    //mainHandTracker.Run();
    xn::ImageGenerator test;
    g_Context.FindExistingNode(XN_NODE_TYPE_IMAGE, test);
    xn::DepthGenerator depth;
    g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, depth);
    
    depth.GetAlternativeViewPointCap().SetViewPoint(test);
    
    glutMainLoop();
    
	return 0;
}