Add a logger assembly and split the main assembly in two : the UI and the parasitemia...
[master-thesis.git] / Parasitemia / ParasitemiaCore / Types.fs
1 module ParasitemiaCore.Types
2
3 open System
4 open System.Drawing
5
6 open Emgu.CV
7 open Emgu.CV.Structure
8
9 open Const
10
11 type Ellipse (cx: float32, cy: float32, a: float32, b: float32, alpha: float32) =
12 member this.Cx = cx
13 member this.Cy = cy
14 member this.A = a
15 member this.B = b
16 member this.Alpha = alpha
17 member this.Area = a * b * PI
18
19 // Does the ellipse contain the point (x, y)?.
20 member this.Contains x y =
21 ((x - cx) * cos alpha + (y - cy) * sin alpha) ** 2.f / a ** 2.f + ((x - cx) * sin alpha - (y - cy) * cos alpha) ** 2.f / b ** 2.f <= 1.f
22
23 member this.CutAVericalLine (y: float32) : bool =
24 a ** 2.f + b ** 2.f - 2.f * y ** 2.f + 4.f * y * cx - 2.f * cx ** 2.f + a ** 2.f * cos (2.f * alpha) - b ** 2.f * cos (2.f * alpha) > 0.f
25
26 member this.CutAnHorizontalLine (x: float32) : bool =
27 a ** 2.f + b ** 2.f - 2.f * x ** 2.f + 4.f * x * cy - 2.f * cy ** 2.f - a ** 2.f * cos (2.f * alpha) + b ** 2.f * cos (2.f * alpha) > 0.f
28
29 member this.isOutside (width: float32) (height: float32) =
30 this.Cx < 0.f || this.Cx >= width ||
31 this.Cy < 0.f || this.Cy >= height ||
32 this.CutAVericalLine 0.f || this.CutAVericalLine width ||
33 this.CutAnHorizontalLine 0.f || this.CutAnHorizontalLine height
34
35 member this.Scale (factor: float32) =
36 Ellipse(this.Cx, this.Cy, this.A * factor, this.B * factor, alpha)
37
38 // Approximation of Ramanujan.
39 member this.Perimeter =
40 PI * (3.f * (this.A + this.B) - sqrt ((3.f * this.A + this.B) * (this.A + 3.f * this.B)))
41
42 override this.ToString () =
43 sprintf "(cx: %A, cy: %A, a: %A, b: %A, alpha: %A)" this.Cx this.Cy this.A this.B this.Alpha
44
45 type CellClass = HealthyRBC | InfectedRBC | Peculiar
46
47 type Cell = {
48 cellClass: CellClass
49 center: Point
50 infectedArea: int
51 stainArea: int
52 elements: Matrix<byte> }
53
54 [<Struct>]
55 type Line (a: float32, b: float32) =
56 member this.A = a
57 member this.B = b
58 member this.Valid = not (Single.IsInfinity this.A)
59
60 [<Struct>]
61 type PointD (x: float32, y: float32) =
62 member this.X = x
63 member this.Y = y
64