X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaUI%2FAnalysis.fs;h=1747fc26bf082f2a9de5b059089a16766f95fec6;hp=4a75a91d3f4a6dd61de144c05042f25e4448172c;hb=8866c578f1210295bdcf04c8212eae81d52d630a;hpb=2d712781def419c9acc98368f7102b19b064f16d diff --git a/Parasitemia/ParasitemiaUI/Analysis.fs b/Parasitemia/ParasitemiaUI/Analysis.fs index 4a75a91..1747fc2 100644 --- a/Parasitemia/ParasitemiaUI/Analysis.fs +++ b/Parasitemia/ParasitemiaUI/Analysis.fs @@ -1,25 +1,18 @@ module ParasitemiaUI.Analysis open System -open System.IO open System.Linq open System.Windows -open System.Windows.Media -open System.Windows.Markup -open System.Windows.Shapes open System.Windows.Controls -open System.Diagnostics -open Microsoft.Win32 // For the common dialogs. - -open Emgu.CV.WPF +open ParasitemiaUIControls open ParasitemiaCore.UnitsOfMeasure open ParasitemiaCore.Config open Types let showWindow (parent : Window) (state : State.State) : bool = - let win = Views.AnalysisWindow () + let win = AnalysisWindow () win.Owner <- parent win.Left <- (if parent.WindowState = WindowState.Maximized then 0. else parent.Left) + parent.ActualWidth / 2. - win.Width / 2. win.Top <- (if parent.WindowState = WindowState.Maximized then 0. else parent.Top) + parent.ActualHeight / 2. - win.Height / 2. @@ -27,7 +20,7 @@ let showWindow (parent : Window) (state : State.State) : bool = let logListener = { new Logger.IListener with - member this.NewEntry severity _header mess = + member this.NewEntry severity header mess = win.Dispatcher.Invoke ( fun () -> win.textLog.Inlines.Add (Documents.Run mess) @@ -54,16 +47,16 @@ let showWindow (parent : Window) (state : State.State) : bool = win.stackSourceImagesSelection.Children.Clear () let width = int win.stackSourceImagesSelection.ActualWidth for srcImg in state.SourceImages do - let imageSourceSelection = Views.ImageSourceSelection (Tag = srcImg, Margin = Thickness 3.) + let imageSourceSelection = ImageSourceSelection (Tag = srcImg, Margin = Thickness 3.) imageSourceSelection.Tag <- srcImg - imageSourceSelection.txtImageNumber.Text <- string srcImg.num - let height = srcImg.img.Height * width / srcImg.img.Width - imageSourceSelection.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource (srcImg.img.Resize (width, height, Emgu.CV.CvEnum.Inter.Cubic)) - imageSourceSelection.chkSelection.IsChecked <- Nullable (srcImg.dateLastAnalysis.Ticks = 0L) - imageSourceSelection.lblDateLastAnalysis.Content <- if srcImg.dateLastAnalysis.Ticks = 0L then "" else string srcImg.dateLastAnalysis + imageSourceSelection.txtImageNumber.Text <- string srcImg.RomanNum + let height = srcImg.Img.Height * width / srcImg.Img.Width + imageSourceSelection.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource (srcImg.Img.Resize (width, height, Emgu.CV.CvEnum.Inter.Cubic)) + imageSourceSelection.chkSelection.IsChecked <- Nullable (srcImg.DateLastAnalysis.Ticks = 0L) + imageSourceSelection.lblDateLastAnalysis.Content <- if srcImg.DateLastAnalysis.Ticks = 0L then "" else string srcImg.DateLastAnalysis - imageSourceSelection.txtResolution.Text <- if srcImg.dateLastAnalysis.Ticks = 0L then "" else string srcImg.config.Parameters.resolution + imageSourceSelection.txtResolution.Text <- if srcImg.DateLastAnalysis.Ticks = 0L then "" else string srcImg.Config.Parameters.resolution for ppi in Utils.predefinedPPI do let menu = MenuItem () @@ -95,7 +88,7 @@ let showWindow (parent : Window) (state : State.State) : bool = // Get the new parameters for each image. If an error occurs then 'None' is returned and a message box is displayed. // The boolean is 'true' if the image is selected (checked). let getInputImagesParameters () : (SourceImage * bool * Parameters) list option = - let sourceImagesControls = win.stackSourceImagesSelection.Children |> Seq.cast + let sourceImagesControls = win.stackSourceImagesSelection.Children |> Seq.cast let parameters = seq { for srcImgCtrl in sourceImagesControls do @@ -103,10 +96,10 @@ let showWindow (parent : Window) (state : State.State) : bool = let isChecked = srcImgCtrl.chkSelection.IsChecked match parseAndValidatePPI srcImgCtrl.txtResolution.Text with | Some resolution -> - yield Some (srcImg, isChecked.HasValue && isChecked.Value, { srcImg.config.Parameters with resolution = resolution * 1. }) + Some (srcImg, isChecked.HasValue && isChecked.Value, { srcImg.Config.Parameters with resolution = resolution * 1. }) | None -> - MessageBox.Show (sprintf "No resolution defined for the image number %d" srcImg.num, "No resolution defined", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore - yield None + MessageBox.Show (sprintf "No resolution defined for the image number %d" srcImg.Num, "No resolution defined", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore + None } |> Seq.takeWhile (fun e -> e.IsSome) |> Seq.map (fun e -> e.Value) |> List.ofSeq if parameters.Count () <> sourceImagesControls.Count () then @@ -114,6 +107,18 @@ let showWindow (parent : Window) (state : State.State) : bool = else Some parameters + win.butSelectAll.Click.AddHandler ( + fun obj args -> + for srcImgCtrl in win.stackSourceImagesSelection.Children |> Seq.cast do + srcImgCtrl.chkSelection.IsChecked <- true + ) + + win.butUnselectAll.Click.AddHandler ( + fun obj args -> + for srcImgCtrl in win.stackSourceImagesSelection.Children |> Seq.cast do + srcImgCtrl.chkSelection.IsChecked <- false + ) + win.butClose.Click.AddHandler (fun obj args -> win.Close ()) win.butStart.Click.AddHandler ( @@ -123,19 +128,25 @@ let showWindow (parent : Window) (state : State.State) : bool = let imagesToProcess = [ for srcImg, selected, parameters in imagesParameters do - srcImg.config.Parameters <- parameters // Save parameters. + srcImg.Config.Parameters <- parameters // Save parameters. if selected then - yield string srcImg.num, srcImg.config, srcImg.img + string srcImg.RomanNum, srcImg.Config, srcImg.Img ] if imagesToProcess.IsEmpty then MessageBox.Show ("No image selected", "Cannot start analysis", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore else win.stackSourceImagesSelection.IsEnabled <- false + win.butSelectAll.IsEnabled <- false + win.butUnselectAll.IsEnabled <- false analysisPerformed <- false win.butStart.IsEnabled <- false + win.textLog.Text <- "" win.butClose.Content <- "Abort" + let sw = System.Diagnostics.Stopwatch () + sw.Start () + async { let maybeResults = ParasitemiaCore.Analysis.doMultipleAnalysis @@ -147,8 +158,8 @@ let showWindow (parent : Window) (state : State.State) : bool = match maybeResults with | Some results -> for id, cells in results do - state.SetResult (int id) cells - Logger.Log.Info "All analyses terminated successfully" + state.SetResult id cells + Logger.Log.Info $"All analyses terminated successfully (total time: %d{sw.ElapsedMilliseconds} ms)" atLeastOneAnalysisPerformed <- true analysisPerformed <- true | None -> @@ -158,6 +169,8 @@ let showWindow (parent : Window) (state : State.State) : bool = fun () -> win.progress.Value <- if maybeResults.IsSome then 100. else 0. win.stackSourceImagesSelection.IsEnabled <- true + win.butSelectAll.IsEnabled <- true + win.butUnselectAll.IsEnabled <- true win.butStart.IsEnabled <- true win.butClose.Content <- "Close" updateSourceImages () @@ -171,7 +184,7 @@ let showWindow (parent : Window) (state : State.State) : bool = win.ShowDialog () |> ignore - Logger.Log.RmListener (logListener) + Logger.Log.RemoveListener (logListener) lock monitor ( fun () ->