|
@@ -19,17 +19,13 @@ namespace bbiwarg.Graphics
|
|
class OutputWindow : GameWindow
|
|
class OutputWindow : GameWindow
|
|
{
|
|
{
|
|
private VideoHandle videoHandle;
|
|
private VideoHandle videoHandle;
|
|
- private uint depthTextureID;
|
|
|
|
- private uint edgeTextureID;
|
|
|
|
- private uint touchEventTextureID;
|
|
|
|
|
|
+ private uint textureId;
|
|
private bool paused = false;
|
|
private bool paused = false;
|
|
private long timeSpacePressed, timeLeftPressed, timeRightPressed;
|
|
private long timeSpacePressed, timeLeftPressed, timeRightPressed;
|
|
private Stopwatch watch;
|
|
private Stopwatch watch;
|
|
|
|
|
|
- private const int numImages = 3;
|
|
|
|
-
|
|
|
|
public OutputWindow(VideoHandle videoHandle)
|
|
public OutputWindow(VideoHandle videoHandle)
|
|
- : base((int) (1.5 * numImages * videoHandle.Width), (int) (1.5 * videoHandle.Height))
|
|
|
|
|
|
+ : base((int) (1.5 * videoHandle.OutputImages.Length * videoHandle.Width), (int) (1.5 * videoHandle.Height))
|
|
{
|
|
{
|
|
this.videoHandle = videoHandle;
|
|
this.videoHandle = videoHandle;
|
|
watch = new Stopwatch();
|
|
watch = new Stopwatch();
|
|
@@ -49,27 +45,13 @@ namespace bbiwarg.Graphics
|
|
//Depth Test
|
|
//Depth Test
|
|
GL.Enable(EnableCap.DepthTest);
|
|
GL.Enable(EnableCap.DepthTest);
|
|
|
|
|
|
- // Textures
|
|
|
|
|
|
+ // Texture
|
|
GL.Enable(EnableCap.Texture2D);
|
|
GL.Enable(EnableCap.Texture2D);
|
|
|
|
|
|
- //depthTexture
|
|
|
|
- GL.GenTextures(1, out depthTextureID);
|
|
|
|
- GL.BindTexture(TextureTarget.Texture2D, depthTextureID);
|
|
|
|
|
|
+ GL.GenTextures(1, out textureId);
|
|
|
|
+ GL.BindTexture(TextureTarget.Texture2D, textureId);
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
|
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
|
-
|
|
|
|
- //edgetexture
|
|
|
|
- GL.GenTextures(1, out edgeTextureID);
|
|
|
|
- GL.BindTexture(TextureTarget.Texture2D, edgeTextureID);
|
|
|
|
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
|
|
|
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
|
|
|
-
|
|
|
|
- //touch event texture
|
|
|
|
- GL.GenTextures(1, out touchEventTextureID);
|
|
|
|
- GL.BindTexture(TextureTarget.Texture2D, touchEventTextureID);
|
|
|
|
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
|
|
|
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnResize(EventArgs e)
|
|
protected override void OnResize(EventArgs e)
|
|
@@ -83,12 +65,12 @@ namespace bbiwarg.Graphics
|
|
int imageHeight = videoHandle.Height;
|
|
int imageHeight = videoHandle.Height;
|
|
float imageAspectRatio = (float)imageWidth / (float)imageHeight;
|
|
float imageAspectRatio = (float)imageWidth / (float)imageHeight;
|
|
|
|
|
|
- int heightForWidth = (int) ((float) screenWidth / ((float) numImages * imageAspectRatio));
|
|
|
|
|
|
+ int heightForWidth = (int) ((float) screenWidth / ((float) videoHandle.OutputImages.Length * imageAspectRatio));
|
|
|
|
|
|
GL.Viewport(0, (screenHeight - heightForWidth) / 2, screenWidth, heightForWidth);
|
|
GL.Viewport(0, (screenHeight - heightForWidth) / 2, screenWidth, heightForWidth);
|
|
|
|
|
|
// top left at (0,0) every image from (i, j) to (i + 1, j + 1)
|
|
// top left at (0,0) every image from (i, j) to (i + 1, j + 1)
|
|
- Matrix4 projection = Matrix4.CreateOrthographicOffCenter(0, 3, 1, 0, 0.001f, 10f);
|
|
|
|
|
|
+ Matrix4 projection = Matrix4.CreateOrthographicOffCenter(0, videoHandle.OutputImages.Length, 1, 0, 0.001f, 10f);
|
|
GL.MatrixMode(MatrixMode.Projection);
|
|
GL.MatrixMode(MatrixMode.Projection);
|
|
GL.LoadMatrix(ref projection);
|
|
GL.LoadMatrix(ref projection);
|
|
}
|
|
}
|
|
@@ -103,8 +85,6 @@ namespace bbiwarg.Graphics
|
|
GL.MatrixMode(MatrixMode.Modelview);
|
|
GL.MatrixMode(MatrixMode.Modelview);
|
|
GL.LoadMatrix(ref modelview);
|
|
GL.LoadMatrix(ref modelview);
|
|
|
|
|
|
- bool changedFrame = false;
|
|
|
|
-
|
|
|
|
const int autoRepeatDelay = 100; // ms
|
|
const int autoRepeatDelay = 100; // ms
|
|
if (videoHandle.sourceIsMovie())
|
|
if (videoHandle.sourceIsMovie())
|
|
{
|
|
{
|
|
@@ -129,7 +109,6 @@ namespace bbiwarg.Graphics
|
|
videoHandle.unpauseMovie();
|
|
videoHandle.unpauseMovie();
|
|
videoHandle.nextFrame();
|
|
videoHandle.nextFrame();
|
|
videoHandle.pauseMovie();
|
|
videoHandle.pauseMovie();
|
|
- changedFrame = true;
|
|
|
|
}
|
|
}
|
|
else if (OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.Left) && (elapsed - timeLeftPressed) >= autoRepeatDelay)
|
|
else if (OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.Left) && (elapsed - timeLeftPressed) >= autoRepeatDelay)
|
|
{
|
|
{
|
|
@@ -139,13 +118,11 @@ namespace bbiwarg.Graphics
|
|
videoHandle.nextFrame();
|
|
videoHandle.nextFrame();
|
|
videoHandle.reversePlay();
|
|
videoHandle.reversePlay();
|
|
videoHandle.pauseMovie();
|
|
videoHandle.pauseMovie();
|
|
- changedFrame = true;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
videoHandle.nextFrame();
|
|
videoHandle.nextFrame();
|
|
- changedFrame = true;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -153,145 +130,28 @@ namespace bbiwarg.Graphics
|
|
videoHandle.nextFrame();
|
|
videoHandle.nextFrame();
|
|
}
|
|
}
|
|
|
|
|
|
- if (changedFrame || !videoHandle.sourceIsMovie())
|
|
|
|
- {
|
|
|
|
- /*foreach (PalmTouchEvent ev in videoHandle.getTouchEvents())
|
|
|
|
- {
|
|
|
|
- //Console.WriteLine("touch at " + ev.Position + " -> " + ev.RelativePalmPosition);
|
|
|
|
- //touchVisualizer.addTouchEvent(ev);
|
|
|
|
- }*/
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (videoHandle.sourceIsMovie())
|
|
if (videoHandle.sourceIsMovie())
|
|
Title = "BBIWARG - Output (Frame " + videoHandle.getCurrentMovieFrame() + ")";
|
|
Title = "BBIWARG - Output (Frame " + videoHandle.getCurrentMovieFrame() + ")";
|
|
|
|
|
|
|
|
|
|
Timer.start("outputTextures");
|
|
Timer.start("outputTextures");
|
|
- //draw textures
|
|
|
|
- Int16[] depthTextureData = new Int16[3 * videoHandle.Width * videoHandle.Height];
|
|
|
|
- Int16[] edgeTextureData = new Int16[3 * videoHandle.Width * videoHandle.Height];
|
|
|
|
- int index = 0;
|
|
|
|
-
|
|
|
|
- for (int y = 0; y < videoHandle.Height; ++y)
|
|
|
|
|
|
+ GL.Enable(EnableCap.Texture2D);
|
|
|
|
+
|
|
|
|
+ int imageIndex = 0;
|
|
|
|
+ foreach (OutputImage image in videoHandle.OutputImages)
|
|
{
|
|
{
|
|
- for (int x = 0; x < videoHandle.Width; ++x)
|
|
|
|
- {
|
|
|
|
- Int16 red = 0;
|
|
|
|
- Int16 green = 0;
|
|
|
|
- Int16 blue = 0;
|
|
|
|
-
|
|
|
|
- //depthTexture
|
|
|
|
- float relDepth = videoHandle.getRelativeDepth(x, y);
|
|
|
|
- red = green = blue = (Int16)((1.0f - videoHandle.getRelativeDepth(x, y)) * Int16.MaxValue);
|
|
|
|
-
|
|
|
|
- // palm
|
|
|
|
- switch (videoHandle.getPalmImageStateAt(x, y))
|
|
|
|
- {
|
|
|
|
- case PalmImageState.palmContour:
|
|
|
|
- red = Int16.MaxValue;
|
|
|
|
- blue = green = 0;
|
|
|
|
- break;
|
|
|
|
- case PalmImageState.palmRect:
|
|
|
|
- blue = Int16.MaxValue;
|
|
|
|
- red = green = 0;
|
|
|
|
- break;
|
|
|
|
- case PalmImageState.thumbLine:
|
|
|
|
- case PalmImageState.wristLine:
|
|
|
|
- green = Int16.MaxValue;
|
|
|
|
- blue = red = 0;
|
|
|
|
- break;
|
|
|
|
- case PalmImageState.palmGrid:
|
|
|
|
- green = (Int16)(green / 2 + Int16.MaxValue / 2);
|
|
|
|
- blue = (Int16)(blue / 2 + Int16.MaxValue / 2);
|
|
|
|
- red = (Int16)(red / 2 + Int16.MaxValue / 2);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // touch
|
|
|
|
- switch (videoHandle.getTouchImageStateAt(x, y))
|
|
|
|
- {
|
|
|
|
- case TouchImageState.touchArea:
|
|
|
|
- red = (Int16)(red / 2);
|
|
|
|
- green = (Int16)(green / 2);
|
|
|
|
- blue = (Int16)(blue / 2);
|
|
|
|
- break;
|
|
|
|
- case TouchImageState.touchAreaMatched:
|
|
|
|
- red = (Int16)(red / 2);
|
|
|
|
- green = (Int16)(green / 2);
|
|
|
|
- blue = Int16.MaxValue;
|
|
|
|
- break;
|
|
|
|
- case TouchImageState.touchAreaStatusBar:
|
|
|
|
- red = (Int16)(red / 2);
|
|
|
|
- green = Int16.MaxValue;
|
|
|
|
- blue = (Int16)(blue / 2);
|
|
|
|
- break;
|
|
|
|
- case TouchImageState.touchDetected:
|
|
|
|
- red = (Int16)(red / 2);
|
|
|
|
- blue = (Int16)(blue / 2);
|
|
|
|
- green = (Int16)(green / 2 + Int16.MaxValue / 2);
|
|
|
|
- break;
|
|
|
|
- case TouchImageState.touchTracked:
|
|
|
|
- red = (Int16)(red / 2 + Int16.MaxValue / 2);
|
|
|
|
- green = (Int16)(green / 2);
|
|
|
|
- blue = (Int16)(blue / 2);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- depthTextureData[index] = red;
|
|
|
|
- depthTextureData[index + 1] = green;
|
|
|
|
- depthTextureData[index + 2] = blue;
|
|
|
|
-
|
|
|
|
- //edgeTexture
|
|
|
|
- FingerImageState fis = videoHandle.getFingerImageStateAt(x, y);
|
|
|
|
- red = green = blue = 0;
|
|
|
|
- if (videoHandle.isEdgeAt(x, y)) blue = Int16.MaxValue;
|
|
|
|
- else if (fis == FingerImageState.fingerTracked) green = Int16.MaxValue;
|
|
|
|
- else if (fis == FingerImageState.fingerDetected) red = Int16.MaxValue;
|
|
|
|
- else if (fis == FingerImageState.fingerSlice) red = blue = Int16.MaxValue;
|
|
|
|
- else if (fis == FingerImageState.possibleFingerSlice) red = Int16.MaxValue;
|
|
|
|
-
|
|
|
|
- edgeTextureData[index] = red;
|
|
|
|
- edgeTextureData[index + 1] = green;
|
|
|
|
- edgeTextureData[index + 2] = blue;
|
|
|
|
-
|
|
|
|
- index += 3;
|
|
|
|
- }
|
|
|
|
|
|
+ GL.BindTexture(TextureTarget.Texture2D, textureId);
|
|
|
|
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 0, PixelFormat.Rgb, PixelType.UnsignedByte, image.Image.MIplImage.imageData);
|
|
|
|
+ GL.Begin(PrimitiveType.Quads);
|
|
|
|
+ GL.Color3(1.0, 1.0, 1.0);
|
|
|
|
+ GL.TexCoord2(0, 0); GL.Vertex3(0 + imageIndex, 0, -1);
|
|
|
|
+ GL.TexCoord2(1, 0); GL.Vertex3(1 + imageIndex, 0, -1);
|
|
|
|
+ GL.TexCoord2(1, 1); GL.Vertex3(1 + imageIndex, 1, -1);
|
|
|
|
+ GL.TexCoord2(0, 1); GL.Vertex3(0 + imageIndex, 1, -1);
|
|
|
|
+ GL.End();
|
|
|
|
+ ++imageIndex;
|
|
}
|
|
}
|
|
|
|
|
|
- GL.Enable(EnableCap.Texture2D);
|
|
|
|
- GL.BindTexture(TextureTarget.Texture2D, edgeTextureID);
|
|
|
|
- GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 0, PixelFormat.Rgb, PixelType.Short, edgeTextureData);
|
|
|
|
- GL.Begin(PrimitiveType.Quads);
|
|
|
|
- GL.Color3(1.0, 1.0, 1.0);
|
|
|
|
- GL.TexCoord2(0, 0); GL.Vertex3(0, 0, -1);
|
|
|
|
- GL.TexCoord2(1, 0); GL.Vertex3(1, 0, -1);
|
|
|
|
- GL.TexCoord2(1, 1); GL.Vertex3(1, 1, -1);
|
|
|
|
- GL.TexCoord2(0, 1); GL.Vertex3(0, 1, -1);
|
|
|
|
- GL.End();
|
|
|
|
-
|
|
|
|
- GL.Enable(EnableCap.Texture2D);
|
|
|
|
- GL.BindTexture(TextureTarget.Texture2D, depthTextureID);
|
|
|
|
- GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 0, PixelFormat.Rgb, PixelType.Short, depthTextureData);
|
|
|
|
- GL.Begin(PrimitiveType.Quads);
|
|
|
|
- GL.Color3(1.0, 1.0, 1.0);
|
|
|
|
- GL.TexCoord2(0, 0); GL.Vertex3(1, 0, -1);
|
|
|
|
- GL.TexCoord2(1, 0); GL.Vertex3(2, 0, -1);
|
|
|
|
- GL.TexCoord2(1, 1); GL.Vertex3(2, 1, -1);
|
|
|
|
- GL.TexCoord2(0, 1); GL.Vertex3(1, 1, -1);
|
|
|
|
- GL.End();
|
|
|
|
-
|
|
|
|
- /*GL.Enable(EnableCap.Texture2D);
|
|
|
|
- GL.BindTexture(TextureTarget.Texture2D, touchEventTextureID);
|
|
|
|
- GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 0, PixelFormat.Rgb, PixelType.Short,
|
|
|
|
- kalmanDemo.getTextureData(videoHandle.Width, videoHandle.Height));
|
|
|
|
- GL.Begin(PrimitiveType.Quads);
|
|
|
|
- GL.Color3(1.0, 1.0, 1.0);
|
|
|
|
- GL.TexCoord2(0, 0); GL.Vertex3(2, 0, -1);
|
|
|
|
- GL.TexCoord2(1, 0); GL.Vertex3(3, 0, -1);
|
|
|
|
- GL.TexCoord2(1, 1); GL.Vertex3(3, 1, -1);
|
|
|
|
- GL.TexCoord2(0, 1); GL.Vertex3(2, 1, -1);
|
|
|
|
- GL.End();*/
|
|
|
|
-
|
|
|
|
Timer.start("swapBuffers");
|
|
Timer.start("swapBuffers");
|
|
SwapBuffers();
|
|
SwapBuffers();
|
|
Timer.stop("swapBuffers");
|
|
Timer.stop("swapBuffers");
|