acb9ce243f198f3156cda1025dd966e410a4cfcd
1
module Parasitemia.GUI.Analysis
5 open System.Windows.Media
6 open System.Windows.Markup
7 open System.Windows.Shapes
8 open System.Windows.Controls
12 let showWindow (parent
: Window) (state
: State.State) (defaultConfig
: Config) : bool =
13 let window = Views.AnalysisWindow()
14 window.Root.Owner <- parent
15 window.Root.Left <- parent
.Left + parent
.ActualWidth / 2. - window.Root.Width / 2.
16 window.Root.Top <- parent
.Top + parent
.ActualHeight / 2. - window.Root.Height / 2.
18 let ctrl (name
: string): 'a =
19 window.Root.FindName(name) :?> 'a
21 let butClose: Button = ctrl "butClose"
22 let butStart: Button = ctrl "butStart"
24 let progressBar: ProgressBar = ctrl "progress"
25 let textLog: TextBlock = ctrl "textLog"
26 let scrollLog: ScrollViewer = ctrl "scrollLog"
28 Utils.log
<- (fun mess
-> window.Root.Dispatcher.Invoke(fun () ->
29 textLog.Inlines.Add(Documents.Run(mess
))
30 textLog.Inlines.Add(Documents.LineBreak())
31 scrollLog.ScrollToBottom()))
33 let monitor = Object()
34 let mutable analysisPerformed = false
35 let mutable analysisCancelled = false
37 butClose.Click.AddHandler(fun obj args
-> window.Root.Close())
39 butStart.Click.AddHandler(fun obj args
->
40 butStart.IsEnabled <- false
41 butClose.Content <- "Abort"
44 ImageAnalysis.doMultipleAnalysis
45 (state
.SourceImages |> Seq.map
(fun srcImg
-> string srcImg
.num
, srcImg
.img
) |> Seq.toList
)
47 (Some (fun progress
-> window.Root.Dispatcher.Invoke(fun () -> progressBar.Value <- float progress)))
51 if not
analysisCancelled
53 for id
, rbcRadius
, cells
in results do
54 state
.SetResult (int id) rbcRadius
cells
56 window.Root.Dispatcher.Invoke(fun () ->
57 butStart.IsEnabled <- false
58 butClose.Content <- "Close")
60 Utils.log
"Analysis terminated successfully"
61 analysisPerformed <- true)
64 window.Root.ShowDialog() |> ignore
66 lock
monitor (fun () ->
67 if not
analysisPerformed
69 analysisCancelled <- true
73 (*let results = ImageAnalysis.doMultipleAnalysis (state.SourceImages |> Seq.map (fun srcImg -> string srcImg.num, srcImg.img) |> Seq.toList) defaultConfig
74 for id, rbcRadius, cells in results do
75 state.SetResult (int id) rbcRadius cells*)