Skip to content

Commit

Permalink
Added compression checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Markowitz committed Oct 4, 2017
1 parent 0b3f42f commit 6065a36
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 43 deletions.
6 changes: 5 additions & 1 deletion kinect2_nidaq/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<RowDefinition Height="*" />
<RowDefinition Height="40" />
<RowDefinition Height="*" />
<RowDefinition Height="40" />
<RowDefinition Height="60" />
<RowDefinition Height="40" />
<RowDefinition Height="*" />
<RowDefinition Height="10" />
Expand All @@ -119,13 +119,17 @@
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<CheckBox Name="CheckNoTimer" VerticalAlignment="Center" Click="CheckNoTimer_Checked" >
<TextBlock Text="Record until user clicks stop" VerticalAlignment="Center" />
</CheckBox>
<CheckBox VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" Name="PreviewMode" Checked="PreviewMode_Checked" Unchecked="PreviewMode_Unchecked">
<TextBlock Text="Preview Mode" />
</CheckBox>
<CheckBox VerticalAlignment="Center" Grid.Row="2" Grid.Column="0" Name="CompressionMode" Checked="CompressionMode_Checked" Unchecked="CompressionMode_Unchecked">
<TextBlock Text="Compress Session" />
</CheckBox>
<Grid Grid.Column="1" Grid.RowSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
Expand Down
72 changes: 57 additions & 15 deletions kinect2_nidaq/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -220,9 +221,10 @@ public partial class MainWindow : Window


/// <summary>
/// Save folder
/// Save folder for tmp data and variable for directory to move files to if we are not compressing the data
/// </summary>
private String SaveFolder;
private String MoveFolder;

/// <summary>
/// All of the files!
Expand Down Expand Up @@ -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)
Expand All @@ -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


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1270,6 +1295,7 @@ private void SettingsChanged()
CheckNoTimer.IsChecked = false;
CheckNoTimer.IsEnabled = false;
RecordingTimeBox.IsEnabled = false;
CompressionMode.IsEnabled = false;
}
else if (CheckNoTimer.IsChecked == true)
{
Expand Down Expand Up @@ -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

Expand All @@ -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;
Expand Down Expand Up @@ -1626,6 +1655,7 @@ private void InactivateSettings()
RecordingTimeBox.IsEnabled = false;
RecordingTimeText.IsEnabled = false;
PreviewMode.IsEnabled = false;
CompressionMode.IsEnabled = false;
}

private void ActivateSettings()
Expand All @@ -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)
Expand Down Expand Up @@ -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();
}
}

}
42 changes: 17 additions & 25 deletions kinect2_nidaq/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kinect2_nidaq/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kinect2_nidaq/kinect2_nidaq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="AForge">
Expand Down

0 comments on commit 6065a36

Please sign in to comment.