X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaUI%2FPiaZ.fs;h=02152542d09407c37c7ecc460f5739531c557508;hb=b87b35b922551f122228df1fd9c530bbb807935a;hp=bb553b8442cc015198a567474913016e47f76b07;hpb=2e3cd07dd099944059ef5e7a7f5ef57ffe3d677b;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaUI/PiaZ.fs b/Parasitemia/ParasitemiaUI/PiaZ.fs index bb553b8..0215254 100644 --- a/Parasitemia/ParasitemiaUI/PiaZ.fs +++ b/Parasitemia/ParasitemiaUI/PiaZ.fs @@ -18,26 +18,32 @@ let extension = ".piaz" let filter = "PIA|*.piaz" // Information associated to a document. -type JSONInformation = { - patientID: string - fileVersion: int } +type JSONInformation = + { + patientID : string + fileVersion : int + } // Information associated to each images. -type JSONSourceImage = { - num: int - name: string - - RBCRadius: float32 // The RBC Radius found by granulometry. - parameters: ParasitemiaCore.Config.Parameters - dateLastAnalysis: DateTime - rbcs: RBC List - - healthyRBCBrightness: float32 // 0 to 1. - infectedRBCBrightness: float32 } // 0 to 1. - -type DocumentData = { - patientID: string - images: SourceImage list } +type JSONSourceImage = + { + num : int + name : string + + RBCRadius : float32 // The RBC Radius found by granulometry. + parameters : ParasitemiaCore.Config.Parameters + dateLastAnalysis : DateTime + rbcs : RBC List + + healthyRBCBrightness : float32 // 0 to 1. + infectedRBCBrightness : float32 // 0 to 1. + } + +type DocumentData = + { + patientID : string + images : SourceImage list + } let mainEntryName = "info.json" let imageExtension = ".tiff" @@ -49,7 +55,7 @@ let currentFileVersion = 2 /// /// /// If the file cannot be written -let save (filePath: string) (data: DocumentData) = +let save (filePath : string) (data : DocumentData) = use file = ZipFile.Open(filePath, ZipArchiveMode.Update) for e in List.ofSeq file.Entries do // 'ofSeq' to not iterate a collection currently modified. @@ -70,16 +76,20 @@ let save (filePath: string) (data: DocumentData) = use imgJSONFileWriter = new StreamWriter(imgJSONEntry.Open()) imgJSONFileWriter.Write( JsonConvert.SerializeObject( - { num = srcImg.num - name = srcImg.name - RBCRadius = srcImg.config.RBCRadius.Pixel - parameters = srcImg.config.Parameters - dateLastAnalysis = srcImg.dateLastAnalysis - rbcs = srcImg.rbcs - healthyRBCBrightness = srcImg.healthyRBCBrightness - infectedRBCBrightness = srcImg.infectedRBCBrightness })) - -let updateDocumentData (fromVersion: int) (toVersion: int) (data: DocumentData) : DocumentData = + { + num = srcImg.num + name = srcImg.name + RBCRadius = srcImg.config.RBCRadius.Pixel + parameters = srcImg.config.Parameters + dateLastAnalysis = srcImg.dateLastAnalysis + rbcs = srcImg.rbcs + healthyRBCBrightness = srcImg.healthyRBCBrightness + infectedRBCBrightness = srcImg.infectedRBCBrightness + } + ) + ) + +let updateDocumentData (fromVersion : int) (toVersion : int) (data : DocumentData) : DocumentData = for v in fromVersion + 1 .. toVersion do match v with | 1 -> // Version 0 -> 1 : set initial brightness for rbc. @@ -92,7 +102,7 @@ let updateDocumentData (fromVersion: int) (toVersion: int) (data: DocumentData) /// /// /// If the file cannot be read -let load (filePath: string) (defaultConfig: ParasitemiaCore.Config.Config) : DocumentData = +let load (filePath : string) (defaultConfig : ParasitemiaCore.Config.Config) : DocumentData = use file = ZipFile.Open(filePath, ZipArchiveMode.Read) let mainEntry = file.GetEntry(mainEntryName) @@ -100,11 +110,13 @@ let load (filePath: string) (defaultConfig: ParasitemiaCore.Config.Config) : Doc let info = JsonConvert.DeserializeObject(mainEntryReader.ReadToEnd()) updateDocumentData info.fileVersion currentFileVersion - { patientID = info.patientID - images = [ let mutable imgNum = 0 - for imgEntry in file.Entries do - if imgEntry.Name.EndsWith(imageExtension) - then + { + patientID = info.patientID + images = + [ + let mutable imgNum = 0 + for imgEntry in file.Entries do + if imgEntry.Name.EndsWith(imageExtension) then use bitmap = new System.Drawing.Bitmap(imgEntry.Open(), false) let img = new Image(bitmap) imgNum <- imgNum + 1 @@ -114,15 +126,22 @@ let load (filePath: string) (defaultConfig: ParasitemiaCore.Config.Config) : Doc let config = defaultConfig.Copy() config.Parameters <- - { ParasitemiaCore.Config.defaultParameters with - resolution = imgInfo.parameters.resolution } + { + ParasitemiaCore.Config.defaultParameters with + resolution = imgInfo.parameters.resolution + } config.SetRBCRadius imgInfo.RBCRadius - yield { num = imgNum + yield + { + num = imgNum name = imgInfo.name config = config dateLastAnalysis = imgInfo.dateLastAnalysis img = img rbcs = imgInfo.rbcs healthyRBCBrightness = imgInfo.healthyRBCBrightness - infectedRBCBrightness = imgInfo.infectedRBCBrightness } ] } \ No newline at end of file + infectedRBCBrightness = imgInfo.infectedRBCBrightness + } + ] + } \ No newline at end of file