b0af4cc198ec565ab2d5634b35bcd25631bc98ec
[master-thesis.git] / Parasitemia / Parasitemia / GUI / GUI.fs
1 module Parasitemia.GUI.Main
2
3 open System
4 open System.IO
5 open System.Linq
6 open System.Windows
7 open System.Windows.Media
8 open System.Windows.Markup
9 open System.Windows.Shapes
10 open System.Windows.Controls
11 open System.Diagnostics
12 open Microsoft.Win32 // For the common dialogs.
13
14 open Emgu.CV.WPF
15
16 open Config
17 open Types
18
19 let run (defaultConfig: Config) =
20 let app = new Application()
21 let mainWindow = Views.MainWindow()
22 let ctrl (name: string): 'a =
23 mainWindow.Root.FindName(name) :?> 'a
24
25 let colorRBCHealthy = Brushes.YellowGreen
26 let colorRBCInfected = Brushes.Red
27
28 let state = State.State()
29 let mutable currentScale = 1.
30 let mutable displayHealthy = false
31
32 let menuExit: MenuItem = ctrl "menuExit"
33 let menuSaveFile: MenuItem = ctrl "menuSave"
34 let menuLoadFile: MenuItem = ctrl "menuOpen"
35 let menuNewFile: MenuItem = ctrl "menuNew"
36 let menuAddSourceImage: MenuItem = ctrl "menuAddSourceImage"
37 let menuStartAnalysis: MenuItem = ctrl "menuStartAnalysis"
38 let menuHightlightRBC: MenuItem = ctrl "menuHightlightRBC"
39
40 let txtPatient: TextBox = ctrl "txtPatient"
41 let txtGlobalParasitemia: TextBox = ctrl "txtGlobalParasitemia"
42
43 let stackPreviews: StackPanel = ctrl "stackPreviews"
44
45 let scrollViewCurrentImage: ScrollViewer = ctrl "scrollViewCurrentImage"
46 let borderCurrentImage: Border = ctrl "borderCurrentImage"
47 let canvasCurrentImage: Canvas = ctrl "canvasCurrentImage"
48 let txtImageInformation: TextBlock = ctrl "txtImageInformation"
49
50 let scrollRBC: ScrollViewer = ctrl "scrollRBC"
51 let stackRBC: StackPanel = ctrl "stackRBC"
52
53 // Initializations.
54 menuHightlightRBC.IsChecked <- displayHealthy
55
56 // Utils.
57 let extractRBCPreview (img: Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte>) (rbc: RBC) : Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> =
58 let rbcWidth = rbc.size.Width
59 let rbcHeight = rbc.size.Height
60 let x = rbc.center.X - rbcWidth / 2. |> Utils.roundInt
61 let y = rbc.center.Y - rbcHeight / 2. |> Utils.roundInt
62 let w = Utils.roundInt rbcWidth
63 let h = Utils.roundInt rbcHeight
64 img.GetSubRect(System.Drawing.Rectangle(System.Drawing.Point((if x < 0 then 0 else x), (if y < 0 then 0 else y)),
65 System.Drawing.Size((if x + w >= img.Width then img.Width - x else w),
66 (if y + h >= img.Height then img.Height - y else h))))
67
68 let setRBCFrameStyle (rbc: RBC) (frame: Views.RBCFrame) =
69 frame.Opacity <- if displayHealthy || rbc.setManually || rbc.infected then 1. else 0.
70 let color = if rbc.infected then colorRBCInfected else colorRBCHealthy
71 frame.manuallyAdded.Visibility <- if rbc.setManually then Visibility.Visible else Visibility.Hidden
72 frame.manuallyAdded.Fill <- color
73 frame.border.Stroke <- color
74
75 let RBCFrameFromExisting (rbc: RBC) (frame: Views.RBCFrame) : Views.RBCFrame =
76 frame.Visibility <- Visibility.Visible
77 frame.Height <- rbc.size.Height
78 frame.Width <- rbc.size.Width
79 frame.Tag <- rbc
80 setRBCFrameStyle rbc frame
81 frame.border.StrokeThickness <- 1.
82 frame.txtRBCNumber.Text <- rbc.num.ToString()
83 frame
84
85 let highlightRBCFrame (frame: Views.RBCFrame) (highlight: bool) =
86 let rbc = frame.Tag :?> RBC
87 if highlight
88 then
89 frame.border.StrokeThickness <- 3.
90 if not rbc.infected && not rbc.setManually && not displayHealthy then frame.Opacity <- 1.
91 else
92 frame.border.StrokeThickness <- 1.
93 if not rbc.infected && not rbc.setManually && not displayHealthy then frame.Opacity <- 0.
94
95 let zoomToRBC (rbc: RBC) =
96 scrollViewCurrentImage.ScrollToHorizontalOffset(rbc.center.X * currentScale - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left)
97 scrollViewCurrentImage.ScrollToVerticalOffset(rbc.center.Y * currentScale - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top)
98
99 let parasitemiaText (nbTotal: int, nbInfected: int) : string =
100 if nbTotal = 0
101 then
102 ""
103 else
104 let percent = 100. * (float nbInfected) / (float nbTotal)
105 sprintf "%.1f %% (%d / %d)" percent nbInfected nbTotal
106
107 let updateCurrentImageInformation () =
108 match state.CurrentImage with
109 | Some srcImg ->
110 let parasitemiaStr = parasitemiaText (state.ImageParasitemia srcImg)
111 txtImageInformation.Inlines.Clear()
112 txtImageInformation.Inlines.Add(Documents.Run("Parasitemia: ", FontWeight = FontWeights.Bold))
113 txtImageInformation.Inlines.Add(parasitemiaStr)
114 txtImageInformation.Inlines.Add(Documents.LineBreak())
115
116 txtImageInformation.Inlines.Add(Documents.Run("Average erytrocyte diameter: ", FontWeight = FontWeights.Bold))
117 txtImageInformation.Inlines.Add(Documents.Run(srcImg.config.FormattedRadius))
118 txtImageInformation.Inlines.Add(Documents.LineBreak())
119
120 txtImageInformation.Inlines.Add(Documents.Run("Last analysis: ", FontWeight = FontWeights.Bold))
121 txtImageInformation.Inlines.Add(Documents.Run(if srcImg.dateLastAnalysis.Ticks = 0L then "<Never>" else srcImg.dateLastAnalysis.ToLocalTime().ToString()))
122 | _ -> ()
123
124 let updateGlobalParasitemia () =
125 txtGlobalParasitemia.Text <- parasitemiaText state.GlobalParasitemia
126
127 let updateViewportPreview () =
128 for preview in stackPreviews.Children |> Seq.cast<Views.ImageSourcePreview> do
129 let srcImg = preview.Tag :?> SourceImage
130 if Some srcImg = state.CurrentImage then
131 preview.viewport.Visibility <- Visibility.Visible
132
133 let canvasWidth = canvasCurrentImage.ActualWidth * currentScale
134 let canvasHeight = canvasCurrentImage.ActualHeight * currentScale
135 let previewWidth = (preview.ActualWidth - preview.BorderThickness.Left - preview.BorderThickness.Right)
136 let previewHeight = (preview.ActualHeight - preview.BorderThickness.Top - preview.BorderThickness.Bottom)
137
138 let marginLeft = previewWidth * (scrollViewCurrentImage.HorizontalOffset - borderCurrentImage.BorderThickness.Left) / canvasWidth - 2.
139 let marginRight = previewWidth * (canvasWidth - (scrollViewCurrentImage.HorizontalOffset - borderCurrentImage.BorderThickness.Right) - scrollViewCurrentImage.ViewportWidth) / canvasWidth - 2.
140 let marginTop = previewHeight * (scrollViewCurrentImage.VerticalOffset - borderCurrentImage.BorderThickness.Top) / canvasHeight - 2.
141 let marginBottom = previewHeight * (canvasHeight - (scrollViewCurrentImage.VerticalOffset - borderCurrentImage.BorderThickness.Bottom) - scrollViewCurrentImage.ViewportHeight) / canvasHeight - 2.
142
143 preview.viewport.Margin <-
144 Thickness(
145 marginLeft,
146 marginTop,
147 marginRight,
148 marginBottom)
149 else
150 preview.viewport.Visibility <- Visibility.Hidden
151
152 let rec setAsInfected (rbc: RBC) (infected: bool) =
153 state.SetAsInfected rbc infected
154 canvasCurrentImage.Children
155 |> Seq.cast<Views.RBCFrame>
156 |> Seq.iter
157 (fun frame ->
158 if (frame.Tag :?> RBC) = rbc
159 then
160 setRBCFrameStyle rbc frame)
161 updateRBCFramesPreview ()
162 updateCurrentImageInformation ()
163 updateGlobalParasitemia ()
164
165 and RBCFrame (rbc: RBC) : Views.RBCFrame =
166 let frame = RBCFrameFromExisting rbc (Views.RBCFrame())
167 frame.SetValue(Panel.ZIndexProperty, Int32.MaxValue - rbc.num) // To be sure the
168 frame.menuRBCSetAsHealthy.Click.AddHandler(fun obj args -> setAsInfected (frame.Tag :?> RBC) false)
169 frame.menuRBCSetAsInfected.Click.AddHandler(fun obj args -> setAsInfected (frame.Tag :?> RBC) true)
170 frame.ContextMenuOpening.AddHandler(
171 fun obj args ->
172 if (frame.Tag :?> RBC).infected
173 then
174 frame.menuRBCSetAsHealthy.Visibility <- Visibility.Visible
175 frame.menuRBCSetAsInfected.Visibility <- Visibility.Collapsed
176 else
177 frame.menuRBCSetAsHealthy.Visibility <- Visibility.Collapsed
178 frame.menuRBCSetAsInfected.Visibility <- Visibility.Visible)
179
180 frame.ContextMenuClosing.AddHandler(fun obj args -> if not frame.IsMouseOver then highlightRBCFrame frame false )
181 frame.MouseEnter.AddHandler(fun obj args -> highlightRBCFrame frame true)
182 frame.MouseLeave.AddHandler(fun obj args -> if not frame.grid.ContextMenu.IsOpen then highlightRBCFrame frame false)
183 frame
184
185 and updateRBCFramesPreview () =
186 match state.CurrentImage with
187 | Some srcImg ->
188 let mutable currentPreview = 0
189 for rbc in srcImg.rbcs |> List.filter (fun rbc -> displayHealthy || rbc.infected) do
190 let previewInfected =
191 if currentPreview < stackRBC.Children.Count
192 then
193 RBCFrameFromExisting rbc (stackRBC.Children.[currentPreview] :?> Views.RBCFrame)
194 else
195 let f = RBCFrame rbc
196 f.MouseLeftButtonUp.AddHandler(fun obj args -> zoomToRBC (f.Tag :?> RBC))
197 stackRBC.Children.Add(f) |> ignore
198 f
199
200 currentPreview <- currentPreview + 1
201
202 previewInfected.Height <- stackRBC.ActualHeight
203 previewInfected.Width <- stackRBC.ActualHeight * rbc.size.Width / rbc.size.Height
204 previewInfected.border.Fill <- ImageBrush(BitmapSourceConvert.ToBitmapSource(extractRBCPreview srcImg.img rbc))
205
206 stackRBC.Children.RemoveRange(currentPreview, stackRBC.Children.Count - currentPreview)
207 | _ -> ()
208
209 updateViewportPreview ()
210
211 let updateRBCFramesCurrent () =
212 match state.CurrentImage with
213 | Some srcImg ->
214 let mutable currentCanvas = 0
215 for rbc in srcImg.rbcs do
216 let frame =
217 if currentCanvas < canvasCurrentImage.Children.Count
218 then
219 RBCFrameFromExisting rbc (canvasCurrentImage.Children.[currentCanvas] :?> Views.RBCFrame)
220 else
221 let f = RBCFrame rbc
222 f.Root.Opacity <- 0.7
223 canvasCurrentImage.Children.Add(f) |> ignore
224 f
225
226 currentCanvas <- currentCanvas + 1
227
228 Canvas.SetLeft(frame, rbc.center.X - rbc.size.Width / 2.)
229 Canvas.SetTop(frame, rbc.center.Y - rbc.size.Height / 2.)
230
231 for i in currentCanvas .. canvasCurrentImage.Children.Count - 1 do
232 canvasCurrentImage.Children.[i].Visibility <- Visibility.Hidden
233 | _ -> ()
234
235 let saveCurrentDocument () =
236 if state.FilePath = ""
237 then
238 let dialog = SaveFileDialog(AddExtension = true, DefaultExt = PiaZ.extension, Filter = PiaZ.filter);
239 let res = dialog.ShowDialog()
240 if res.HasValue && res.Value
241 then
242 state.FilePath <- dialog.FileName
243 state.Save()
244 else
245 state.Save()
246
247 // Ask the use to save the current document if neccessary.
248 let askSaveCurrent () =
249 if state.AlteredSinceLastSave
250 then
251 match MessageBox.Show("Would you like to save the current document?", "Saving the current document", MessageBoxButton.YesNo, MessageBoxImage.Question) with
252 | MessageBoxResult.Yes -> saveCurrentDocument ()
253 | _ -> ()
254
255 let updateCurrentImage () =
256 match state.CurrentImage with
257 | Some srcImg ->
258 // Highlight the preview.
259 stackPreviews.Children
260 |> Seq.cast<Views.ImageSourcePreview>
261 |> Seq.iter (fun preview -> preview.border.BorderThickness <- Thickness(if preview.Tag = (srcImg :> Object) then 3. else 0.))
262
263 canvasCurrentImage.Height <- float srcImg.img.Height
264 canvasCurrentImage.Width <- float srcImg.img.Width
265 canvasCurrentImage.Background <- ImageBrush(BitmapSourceConvert.ToBitmapSource(srcImg.img))
266
267 updateRBCFramesCurrent ()
268 updateRBCFramesPreview ()
269 updateCurrentImageInformation ()
270 | None ->
271 stackRBC.Children.Clear()
272 canvasCurrentImage.Children.Clear()
273 canvasCurrentImage.Background <- Brushes.Black
274
275 let setCurrentImage (srcImg: SourceImage) =
276 if state.CurrentImage.IsNone || state.CurrentImage.Value <> srcImg
277 then
278 state.CurrentImage <- Some srcImg
279 updateCurrentImage ()
280
281 let addPreview (srcImg: SourceImage) =
282 let imgCtrl = Views.ImageSourcePreview(Margin = Thickness(3.))
283
284 imgCtrl.menuRemoveImage.Click.AddHandler(fun obj args ->
285 stackPreviews.Children.Remove(imgCtrl)
286 let srcImg = imgCtrl.Tag :?> SourceImage
287 let currentRemoved = Some srcImg = state.CurrentImage
288 state.RemoveSourceImage srcImg
289 if currentRemoved
290 then
291 updateCurrentImage()
292 stackPreviews.Children |> Seq.cast<Views.ImageSourcePreview> |> Seq.iter (fun imgPreview -> imgPreview.txtImageNumber.Text <- (imgPreview.Tag :?> SourceImage).num.ToString()))
293
294 imgCtrl.Tag <- srcImg
295 imgCtrl.txtImageNumber.Text <- srcImg.num.ToString()
296 let width = 200
297 let height = srcImg.img.Height * width / srcImg.img.Width
298 imgCtrl.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource(srcImg.img.Resize(width, height, Emgu.CV.CvEnum.Inter.Cubic))
299 stackPreviews.Children.Add(imgCtrl) |> ignore
300
301 // Zoom to a mouse position into the control 'imgCtrl'.
302 let zoomTo (mousePos: Point) =
303 let canvasW = canvasCurrentImage.ActualWidth * currentScale
304 let canvasH = canvasCurrentImage.ActualHeight * currentScale
305 let centerX = (mousePos.X - imgCtrl.BorderThickness.Left) / (imgCtrl.ActualWidth - imgCtrl.BorderThickness.Left) * canvasW
306 let centerY = (mousePos.Y - imgCtrl.BorderThickness.Top) / (imgCtrl.ActualHeight - imgCtrl.BorderThickness.Top) * canvasH
307 scrollViewCurrentImage.ScrollToHorizontalOffset(centerX - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left)
308 scrollViewCurrentImage.ScrollToVerticalOffset(centerY - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top)
309
310 imgCtrl.MouseLeftButtonDown.AddHandler(fun obj args ->
311 setCurrentImage (state.SourceImages |> Seq.find (fun srcImg -> (srcImg :> Object) = imgCtrl.Tag))
312 imgCtrl.UpdateLayout()
313 zoomTo (args.GetPosition(imgCtrl))
314 imgCtrl.CaptureMouse() |> ignore)
315
316 imgCtrl.MouseMove.AddHandler(fun obj args ->
317 if imgCtrl.IsMouseCaptured
318 then
319 zoomTo (args.GetPosition(imgCtrl)))
320
321 imgCtrl.MouseLeftButtonUp.AddHandler(fun obj args ->
322 if imgCtrl.IsMouseCaptured
323 then
324 imgCtrl.ReleaseMouseCapture())
325
326 let updatePreviews () =
327 stackPreviews.Children.Clear ()
328 for srcImg in state.SourceImages do
329 addPreview srcImg
330 updateCurrentImage ()
331
332 let updateGUI () =
333 txtPatient.Text <- state.PatientID
334 updatePreviews ()
335 updateGlobalParasitemia ()
336
337 txtPatient.LostFocus.AddHandler(fun obj args -> state.PatientID <- txtPatient.Text)
338
339 menuExit.Click.AddHandler(fun obj args ->
340 askSaveCurrent ()
341 mainWindow.Root.Close())
342
343 menuSaveFile.Click.AddHandler(fun obj args -> saveCurrentDocument ())
344
345 menuLoadFile.Click.AddHandler(fun obj args ->
346 // TODO: if current state not saved and not empty, ask to save it.
347 let dialog = OpenFileDialog(Filter = PiaZ.filter)
348 let res = dialog.ShowDialog()
349 if res.HasValue && res.Value
350 then
351 askSaveCurrent ()
352 state.FilePath <- dialog.FileName
353 state.Load()
354 updateGUI ())
355
356 menuNewFile.Click.AddHandler(fun obj args ->
357 askSaveCurrent ()
358 state.Reset()
359 updateGUI())
360
361 menuAddSourceImage.Click.AddHandler(fun obj args ->
362 let dialog = OpenFileDialog(Filter = "Image Files|*.png;*.jpg;*.tif;*.tiff")
363 let res = dialog.ShowDialog()
364 if res.HasValue && res.Value
365 then
366 let srcImg = state.AddSourceImage dialog.FileName defaultConfig
367 addPreview srcImg
368 updateGlobalParasitemia ()
369 if state.SourceImages.Count() = 1
370 then
371 updateCurrentImage ())
372
373 menuStartAnalysis.Click.AddHandler(fun obj args ->
374 if Analysis.showWindow mainWindow.Root state
375 then
376 updateGlobalParasitemia ()
377 updateCurrentImage ())
378
379 menuHightlightRBC.Click.AddHandler(fun obj args ->
380 displayHealthy <- menuHightlightRBC.IsChecked
381 updateRBCFramesPreview ()
382 updateRBCFramesCurrent ())
383
384 // Zoom on the current image.
385 let adjustCurrentImageBorders (deltaX: float) (deltaY: float) =
386 borderCurrentImage.BorderThickness <-
387 Thickness(
388 (scrollViewCurrentImage.ViewportWidth + deltaX) / 2.,
389 (scrollViewCurrentImage.ViewportHeight + deltaY) / 2.,
390 (scrollViewCurrentImage.ViewportWidth + deltaX) / 2.,
391 (scrollViewCurrentImage.ViewportHeight + deltaY) / 2.)
392
393 canvasCurrentImage.SizeChanged.AddHandler(fun obj args ->
394 let deltaX = args.NewSize.Width - args.PreviousSize.Width
395 let deltaY = args.NewSize.Height - args.PreviousSize.Height
396 if deltaX > 0.5 || deltaY > 0.5
397 then
398 adjustCurrentImageBorders 0.0 0.0
399 // Center the view at the center of the image initialy.
400 scrollViewCurrentImage.UpdateLayout()
401 scrollViewCurrentImage.ScrollToHorizontalOffset(borderCurrentImage.ActualWidth / 2. - scrollViewCurrentImage.ViewportWidth / 2.)
402 scrollViewCurrentImage.ScrollToVerticalOffset(borderCurrentImage.ActualHeight / 2. - scrollViewCurrentImage.ViewportHeight / 2.))
403
404 scrollViewCurrentImage.SizeChanged.AddHandler(fun obj args ->
405 let deltaX = args.NewSize.Width - args.PreviousSize.Width
406 let deltaY = args.NewSize.Height - args.PreviousSize.Height
407 adjustCurrentImageBorders deltaX deltaY
408 scrollViewCurrentImage.ScrollToHorizontalOffset(scrollViewCurrentImage.HorizontalOffset + deltaX / 8.)
409 scrollViewCurrentImage.ScrollToVerticalOffset(scrollViewCurrentImage.VerticalOffset + deltaY / 8.))
410
411 let mutable maxScale = 4.
412 let mutable minScale = 0.25
413 let currentImageScaleTransform = ScaleTransform()
414 canvasCurrentImage.LayoutTransform <- currentImageScaleTransform
415 borderCurrentImage.PreviewMouseWheel.AddHandler(fun obj args ->
416 let scaleFactor = if args.Delta > 0 then 2.0 else 0.5
417 if scaleFactor > 1. && currentScale < maxScale || scaleFactor < 1. && currentScale > minScale
418 then
419 let previousScale = currentScale
420 currentScale <-
421 let newScale = currentScale * scaleFactor
422 if newScale > maxScale then maxScale elif newScale < minScale then minScale else newScale
423 let realScaleFactor = currentScale / previousScale
424
425 let centerX = scrollViewCurrentImage.HorizontalOffset + scrollViewCurrentImage.ViewportWidth / 2. - borderCurrentImage.BorderThickness.Left
426 let centerY = scrollViewCurrentImage.VerticalOffset + scrollViewCurrentImage.ViewportHeight / 2. - borderCurrentImage.BorderThickness.Top
427
428 currentImageScaleTransform.ScaleX <- currentScale
429 currentImageScaleTransform.ScaleY <- currentScale
430
431 scrollViewCurrentImage.ScrollToHorizontalOffset(centerX * realScaleFactor - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left)
432 scrollViewCurrentImage.ScrollToVerticalOffset(centerY * realScaleFactor - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top)
433
434 args.Handled <- true)
435
436 // Pan on the current image.
437 let mutable scrollStartPosition = Point(0., 0.)
438 let mutable scrollStartOffsetX = 0.
439 let mutable scrollStartOffsetY = 0.
440 borderCurrentImage.PreviewMouseLeftButtonDown.AddHandler(fun obj args ->
441 scrollStartPosition <- args.GetPosition(scrollViewCurrentImage)
442 scrollStartOffsetX <- scrollViewCurrentImage.HorizontalOffset
443 scrollStartOffsetY <- scrollViewCurrentImage.VerticalOffset
444 borderCurrentImage.Cursor <- Input.Cursors.ScrollAll
445 borderCurrentImage.CaptureMouse() |> ignore
446 args.Handled <- true)
447
448 borderCurrentImage.PreviewMouseMove.AddHandler(fun obj args ->
449 if borderCurrentImage.IsMouseCaptured
450 then
451 let position = args.GetPosition(scrollViewCurrentImage)
452 let deltaX = scrollStartPosition.X - position.X
453 let deltaY = scrollStartPosition.Y - position.Y
454 scrollViewCurrentImage.ScrollToHorizontalOffset(deltaX + scrollStartOffsetX)
455 scrollViewCurrentImage.ScrollToVerticalOffset(deltaY + scrollStartOffsetY)
456
457 args.Handled <- true)
458
459 borderCurrentImage.PreviewMouseLeftButtonUp.AddHandler(fun obj args ->
460 if borderCurrentImage.IsMouseCaptured
461 then
462 borderCurrentImage.Cursor <- Input.Cursors.Arrow
463 borderCurrentImage.ReleaseMouseCapture()
464 args.Handled <- true)
465
466 // Viewport preview.
467 scrollViewCurrentImage.ScrollChanged.AddHandler(fun obj args -> updateViewportPreview ())
468
469 mainWindow.Root.Show()
470 app.Run()