X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaUI%2FPiaZ.fs;h=c9dfd5b8247d4022dfd1dcd810c38d1516654dec;hp=d4ea46fa6eb062492bc5b1624e9555f68dd4ebb8;hb=cb90b01c85183b2c75ee6d22b378b3ca99df6bf3;hpb=074d6b0377f51e868deb1c427891c722d0270deb diff --git a/Parasitemia/ParasitemiaUI/PiaZ.fs b/Parasitemia/ParasitemiaUI/PiaZ.fs index d4ea46f..c9dfd5b 100644 --- a/Parasitemia/ParasitemiaUI/PiaZ.fs +++ b/Parasitemia/ParasitemiaUI/PiaZ.fs @@ -20,6 +20,7 @@ let filter = "PIA|*.piaz" // Information associated to a document. type JSONInformation = { patientID: string + fileVersion: int } // Information associated to each images. @@ -29,6 +30,9 @@ type JSONSourceImage = { parameters: ParasitemiaCore.Config.Parameters dateLastAnalysis: DateTime rbcs: RBC List + + healthyRBCBrightness: float32 // 0 to 1. + infectedRBCBrightness: float32 // 0 to 1. } type DocumentData = { @@ -38,6 +42,7 @@ type DocumentData = { let mainEntryName = "info.json" let imageExtension = ".tiff" +let currentFileVersion = 1 /// /// Save a document in a give file path. The file may already exist. @@ -54,7 +59,7 @@ let save (filePath: string) (data: DocumentData) = // Main JSON file. let mainEntry = file.CreateEntry(mainEntryName, CompressionLevel.Fastest) use mainEntryWriter = new StreamWriter(mainEntry.Open()) - mainEntryWriter.Write(JsonConvert.SerializeObject({ JSONInformation.patientID = data.patientID })) + mainEntryWriter.Write(JsonConvert.SerializeObject({ patientID = data.patientID; fileVersion = currentFileVersion })) // Write each images and the associated information. for srcImg in data.images do @@ -64,7 +69,23 @@ let save (filePath: string) (data: DocumentData) = let imgJSONEntry = file.CreateEntry(imgFilename + ".json", CompressionLevel.Fastest) use imgJSONFileWriter = new StreamWriter(imgJSONEntry.Open()) - imgJSONFileWriter.Write(JsonConvert.SerializeObject({ num = srcImg.num; RBCRadius = srcImg.config.RBCRadius.Pixel; parameters = srcImg.config.Parameters; dateLastAnalysis = srcImg.dateLastAnalysis; rbcs = srcImg.rbcs })) + imgJSONFileWriter.Write( + JsonConvert.SerializeObject( + { num = srcImg.num + 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. + data.images |> List.iter (fun i -> i.healthyRBCBrightness <- 1.f; i.infectedRBCBrightness <- 1.f) + | _ -> () + data /// /// Load document from a give file path. @@ -78,20 +99,24 @@ let load (filePath: string) : DocumentData = use mainEntryReader = new StreamReader(mainEntry.Open()) let info = JsonConvert.DeserializeObject(mainEntryReader.ReadToEnd()) - { patientID = info.patientID - images = [ let mutable imgNum = 0 - for imgEntry in file.Entries do - if imgEntry.Name.EndsWith(imageExtension) - then - let img = new Image(new System.Drawing.Bitmap(imgEntry.Open(), false)) // FIXME: Should we dispose the bitmap? - imgNum <- imgNum + 1 - let imgEntry = file.GetEntry(imgEntry.Name + ".json") - use imgEntryFileReader = new StreamReader(imgEntry.Open()) - let imgInfo = JsonConvert.DeserializeObject(imgEntryFileReader.ReadToEnd()) - let config = ParasitemiaCore.Config.Config(imgInfo.parameters) - config.SetRBCRadius imgInfo.RBCRadius - yield { num = imgNum - config = config - dateLastAnalysis = imgInfo.dateLastAnalysis - img = img - rbcs = imgInfo.rbcs } ] } \ No newline at end of file + updateDocumentData info.fileVersion currentFileVersion + { 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 + let imgEntry = file.GetEntry(imgEntry.Name + ".json") + use imgEntryFileReader = new StreamReader(imgEntry.Open()) + let imgInfo = JsonConvert.DeserializeObject(imgEntryFileReader.ReadToEnd()) + let config = ParasitemiaCore.Config.Config(imgInfo.parameters) + config.SetRBCRadius imgInfo.RBCRadius + yield { num = imgNum + config = config + dateLastAnalysis = imgInfo.dateLastAnalysis + img = img + rbcs = imgInfo.rbcs + healthyRBCBrightness = imgInfo.healthyRBCBrightness + infectedRBCBrightness = imgInfo.infectedRBCBrightness } ] } \ No newline at end of file