X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaUI%2FState.fs;h=96dfc2459465ddfe373b6d064cab4c2492d54160;hb=c4a76a01f62568c6353396ff85551a3151fc5236;hp=5b89810591e6cb93b5072cbdec609bd411df7616;hpb=4bfa3cbdc6145e6944f02e24829ab2ef3a851ac1;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaUI/State.fs b/Parasitemia/ParasitemiaUI/State.fs index 5b89810..96dfc24 100644 --- a/Parasitemia/ParasitemiaUI/State.fs +++ b/Parasitemia/ParasitemiaUI/State.fs @@ -30,6 +30,25 @@ type State () = 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 -> @@ -56,18 +75,29 @@ type State () = /// /// Load the current state. 'FilePath' must have been defined. /// - /// If the file cannot be laoded + /// If the file cannot be loaded member this.Load () = let data = PiaZ.load this.FilePath this.PatientID <- data.patientID sourceImages.Clear() sourceImages.InsertRange(0, data.images) - if sourceImages.Count > 0 - then this.CurrentImage <- Some sourceImages.[0] + this.CurrentImage <- if sourceImages.Count > 0 then Some sourceImages.[0] else None alteredSinceLastSave <- false + /// + /// + /// If the image cannot be read member this.AddSourceImage (filePath: string) (defaultConfig: ParasitemiaCore.Config.Config) : SourceImage = - let srcImg = { num = sourceImages.Count + 1; config = defaultConfig.Copy(); dateLastAnalysis = DateTime(0L); rbcs = []; img = new Image(filePath) } + let srcImg = + { num = sourceImages.Count + 1 + name = System.IO.FileInfo(filePath).Name + config = defaultConfig.Copy() + dateLastAnalysis = DateTime(0L) + rbcs = [] + img = new Image(filePath) + healthyRBCBrightness = 1.f + infectedRBCBrightness = 1.f } + sourceImages.Add(srcImg) if sourceImages.Count = 1 then this.CurrentImage <- Some sourceImages.[0] @@ -89,6 +119,12 @@ type State () = // Re-numbered the images. 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 + alteredSinceLastSave <- true + member this.SetResult (imgNum: int) (cells: ParasitemiaCore.Types.Cell list) = let sourceImage = sourceImages.Find(fun srcImg -> srcImg.num = imgNum)