private void MorphComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (morphComboBox.SelectedIndex > 0 && morphComboBox.SelectedIndex < morphDict.Count) { toBeDeleted = morphDict[(string)(morphComboBox.SelectedValue)]; } }
private void newMorph(Morph mrph) { Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; morpher.Mrph = mrph; morpher.SrcLines = srcViewer.ControlLines; morpher.DestLines = destViewer.ControlLines; morpher.setSrc((BitmapSource)srcViewer.ImageSrc); morpher.setDest((BitmapSource)destViewer.ImageSrc); morpher.startThreads(); save(); morphViewer.updateMorphs(); Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow; }
private void OpenProject_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; Stream openFileStream = File.OpenRead(openFileDialog.FileName); srcViewer.image.Source = null; destViewer.image.Source = null; BinaryFormatter deserializer = new BinaryFormatter(); //must be temporarily set to 0 to ensure it's lower than saved tolerance due to sorted dictionary ControlPoint.TOLERANCE = 0; ProjectPersistence loaded = (ProjectPersistence)deserializer.Deserialize(openFileStream); loadSettings(loaded); morphViewer.morphDict.Clear(); if (loaded.MorphNames.Count > 0) { foreach (string key in loaded.MorphNames.Keys) { Morph morph = new Morph(); morph.Frames = new List <BitmapSource>(); for (int j = 0; j < loaded.MorphNames[key]; j++) { BitmapSource bms = Morpher.LoadImage(loaded.ProjectPath + loaded.ProjectName + "\\" + key + "_" + j + ".png"); morph.Frames.Add(bms); } morph.MorphName = key; morphViewer.morphDict.Add(key, morph); modeItem.IsEnabled = true; } } Morpher.PROJECT_NAME = loaded.ProjectName; Morpher.PROJECT_PATH = loaded.ProjectPath; srcViewer.loadProject(loaded.SrcControlLines, loaded.SrcControlDict, loaded.SrcImageFilename); destViewer.loadProject(loaded.DestControlLines, loaded.DestControlDict, loaded.DestImageFilename); openFileStream.Close(); morphViewer.Src = srcViewer.ImageSrc; morphViewer.Dest = destViewer.ImageSrc; morphViewer.updateMorphs(); manageItem.IsEnabled = true; morphItem.IsEnabled = true; modeItem.IsEnabled = true; setsrcItem.IsEnabled = true; setdestItem.IsEnabled = true; Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow; } }
private void NewMorph_Click(object sender, RoutedEventArgs e) { if (srcViewer.image == null || destViewer.image == null || srcViewer.ControlLines.Count == 0) { MessageBoxResult mbr = MessageBox.Show("You can't create a morph unless both source" + "and destination images are set and there is at least one control line pair drawn", "", MessageBoxButton.OK, MessageBoxImage.Stop); } else { NewDialog newMorphDialog = new NewDialog(); string morphName = ""; newMorphDialog.OkEvent += (snd, args) => { morphName = newMorphDialog.box.Text; newMorphDialog.DialogResult = true; newMorphDialog.Close(); }; if (newMorphDialog.ShowDialog() == true) { if (!(bool)settings.performSettings.benchmarkBox.IsChecked) { Morph morph = new Morph(); morphViewer.morphDict.Add(morphName, morph); morph.MorphName = morphName; newMorph(morph); modeItem.IsEnabled = true; MessageBoxResult mbr = MessageBox.Show("Morph Ready!", "", MessageBoxButton.OK, MessageBoxImage.Information); } else { Dictionary <string, TimeSpan> times = new Dictionary <string, TimeSpan>(); Stopwatch sw = new Stopwatch(); string[] benchMarkKeys = new string[16] { "1 Thread", "2 Threads", "3 Threads", "4 Threads", "5 Threads", "6 Threads", "7 Threads", "8 Threads", "1 Thread with SSE", "2 Threads with SSE", "3 Threads with SSE", "4 Threads with SSE", "5 Threads with SSE", "6 Threads with SSE", "7 Threads with SSE", "8 Threads with SSE" }; Morph morph = new Morph(); morphViewer.morphDict.Add(morphName, morph); morph.MorphName = morphName; if ((bool)settings.performSettings.thread1Box.IsChecked) { Morpher.NumThreads = 1; Morpher.SSE = false; sw.Start(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[0], sw.Elapsed); morph.MorphName = "BenchMark"; } if ((bool)settings.performSettings.thread2Box.IsChecked) { Morpher.NumThreads = 2; Morpher.SSE = false; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[1], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread3Box.IsChecked) { Morpher.NumThreads = 3; Morpher.SSE = false; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[2], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread4Box.IsChecked) { Morpher.NumThreads = 4; Morpher.SSE = false; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[3], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread5Box.IsChecked) { Morpher.NumThreads = 5; Morpher.SSE = false; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[4], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread6Box.IsChecked) { Morpher.NumThreads = 6; Morpher.SSE = false; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[5], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread7Box.IsChecked) { Morpher.NumThreads = 7; Morpher.SSE = false; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[6], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread8Box.IsChecked) { Morpher.NumThreads = 8; Morpher.SSE = false; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[7], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread1BoxSSE.IsChecked) { Morpher.NumThreads = 1; Morpher.SSE = true; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[8], sw.Elapsed); morph.MorphName = "BenchMark"; } if ((bool)settings.performSettings.thread2BoxSSE.IsChecked) { Morpher.NumThreads = 2; Morpher.SSE = true; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[9], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread3BoxSSE.IsChecked) { Morpher.NumThreads = 3; Morpher.SSE = true; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[10], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread4BoxSSE.IsChecked) { Morpher.NumThreads = 4; Morpher.SSE = true; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[11], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread5BoxSSE.IsChecked) { Morpher.NumThreads = 5; Morpher.SSE = true; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[12], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread6BoxSSE.IsChecked) { Morpher.NumThreads = 6; Morpher.SSE = true; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[13], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread7BoxSSE.IsChecked) { Morpher.NumThreads = 7; Morpher.SSE = true; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[14], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } if ((bool)settings.performSettings.thread8BoxSSE.IsChecked) { Morpher.NumThreads = 8; Morpher.SSE = true; sw.Restart(); newMorph(morph); sw.Stop(); times.Add(benchMarkKeys[15], sw.Elapsed); for (int i = 0; i < morph.Frames.Count; i++) { File.Delete(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME + "\\" + morph.MorphName + "_" + i + ".png"); } } MessageBoxResult mbr = MessageBox.Show("Morph Ready!", "", MessageBoxButton.OK, MessageBoxImage.Information); foreach (string key in times.Keys) { double ratio = (double)times[benchMarkKeys[0]].Ticks / (double)times[key].Ticks; MessageBoxResult mbr2 = MessageBox.Show(key + " / 1 Thread: " + ratio, "", MessageBoxButton.OK, MessageBoxImage.Information); } } } } }