- imageSourceSelection.txtResolution.LostFocus.AddHandler(fun obj args -> updateResolution ())
-
- stackImagesSourceSelection.Children.Add(imageSourceSelection) |> ignore
-
- butClose.Click.AddHandler(fun obj args -> window.Root.Close())
-
- butStart.Click.AddHandler(fun obj args ->
- let imagesToProcess = [
- for imageSelection in stackImagesSourceSelection.Children |> Seq.cast<Views.ImageSourceSelection> do
- let chk = imageSelection.chkSelection.IsChecked
- if chk.HasValue && chk.Value
- then
- let srcImg = imageSelection.Tag :?> SourceImage
- yield srcImg.num.ToString(), srcImg.config, srcImg.img ]
-
- if imagesToProcess.IsEmpty
- then
- MessageBox.Show("No image selected", "Cannot start analysis", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore
- else
- analysisPerformed <- false
- butStart.IsEnabled <- false
- butClose.Content <- "Abort"
- async {
- let results =
- ParasitemiaCore.Analysis.doMultipleAnalysis
- imagesToProcess
- (Some (fun progress -> window.Root.Dispatcher.Invoke(fun () -> progressBar.Value <- float progress)))
-
- lock monitor (
- fun() ->
- if not analysisCancelled
- then
- for id, cells in results do
- state.SetResult (int id) cells
-
- window.Root.Dispatcher.Invoke(fun () ->
- butStart.IsEnabled <- true
- butClose.Content <- "Close"
- updateSourceImages ())
-
- Logger.Log.User("All analyses terminated successfully")
- atLeastOneAnalysisPerformed <- true
- analysisPerformed <- true)
- } |> Async.Start)
-
- window.Root.Loaded.AddHandler(fun obj args -> updateSourceImages ())
-
- window.Root.ShowDialog() |> ignore
+ win.stackSourceImagesSelection.Children.Add(imageSourceSelection) |> ignore
+
+ // 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<Views.ImageSourceSelection>
+ let parameters = seq {
+ for srcImgCtrl in sourceImagesControls do
+ let srcImg = srcImgCtrl.Tag :?> SourceImage
+ 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.<ppi> })
+ | None ->
+ MessageBox.Show(sprintf "No resolution defined for the image number %d" srcImg.num, "No resolution defined", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore
+ yield None } |> Seq.takeWhile (fun e -> e.IsSome) |> Seq.map (fun e -> e.Value) |> List.ofSeq
+ if parameters.Count() <> sourceImagesControls.Count()
+ then None
+ else Some parameters
+
+ win.butClose.Click.AddHandler(fun obj args -> win.Root.Close())
+
+ win.butStart.Click.AddHandler(fun obj args ->
+ match getInputImagesParameters () with
+ | Some imagesParameters ->
+ let imagesToProcess = [
+ for srcImg, selected, parameters in imagesParameters do
+ srcImg.config.Parameters <- parameters // Save parameters.
+ if selected
+ then yield srcImg.num.ToString(), 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
+ analysisPerformed <- false
+ win.butStart.IsEnabled <- false
+ win.butClose.Content <- "Abort"
+
+ async {
+ let maybeResults =
+ ParasitemiaCore.Analysis.doMultipleAnalysis
+ imagesToProcess
+ (Some (fun progress -> win.Root.Dispatcher.Invoke(fun () -> win.progress.Value <- float progress); not analysisCancelled))
+
+ lock monitor (
+ fun() ->
+ match maybeResults with
+ | Some results ->
+ for id, cells in results do
+ state.SetResult (int id) cells
+ Logger.Log.User("All analyses terminated successfully")
+ atLeastOneAnalysisPerformed <- true
+ analysisPerformed <- true
+ | None ->
+ Logger.Log.User("Analysis aborted")
+
+ win.Root.Dispatcher.Invoke(fun () ->
+ win.progress.Value <- if maybeResults.IsSome then 100. else 0.
+ win.stackSourceImagesSelection.IsEnabled <- true
+ win.butStart.IsEnabled <- true
+ win.butClose.Content <- "Close"
+ updateSourceImages ()))
+ } |> Async.Start
+ | _ -> ())
+
+ win.Root.Loaded.AddHandler(fun obj args -> updateSourceImages ())
+
+ win.Root.ShowDialog() |> ignore