void drawSelectionChanged(SelectionState state, IntRect selection) { g_DrawUserInput.State = state; g_DrawUserInput.Rect = selection; if (state == SELECTION_DONE) { // Crop depth if (getDepthGenerator() != NULL && g_DrawConfig.Streams.Depth.Coloring != DEPTH_OFF) { drawCropStream(getDepthGenerator(), g_DrawConfig.DepthLocation, selection, 2); } // Crop image if (getImageGenerator() != NULL && g_DrawConfig.Streams.Image.Coloring != IMAGE_OFF) { drawCropStream(getImageGenerator(), g_DrawConfig.ImageLocation, selection, 4); } // Crop IR if (getIRGenerator() != NULL && g_DrawConfig.Streams.Image.Coloring != IMAGE_OFF) { drawCropStream(getIRGenerator(), g_DrawConfig.ImageLocation, selection, 4); } } }
void changePrimaryStream(int nIndex) { if (nIndex == 0) { g_pPrimary = NULL; return; } XnProductionNodeType Type; xnProductionNodeTypeFromString(g_PrimaryStream.pValues[nIndex], &Type); switch (Type) { case XN_NODE_TYPE_DEPTH: g_pPrimary = getDepthGenerator(); break; case XN_NODE_TYPE_IMAGE: g_pPrimary = getImageGenerator(); break; case XN_NODE_TYPE_IR: g_pPrimary = getIRGenerator(); break; case XN_NODE_TYPE_AUDIO: g_pPrimary = getAudioGenerator(); break; } }
bool ofxOpenNIContext::toggleRegisterViewport() { // get refs to depth and image generators TODO: make work with IR generator xn::DepthGenerator depth_generator; getDepthGenerator(&depth_generator); xn::ImageGenerator image_generator; if (!getImageGenerator(&image_generator)) { printf("No Image generator found: cannot register viewport"); return false; } // Toggle registering view point to image map if (depth_generator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT)) { if(depth_generator.GetAlternativeViewPointCap().IsViewPointAs(image_generator)) { unregisterViewport(); } else { registerViewport(); } } else return false; return true; }
void resetAllCropping(int) { if (getDepthGenerator() != NULL) resetDepthCropping(0); if (getImageGenerator() != NULL) resetImageCropping(0); if (getIRGenerator() != NULL) resetIRCropping(0); }
bool captureOpenWriteDevice() { XnStatus nRetVal = XN_STATUS_OK; NodeInfoList recordersList; nRetVal = g_Context.EnumerateProductionTrees(XN_NODE_TYPE_RECORDER, NULL, recordersList); START_CAPTURE_CHECK_RC(nRetVal, "Enumerate recorders"); // take first NodeInfo chosen = *recordersList.Begin(); nRetVal = g_Context.CreateProductionTree(chosen); START_CAPTURE_CHECK_RC(nRetVal, "Create recorder"); g_Capture.pRecorder = new Recorder; nRetVal = chosen.GetInstance(*g_Capture.pRecorder); START_CAPTURE_CHECK_RC(nRetVal, "Get recorder instance"); nRetVal = g_Capture.pRecorder->SetDestination(XN_RECORD_MEDIUM_FILE, g_Capture.csFileName); START_CAPTURE_CHECK_RC(nRetVal, "Set output file"); if (getDevice() != NULL) { nRetVal = g_Capture.pRecorder->AddNodeToRecording(*getDevice(), XN_CODEC_UNCOMPRESSED); START_CAPTURE_CHECK_RC(nRetVal, "add device node"); } if (isDepthOn() && (g_Capture.DepthFormat != CODEC_DONT_CAPTURE)) { nRetVal = g_Capture.pRecorder->AddNodeToRecording(*getDepthGenerator(), g_Capture.DepthFormat); START_CAPTURE_CHECK_RC(nRetVal, "add depth node"); } if (isImageOn() && (g_Capture.ImageFormat != CODEC_DONT_CAPTURE)) { nRetVal = g_Capture.pRecorder->AddNodeToRecording(*getImageGenerator(), g_Capture.ImageFormat); START_CAPTURE_CHECK_RC(nRetVal, "add image node"); } if (isIROn() && (g_Capture.IRFormat != CODEC_DONT_CAPTURE)) { nRetVal = g_Capture.pRecorder->AddNodeToRecording(*getIRGenerator(), g_Capture.IRFormat); START_CAPTURE_CHECK_RC(nRetVal, "add IR stream"); } if (isAudioOn() && (g_Capture.AudioFormat != CODEC_DONT_CAPTURE)) { nRetVal = g_Capture.pRecorder->AddNodeToRecording(*getAudioGenerator(), g_Capture.AudioFormat); START_CAPTURE_CHECK_RC(nRetVal, "add Audio stream"); } return true; }
void calculateHistogram() { DepthGenerator* pDepthGen = getDepthGenerator(); if (pDepthGen == NULL) return; XnUInt32 nZRes = pDepthGen->GetDeviceMaxDepth() + 1; if (g_pDepthHist == NULL) { g_pDepthHist = new float[nZRes]; } xnOSMemSet(g_pDepthHist, 0, nZRes*sizeof(float)); int nNumberOfPoints = 0; XnDepthPixel nValue; const XnDepthPixel* pDepth = pDepthGen->GetDepthMap(); const XnDepthPixel* pDepthEnd = pDepth + (pDepthGen->GetDataSize() / sizeof(XnDepthPixel)); while (pDepth != pDepthEnd) { nValue = *pDepth; XN_ASSERT(nValue <= nZRes); if (nValue != 0) { g_pDepthHist[nValue]++; nNumberOfPoints++; } pDepth++; } XnUInt32 nIndex; for (nIndex = 1; nIndex < nZRes; nIndex++) { g_pDepthHist[nIndex] += g_pDepthHist[nIndex-1]; } for (nIndex = 1; nIndex < nZRes; nIndex++) { if (g_pDepthHist[nIndex] != 0) { g_pDepthHist[nIndex] = (nNumberOfPoints-g_pDepthHist[nIndex]) / nNumberOfPoints; } } }
bool ofxOpenNIContext::unregisterViewport() { // get refs to depth generator xn::DepthGenerator depth_generator; getDepthGenerator(&depth_generator); // Unregister view point from (image) any map if (depth_generator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT)) { XnStatus result = depth_generator.GetAlternativeViewPointCap().ResetViewPoint(); CHECK_RC(result, "Unregister viewport"); } else return false; return true; }
bool ofxOpenNIContext::registerViewport() { // get refs to depth and image generators TODO: make work with IR generator xn::DepthGenerator depth_generator; getDepthGenerator(&depth_generator); xn::ImageGenerator image_generator; if (!getImageGenerator(&image_generator)) { printf("No Image generator found: cannot register viewport"); return false; } // Register view point to image map if (depth_generator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT)) { XnStatus result = depth_generator.GetAlternativeViewPointCap().SetViewPoint(image_generator); CHECK_RC(result, "Register viewport"); } else return false; return true; }
void statisticsStart(int) { const DepthMetaData* pDepthMD = getDepthMetaData(); if (pDepthMD == NULL) { displayMessage("Can't collect statistics: Depth is turned off!"); return; } int nCount = pDepthMD->FullXRes() * pDepthMD->FullYRes(); XnDepthPixel nMaxDepth = getDepthGenerator()->GetDeviceMaxDepth(); XnPixelStatistics* pPixel = g_PixelStatistics; for (int i = 0; i < nCount; ++i, ++pPixel) { xnOSMemSet(pPixel, 0, sizeof(XnPixelStatistics)); pPixel->nMin = nMaxDepth; } g_StatisticsState = SHOULD_COLLECT; }
void drawFrame() { // calculate locations g_DrawConfig.DepthLocation.uBottom = 0; g_DrawConfig.DepthLocation.uTop = WIN_SIZE_Y - 1; g_DrawConfig.DepthLocation.uLeft = 0; g_DrawConfig.DepthLocation.uRight = WIN_SIZE_X - 1; g_DrawConfig.ImageLocation.uBottom = 0; g_DrawConfig.ImageLocation.uTop = WIN_SIZE_Y - 1; g_DrawConfig.ImageLocation.uLeft = 0; g_DrawConfig.ImageLocation.uRight = WIN_SIZE_X - 1; if (g_DrawConfig.Streams.ScreenArrangement == SIDE_BY_SIDE) { g_DrawConfig.DepthLocation.uTop = WIN_SIZE_Y / 2 - 1; g_DrawConfig.DepthLocation.uRight = WIN_SIZE_X / 2 - 1; g_DrawConfig.ImageLocation.uTop = WIN_SIZE_Y / 2 - 1; g_DrawConfig.ImageLocation.uLeft = WIN_SIZE_X / 2; } // Texture map init const DepthMetaData* pDepthMD = getDepthMetaData(); if (isDepthOn()) { g_nMaxDepth = getDepthGenerator()->GetDeviceMaxDepth(); TextureMapInit(&g_texDepth, pDepthMD->FullXRes(), pDepthMD->FullYRes(), 4, pDepthMD->XRes(), pDepthMD->YRes()); fixLocation(&g_DrawConfig.DepthLocation, pDepthMD->FullXRes(), pDepthMD->FullYRes()); } const MapMetaData* pImageMD = NULL; if (isImageOn()) { pImageMD = getImageMetaData(); } else if (isIROn()) { pImageMD = getIRMetaData(); } if (pImageMD != NULL) { TextureMapInit(&g_texImage, pImageMD->FullXRes(), pImageMD->FullYRes(), 4, pImageMD->XRes(), pImageMD->YRes()); fixLocation(&g_DrawConfig.ImageLocation, pImageMD->FullXRes(), pImageMD->FullYRes()); } // check if pointer is over a map bool bOverDepth = (pDepthMD != NULL) && isPointInRect(g_DrawUserInput.Cursor, &g_DrawConfig.DepthLocation); bool bOverImage = (pImageMD != NULL) && isPointInRect(g_DrawUserInput.Cursor, &g_DrawConfig.ImageLocation); bool bDrawDepthPointer = false; bool bDrawImagePointer = false; int imagePointerRed = 255; int imagePointerGreen = 0; int imagePointerBlue = 0; IntPair pointerInDepth; IntPair pointerInImage; if (bOverImage) { pointerInImage.X = (double)(g_DrawUserInput.Cursor.X - g_DrawConfig.ImageLocation.uLeft) / (g_DrawConfig.ImageLocation.uRight - g_DrawConfig.ImageLocation.uLeft + 1) * pImageMD->FullXRes(); pointerInImage.Y = (double)(g_DrawUserInput.Cursor.Y - g_DrawConfig.ImageLocation.uBottom) / (g_DrawConfig.ImageLocation.uTop - g_DrawConfig.ImageLocation.uBottom + 1) * pImageMD->FullYRes(); bDrawImagePointer = true; } if (bOverDepth) { pointerInDepth.X = (double)(g_DrawUserInput.Cursor.X - g_DrawConfig.DepthLocation.uLeft) / (g_DrawConfig.DepthLocation.uRight - g_DrawConfig.DepthLocation.uLeft + 1) * pDepthMD->FullXRes(); pointerInDepth.Y = (double)(g_DrawUserInput.Cursor.Y - g_DrawConfig.DepthLocation.uBottom) / (g_DrawConfig.DepthLocation.uTop - g_DrawConfig.DepthLocation.uBottom + 1) * pDepthMD->FullYRes(); // make sure we're in cropped area if (pointerInDepth.X >= pDepthMD->XOffset() && pointerInDepth.X < (pDepthMD->XOffset() + pDepthMD->XRes()) && pointerInDepth.Y >= pDepthMD->YOffset() && pointerInDepth.Y < (pDepthMD->YOffset() + pDepthMD->YRes())) { bDrawDepthPointer = true; if (!bOverImage && g_DrawConfig.bShowPointer) { // try to translate depth pixel to image if (getImageCoordinatesForDepthPixel(pointerInDepth.X, pointerInDepth.Y, pointerInImage.X, pointerInImage.Y)) { bDrawImagePointer = true; imagePointerRed = 0; imagePointerGreen = 0; imagePointerBlue = 255; } } } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Setup the opengl env for fixed location view glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0,WIN_SIZE_X,WIN_SIZE_Y,0,-1.0,1.0); glDisable(GL_DEPTH_TEST); if (g_DrawConfig.Streams.Depth.Coloring == CYCLIC_RAINBOW_HISTOGRAM || g_DrawConfig.Streams.Depth.Coloring == LINEAR_HISTOGRAM || g_DrawConfig.bShowPointer) calculateHistogram(); drawColorImage(&g_DrawConfig.ImageLocation, bDrawImagePointer ? &pointerInImage : NULL, imagePointerRed, imagePointerGreen, imagePointerBlue); drawDepth(&g_DrawConfig.DepthLocation, bDrawDepthPointer ? &pointerInDepth : NULL); printStatisticsInfo(); printRecordingInfo(); if (g_DrawConfig.bShowPointer) drawPointerMode(bDrawDepthPointer ? &pointerInDepth : NULL); drawUserInput(!bOverDepth && !bOverImage); drawUserMessage(); drawPlaybackSpeed(); if (g_DrawConfig.strErrorState != NULL) drawErrorState(); if (g_DrawConfig.bHelp) drawHelpScreen(); glutSwapBuffers(); }
void drawPointerMode(IntPair* pPointer) { char buf[512] = ""; int nCharWidth = glutBitmapWidth(GLUT_BITMAP_HELVETICA_18, '0'); int nPointerValue = 0; XnDouble dTimestampDivider = 1E6; const DepthMetaData* pDepthMD = getDepthMetaData(); if (pDepthMD != NULL) { // Print the scale black background glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glColor4f(0, 0, 0, 0.7); glVertex2i(0, WIN_SIZE_Y); // lower left glVertex2i(WIN_SIZE_X, WIN_SIZE_Y); glVertex2i(WIN_SIZE_X, WIN_SIZE_Y - 135); glVertex2i(0, WIN_SIZE_Y - 135); glEnd(); glDisable(GL_BLEND); // set a large point size (for the scale) glPointSize(15); // Print the scale data glBegin(GL_POINTS); for (int i = 0; i < pDepthMD->ZRes(); i+=1) { float fNewColor = g_pDepthHist[i]; if ((fNewColor > 0.004) && (fNewColor < 0.996)) { glColor3f(fNewColor, fNewColor, 0); glVertex3f(((i/10)*2), WIN_SIZE_Y - 23, 1); } } glEnd(); // Print the pointer scale data if (pPointer != NULL) { // make sure pointer in on a depth pixel (take in mind cropping might be in place) IntPair pointerInDepth = *pPointer; pointerInDepth.X -= pDepthMD->XOffset(); pointerInDepth.Y -= pDepthMD->YOffset(); if (pointerInDepth.X < (int)pDepthMD->XRes() && pointerInDepth.Y < (int)pDepthMD->YRes()) { nPointerValue = (*pDepthMD)(pointerInDepth.X, pointerInDepth.Y); glBegin(GL_POINTS); glColor3f(1,0,0); glVertex3f(10 + ((nPointerValue/10)*2), WIN_SIZE_Y - 70, 1); glEnd(); } } // Print the scale texts for (int i = 0; i < pDepthMD->ZRes()/10; i+=25) { int xPos = i*2 + 10; // draw a small line in this position glBegin(GL_LINES); glColor3f(0, 1, 0); glVertex2i(xPos, WIN_SIZE_Y - 54); glVertex2i(xPos, WIN_SIZE_Y - 62); glEnd(); // place a label under, and in the middle of, that line. int chars = sprintf(buf, "%d", i); glColor3f(1,0,0); glRasterPos2i(xPos - chars*nCharWidth/2, WIN_SIZE_Y - 40); glPrintString(GLUT_BITMAP_HELVETICA_18,buf); } sprintf(buf, "%s - Frame %4u, Timestamp %.3f", getDepthGenerator()->GetInfo().GetInstanceName(), pDepthMD->FrameID(), (double)pDepthMD->Timestamp()/dTimestampDivider); } const ImageMetaData* pImageMD = getImageMetaData(); if (pImageMD != NULL) { if (buf[0] != '\0') sprintf(buf + strlen(buf), " | "); sprintf(buf + strlen(buf), "%s - Frame %4u, Timestamp %.3f", getImageGenerator()->GetInfo().GetInstanceName(), pImageMD->FrameID(), (double)pImageMD->Timestamp()/dTimestampDivider); } const IRMetaData* pIRMD = getIRMetaData(); if (pIRMD != NULL) { if (buf[0] != '\0') sprintf(buf + strlen(buf), " | "); sprintf(buf + strlen(buf), "%s - Frame %4u, Timestamp %.3f", getIRGenerator()->GetInfo().GetInstanceName(), pIRMD->FrameID(), (double)pIRMD->Timestamp()/dTimestampDivider); } const AudioMetaData* pAudioMD = getAudioMetaData(); if (pAudioMD != NULL) { if (buf[0] != '\0') sprintf(buf + strlen(buf), " | "); sprintf(buf + strlen(buf), "%s - Timestamp %.3f", getAudioGenerator()->GetInfo().GetInstanceName(), (double)pAudioMD->Timestamp()/dTimestampDivider); } int nYLocation = WIN_SIZE_Y - 88; glColor3f(1,0,0); glRasterPos2i(10,nYLocation); glPrintString(GLUT_BITMAP_HELVETICA_18, buf); nYLocation -= 26; if (pPointer != NULL && isStatisticsActive()) { XnPixelStatistics* pStatistics = &g_PixelStatistics[pPointer->Y * pDepthMD->XRes() + pPointer->X]; sprintf(buf, "Collected: %3u, Min: %4u Max: %4u Avg: %6.2f StdDev: %6.2f", pStatistics->nCount, pStatistics->nMin, pStatistics->nMax, pStatistics->dAverage, pStatistics->dStdDev); glRasterPos2i(10,nYLocation); glPrintString(GLUT_BITMAP_HELVETICA_18, buf); nYLocation -= 26; } if (pPointer != NULL) { // Print the pointer text XnUInt64 nCutOffMin = 0; XnUInt64 nCutOffMax = (pDepthMD != NULL) ? g_nMaxDepth : 0; XnChar sPointerValue[100]; if (nPointerValue != g_nMaxDepth) { sprintf(sPointerValue, "%.1f", (float)nPointerValue/10); } else { sprintf(sPointerValue, "-"); } sprintf(buf, "Pointer Value: %s (X:%d Y:%d) Cutoff: %llu-%llu.", sPointerValue, pPointer->X, pPointer->Y, nCutOffMin, nCutOffMax); glRasterPos2i(10,nYLocation); glPrintString(GLUT_BITMAP_HELVETICA_18, buf); nYLocation -= 26; } }
void setDepthFPS(int fps) { setFPS(getDepthGenerator(), fps); }
void setDepthResolution(int res) { setResolution(getDepthGenerator(), res); }
void captureSetDepthFormat(int format) { captureSetFormat(&g_Capture.DepthFormat, format, *getDepthGenerator()); }
void resetDepthCropping(int) { resetCropping(getDepthGenerator()); }