Browse Source

Added comparison to loaded files

Martin Edlund 5 years ago
parent
commit
893bc3ace8

+ 1 - 1
SketchAssistant/SketchAssistantWPF/DebugData.cs

@@ -75,7 +75,7 @@ namespace SketchAssistantWPF
 
             for (int i = 0; i < len; i++)
             {
-                int opX = rnd.Next(0, 1); int opY = rnd.Next(0, 1);
+                int opX = rnd.Next(0, 2); int opY = rnd.Next(0, 1);
                 int changeX = rnd.Next(0, 50); int changeY = rnd.Next(0, 50);
                 if (opX == 0) prevX = prevX - changeX;
                 else prevX = prevX + changeX;

+ 1 - 1
SketchAssistant/SketchAssistantWPF/FileImporter.cs

@@ -43,7 +43,7 @@ namespace SketchAssistantWPF
         /// </summary>
         /// <param name="fileName">the path of the input file</param>
         /// <returns>the width and height of the left canvas and the parsed picture as a list of lines</returns>
-public Tuple<int, int, List<InternalLine>> ParseISADInputFile(String fileName)
+        public Tuple<int, int, List<InternalLine>> ParseISADInputFile(String fileName)
         {
             return ParseISADInput(System.IO.File.ReadAllLines(fileName));
         }

+ 2 - 1
SketchAssistant/SketchAssistantWPF/GeometryCalculator.cs

@@ -91,10 +91,11 @@ namespace SketchAssistantWPF
 
                     for (int i = 0; i < shortL.Count - 1; i++)
                     {
-                        if (i + 1 == shortL.Count || i + dif == longL.Count) break;
+                        if (i + 1 == shortL.Count) break;
                         for (int j = 0; j <= dif; j++)
                         {
                             var k = i + j;
+                            if (k + 1 == longL.Count) break;
                             Vector v0 = new Vector(shortL[i + 1].X - shortL[i].X, shortL[i + 1].Y - shortL[i].Y);
                             Vector v1 = new Vector(longL[k + 1].X - longL[k].X, longL[k + 1].Y - longL[k].Y);
                             sum += CosineSimilarity(v0, v1); adds++;

+ 14 - 0
SketchAssistant/SketchAssistantWPF/InternalLine.cs

@@ -66,6 +66,20 @@ namespace SketchAssistantWPF
             isTemporary = false;
         }
 
+        /// <summary>
+        /// A function to make temporary lines non-temporary.
+        /// </summary>
+        /// <param name="id">The id of the line.</param>
+        public void MakePermanent(int id)
+        {
+            if (isTemporary)
+            {
+                identifier = id;
+                CleanPoints();
+                isTemporary = false;
+            }
+        }
+
         public Point GetStartPoint()
         {
             return linePoints.First();

+ 1 - 5
SketchAssistant/SketchAssistantWPF/MVP_Model.cs

@@ -375,11 +375,7 @@ namespace SketchAssistantWPF
                     //TODO: For the person implementing overlay: Add check if overlay needs to be added
                     programPresenter.UpdateRightLines(rightLineList);
                     currentLine.Clear();
-                    //programPresenter.UpdateCurrentLine(currentLine);
-                    if(rightLineList.Count >= 2)
-                    {
-                        Console.WriteLine(GeometryCalculator.CalculateSimilarity(rightLineList[rightLineList.Count -1].Item2, rightLineList[rightLineList.Count -2].Item2));
-                    }
+                    //programPresenter.UpdateCurrentLine(currentLine)
                 }
             }
             else

+ 54 - 4
SketchAssistant/SketchAssistantWPF/MVP_Presenter.cs

@@ -34,6 +34,10 @@ namespace SketchAssistantWPF
 
         ImageDimension ImageSizeRight = new ImageDimension(0, 0);
 
+        List<double> ImageSimilarity = new List<double>();
+
+        List<InternalLine> LeftLines = new List<InternalLine>();
+
         /*******************/
         /*** ENUMERATORS ***/
         /*******************/
@@ -85,9 +89,10 @@ namespace SketchAssistantWPF
         /// <summary>
         /// Display a new FileDialog to load a collection of lines.
         /// </summary>
-        public void ExamplePictureToolStripMenuItemClick()
+        /// <returns>True if loading was a success</returns>
+        public bool ExamplePictureToolStripMenuItemClick()
         {
-            var okToContinue = true;
+            var okToContinue = true; bool returnval = false;
             if (programModel.HasUnsavedProgress())
             {
                 okToContinue = programView.ShowWarning("You have unsaved progress. Continue?");
@@ -101,6 +106,7 @@ namespace SketchAssistantWPF
                     try
                     {
                         Tuple<int, int, List<InternalLine>> values = fileImporter.ParseISADInputFile(fileNameTup.Item1);
+                        values.Item3.ForEach(line => line.MakePermanent(0)); //Make all lines permanent
                         programModel.SetLeftLineList(values.Item1, values.Item2, values.Item3);
 
                         programModel.ResetRightImage();
@@ -108,6 +114,7 @@ namespace SketchAssistantWPF
                         programModel.ChangeState(true);
                         programView.EnableTimer();
                         ClearRightLines();
+                        returnval = true;
                     }
                     catch (FileImporterException ex)
                     {
@@ -119,14 +126,16 @@ namespace SketchAssistantWPF
                     }
                 }
             }
+            return returnval;
         }
 
         /// <summary>
         /// Display a new FileDialog to a svg drawing.
         /// </summary>
-        public void SVGToolStripMenuItemClick()
+        /// <returns>True if loading was a success</returns>
+        public bool SVGToolStripMenuItemClick()
         {
-            var okToContinue = true;
+            var okToContinue = true; bool returnval = false;
             if (programModel.HasUnsavedProgress())
             {
                 okToContinue = programView.ShowWarning("You have unsaved progress. Continue?");
@@ -140,12 +149,14 @@ namespace SketchAssistantWPF
                     try
                     {
                         Tuple<int, int, List<InternalLine>> values = fileImporter.ParseSVGInputFile(fileNameTup.Item1, programModel.leftImageBoxWidth, programModel.leftImageBoxHeight);
+                        values.Item3.ForEach(line => line.MakePermanent(0)); //Make all lines permanent
                         programModel.SetLeftLineList(values.Item1, values.Item2, values.Item3);
                         programModel.ResetRightImage();
                         programModel.CanvasActivated();
                         programModel.ChangeState(true);
                         programView.EnableTimer();
                         ClearRightLines();
+                        returnval = true;
                     }
                     catch (FileImporterException ex)
                     {
@@ -157,6 +168,7 @@ namespace SketchAssistantWPF
                     }
                 }
             }
+            return returnval;
         }
 
         /// <summary>
@@ -278,6 +290,8 @@ namespace SketchAssistantWPF
         {
             programView.RemoveAllRightLines();
             rightPolyLines = new Dictionary<int, Shape>();
+            //Reset the similarity display
+            UpdateSimilarityScore(Double.NaN);
         }
 
         /// <summary>
@@ -307,6 +321,21 @@ namespace SketchAssistantWPF
                 }
                 SetVisibility(rightPolyLines[line.GetID()], status);
             }
+            //Calculate similarity scores, maybe change later to compare to the 
+            UpdateSimilarityScore(Double.NaN); var templist = lines.Where(tup => tup.Item1).ToList();
+            if(LeftLines.Count > 0)
+            {
+                for(int i = 0; i < LeftLines.Count; i++)
+                {
+                    if (templist.Count == i) break;
+                    UpdateSimilarityScore(GeometryCalculator.CalculateSimilarity(templist[i].Item2, LeftLines[i]));
+                }
+            }
+            else
+            {
+                for (int i = 0; i < templist.Count - 1; i++)
+                    UpdateSimilarityScore(GeometryCalculator.CalculateSimilarity(templist[i].Item2, templist[i + 1].Item2));
+            }
         }
 
         /*
@@ -337,6 +366,8 @@ namespace SketchAssistantWPF
             }
             programView.SetCanvasState("LeftCanvas", true);
             programView.SetCanvasState("RightCanvas", true);
+
+            LeftLines = lines;
         }
 
         /// <summary>
@@ -405,6 +436,25 @@ namespace SketchAssistantWPF
             return programView.IsMousePressed();
         }
 
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="score">Score will be reset if NaN is passed, 
+        /// will be ignored if the score is not between 0 and 1</param>
+        public void UpdateSimilarityScore(double score)
+        {
+            if (Double.IsNaN(score))
+            {
+                ImageSimilarity.Clear();
+                programView.SetImageSimilarityText("");
+            }
+            else
+            {
+                if (score >= 0 && score <= 1) ImageSimilarity.Add(score);
+                programView.SetImageSimilarityText((ImageSimilarity.Sum() / ImageSimilarity.Count).ToString());
+            }
+        }
+
         /*************************/
         /*** HELPING FUNCTIONS ***/
         /*************************/

+ 8 - 0
SketchAssistant/SketchAssistantWPF/MVP_View.cs

@@ -120,5 +120,13 @@ namespace SketchAssistantWPF
         /// </summary>
         /// <returns>The cursor Position</returns>
         Point GetCursorPosition();
+
+        /// <summary>
+        /// Sets the contents of the status bar label containing
+        /// the similarity score of the left and right image.
+        /// </summary>
+        /// <param name="message">The message to be set, 
+        /// will be set to the default value if left empty.</param>
+        void SetImageSimilarityText(string message);
     }
 }

+ 2 - 0
SketchAssistant/SketchAssistantWPF/MainWindow.xaml

@@ -190,6 +190,8 @@
                 <TextBox Name="LoadStatusBox" Text="nothing loaded" Background="LightGray"/>
                 <Separator/>
                 <TextBox Name="LastActionBox" Text="none" Background="LightGray"/>
+                <Separator/>
+                <TextBox Name="LineSimilarityBox" Text="-" Background="LightGray"/>
             </StatusBar>
         </DockPanel>
     </Grid>

+ 16 - 2
SketchAssistant/SketchAssistantWPF/MainWindow.xaml.cs

@@ -212,7 +212,8 @@ namespace SketchAssistantWPF
         /// </summary>
         private void ISADMenuItem_Click(object sender, RoutedEventArgs e)
         {
-            ProgramPresenter.ExamplePictureToolStripMenuItemClick();
+            if(ProgramPresenter.ExamplePictureToolStripMenuItemClick())
+                RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
         }
 
         /// <summary>
@@ -220,7 +221,8 @@ namespace SketchAssistantWPF
         /// </summary>
         private void SVGMenuItem_Click(object sender, RoutedEventArgs e)
         {
-            ProgramPresenter.SVGToolStripMenuItemClick();
+            if(ProgramPresenter.SVGToolStripMenuItemClick())
+                RightCanvas.EditingMode = InkCanvasEditingMode.Ink;
         }
 
         /*************************/
@@ -366,6 +368,18 @@ namespace SketchAssistantWPF
             LastActionBox.Text = message;
         }
 
+        /// <summary>
+        /// Sets the contents of the status bar label containing
+        /// the similarity score of the left and right image.
+        /// </summary>
+        /// <param name="message">The message to be set, 
+        /// will be set to the default value if left empty.</param>
+        public void SetImageSimilarityText(string message)
+        {
+            if (message.Count() > 0) LineSimilarityBox.Text = message;
+            else LineSimilarityBox.Text = "-";
+        }
+
         /// <summary>
         /// Changes the states of a tool strip button.
         /// </summary>

+ 1 - 1
SketchAssistant/WhiteTests/UITest.cs

@@ -20,7 +20,7 @@ using System.Threading.Tasks;
 
 namespace WhiteTests
 {
-    
+
     [TestClass]
     public class UITest
     {

+ 13 - 0
userstory8.md

@@ -0,0 +1,13 @@
+# Userstory 8
+
+|**ID**|8|
+|-|-|
+|**Name**|Vergleich vom gezeichneten Bild mit der Ursprungsgrafik|
+|**Beschreibung**|Ein Feature, das die vom Nutzer gezeichnete Grafik, mit der geladenen Grafik vergleicht.|
+|**Akzeptanzkriterium**|Eine Funktion bei der Ähnlichkeit der vom Nutzer gezeichneten Zeichnung und der geladenen Grafik in der UI angezeigt wird.|
+|Geschätzter Aufwand (Story Points)|10|
+|Entwickler|Martin Edlund|
+|Umgesetzt in Iteration|14|
+|Tatsächlicher Aufwand (Std.)|keine|
+|Velocity (Std./Story Point)|keine|
+|Bemerkungen|Keine|