123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- using BBIWARG.Input.InputHandling;
- using BBIWARG.Input.InputProviding;
- using System;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace BBIWARG.Output.DebugOutput
- {
- /// <summary>
- /// A Windows Form which shows the debug images.
- /// </summary>
- public partial class DebugWindow : Form
- {
- /// <summary>
- /// id of the current frame
- /// </summary>
- private int currentFrameID;
- private API.Grid grid;
- /// <summary>
- /// the debug image creator
- /// </summary>
- private DebugImageCreator debugImageCreator;
- /// <summary>
- /// true iff the window is showing the latest data
- /// </summary>
- private bool guiUpToDate;
- /// <summary>
- /// the input handler
- /// </summary>
- private InputHandler inputHandler;
- /// <summary>
- /// the input provider
- /// </summary>
- private IInputProvider inputProvider;
- /// <summary>
- /// timer to periodically update the window
- /// </summary>
- private System.Windows.Forms.Timer timer;
- /// <summary>
- /// Creates the DebugWindow.
- /// </summary>
- /// <param name="inputProvider">input provider</param>
- /// <param name="inputHandler">input handle</param>
- /// <param name="name">the title of the window</param>
- /// <param name="updateInterval">the update interval for the window in milliseconds</param>
- public DebugWindow(IInputProvider inputProvider, InputHandler inputHandler, String name, int updateInterval)
- {
- InitializeComponent();
- this.inputProvider = inputProvider;
- this.inputHandler = inputHandler;
- guiUpToDate = false;
- Name = name;
- Text = name;
- TouchEventVisualizer touchEventVisualizer = new TouchEventVisualizer();
- inputHandler.NewProcessedFrameEvent += touchEventVisualizer.handleNewFrameData;
- debugImageCreator = new DebugImageCreator(touchEventVisualizer);
- if (inputProvider is VideoInputProvider)
- playPauseButton.Enabled = true;
- palmGridNumRowsTrackBar.Value = Parameters.PalmGridDefaultNumRows;
- palmGridNumColumnsTrackBar.Value = Parameters.PalmGridDefaultNumColumns;
- grid = API.Grid.getInctance();
- grid.Cols = Parameters.PalmGridDefaultNumColumns;
- grid.Rows = Parameters.PalmGridDefaultNumRows;
- timer = new System.Windows.Forms.Timer();
- timer.Interval = updateInterval;
- timer.Tick += update;
- timer.Start();
- }
- /// <summary>
- /// Stops the input provider when closing the window.
- /// </summary>
- /// <param name="e">event arguments</param>
- protected override void OnClosing(CancelEventArgs e)
- {
- base.OnClosing(e);
- inputProvider.stop();
- }
- /// <summary>
- /// Jumps to the next movie frame.
- /// </summary>
- private void handleGoToNextFrame()
- {
- VideoInputProvider videoInputProvider = inputProvider as VideoInputProvider;
- videoInputProvider.goToNextFrame();
- }
- /// <summary>
- /// Jumps to the previous movie frame.
- /// </summary>
- private void handleGoToPreviousFrame()
- {
- VideoInputProvider videoInputProvider = inputProvider as VideoInputProvider;
- videoInputProvider.goToPreviousFrame();
- }
- /// <summary>
- /// Toggles the paused state of the movie.
- /// </summary>
- private void handlePlayPause()
- {
- VideoInputProvider videoInputProvider = inputProvider as VideoInputProvider;
- if (videoInputProvider.IsPaused)
- {
- videoInputProvider.play();
- playPauseButton.Text = "Pause";
- nextFrameButton.Enabled = false;
- previousFrameButton.Enabled = false;
- }
- else
- {
- videoInputProvider.pause();
- playPauseButton.Text = "Play";
- nextFrameButton.Enabled = true;
- previousFrameButton.Enabled = true;
- }
- }
- /// <summary>
- /// Handles the click on the next frame button.
- /// </summary>
- /// <param name="sender">event sender</param>
- /// <param name="e">event arguments</param>
- private void nextFrameButton_Click(object sender, EventArgs e)
- {
- handleGoToNextFrame();
- }
- /// <summary>
- /// Updates the window when the number of rows or columns in the palm grid are changed.
- /// </summary>
- /// <param name="sender">event sender</param>
- /// <param name="e">event arguments</param>
- private void palmGridTrackBar_Scroll(object sender, EventArgs e)
- {
- currentFrameID = -1;
- update(sender, e);
- }
- /// <summary>
- /// Handles the click on the play / pause button.
- /// </summary>
- /// <param name="sender">event sender</param>
- /// <param name="e">event arguments</param>
- private void playPauseButton_Click(object sender, EventArgs e)
- {
- handlePlayPause();
- }
- /// <summary>
- /// Handles the click on the previous frame button.
- /// </summary>
- /// <param name="sender">event sender</param>
- /// <param name="e">event arguments</param>
- private void previousFrameButton_Click(object sender, EventArgs e)
- {
- handleGoToPreviousFrame();
- }
- /// <summary>
- /// Updates the window.
- /// </summary>
- /// <param name="sender">the event sender</param>
- /// <param name="e">the event arguments</param>
- private void update(object sender, EventArgs e)
- {
- Utility.Timer.start("DebugWindow.update");
- if (!inputProvider.IsActive)
- Close();
- FrameData frameData = inputHandler.FrameData;
- if (frameData != null)
- {
- lock (frameData)
- {
- if (currentFrameID != frameData.FrameID)
- {
- currentFrameID = frameData.FrameID;
- Utility.Timer.start("DebugWindow.update::updateImages");
- updateImages(frameData);
- Utility.Timer.stop("DebugWindow.update::updateImages");
- }
- }
- }
- if (!guiUpToDate)
- {
- Utility.Timer.start("DebugWindow.update::updateGUI");
- updateGUI();
- Utility.Timer.stop("DebugWindow.update::updateGUI");
- }
- Utility.Timer.stop("DebugWindow.update");
- }
- /// <summary>
- /// Updates the GUI elements.
- /// </summary>
- private void updateGUI()
- {
- // update image boxes
- depthImageBox.Image = debugImageCreator.DepthImage;
- fingerImageBox.Image = debugImageCreator.FingerImage;
- handImageBox.Image = debugImageCreator.HandImage;
- palmImageBox.Image = debugImageCreator.PalmImage;
- touchImageBox.Image = debugImageCreator.TouchImage;
- // update frame label
- frameLabel.Text = "Frame: " + currentFrameID;
- guiUpToDate = true;
- }
- /// <summary>
- /// Updates the debug images.
- /// </summary>
- /// <param name="frameData">data for the new frame</param>
- private void updateImages(FrameData frameData)
- {
- guiUpToDate = false;
- int numRows = palmGridNumRowsTrackBar.Value;
- int numColumns = palmGridNumColumnsTrackBar.Value;
- debugImageCreator.updateImages(frameData, numRows, numColumns);
- }
- }
- }
|