Frame width depends now from the RBC sizes #275
[master-thesis.git] / Parasitemia / ParasitemiaUI / State.fs
index 3355a42..129e6a6 100644 (file)
@@ -25,36 +25,11 @@ type State (defaultConfig : ParasitemiaCore.Config.Config) =
                 alteredSinceLastSave <- true
                 patientID <- id
 
-    member this.ImageParasitemia (srcImg : SourceImage) : int * int =
-        List.length srcImg.rbcs,
-        srcImg.rbcs |> List.fold (fun nbInfected rbc -> if rbc.infected then nbInfected + 1 else nbInfected) 0
-
-    member this.ImageNbManuallyChangedRBC (srcImg : SourceImage) (setAsInfected : bool) : int * int =
-        List.length srcImg.rbcs,
-        srcImg.rbcs |> List.fold (fun nb rbc -> if rbc.setManually && rbc.infected = setAsInfected then nb + 1 else nb) 0
-
-    member this.ImageNbManuallyChangedRBCStr (srcImg : SourceImage) (setAsInfected : bool) : string =
-        Utils.percentText (this.ImageNbManuallyChangedRBC srcImg setAsInfected)
-
-    member this.ImageManuallyChangedRBC (srcImg : SourceImage) (setAsInfected : bool) : int seq =
-        query {
-            for rbc in srcImg.rbcs do
-            where (rbc.setManually && rbc.infected = setAsInfected)
-            select rbc.num
-        }
-
-    member this.ImageManuallyChangedRBCStr (srcImg : SourceImage) (setAsInfected : bool) : string =
-        let listStr = Utils.listAsStr <| this.ImageManuallyChangedRBC srcImg setAsInfected
-        if listStr = "" then
-            ""
-        else
-            "[" + listStr + "]"
-
     member this.GlobalParasitemia : int * int =
         sourceImages
         |> Seq.fold (
             fun (nbTotal, nbTotalInfected) srcImg ->
-                let nb, nbInfected = this.ImageParasitemia srcImg
+                let nb, nbInfected = srcImg.ImageParasitemia
                 nbTotal + nb, nbTotalInfected + nbInfected
         ) (0, 0)
 
@@ -89,18 +64,7 @@ type State (defaultConfig : ParasitemiaCore.Config.Config) =
     /// </summary>
     /// <exception cref="System.IOException">If the image cannot be read</exception>
     member this.AddSourceImage (filePath : string) (defaultConfig : ParasitemiaCore.Config.Config) : SourceImage =
-        let srcImg =
-            {
-                num = sourceImages.Count + 1
-                name = System.IO.FileInfo(filePath).Name
-                config = defaultConfig.Copy ()
-                dateLastAnalysis = DateTime (0L)
-                rbcs = []
-                img = new Image<Bgr, byte> (filePath)
-                healthyRBCBrightness = 1.f
-                infectedRBCBrightness = 1.f
-            }
-
+        let srcImg = SourceImage (sourceImages.Count + 1, System.IO.FileInfo(filePath).Name, defaultConfig.Copy (), DateTime (0L), new Image<Bgr, byte> (filePath), [])
         sourceImages.Add srcImg
         if sourceImages.Count = 1 then
             this.CurrentImage <- Some sourceImages.[0]
@@ -118,24 +82,24 @@ type State (defaultConfig : ParasitemiaCore.Config.Config) =
             if isCurrent then
                 this.CurrentImage <- if sourceImages.Count > 0 then Some sourceImages.[0] else None
         // Re-numbered the images.
-        sourceImages |> Seq.iteri (fun i srcImg -> srcImg.num <- i + 1)
+        sourceImages |> Seq.iteri (fun i srcImg -> srcImg.Num <- i + 1)
 
     member this.SetName (srcImg : SourceImage) (name : string) =
-        if name <> srcImg.name then
-            srcImg.name <- name
+        if name <> srcImg.Name then
+            srcImg.Name <- name
             alteredSinceLastSave <- true
 
-    member this.SetResult (imgNum : int) (cells : ParasitemiaCore.Types.Cell list) =
-        let sourceImage = sourceImages.Find (fun srcImg -> srcImg.num = imgNum)
+    member this.SetResult (imgNum : int) (result : ParasitemiaCore.Types.AnalysisResult) =
+        let sourceImage = sourceImages.Find (fun srcImg -> srcImg.Num = imgNum)
 
-        let w = sourceImage.img.Width
-        let h = sourceImage.img.Height
+        let w = sourceImage.Img.Width
+        let h = sourceImage.Img.Height
 
-        sourceImage.dateLastAnalysis <- DateTime.UtcNow
+        sourceImage.DateLastAnalysis <- DateTime.UtcNow
 
         // To match with previously manually altered RBC.
-        let manuallyAlteredPreviousRBCS = sourceImage.rbcs |> List.filter (fun rbc -> rbc.setManually)
-        let tolerance = (float sourceImage.config.RBCRadius.Pixel) * 0.5 // +/-.
+        let manuallyAlteredPreviousRBCS = sourceImage.RBCs |> List.filter (fun rbc -> rbc.setManually)
+        let tolerance = (float sourceImage.Config.RBCRadius.Pixel) * 0.5 // +/-.
         let getPreviousManuallyAlteredRBC (center : Point) : RBC option =
             manuallyAlteredPreviousRBCS
             |> List.tryFind (
@@ -146,8 +110,8 @@ type State (defaultConfig : ParasitemiaCore.Config.Config) =
                     rbc.center.Y < center.Y + tolerance
             )
 
-        sourceImage.rbcs <-
-            cells
+        sourceImage.RBCs <-
+            result.Cells
             |> List.filter (fun cell -> match cell.cellClass with ParasitemiaCore.Types.HealthyRBC | ParasitemiaCore.Types.InfectedRBC -> true | _ -> false )
             |> List.sortByDescending (fun cell -> cell.nucleusArea, (w - cell.center.X) + (h - cell.center.Y))
             |> List.mapi (