int main()
{
	XnStatus nRetVal = XN_STATUS_OK;
	nRetVal = xnLogInitFromXmlFile(SAMPLE_XML_PATH);
	if (nRetVal != XN_STATUS_OK)
	{
		printf("Log couldn't be opened: %s. Running without log", xnGetStatusString(nRetVal));
	}

	Context context;
	nRetVal = context.Init();
	CHECK_RC(nRetVal, "Init");

	// create recorder
	Recorder recorder;

	nRetVal = recorder.Create(context);
	CHECK_RC(nRetVal, "Create recorder");

	nRetVal = recorder.SetDestination(XN_RECORD_MEDIUM_FILE, RECORDING_FILE_NAME);
	CHECK_RC(nRetVal, "Set recorder destination file");

	// Create mock raw node
	MockRawGenerator rawGenerator;
	nRetVal = rawGenerator.Create(context, "MockRaw");
	CHECK_RC(nRetVal, "Create mock raw generator");

	nRetVal = rawGenerator.SetStringProperty("Type", "ReverseT");
	CHECK_RC(nRetVal, "Set property");

	nRetVal = rawGenerator.SetIntProperty("X", 5);
	CHECK_RC(nRetVal, "Set property");

	nRetVal = recorder.AddNodeToRecording(rawGenerator);
	CHECK_RC(nRetVal, "Add node to recording");

	//Now we set one property after adding to recording
	nRetVal = rawGenerator.SetIntProperty("Y", 8);
	CHECK_RC(nRetVal, "Set property");

	XnChar buff[20];
	
	for (XnUInt32 i = 1; i <= 10; i++)
	{
		for (XnUInt32 j = 0; j < 20; j++)
		{
			buff[j] = (XnChar)i;
		}

		printf("Recording frame %d/10...\r", i);
		nRetVal = rawGenerator.SetData(1000 * i, i, sizeof(buff), buff);
		CHECK_RC(nRetVal, "Set raw node new data");

		nRetVal = recorder.Record();
		CHECK_RC(nRetVal, "Record");
	}

	nRetVal = recorder.RemoveNodeFromRecording(rawGenerator);
	CHECK_RC(nRetVal, "Remove node from recording");

	recorder.Release();
	printf("\nDone recording.\n");

	rawGenerator.Release();

	Player player;
	nRetVal = context.OpenFileRecording(RECORDING_FILE_NAME, player);
	CHECK_RC(nRetVal, "Open file recording");
	
	nRetVal = player.SetRepeat(FALSE);
	CHECK_RC(nRetVal, "Turn repeat off");

	nRetVal = context.GetProductionNodeByName("MockRaw", rawGenerator);
	CHECK_RC(nRetVal, "Get raw node by name");

	const XnChar* pData = NULL;
	XnUInt32 nSize = 0;

	printf("Reading Data:\n");
	while ((nRetVal = context.WaitAnyUpdateAll()) != XN_STATUS_EOF)
	{
		CHECK_RC(nRetVal, "Read data from file");
		pData = (const XnChar*)rawGenerator.GetData();
		nSize = rawGenerator.GetDataSize();
		for (XnUInt32 i = 0; i < nSize; i++)
		{
			printf("%d ", pData[i]);
		}
		printf("\n");
	}

	player.Release();
	rawGenerator.Release();
	recorder.Release();
	context.Release();

	return 0;
}
Example #2
0
//----------------------------------------------------
// キーボード処理
//----------------------------------------------------
void glutKeyboard (unsigned char key, int x, int y){
	switch (key){
		case '1':	// オーバーレイモード
			g_nViewState = DISPLAY_MODE_OVERLAY;
			g_depth.GetAlternativeViewPointCap().SetViewPoint(g_image);	// イメージとデプスのずれを無くす
			break;
		case '2':	// デプスモード
			g_nViewState = DISPLAY_MODE_DEPTH;
			g_depth.GetAlternativeViewPointCap().ResetViewPoint();		// デプスの大きさを元に戻す?
			break;
		case '3':	// イメージモード
			g_nViewState = DISPLAY_MODE_IMAGE;
			g_depth.GetAlternativeViewPointCap().SetViewPoint(g_image);	// イメージとデプスのずれを無くす
			break;
		case '4':	// クロマキーモード
			g_nViewState = DISPLAY_MODE_CHROMA;
			g_depth.GetAlternativeViewPointCap().SetViewPoint(g_image);	// イメージとデプスのずれを無くす
			break;
		case '5':	// ポイントクラウドモード
			g_nViewState = DISPLAY_MODE_POINT_CLOUD;
			g_depth.GetAlternativeViewPointCap().SetViewPoint(g_image);	// イメージとデプスのずれを無くす
			break;
			
		case 'm':	// ★連打厳禁!!(何故か重くなる)★
			g_context.SetGlobalMirror(!g_context.GetGlobalMirror());	// ミラーリング
			break;
		case 'd':
			g_debugMode = !g_debugMode;									// デバッグモードのオンオフ
			break;

		case 'f':
			g_fullScreenMode = !g_fullScreenMode;	// フルスクリーンモードの切り替え(トグルスイッチ)

			if(g_fullScreenMode){					// フルスクリーンモード
				glutFullScreen();
			}else{									// ウィンドウモード
				glutPositionWindow(100, 100);
				glutReshapeWindow(KINECT_IMAGE_WIDTH, KINECT_IMAGE_HEIGHT);
			}
			break;

		case 's':	// スクリーンショットを撮る(深さも撮る)
			g_screenShotDepthMode = true;
		case 'S':	// スクリーンショットを撮る(深さは撮らない)
			g_screenShotImageMode = true;
			break;

		case 'R':	// レコードストップ
			g_recorder.RemoveNodeFromRecording(g_image);
			g_recorder.RemoveNodeFromRecording(g_depth);

			cout << "recording stop!" << endl;
			break;

		// 閾値の増減
		case 't': g_chromaThresh += 10; break;
		case 'T': g_chromaThresh -= 10; break;

		//case 'p':
		//	g_pointSize += 0.000001;
		//	break;
		//case 'P':
		//	g_pointSize -= 0.000001;
		//	break;

		// 視点移動
		case 'x': g_lokEyeX ++; g_lokDirX ++; break;
		case 'X': g_lokEyeX --; g_lokDirX --; break;
		case 'y': g_lokEyeY ++; g_lokDirY ++; break;
		case 'Y': g_lokEyeY --; g_lokDirY --; break;
		case 'z': g_lokEyeZ += 1; g_lokDirZ += 1; break;
		case 'Z': g_lokEyeZ -= 1; g_lokDirZ -= 1; break;

		// 強制終了
		case 27:	// Escボタン
		case 'q':
		case 'Q':
			exit (1);
	}
}