X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FGUI%2FPia.fs;fp=Parasitemia%2FParasitemia%2FGUI%2FPia.fs;h=9ddd063c37d557903c6bf74412832f509e41bfd1;hb=3ddaf64dc5ba6a7066a279ad75b9a1ee72194639;hp=0000000000000000000000000000000000000000;hpb=6b550c3faf4dea77738fa5c27cd9af277f45549c;p=master-thesis.git diff --git a/Parasitemia/Parasitemia/GUI/Pia.fs b/Parasitemia/Parasitemia/GUI/Pia.fs new file mode 100644 index 0000000..9ddd063 --- /dev/null +++ b/Parasitemia/Parasitemia/GUI/Pia.fs @@ -0,0 +1,71 @@ +// ParasitemIA file format. +module Pia + +open System.Drawing +open System.IO +open System.IO.Compression + +open FSharp.Data + +open Emgu.CV +open Emgu.CV.Structure + +let extension = ".pia" +let filter = "PIA|*.pia" + +type RBC = { + infected: bool + addedManually: bool + removed: bool + + center: Point + size: Size + stainArea: int } + +type ImageSource = { + img: Image + rbcs: RBC list } + +type FileData = { + sources: ImageSource list + patientID: string } + +// The json type associated to a source image. +type JSONSourceImage = JsonProvider<""" + { + "rbcs": [ + { "infected": true, "addedManually": false, "removed": false, "posX" : 42, "posY" : 42, "width" : 10, "height" : 10, "stainArea" : 10 } + ] + } +"""> + +// The json type associated to a file. +type JSONMainInformation = JsonProvider<""" + { + "patientID": "1234abcd" + } +"""> + +let mainFilename = "info.json" + +let save (filePath: string) (data: FileData) = + use file = ZipFile.Open(filePath, ZipArchiveMode.Update) + + let mainJSON = JSONMainInformation.Root(data.patientID) + + let mainFile = + match file.GetEntry(mainFilename) with + | null -> file.CreateEntry(mainFilename) + | entry -> entry + + use mainFileWriter = new StreamWriter(mainFile.Open()) + mainJSON.JsonValue.WriteTo(mainFileWriter, JsonSaveOptions.None) + + +let load (filePath: string) : FileData = + use file = ZipFile.Open(filePath, ZipArchiveMode.Read) + + let mainFile = file.GetEntry(mainFilename) + let mainJSON = JSONMainInformation.Load(mainFile.Open()) + + { sources = []; patientID = mainJSON.PatientId } \ No newline at end of file