a1ae0521c01ea831a35876f05053eef6d4052366
[master-thesis.git] / Parasitemia / Parasitemia / GUI / State.fs
1 module Parasitemia.GUI.State
2
3 open System.Collections.Generic
4 open System.Windows
5
6 open Emgu.CV
7 open Emgu.CV.Structure
8
9 open Types
10
11 type State () =
12 let sourceImages = List<SourceImage>()
13
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
17
18 member this.Save () =
19 let data = { PiaZ.sources = List.ofSeq sourceImages; PiaZ.patientID = this.PatientID }
20 PiaZ.save this.FilePath data
21
22 member this.Load () =
23 let data = PiaZ.load this.FilePath
24 this.PatientID <- data.patientID
25 sourceImages.Clear()
26 sourceImages.InsertRange(0, data.sources)
27
28 member this.AddSourceImage (filePath: string) : SourceImage =
29 let srcImg = { num = sourceImages.Count + 1; rbcs = []; img = new Image<Bgr, byte>(filePath) }
30 sourceImages.Add(srcImg)
31 srcImg
32
33 member this.SetResult (num: int) (cells: Cell list) =
34 let sourceImage = sourceImages.Find(fun srcImg -> srcImg.num = num)
35 sourceImage.rbcs <- cells
36 |> List.filter (fun cell -> match cell.cellClass with HealthyRBC | InfectedRBC -> true | _ -> false )
37 |> List.mapi (fun i cell ->
38 { num = i
39 infected = cell.cellClass = InfectedRBC
40 setManually = false
41 center = Point(float cell.center.X, float cell.center.Y)
42 size = Size(float cell.elements.Width, float cell.elements.Height)
43 stainArea = cell.stainArea })
44
45 member this.SourceImages : SourceImage seq =
46 sourceImages :> SourceImage seq
47
48 member this.Reset () =
49 this.PatientID <- ""
50 sourceImages.Clear()