using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows; using bbiwarg.Input.InputProviding; using bbiwarg.Input.InputHandling; using bbiwarg.Utility; using Emgu.CV.UI; namespace bbiwarg.Output.DebugOutput { public partial class DebugWindow : Form { private InputHandler inputHandler; private InputProvider inputProvider; private DebugImageCreator debugImageCreator; private System.Windows.Forms.Timer timer; private int currentFrameID; private bool guiUpToDate; public DebugWindow(InputProvider 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; timer = new System.Windows.Forms.Timer(); timer.Interval = updateInterval; timer.Tick += update; timer.Start(); } protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); inputProvider.stop(); } 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"); } private void updateImages(FrameData frameData) { guiUpToDate = false; int numRows = palmGridNumRowsTrackBar.Value; int numColumns = palmGridNumColumnsTrackBar.Value; debugImageCreator.updateImages(frameData, numRows, numColumns); } 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; } private void playPauseButton_Click(object sender, EventArgs e) { handlePlayPause(); } private void nextFrameButton_Click(object sender, EventArgs e) { handleGoToNextFrame(); } private void previousFrameButton_Click(object sender, EventArgs e) { handleGoToPreviousFrame(); } 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; } } private void handleGoToNextFrame() { VideoInputProvider videoInputProvider = inputProvider as VideoInputProvider; videoInputProvider.goToNextFrame(); } private void handleGoToPreviousFrame() { VideoInputProvider videoInputProvider = inputProvider as VideoInputProvider; videoInputProvider.goToPreviousFrame(); } private void palmGridTrackBar_Scroll(object sender, EventArgs e) { currentFrameID = -1; update(sender, e); } } }