BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
ImageView.ScrollBars.cs
Go to the documentation of this file.
1using AForge;
2using BioLib;
3
4namespace BioImager
5{
6 public partial class ImageView
7 {
8 // Normalized positions avoid integer overflow at high slide magnifications.
9 private const int ScrollRange = 1_000_000;
10 private bool updatingScrollBars;
11 private double scrollLeft, scrollTop, scrollWidth, scrollHeight;
12
13 private void UpdateScrollBars()
14 {
15 if (updatingScrollBars || hScrollBar == null || vScrollBar == null || viewpanel == null)
16 return;
17 BioImage image = OverviewSelectedImage;
18 if (image == null || !image.isPyramidal || image.Resolution <= 0 ||
19 !double.IsFinite(image.Resolution) || ViewWidth <= 0 || ViewHeight <= 0)
20 return;
21
22 RectangleD bounds = OverviewWorldBounds(image);
23 double left = bounds.X;
24 double top = bounds.Y;
25 double width = bounds.W / image.Resolution;
26 double height = bounds.H / image.Resolution;
27 if (!double.IsFinite(left) || !double.IsFinite(top) || !double.IsFinite(width) ||
28 !double.IsFinite(height) || width <= 0 || height <= 0)
29 return;
30
31 scrollLeft = left;
32 scrollTop = top;
33 scrollWidth = Math.Max(0, bounds.W - ViewWidth * image.Resolution);
34 scrollHeight = Math.Max(0, bounds.H - ViewHeight * image.Resolution);
35 updatingScrollBars = true;
36 try
37 {
38 ConfigureScrollBar(hScrollBar, image.PyramidalOrigin.X, left, scrollWidth, width, ViewWidth);
39 ConfigureScrollBar(vScrollBar, image.PyramidalOrigin.Y, top, scrollHeight, height, ViewHeight);
40 }
41 finally
42 {
43 updatingScrollBars = false;
44 }
45 }
46
47 private static void ConfigureScrollBar(ScrollBar bar, double position, double start,
48 double travel, double imageSize, int viewSize)
49 {
50 int page = (int)Math.Clamp(Math.Round(ScrollRange * Math.Min(1, viewSize / imageSize)), 1, ScrollRange);
51 bar.Minimum = 0;
52 bar.Maximum = ScrollRange;
53 bar.LargeChange = page;
54 bar.SmallChange = Math.Max(1, page / 10);
55 int effectiveMaximum = bar.Maximum - bar.LargeChange + 1;
56 bar.Enabled = travel > 0;
57 double fraction = travel > 0 ? Math.Clamp((position - start) / travel, 0, 1) : 0;
58 bar.Value = (int)Math.Round(fraction * effectiveMaximum);
59 }
60
61 private void vScrollBar_ValueChanged(object sender, EventArgs e)
62 {
63 BioImage image = OverviewSelectedImage;
64 if (updatingScrollBars || image == null || !image.isPyramidal)
65 return;
66 App.viewer = this;
67 PointD origin = image.PyramidalOrigin;
68 if (sender == hScrollBar && scrollWidth > 0)
69 origin.X = scrollLeft + scrollWidth * hScrollBar.Value / (hScrollBar.Maximum - hScrollBar.LargeChange + 1.0);
70 else if (sender == vScrollBar && scrollHeight > 0)
71 origin.Y = scrollTop + scrollHeight * vScrollBar.Value / (vScrollBar.Maximum - vScrollBar.LargeChange + 1.0);
72 else
73 return;
74 image.PyramidalOrigin = origin;
75 UpdateView();
76 }
77 }
78}
AForge.RectangleD RectangleD
AForge.PointD PointD
BioLib.BioImage BioImage
Definition TabsView.cs:15
ImageView control for image stacks, pyramidal and whole-slide-images.
void UpdateView(bool refreshImages=true)