Use two radius in the configuration, one computed with the image resolution and one...
[master-thesis.git] / Parasitemia / Parasitemia / GUI / State.fs
index 44ca21b..45272ca 100644 (file)
@@ -45,7 +45,7 @@ type State () =
             rbc.setManually <- not rbc.setManually
 
     member this.Save () =
-        let data = { PiaZ.sources = List.ofSeq sourceImages; PiaZ.patientID = this.PatientID }
+        let data = { PiaZ.FileData.patientID = this.PatientID; PiaZ.FileData.images = List.ofSeq sourceImages }
         PiaZ.save this.FilePath data
         alteredSinceLastSave <- false
 
@@ -53,13 +53,13 @@ type State () =
         let data = PiaZ.load this.FilePath
         this.PatientID <- data.patientID
         sourceImages.Clear()
-        sourceImages.InsertRange(0, data.sources)
+        sourceImages.InsertRange(0, data.images)
         if sourceImages.Count > 0
         then this.CurrentImage <- Some sourceImages.[0]
         alteredSinceLastSave <- false
 
-    member this.AddSourceImage (filePath: string) : SourceImage =
-        let srcImg = { num = sourceImages.Count + 1; rbcRadius = 0.; dateLastAnalysis = DateTime(0L); rbcs = []; img = new Image<Bgr, byte>(filePath) }
+    member this.AddSourceImage (filePath: string) (defaultConfig: Config.Config) : SourceImage =
+        let srcImg = { num = sourceImages.Count + 1; config = defaultConfig.Copy(); dateLastAnalysis = DateTime(0L); rbcs = []; img = new Image<Bgr, byte>(filePath) }
         sourceImages.Add(srcImg)
         if sourceImages.Count = 1
         then this.CurrentImage <- Some sourceImages.[0]
@@ -81,18 +81,17 @@ type State () =
         // Re-numbered the images.
         sourceImages |> Seq.iteri (fun i srcImg -> srcImg.num <- i + 1)
 
-    member this.SetResult (imgNum: int) (rbcRadius: float) (cells: Cell list) =
+    member this.SetResult (imgNum: int) (cells: Cell list) =
         let sourceImage = sourceImages.Find(fun srcImg -> srcImg.num = imgNum)
 
         let w = sourceImage.img.Width
         let h = sourceImage.img.Height
 
-        sourceImage.rbcRadius <- rbcRadius
         sourceImage.dateLastAnalysis <- DateTime.UtcNow
 
         // To match with previously manually altered RBC.
         let manuallyAlteredPreviousRBCS = sourceImage.rbcs |> List.filter (fun rbc -> rbc.setManually)
-        let tolerance = rbcRadius * 0.5 // +/-.
+        let tolerance = (float sourceImage.config.RBCRadius.Pixel) * 0.5 // +/-.
         let getPreviousRBC (center: Point) : RBC option =
             manuallyAlteredPreviousRBCS |> List.tryFind (fun rbc -> rbc.center.X > center.X - tolerance && rbc.center.X < center.X + tolerance &&
                                                                     rbc.center.Y > center.Y - tolerance && rbc.center.Y < center.Y + tolerance)