From 6065a36a144091b40ea4bc93c15333482c5f5b5f Mon Sep 17 00:00:00 2001 From: Jeffrey Markowitz Date: Wed, 4 Oct 2017 14:09:27 -0400 Subject: [PATCH] Added compression checkbox --- kinect2_nidaq/MainWindow.xaml | 6 +- kinect2_nidaq/MainWindow.xaml.cs | 72 +++++++++++++++---- .../Properties/Resources.Designer.cs | 42 +++++------ kinect2_nidaq/Properties/Settings.Designer.cs | 2 +- kinect2_nidaq/kinect2_nidaq.csproj | 2 +- 5 files changed, 81 insertions(+), 43 deletions(-) diff --git a/kinect2_nidaq/MainWindow.xaml b/kinect2_nidaq/MainWindow.xaml index 888a67a..978df75 100644 --- a/kinect2_nidaq/MainWindow.xaml +++ b/kinect2_nidaq/MainWindow.xaml @@ -93,7 +93,7 @@ - + @@ -119,6 +119,7 @@ + @@ -126,6 +127,9 @@ + + + diff --git a/kinect2_nidaq/MainWindow.xaml.cs b/kinect2_nidaq/MainWindow.xaml.cs index d4d5ab2..b6f25ee 100644 --- a/kinect2_nidaq/MainWindow.xaml.cs +++ b/kinect2_nidaq/MainWindow.xaml.cs @@ -187,6 +187,7 @@ public partial class MainWindow : Window private bool IsRecordingEnabled = false; private bool IsColorStreamEnabled = false; private bool IsDepthStreamEnabled = false; + private bool IsCompressionEnabled = false; private bool IsDataCompressed = false; private bool IsSessionClean = false; private bool IsNidaqEnabled = false; @@ -220,9 +221,10 @@ public partial class MainWindow : Window /// - /// Save folder + /// Save folder for tmp data and variable for directory to move files to if we are not compressing the data /// private String SaveFolder; + private String MoveFolder; /// /// All of the files! @@ -368,7 +370,7 @@ private void StartButton_Click(object sender, RoutedEventArgs e) ColorFramesDropped = 0; DepthFramesDropped = 0; - + // if the user checked previewmode, don't record any data if (PreviewMode.IsChecked == true) @@ -382,6 +384,13 @@ private void StartButton_Click(object sender, RoutedEventArgs e) IsPreviewEnabled = false; } + if (!IsCompressionEnabled && IsRecordingEnabled) + { + Directory.CreateDirectory(MoveFolder); + Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(MoveFolder)); + } + + // Only create new files if we're not in preview mode @@ -689,10 +698,24 @@ private void SessionCleanup() // If we were recording and the data isn't compressed, compress it! - if (!IsDataCompressed && IsRecordingEnabled) + if (!IsDataCompressed && IsRecordingEnabled && IsCompressionEnabled) { CompressTask = System.Threading.Tasks.Task.Factory.StartNew(CompressSession, fCancellationTokenSource.Token); } + else if (!IsDataCompressed && IsRecordingEnabled && !IsCompressionEnabled) + { + foreach (string[] FileName in FilePaths) + { + Console.WriteLine(String.Format("{0} {1}", FileName[0], FileName[1])); + + if (File.Exists(FileName[0])) + { + Console.WriteLine(String.Format("Moving {0} to {1}", FileName[0], Path.Combine(MoveFolder,FileName[1]))); + File.Move(FileName[0], Path.Combine(MoveFolder, FileName[1])); + } + } + IsSessionClean = true; + } else if (!IsDataCompressed) { IsSessionClean = true; @@ -1226,13 +1249,15 @@ private void SettingsChanged() SaveFolder = FolderName.Text; double tmp = 0; bool TimeFlag = true; + IsCompressionEnabled = CompressionMode.IsChecked == true; + CompressionMode.IsEnabled = true; // if preview is checked, then we're previewing depth and color // else if notimer is selected, disable time related options // else if recording time box is specified correctly, then convert recording time to minutes // else everything enabled - + // how do the nidaq options look? // disable the nidaq stuff if there's no nidaq device @@ -1270,6 +1295,7 @@ private void SettingsChanged() CheckNoTimer.IsChecked = false; CheckNoTimer.IsEnabled = false; RecordingTimeBox.IsEnabled = false; + CompressionMode.IsEnabled = false; } else if (CheckNoTimer.IsChecked == true) { @@ -1310,15 +1336,17 @@ private void SettingsChanged() // Temporary directory is defined here //string BasePath = Path.GetTempPath(); - string BasePath = SaveFolder; + // string BasePath = SaveFolder; string now = DateTime.Now.ToString("yyyyMMddHHmmss"); - FilePath_ColorTs = Path.Combine(BasePath, String.Format("rgb_ts_{0}.txt", now)); - FilePath_ColorVid = Path.Combine(BasePath, String.Format("rgb_{0}.mp4", now)); - FilePath_DepthTs = Path.Combine(BasePath, String.Format("depth_ts_{0}.txt", now)); - FilePath_DepthVid = Path.Combine(BasePath, String.Format("depth_{0}.dat", now)); - FilePath_Nidaq = Path.Combine(BasePath, String.Format("nidaq_{0}.dat", now)); - FilePath_Metadata = Path.Combine(BasePath, String.Format("metadata_{0}.json", now)); + MoveFolder = Path.Combine(SaveFolder,String.Format("session_{0}", now)); + + FilePath_ColorTs = Path.Combine(SaveFolder, String.Format("rgb_ts_{0}.txt", now)); + FilePath_ColorVid = Path.Combine(SaveFolder, String.Format("rgb_{0}.mp4", now)); + FilePath_DepthTs = Path.Combine(SaveFolder, String.Format("depth_ts_{0}.txt", now)); + FilePath_DepthVid = Path.Combine(SaveFolder, String.Format("depth_{0}.dat", now)); + FilePath_Nidaq = Path.Combine(SaveFolder, String.Format("nidaq_{0}.dat", now)); + FilePath_Metadata = Path.Combine(SaveFolder, String.Format("metadata_{0}.json", now)); // Paths for the tarball and metadata @@ -1338,7 +1366,8 @@ private void SettingsChanged() // if any of the files overwrite old data or cannot be created, NO GO if (FilePaths.All(p => !File.Exists(p[0])) && !File.Exists(FilePath_Tar) && Directory.Exists(SaveFolder) - && (CheckColorStream.IsChecked==true || CheckDepthStream.IsChecked==true || CheckNidaqStream.IsChecked==true)) + && (CheckColorStream.IsChecked==true || CheckDepthStream.IsChecked==true || CheckNidaqStream.IsChecked==true) + && (IsCompressionEnabled==true || (IsCompressionEnabled==false && !Directory.Exists(MoveFolder)))) { //NidaqPrepare.IsEnabled = true; StartButton.IsEnabled = true; @@ -1626,6 +1655,7 @@ private void InactivateSettings() RecordingTimeBox.IsEnabled = false; RecordingTimeText.IsEnabled = false; PreviewMode.IsEnabled = false; + CompressionMode.IsEnabled = false; } private void ActivateSettings() @@ -1646,6 +1676,7 @@ private void ActivateSettings() RecordingTimeBox.IsEnabled = true; RecordingTimeText.IsEnabled = true; PreviewMode.IsEnabled = true; + CompressionMode.IsEnabled = true; } private void PreviewMode_Checked(object sender, RoutedEventArgs e) @@ -1681,18 +1712,29 @@ private void DepthBox_TextChanged(object sender, RoutedEventArgs e) private void FlipDepth_Checked(object sender, RoutedEventArgs e) { - System.Windows.Media.RotateTransform rotateTransform = new System.Windows.Media.RotateTransform(180); + System.Windows.Media.ScaleTransform rotateTransform = new System.Windows.Media.ScaleTransform(); + rotateTransform.ScaleX = -1; DepthDisplay.RenderTransform = rotateTransform; ColorDisplay.RenderTransform = rotateTransform; } private void FlipDepth_Unchecked(object sender, RoutedEventArgs e) { - System.Windows.Media.RotateTransform rotateTransform = new System.Windows.Media.RotateTransform(0); + System.Windows.Media.ScaleTransform rotateTransform = new System.Windows.Media.ScaleTransform(); + rotateTransform.ScaleX = 1; DepthDisplay.RenderTransform = rotateTransform; ColorDisplay.RenderTransform = rotateTransform; } - + + private void CompressionMode_Unchecked(object sender, RoutedEventArgs e) + { + SettingsChanged(); + } + + private void CompressionMode_Checked(object sender, RoutedEventArgs e) + { + SettingsChanged(); + } } } \ No newline at end of file diff --git a/kinect2_nidaq/Properties/Resources.Designer.cs b/kinect2_nidaq/Properties/Resources.Designer.cs index ac73882..b634e10 100644 --- a/kinect2_nidaq/Properties/Resources.Designer.cs +++ b/kinect2_nidaq/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace kinect2_nidaq.Properties -{ - - +namespace kinect2_nidaq.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -22,48 +22,40 @@ namespace kinect2_nidaq.Properties [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("kinect2_nidaq.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } diff --git a/kinect2_nidaq/Properties/Settings.Designer.cs b/kinect2_nidaq/Properties/Settings.Designer.cs index e145e34..29be45a 100644 --- a/kinect2_nidaq/Properties/Settings.Designer.cs +++ b/kinect2_nidaq/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace kinect2_nidaq.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/kinect2_nidaq/kinect2_nidaq.csproj b/kinect2_nidaq/kinect2_nidaq.csproj index 0471e37..04a9c57 100644 --- a/kinect2_nidaq/kinect2_nidaq.csproj +++ b/kinect2_nidaq/kinect2_nidaq.csproj @@ -100,7 +100,7 @@ true - true + false