+ let scrollRBC: ScrollViewer = ctrl "scrollRBC"
+ let stackRBC: StackPanel = ctrl "stackRBC"
+
+ // Initializations.
+ menuHightlightRBC.IsChecked <- displayHealthy
+
+ // Utils.
+ let extractRBCPreview (img: Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte>) (rbc: RBC) : Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> =
+ let rbcWidth = rbc.size.Width
+ let rbcHeight = rbc.size.Height
+ let x = rbc.center.X - rbcWidth / 2. |> Utils.roundInt
+ let y = rbc.center.Y - rbcHeight / 2. |> Utils.roundInt
+ let w = Utils.roundInt rbcWidth
+ let h = Utils.roundInt rbcHeight
+ img.GetSubRect(System.Drawing.Rectangle(System.Drawing.Point((if x < 0 then 0 else x), (if y < 0 then 0 else y)),
+ System.Drawing.Size((if x + w >= img.Width then img.Width - x else w),
+ (if y + h >= img.Height then img.Height - y else h))))
+
+ let setRBCFrameStyle (rbc: RBC) (frame: Views.RBCFrame) =
+ frame.Opacity <- if displayHealthy || rbc.setManually || rbc.infected then 1. else 0.
+ let color = if rbc.infected then colorRBCInfected else colorRBCHealthy
+ frame.manuallyAdded.Visibility <- if rbc.setManually then Visibility.Visible else Visibility.Hidden
+ frame.manuallyAdded.Fill <- color
+ frame.border.Stroke <- color
+
+ let RBCFrameFromExisting (rbc: RBC) (frame: Views.RBCFrame) : Views.RBCFrame =
+ frame.Visibility <- Visibility.Visible
+ frame.Height <- rbc.size.Height
+ frame.Width <- rbc.size.Width
+ frame.Tag <- rbc
+ setRBCFrameStyle rbc frame
+ frame.border.StrokeThickness <- 1.
+ frame.txtRBCNumber.Text <- rbc.num.ToString()
+ frame
+
+ let highlightRBCFrame (frame: Views.RBCFrame) (highlight: bool) =
+ let rbc = frame.Tag :?> RBC
+ if highlight
+ then
+ frame.border.StrokeThickness <- 3.
+ if not rbc.infected && not rbc.setManually && not displayHealthy then frame.Opacity <- 1.
+ else
+ frame.border.StrokeThickness <- 1.
+ if not rbc.infected && not rbc.setManually && not displayHealthy then frame.Opacity <- 0.
+
+ let zoomToRBC (rbc: RBC) =
+ scrollViewCurrentImage.ScrollToHorizontalOffset(rbc.center.X * currentScale - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left)
+ scrollViewCurrentImage.ScrollToVerticalOffset(rbc.center.Y * currentScale - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top)
+
+ let parasitemiaText (nbTotal: int, nbInfected: int) : string =
+ if nbTotal = 0
+ then
+ ""
+ else
+ let percent = 100. * (float nbInfected) / (float nbTotal)
+ sprintf "%.1f %% (%d / %d)" percent nbInfected nbTotal
+
+ let updateCurrentImageInformation () =
+ match state.CurrentImage with
+ | Some srcImg ->
+ let parasitemiaStr = parasitemiaText (state.ImageParasitemia srcImg)
+ txtImageInformation.Inlines.Clear()
+ txtImageInformation.Inlines.Add(Documents.Run("Parasitemia: ", FontWeight = FontWeights.Bold))
+ txtImageInformation.Inlines.Add(parasitemiaStr)
+ txtImageInformation.Inlines.Add(Documents.LineBreak())
+
+ txtImageInformation.Inlines.Add(Documents.Run("Average erytrocyte diameter: ", FontWeight = FontWeights.Bold))
+ txtImageInformation.Inlines.Add(Documents.Run(srcImg.config.RBCRadius.ToString()))
+ txtImageInformation.Inlines.Add(Documents.LineBreak())
+
+ txtImageInformation.Inlines.Add(Documents.Run("Last analysis: ", FontWeight = FontWeights.Bold))
+ txtImageInformation.Inlines.Add(Documents.Run(if srcImg.dateLastAnalysis.Ticks = 0L then "<Never>" else srcImg.dateLastAnalysis.ToLocalTime().ToString()))
+ | _ -> ()
+
+ let updateGlobalParasitemia () =
+ txtGlobalParasitemia.Text <- parasitemiaText state.GlobalParasitemia
+
+ let updateViewportPreview () =
+ for preview in stackPreviews.Children |> Seq.cast<Views.ImageSourcePreview> do
+ let srcImg = preview.Tag :?> SourceImage
+ if Some srcImg = state.CurrentImage then
+ preview.viewport.Visibility <- Visibility.Visible
+
+ let canvasWidth = canvasCurrentImage.ActualWidth * currentScale
+ let canvasHeight = canvasCurrentImage.ActualHeight * currentScale
+ let previewWidth = (preview.ActualWidth - preview.BorderThickness.Left - preview.BorderThickness.Right)
+ let previewHeight = (preview.ActualHeight - preview.BorderThickness.Top - preview.BorderThickness.Bottom)
+
+ let marginLeft = previewWidth * (scrollViewCurrentImage.HorizontalOffset - borderCurrentImage.BorderThickness.Left) / canvasWidth - 2.
+ let marginRight = previewWidth * (canvasWidth - (scrollViewCurrentImage.HorizontalOffset - borderCurrentImage.BorderThickness.Right) - scrollViewCurrentImage.ViewportWidth) / canvasWidth - 2.
+ let marginTop = previewHeight * (scrollViewCurrentImage.VerticalOffset - borderCurrentImage.BorderThickness.Top) / canvasHeight - 2.
+ let marginBottom = previewHeight * (canvasHeight - (scrollViewCurrentImage.VerticalOffset - borderCurrentImage.BorderThickness.Bottom) - scrollViewCurrentImage.ViewportHeight) / canvasHeight - 2.
+
+ preview.viewport.Margin <-
+ Thickness(
+ marginLeft,
+ marginTop,
+ marginRight,
+ marginBottom)
+ else
+ preview.viewport.Visibility <- Visibility.Hidden
+
+ let rec setAsInfected (rbc: RBC) (infected: bool) =
+ state.SetAsInfected rbc infected
+ canvasCurrentImage.Children
+ |> Seq.cast<Views.RBCFrame>
+ |> Seq.iter
+ (fun frame ->
+ if (frame.Tag :?> RBC) = rbc
+ then
+ setRBCFrameStyle rbc frame)
+ updateRBCFramesPreview ()
+ updateCurrentImageInformation ()
+ updateGlobalParasitemia ()