1
namespace ParasitemiaUI
5 open System.Windows.Media
13 | FromMemory of Image<Bgr, byte
>
14 | FromFile of string // This file will be stored in a temporary directory until the image is saved in a piaz file.
16 type SourceImage (num
: int, name
: string, originalName
: string, config
: ParasitemiaCore.Config.Config, dateLastAnalysis
: DateTime, imgData
: ImageData, rbcs
: RBC list
) =
18 let mutable name = name
19 let mutable config = config
20 let mutable dateLastAnalysis = dateLastAnalysis // UTC.
24 | FromFile path
-> new Image<Bgr, byte
> (path
)
26 let mutable tempFile : string option =
28 | FromMemory _
-> None
30 let tmpDirname = Guid.NewGuid ()
31 let filename = Path.GetFileName path
33 // Copy it to a temporary directory.
34 let tmpDir = Path.Combine (Path.GetTempPath (), string tmpDirname)
35 Directory.CreateDirectory tmpDir |> ignore
36 let tmpPath = Path.Combine (tmpDir, filename)
38 File.Copy (path, tmpPath)
42 let mutable rbcs = rbcs
43 let mutable healthyRBCBrightness = 1.f
44 let mutable infectedRBCBrightness = 1.f
46 let mutable averageRBCSize = 1.
48 let healthyRBColor = Color.FromRgb (255uy, 255uy, 0uy) // Yellow-green.
49 let infectedRBColor = Color.FromRgb (255uy, 0uy, 40uy) // Red with a bit of blue.
51 let updateAverageRBCSize () =
52 if List.isEmpty
rbcs |> not
then
55 |> List.collect
(fun rbc
-> [ rbc
.size
.Width; rbc
.size
.Height ])
59 updateAverageRBCSize ()
61 member this
.Num with get
() = num and set
value = num <- value
63 member this
.RomanNum = Utils.toRomanNumber this
.Num
65 member this
.Name with get
() = name and set
value = name <- value
67 member this
.OriginalName = originalName
69 member this
.Config = config
71 member this
.DateLastAnalysis with get
() = dateLastAnalysis and set
value = dateLastAnalysis <- value
76 with get
() = tempFile
77 and set
value = tempFile <- value // TODO: remove temp file if set to None
83 updateAverageRBCSize ()
85 member this
.ImageParasitemia : int * int =
87 rbcs |> List.fold
(fun nbInfected rbc
-> if rbc
.infected
then nbInfected
+ 1 else nbInfected) 0
89 member this
.ImageNbManuallyChangedRBC (setAsInfected
: bool) : int * int =
91 rbcs |> List.fold
(fun nb rbc
-> if rbc
.setManually
&& rbc
.infected
= setAsInfected
then nb
+ 1 else nb) 0
93 member this
.ImageNbManuallyChangedRBCStr (setAsInfected
: bool) : string =
94 Utils.percentText
(this
.ImageNbManuallyChangedRBC setAsInfected
)
96 member this
.ImageManuallyChangedRBC (setAsInfected
: bool) : int seq =
99 where
(rbc
.setManually
&& rbc
.infected
= setAsInfected
)
103 member this
.ImageManuallyChangedRBCStr (setAsInfected
: bool) : string =
104 let listStr = Utils.listAsStr
<| this.ImageManuallyChangedRBC setAsInfected
110 member this.HealthyRBCBrightness with get
() = healthyRBCBrightness and set
value = healthyRBCBrightness <- value
111 member this.InfectedRBCBrightness with get
() = infectedRBCBrightness and set
value = infectedRBCBrightness <- value
113 member this.HealthyRBCColor : SolidColorBrush =
114 let mutable color = healthyRBColor * healthyRBCBrightness
116 SolidColorBrush (color)
118 member this.InfectedRBCColor : SolidColorBrush =
119 let mutable color = infectedRBColor * infectedRBCBrightness
121 SolidColorBrush (color)
123 member this.AverageRBCSize = averageRBCSize