X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaUI%2FSourceImage.fs;h=8dd20df4b32cf69e67bd6caff26fe9fcf129e565;hb=HEAD;hp=2330227295a005c82a54f83d991d6a793c8ecc3c;hpb=42d4db26f30bccbcc2e1b6d1f82a5b04a1f3dcd2;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaUI/SourceImage.fs b/Parasitemia/ParasitemiaUI/SourceImage.fs index 2330227..8dd20df 100644 --- a/Parasitemia/ParasitemiaUI/SourceImage.fs +++ b/Parasitemia/ParasitemiaUI/SourceImage.fs @@ -1,7 +1,7 @@ namespace ParasitemiaUI open System -open System.Windows +open System.IO open System.Windows.Media open Emgu.CV @@ -9,12 +9,36 @@ open Emgu.CV.Structure open Types -type SourceImage (num : int, name : string, config : ParasitemiaCore.Config.Config, dateLastAnalysis : DateTime, img : Image, rbcs : RBC list) = +type ImageData = + | FromMemory of Image + | FromFile of string // This file will be stored in a temporary directory until the image is saved in a piaz file. + +type SourceImage (num : int, name : string, originalName : string, config : ParasitemiaCore.Config.Config, dateLastAnalysis : DateTime, imgData : ImageData, rbcs : RBC list) = let mutable num = num let mutable name = name let mutable config = config let mutable dateLastAnalysis = dateLastAnalysis // UTC. - let img = img + let img = + match imgData with + | FromMemory i -> i + | FromFile path -> new Image (path) + + let mutable tempFile : string option = + match imgData with + | FromMemory _ -> None + | FromFile path -> + let tmpDirname = Guid.NewGuid () + let filename = Path.GetFileName path + + // Copy it to a temporary directory. + let tmpDir = Path.Combine (Path.GetTempPath (), string tmpDirname) + Directory.CreateDirectory tmpDir |> ignore + let tmpPath = Path.Combine (tmpDir, filename) + + File.Copy (path, tmpPath) + + Some tmpPath + let mutable rbcs = rbcs let mutable healthyRBCBrightness = 1.f let mutable infectedRBCBrightness = 1.f @@ -25,27 +49,38 @@ type SourceImage (num : int, name : string, config : ParasitemiaCore.Config.Conf let infectedRBColor = Color.FromRgb (255uy, 0uy, 40uy) // Red with a bit of blue. let updateAverageRBCSize () = - averageRBCSize <- - rbcs - |> List.collect (fun rbc -> [ rbc.size.Width; rbc.size.Height ]) - |> List.average + 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.OriginalName = originalName + member this.Config = config member this.DateLastAnalysis with get () = dateLastAnalysis and set value = dateLastAnalysis <- value member this.Img = img + member this.TempFile + with get () = tempFile + and set value = tempFile <- value // TODO: remove temp file if set to None + member this.RBCs with get () = rbcs - and set value = rbcs <- value + and set value = + rbcs <- value + updateAverageRBCSize () member this.ImageParasitemia : int * int = List.length rbcs,