X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FGUI%2FAnalysis.fs;fp=Parasitemia%2FParasitemia%2FGUI%2FAnalysis.fs;h=acb9ce243f198f3156cda1025dd966e410a4cfcd;hb=807437584bdd3d7b7b33be8282472f81f8cce606;hp=0000000000000000000000000000000000000000;hpb=8013d6a586604e443332e6e9a715c86df444a875;p=master-thesis.git diff --git a/Parasitemia/Parasitemia/GUI/Analysis.fs b/Parasitemia/Parasitemia/GUI/Analysis.fs new file mode 100644 index 0000000..acb9ce2 --- /dev/null +++ b/Parasitemia/Parasitemia/GUI/Analysis.fs @@ -0,0 +1,75 @@ +module Parasitemia.GUI.Analysis + +open System +open System.Windows +open System.Windows.Media +open System.Windows.Markup +open System.Windows.Shapes +open System.Windows.Controls + +open Config + +let showWindow (parent: Window) (state: State.State) (defaultConfig: Config) : bool = + let window = Views.AnalysisWindow() + window.Root.Owner <- parent + window.Root.Left <- parent.Left + parent.ActualWidth / 2. - window.Root.Width / 2. + window.Root.Top <- parent.Top + parent.ActualHeight / 2. - window.Root.Height / 2. + + let ctrl (name: string): 'a = + window.Root.FindName(name) :?> 'a + + let butClose: Button = ctrl "butClose" + let butStart: Button = ctrl "butStart" + + let progressBar: ProgressBar = ctrl "progress" + let textLog: TextBlock = ctrl "textLog" + let scrollLog: ScrollViewer = ctrl "scrollLog" + + Utils.log <- (fun mess -> window.Root.Dispatcher.Invoke(fun () -> + textLog.Inlines.Add(Documents.Run(mess)) + textLog.Inlines.Add(Documents.LineBreak()) + scrollLog.ScrollToBottom())) + + let monitor = Object() + let mutable analysisPerformed = false + let mutable analysisCancelled = false + + butClose.Click.AddHandler(fun obj args -> window.Root.Close()) + + butStart.Click.AddHandler(fun obj args -> + butStart.IsEnabled <- false + butClose.Content <- "Abort" + async { + let results = + ImageAnalysis.doMultipleAnalysis + (state.SourceImages |> Seq.map (fun srcImg -> string srcImg.num, srcImg.img) |> Seq.toList) + defaultConfig + (Some (fun progress -> window.Root.Dispatcher.Invoke(fun () -> progressBar.Value <- float progress))) + + lock monitor ( + fun() -> + if not analysisCancelled + then + for id, rbcRadius, cells in results do + state.SetResult (int id) rbcRadius cells + + window.Root.Dispatcher.Invoke(fun () -> + butStart.IsEnabled <- false + butClose.Content <- "Close") + + Utils.log "Analysis terminated successfully" + analysisPerformed <- true) + } |> Async.Start) + + window.Root.ShowDialog() |> ignore + + lock monitor (fun () -> + if not analysisPerformed + then + analysisCancelled <- true + analysisPerformed) + + + (*let results = ImageAnalysis.doMultipleAnalysis (state.SourceImages |> Seq.map (fun srcImg -> string srcImg.num, srcImg.img) |> Seq.toList) defaultConfig + for id, rbcRadius, cells in results do + state.SetResult (int id) rbcRadius cells*) \ No newline at end of file