namespace ParasitemiaUI open System open System.Windows.Media open Emgu.CV open Emgu.CV.Structure open Types type SourceImage (num : int, name : string, config : ParasitemiaCore.Config.Config, dateLastAnalysis : DateTime, img : Image, rbcs : RBC list) = let mutable num = num let mutable name = name let mutable config = config let mutable dateLastAnalysis = dateLastAnalysis // UTC. let img = img let mutable rbcs = rbcs let mutable healthyRBCBrightness = 1.f let mutable infectedRBCBrightness = 1.f let mutable averageRBCSize = 1. let healthyRBColor = Color.FromRgb (255uy, 255uy, 0uy) // Yellow-green. let infectedRBColor = Color.FromRgb (255uy, 0uy, 40uy) // Red with a bit of blue. let updateAverageRBCSize () = if List.isEmpty rbcs |> not then averageRBCSize <- rbcs |> List.collect (fun rbc -> [ rbc.size.Width; rbc.size.Height ]) |> List.average do updateAverageRBCSize () member this.Num with get () = num and set value = num <- value member this.RomanNum = Utils.toRomanNumber this.Num member this.Name with get () = name and set value = name <- value member this.Config = config member this.DateLastAnalysis with get () = dateLastAnalysis and set value = dateLastAnalysis <- value member this.Img = img member this.RBCs with get () = rbcs and set value = rbcs <- value updateAverageRBCSize () member this.ImageParasitemia : int * int = List.length rbcs, rbcs |> List.fold (fun nbInfected rbc -> if rbc.infected then nbInfected + 1 else nbInfected) 0 member this.ImageNbManuallyChangedRBC (setAsInfected : bool) : int * int = List.length rbcs, rbcs |> List.fold (fun nb rbc -> if rbc.setManually && rbc.infected = setAsInfected then nb + 1 else nb) 0 member this.ImageNbManuallyChangedRBCStr (setAsInfected : bool) : string = Utils.percentText (this.ImageNbManuallyChangedRBC setAsInfected) member this.ImageManuallyChangedRBC (setAsInfected : bool) : int seq = query { for rbc in rbcs do where (rbc.setManually && rbc.infected = setAsInfected) select rbc.num } member this.ImageManuallyChangedRBCStr (setAsInfected : bool) : string = let listStr = Utils.listAsStr <| this.ImageManuallyChangedRBC setAsInfected if listStr = "" then "" else "[" + listStr + "]" member this.HealthyRBCBrightness with get () = healthyRBCBrightness and set value = healthyRBCBrightness <- value member this.InfectedRBCBrightness with get () = infectedRBCBrightness and set value = infectedRBCBrightness <- value member this.HealthyRBCColor : SolidColorBrush = let mutable color = healthyRBColor * healthyRBCBrightness color.A <- 255uy SolidColorBrush (color) member this.InfectedRBCColor : SolidColorBrush = let mutable color = infectedRBColor * infectedRBCBrightness color.A <- 255uy SolidColorBrush (color) member this.AverageRBCSize = averageRBCSize