44de2e335f3f2245f077dbda2e3d3cdcd0995bb9
1
module Parasitemia.GUI.State
3 open System.Collections.Generic
12 let sourceImages = List<SourceImage>()
14 member val CurrentImage: SourceImage option = None with get
, set
15 member val FilePath: string = "" with get
, set
16 member val PatientID: string = "" with get
, set
18 member this
.ImageParasitemia (srcImg
: SourceImage) : int * int =
19 List.length srcImg
.rbcs
,
20 srcImg
.rbcs
|> List.fold
(fun nbInfected rbc
-> if rbc
.infected
then nbInfected
+ 1 else nbInfected) 0
22 member this
.GlobalParasitemia : int * int =
24 |> Seq.fold
(fun (nbTotal
, nbTotalInfected
) srcImg
->
25 let nb, nbInfected = this
.ImageParasitemia srcImg
26 nbTotal
+ nb, nbTotalInfected
+ nbInfected) (0, 0)
29 let data = { PiaZ.sources
= List.ofSeq
sourceImages; PiaZ.patientID
= this
.PatientID }
30 PiaZ.save
this.FilePath data
33 let data = PiaZ.load
this.FilePath
34 this.PatientID <- data.patientID
36 sourceImages.InsertRange(0, data.sources
)
37 if sourceImages.Count > 0
38 then this.CurrentImage <- Some sourceImages.[0]
40 member this.AddSourceImage (filePath
: string) : SourceImage =
41 let srcImg = { num
= sourceImages.Count + 1; rbcs
= []; img
= new Image<Bgr, byte
>(filePath
) }
42 sourceImages.Add(srcImg)
43 if sourceImages.Count = 1
44 then this.CurrentImage <- Some sourceImages.[0]
47 member this.SetResult (imgNum
: int) (cells
: Cell list) =
48 let sourceImage = sourceImages.Find(fun srcImg -> srcImg.num
= imgNum
)
49 let w = sourceImage.img
.Width
50 let h = sourceImage.img
.Height
51 sourceImage.rbcs
<- cells
52 |> List.filter
(fun cell
-> match cell
.cellClass
with HealthyRBC | InfectedRBC -> true | _ -> false )
53 |> List.sortByDescending
(fun cell
-> cell
.infectedArea
, (w - cell
.center
.X) + (h - cell
.center
.Y))
54 |> List.mapi
(fun i cell
->
56 infected
= cell
.cellClass
= InfectedRBC
58 center
= Point(float cell.center
.X, float cell.center
.Y)
59 size
= Size(float cell.elements
.Width, float cell.elements
.Height)
60 infectedArea
= cell.infectedArea
})
62 member this.SourceImages : SourceImage seq =
63 sourceImages :> SourceImage seq
65 member this.Reset () =