Пример #1
0
// this function is called each frame
void glutDisplay (void)
{
    // Read next available data
    g_Context.WaitAnyUpdateAll();

    // Process the data
    g_pSessionManager->Update(&g_Context);

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Setup the OpenGL viewpoint
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

#ifdef USE_GLUT
    //glOrtho(0, GL_WIN_SIZE_X, 0, GL_WIN_SIZE_Y, -1.0, 1.0);
    glOrtho(0, 1.0, 1.0, 0, -1.0, 1.0);
#else
    //glOrthof(0, GL_WIN_SIZE_X, 0, GL_WIN_SIZE_Y, -1.0, 1.0);
    glOrthof(0, 1.0, 1.0, 0, -1.0, 1.0);
#endif

    // draw
    if (g_bDrawFrame)
    {
        DrawFrame(xnCreatePoint3D(0.0, 0.0, 0), xnCreatePoint3D(1.0, 1.0, 0), 8, g_fFrameR, g_fFrameG, g_fFrameB);
    }

    if (g_bDrawCircle)
    {
        XnV3DVector vec(0.5, 0.5, 0);
        vec += XnV3DVector(sin(g_fCircleAngle), -cos(g_fCircleAngle), 0) * 0.3;
        DrawCircle(xnCreatePoint3D(0.5, 0.5, 0), 0.3, 3, g_fCircleR, g_fCircleG, g_fCircleB);
        DrawLine(xnCreatePoint3D(0.5, 0.5, 0), vec, 4, g_fCircleLineR, g_fCircleLineG, g_fCircleLineB);
    }

    // flip surfaces
#ifdef USE_GLUT
    glutSwapBuffers();
#else
    eglSwapBuffers(display, surface);
#endif
}
Пример #2
0
// More drawing
void DrawSlider()
{
	if (!g_bInSession)
		return;

	XnPoint3D ptMin = xnCreatePoint3D(50, GL_WIN_SIZE_Y-380, 0);
	XnPoint3D ptMax = xnCreatePoint3D(650, GL_WIN_SIZE_Y-460, 0);

	XnDouble r, g, b;
	XnBool bDrawCursor = false;

	if (!g_bActive)
	{
		r = g = b = 1;
	}
	else if (!g_bIsInput)
	{
		r = g = b = 0.5;
	}
	else
	{
		r = b = 0;
		g = 1;
		bDrawCursor = true;
	}

	DrawFrame(ptMin, ptMax, 20, r, g, b);

	if (bDrawCursor)
	{
		DrawLine(600*g_fValue+50, GL_WIN_SIZE_Y-380, 0,
				600*g_fValue+50, GL_WIN_SIZE_Y-460, 0,
				30, 1, 1, 0);
	}

}
Пример #3
0
void DrawFrame(const XnPoint3D& ptMins, const XnPoint3D& ptMaxs, int width, double r, double g, double b)
{
    XnPoint3D ptTopLeft = ptMins;
    XnPoint3D ptBottomRight = ptMaxs;

    // Top line
    DrawLine(xnCreatePoint3D(ptTopLeft.X, ptTopLeft.Y, 0),
             xnCreatePoint3D(ptBottomRight.X, ptTopLeft.Y, 0),
             width, r, g, b);
    // Right Line
    DrawLine(xnCreatePoint3D(ptBottomRight.X, ptTopLeft.Y, 0),
             xnCreatePoint3D(ptBottomRight.X, ptBottomRight.Y,0),
             width, r, g, b);
    // Bottom Line
    DrawLine(xnCreatePoint3D(ptBottomRight.X, ptBottomRight.Y,0),
             xnCreatePoint3D(ptTopLeft.X, ptBottomRight.Y,0),
             width, r, g, b);
    // Left Line
    DrawLine(xnCreatePoint3D(ptTopLeft.X, ptBottomRight.Y,0),
             xnCreatePoint3D(ptTopLeft.X, ptTopLeft.Y,0),
             width, r, g, b);
}
void DrawDepthMap(const xn::DepthMetaData& dmd, const xn::SceneMetaData& smd)
{
	static bool bInitialized = false;
	static GLuint depthTexID;
	static unsigned char* pDepthTexBuf;
	static int texWidth, texHeight;

	 float topLeftX;
	 float topLeftY;
	 float bottomRightY;
	 float bottomRightX;
	float texXpos;
	float texYpos;

	if(!bInitialized)
	{

		texWidth =  getClosestPowerOfTwo(dmd.XRes());
		texHeight = getClosestPowerOfTwo(dmd.YRes());

//		printf("Initializing depth texture: width = %d, height = %d\n", texWidth, texHeight);
		depthTexID = initTexture((void**)&pDepthTexBuf,texWidth, texHeight) ;

//		printf("Initialized depth texture: width = %d, height = %d\n", texWidth, texHeight);
		bInitialized = true;

		topLeftX = dmd.XRes();
		topLeftY = 0;
		bottomRightY = dmd.YRes();
		bottomRightX = 0;
		texXpos =(float)dmd.XRes()/texWidth;
		texYpos  =(float)dmd.YRes()/texHeight;

		memset(texcoords, 0, 8*sizeof(float));
		texcoords[0] = texXpos, texcoords[1] = texYpos, texcoords[2] = texXpos, texcoords[7] = texYpos;

	}
	unsigned int nValue = 0;
	unsigned int nHistValue = 0;
	unsigned int nIndex = 0;
	unsigned int nX = 0;
	unsigned int nY = 0;
	unsigned int nNumberOfPoints = 0;
	XnUInt16 g_nXRes = dmd.XRes();
	XnUInt16 g_nYRes = dmd.YRes();

	unsigned char* pDestImage = pDepthTexBuf;

	const XnDepthPixel* pDepth = dmd.Data();
	const XnLabel* pLabels = smd.Data();

	// Calculate the accumulative histogram
	memset(g_pDepthHist, 0, MAX_DEPTH*sizeof(float));
	for (nY=0; nY<g_nYRes; nY++)
	{
		for (nX=0; nX<g_nXRes; nX++)
		{
			nValue = *pDepth;

			if (nValue != 0)
			{
				g_pDepthHist[nValue]++;
				nNumberOfPoints++;
			}

			pDepth++;
		}
	}

	for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
	{
		g_pDepthHist[nIndex] += g_pDepthHist[nIndex-1];
	}
	if (nNumberOfPoints)
	{
		for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
		{
			g_pDepthHist[nIndex] = (unsigned int)(256 * (1.0f - (g_pDepthHist[nIndex] / nNumberOfPoints)));
		}
	}

	XnPoint3D coms[20];
	XnUInt32 labels[20] = {0};
	for (int i = 0; i < 20; ++i)
	{
		coms[i] = xnCreatePoint3D(0,0,0);
	}

	pDepth = dmd.Data();
	{
		XnUInt32 nIndex = 0;
		// Prepare the texture map
		for (nY=0; nY<g_nYRes; nY++)
		{
			for (nX=0; nX < g_nXRes; nX++, nIndex++)
			{
				nValue = *pDepth;
				XnLabel label = *pLabels;
				XnUInt32 nColorID = label % nColors;
				if (label == 0)
				{
					nColorID = nColors;
				}

				if (nValue != 0)
				{
					nHistValue = g_pDepthHist[nValue];

					pDestImage[0] = nHistValue * Colors[nColorID][0];
					pDestImage[1] = nHistValue * Colors[nColorID][1];
					pDestImage[2] = nHistValue * Colors[nColorID][2];

					if (label < 20 && label > 0)
					{
						coms[label].X += nX;
						coms[label].Y += nY;
						coms[label].Z += *pDepth;
						labels[label]++;
					}
				}
				else
				{
					pDestImage[0] = 0;
					pDestImage[1] = 0;
					pDestImage[2] = 0;
				}

				pDepth++;
				pLabels++;
				pDestImage+=3;
			}

			pDestImage += (texWidth - g_nXRes) *3;
		}
	}

	glBindTexture(GL_TEXTURE_2D, depthTexID);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pDepthTexBuf);

	// Display the OpenGL texture map
	glColor4f(0.75,0.75,0.75,1);

	glEnable(GL_TEXTURE_2D);
	DrawTexture(dmd.XRes(),dmd.YRes(),0,0);
	glDisable(GL_TEXTURE_2D);
#ifdef USE_GLUT
	char strLabel[3] = "";
	for (int i = 0; i < 20; ++i)
	{
		if (labels[i] == 0)
			continue;
		coms[i].X /= labels[i];
		coms[i].Y /= labels[i];
		coms[i].Z /= labels[i];

		sprintf(strLabel, "%d", i);

		glColor4f(1-Colors[i%nColors][0], 1-Colors[i%nColors][1], 1-Colors[i%nColors][2], 1);

		glRasterPos2i(coms[i].X, coms[i].Y);
		glPrintString(GLUT_BITMAP_HELVETICA_18, strLabel);
	}
#endif
}
Пример #5
0
// More drawing
void DrowTrackPad()
{
  if (!g_bInSession)
    return;
  
  XnDouble r, g, b;
  
  if (!g_bActive)
    {
      r = g = b = 1;
    }
  else if (!g_bIsInput)
    {
      r = g = b = 0.5;
    }
  else
    {
      r = b = 0;
      g = 1;
    }
  
  
  XnFloat width = 20;
  XnFloat x_step = (XnFloat)GL_WIN_SIZE_X/g_TP_XDim;
  for(XnUInt32 i=0 ; i<=g_TP_XDim ; ++i)
  {
    DrawLine(xnCreatePoint3D(GL_WIN_SIZE_X-(i*x_step), GL_WIN_SIZE_Y, 0.0),
	     xnCreatePoint3D(GL_WIN_SIZE_X-(i*x_step), 0.0, 0.0),
	     width, r, g, b);
  }
  
  XnFloat y_step = (XnFloat)GL_WIN_SIZE_Y/g_TP_YDim;
  for(XnUInt32 j=1 ; j<=g_TP_YDim ; ++j)
    {
      DrawLine(xnCreatePoint3D(GL_WIN_SIZE_X, GL_WIN_SIZE_Y-(j*y_step), 0.0),
	       xnCreatePoint3D(0.0, GL_WIN_SIZE_Y-(j*y_step), 0.0),
	       width, r, g, b); 
    }
  
  
  if(TRUE == g_isPrintItemHover)
    {
      XnPoint3D ptTopLeft = xnCreatePoint3D((CurrentItem.X*x_step), /*GL_WIN_SIZE_Y-*/(CurrentItem.Y*y_step), 0.0);
      XnPoint3D ptBottomRight = xnCreatePoint3D(((CurrentItem.X+1)*x_step), /*GL_WIN_SIZE_Y-*/((CurrentItem.Y+1)*y_step), 0.0);
      
      if(TRUE == g_isInputStarted)
	DrawFrame(ptTopLeft, ptBottomRight, width, 1, 1, 0);
      else
	DrawFrame(ptTopLeft, ptBottomRight, width, 0.2, 0.2, 0);
      
    }
  
  width /= 2;
  if(TRUE == g_isPrintValueChange)
    {
      XnFloat TopPointX = (g_fXValue)*GL_WIN_SIZE_X;
      XnFloat TopPointY = (g_fYValue)*GL_WIN_SIZE_Y;
      XnPoint3D ptTopLeft = xnCreatePoint3D(TopPointX, TopPointY, 0.0);
      XnPoint3D ptBottomRight = xnCreatePoint3D(TopPointX+width, TopPointY+width, 0.0);
      
      if(TRUE == g_isInputStarted)
	DrawFrame(ptTopLeft, ptBottomRight, width, 1, 0, 0);
      else
	DrawFrame(ptTopLeft, ptBottomRight, width, 0.2, 0, 0);
      
    }
  
  if(TRUE == g_bIsPushed)
    {
      XnPoint3D ptTopLeft = xnCreatePoint3D((CurrentItem.X*x_step), (CurrentItem.Y*y_step), 0.0);
      XnPoint3D ptBottomRight = xnCreatePoint3D(((CurrentItem.X+1)*x_step), ((CurrentItem.Y+1)*y_step), 0.0);
      DrawFrame(ptTopLeft, ptBottomRight, width, 1, 0.5, 0);
      
      ++g_nCurrentFrame;
      if(XN_PUSH_DISPLAY_FRAMES <= g_nCurrentFrame)
	{
	  g_bIsPushed = FALSE;
	  g_nCurrentFrame = 0;
	}
    }
}