2using AForge.Imaging.Filters;
7using OpenTK.Mathematics;
8using OpenTK.Windowing.Common;
9using OpenTK.Windowing.Desktop;
10using OpenTK.Windowing.GraphicsLibraryFramework;
12using System.ComponentModel;
13using System.Runtime.InteropServices;
15using Image = System.Drawing.Image;
16using Keys = System.Windows.Forms.Keys;
26 public partial class ImageView : UserControl, IDisposable
29 SlideGLArea gl =
new SlideGLArea();
30 SlideRenderer slideRenderer;
32 public ImageView(BioImage im,
bool OpenWithOpenSlide =
true)
34 string file = im.ID.Replace(
"\\",
"/");
35 InitializeComponent();
40 gl.Size =
new System.Drawing.Size(800, 600);
41 if (im.openSlideImage !=
null && OpenWithOpenSlide)
44 Initialize(im.file, im);
47 Initialize(im.file, im);
48 hScrollBar.Visible =
true;
49 vScrollBar.Visible =
true;
53 hScrollBar.Visible =
false;
54 vScrollBar.Visible =
false;
57 Tools.selectBoxSize = ROI.selectBoxSize;
60 if (im.SlideBase !=
null && im.isPyramidal &&
OpenSlide)
63 Dock = DockStyle.Fill;
66 if (file ==
"" || file ==
null)
72 zBar.Value = Math.Clamp(im.Coordinate.Z, zBar.Minimum, zBar.Maximum);
73 cBar.Value = Math.Clamp(im.Coordinate.C, cBar.Minimum, cBar.Maximum);
74 tBar.Value = Math.Clamp(im.Coordinate.T, tBar.Minimum, tBar.Maximum);
76 MouseWheel +=
new System.Windows.Forms.MouseEventHandler(ImageView_MouseWheel);
77 zBar.MouseWheel +=
new System.Windows.Forms.MouseEventHandler(ZTrackBar_MouseWheel);
78 cBar.MouseWheel +=
new System.Windows.Forms.MouseEventHandler(CTrackBar_MouseWheel);
79 tBar.MouseWheel +=
new System.Windows.Forms.MouseEventHandler(TimeTrackBar_MouseWheel);
81 zBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled =
true;
82 tBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled =
true;
83 cBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled =
true;
84 this.SizeChanged += ImageView_SizeChanged;
91 resolutions = im.Resolutions;
95 if (im.OpenSlideBase !=
null)
97 slideRenderer.SetSource(im.OpenSlideBase);
99 else if (im.SlideBase !=
null)
101 slideRenderer.SetSource(im.SlideBase);
111 Initialize(im.ID, im);
116 InitializeComponent();
117 InitializeViewport();
119 Dock = DockStyle.Fill;
123 gl.Paint += Gl_Paint;
125 MouseWheel +=
new System.Windows.Forms.MouseEventHandler(ImageView_MouseWheel);
126 zBar.MouseWheel +=
new System.Windows.Forms.MouseEventHandler(ZTrackBar_MouseWheel);
127 cBar.MouseWheel +=
new System.Windows.Forms.MouseEventHandler(CTrackBar_MouseWheel);
128 tBar.MouseWheel +=
new System.Windows.Forms.MouseEventHandler(TimeTrackBar_MouseWheel);
129 this.SizeChanged += ImageView_SizeChanged;
131 zBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled =
true;
132 tBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled =
true;
133 cBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled =
true;
143 private void InitializeViewport()
145 gl.Dock = DockStyle.Fill;
147 gl.ContextMenuStrip = contextMenuStrip;
148 viewport.ContextMenuStrip = contextMenuStrip;
149 contextMenuStrip.Opening += contextMenuStrip_Opening;
150 viewport.Controls.Add(gl);
151 viewpanel.BringToFront();
152 InitializeOverview();
154 foreach (System.Windows.Forms.Control surface in
new System.Windows.Forms.Control[] { viewpanel, gl })
156 surface.MouseDown += pictureBox_MouseDown;
157 surface.MouseMove += rgbPictureBox_MouseMove;
158 surface.MouseUp += pictureBox_MouseUp;
159 surface.MouseWheel += ImageView_MouseWheel;
163 private void UpdateImageSurface()
166 gl.Visible = pyramidal;
167 viewpanel.Visible = !pyramidal;
171 viewpanel.BringToFront();
172 UpdateOverviewVisibility();
175 private void InvalidateView()
177 UpdateOverviewVisibility();
178 overviewPanel.Invalidate();
183 viewpanel.Invalidate();
186 protected override void OnLayout(LayoutEventArgs e)
189 if (viewport ==
null || statusPanel ==
null || trackBarPanel ==
null ||
190 hScrollBar ==
null || vScrollBar ==
null)
193 int top = statusPanel.Visible ? statusPanel.Bottom : 0;
194 int bottom = trackBarPanel.Visible ? trackBarPanel.Top : ClientSize.Height;
195 int width = Math.Max(0, ClientSize.Width - (vScrollBar.Visible ? vScrollBar.Width : 0));
196 int height = Math.Max(0, bottom - top - (hScrollBar.Visible ? hScrollBar.Height : 0));
199 viewport.Bounds =
new System.Drawing.Rectangle(0, top, width, height);
200 hScrollBar.SetBounds(0, top + height, width, hScrollBar.Height);
201 vScrollBar.SetBounds(width, top, vScrollBar.Width, height);
207 const int WM_KEYDOWN = 0x0100;
208 const int WM_KEYUP = 0x0101;
209 const int WM_CHAR = 0x0102;
222 char ch = (char)msg.WParam;
227 return base.ProcessCmdKey(ref msg, keyData);
230 private void ImageView_SizeChanged(
object? sender, EventArgs e)
234 SelectedImage.PyramidalSize =
new AForge.Size(gl.Width, gl.Height);
237 private void InitGL()
239 var gameWindowSettings =
new GameWindowSettings()
241 UpdateFrequency = 60,
243 NativeWindowSettings nativeSettings;
245 nativeSettings =
new NativeWindowSettings()
247 ClientSize =
new Vector2i(Width, Height),
248 Location =
new Vector2i(0, 0),
249 Title =
"OpenGL Context",
250 StartVisible =
false,
251 API = ContextAPI.OpenGL,
252 Profile = ContextProfile.Core,
253 APIVersion =
new Version(3, 3)
255 window =
new GLWindow(gameWindowSettings, nativeSettings);
256 GLFWProvider.SetErrorCallback((error, description) =>
258 Console.WriteLine($
"BioImager GLFW Error {error}: {description}");
262 private void Gl_Paint(
object? sender, PaintEventArgs e)
283 public Layer(
double d,
bool enabled)
290 public List<Layer>
Layers =
new List<Layer>();
292 private bool IsLayerEnabled(
double d)
301 List<System.Drawing.Bitmap> Bitmaps =
new List<System.Drawing.Bitmap>();
302 List<Resolution> resolutions =
new List<Resolution>();
304 private static int selectedIndex = 0;
338 public static bool up;
346 private bool x1State =
false;
347 private bool x2State =
false;
355 private bool update =
false;
356 private bool updateOverlay =
false;
357 private List<BioImage> imgs =
new List<BioImage>();
370 private void Render(System.Drawing.Graphics canvas)
378 foreach (BioImage im
in Images)
380 List<ROI> rois =
new List<ROI>();
381 rois.AddRange(im.Annotations);
384 canvas.TranslateTransform((
float)gl.Width / 2f, (
float)gl.Height / 2f);
385 RectangleD rp =
ToScreenSpace(
new RectangleD(im.StageSizeX * im.PhysicalSizeX, im.StageSizeX * im.PhysicalSizeY, im.SizeX * im.PhysicalSizeX, im.SizeY * im.PhysicalSizeY));
388 canvas.DrawImage(Bitmaps[i],
new System.Drawing.PointF((
float)rp.X, (
float)rp.Y));
391 System.Drawing.Rectangle rf =
new System.Drawing.Rectangle((
int)canvas.Clip.GetBounds(canvas).X, (
int)canvas.Clip.GetBounds(canvas).Y,
392 (
int)canvas.Clip.GetBounds(canvas).Width, (
int)canvas.Clip.GetBounds(canvas).Height);
399 Console.WriteLine($
"Annotation render error: {ex.Message}");
404 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
410 if (value >= 0 &&
Images.Count > 0)
413 selectedIndex = field;
426 private AForge.Rectangle overview;
429 get {
return overview; }
431 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
433 private double pxWmicron = 0.004;
434 private double pxHmicron = 0.004;
435 AForge.SizeF scale =
new AForge.SizeF(1, 1);
445 System.Threading.Tasks.Task.Run(() =>
449 App.
viewer.Invoke((MethodInvoker)delegate
454 zBar.Value = zBar.Maximum;
456 cBar.Value = cBar.Maximum;
458 tBar.Value = tBar.Maximum;
466 Console.WriteLine(e.Message);
487 ZarrChannelView.InitializeChannels(im);
494 foreach (var item
in Layers)
496 if (item.Resolution == im.PhysicalSizeX)
503 hScrollBar.Visible =
true;
504 vScrollBar.Visible =
true;
509 hScrollBar.Visible =
false;
510 vScrollBar.Visible =
false;
513 Tools.selectBoxSize = ROI.selectBoxSize;
515 Initialize(im.ID, im);
521 private bool showControls =
true;
523 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
526 get {
return trackBarPanel.Visible; }
529 showControls = value;
532 trackBarPanel.Hide();
543 hideControlsToolStripMenuItem1.Text =
"Show Controls";
547 trackBarPanel.Show();
560 hideControlsToolStripMenuItem1.Text =
"Hide Controls";
566 private bool showStatus =
true;
568 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
571 get {
return showStatus; }
580 showControlsToolStripMenuItem.Visible =
true;
581 hideControlsToolStripMenuItem.Text =
"Show Status";
586 statusPanel.Visible = value;
588 showControlsToolStripMenuItem.Visible =
false;
589 hideControlsToolStripMenuItem.Text =
"Hide Status";
597 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
612 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
633 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
654 rgbBoxsPanel.BringToFront();
662 rgbBoxsPanel.SendToBack();
664 cLabel.BringToFront();
670 rgbBoxsPanel.SendToBack();
672 cLabel.BringToFront();
678 rgbBoxsPanel.BringToFront();
717 PointD origin =
new PointD(0, 0);
718 bool hardwareAcceleration =
true;
719 bool openSlide =
false;
722 get {
return openSlide; }
730 return viewport.ClientSize.Width;
737 return viewport.ClientSize.Height;
741 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
744 get {
return origin; }
753 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
759 return new PointD(0, 0);
764 SelectedImage.PyramidalOrigin = value;
768 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
781 SelectedImage.Resolution = value;
783 SelectedImage.Level = (int)value;
803 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
818 Tools.selectBoxSize = (float)(ROI.selectBoxSize *
Resolution);
821 Tools.selectBoxSize = ROI.selectBoxSize;
829 return contextMenuStrip;
836 private readonly
bool[] rgbEnabled = {
true,
true,
true };
837 private bool initializingRgbSelectors;
838 private BioImage rgbSelectorImage;
840 private int[] SelectedRgbChannels(BioImage image) => Enumerable.Range(0, 3)
841 .Select(i => rgbEnabled[i] ? image.rgbChannels[i] : -1).ToArray();
846 System.Windows.Forms.ComboBox[] boxes = { channelBoxR, channelBoxG, channelBoxB };
847 for (
int i = 0; i < boxes.Length; i++)
849 rgbEnabled[i] = boxes[i].SelectedIndex > 0;
850 if (rgbEnabled[i])
SelectedImage.rgbChannels[i] = boxes[i].SelectedIndex - 1;
853 private bool timeEnabled =
false;
856 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
867 zTimer.Interval = (int)Math.Floor(1000 / f);
872 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
883 timelineTimer.Interval = (int)Math.Floor(1000 / f);
888 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
899 cTimer.Interval = (int)Math.Floor(1000 / f);
909 zBar.Maximum = SelectedImage.SizeZ - 1;
913 cBar.Maximum = SelectedImage.SizeC - 1;
916 tBar.Maximum = SelectedImage.SizeT - 1;
921 tBar.Enabled =
false;
923 tBar.Maximum = SelectedImage.SizeT - 1;
927 bool sameImage = ReferenceEquals(rgbSelectorImage,
SelectedImage);
929 bool[] previousEnabled = (
bool[])rgbEnabled.Clone();
930 int[] previousChannels = (
int[])
SelectedImage.rgbChannels.Clone();
931 initializingRgbSelectors =
true;
932 channelBoxR.Items.Clear();
933 channelBoxG.Items.Clear();
934 channelBoxB.Items.Clear();
936 channelBoxR.Items.Add(
"");
937 channelBoxG.Items.Add(
"");
938 channelBoxB.Items.Add(
"");
941 channelBoxR.Items.Add(ch);
942 channelBoxG.Items.Add(ch);
943 channelBoxB.Items.Add(ch);
945 System.Windows.Forms.ComboBox[] rgbBoxes = { channelBoxR, channelBoxG, channelBoxB };
947 for (
int i = 0; i < rgbBoxes.Length; i++)
948 rgbBoxes[i].
SelectedIndex = count == 0 || (sameImage && !previousEnabled[i]) ? 0 :
949 (sameImage ? Math.Clamp(previousChannels[i], 0, count - 1) : (i < count ? i : 0)) + 1;
950 initializingRgbSelectors =
false;
961 ROI.selectBoxSize = size;
969 updateOverlay =
true;
984 res = $
"Res.:{Resolution:G4} Level:{Level}";
986 string origin = $
"({-Origin.X:0.##}, {-Origin.Y:0.##})";
987 string location = $
"({SelectedImage.Volume.Location.X:0.##}, {SelectedImage.Volume.Location.Y:0.##})";
992 statusLabel.Text = (zBar.Value + 1) +
"/" + (zBar.Maximum + 1) +
", " + (tBar.Value + 1) +
"/" + (tBar.Maximum + 1) +
", " +
993 mousePoint + mouseColor +
", " +
SelectedImage.Buffers[0].PixelFormat.ToString() +
", " + origin +
", " + location +
" " + res;
997 statusLabel.Text = (zBar.Value + 1) +
"/" + (cBar.Maximum + 1) +
", " + mousePoint + mouseColor +
", " +
SelectedImage.Buffers[0].PixelFormat.ToString()
998 +
", " + origin +
", " + location +
" " + res;
1006 statusLabel.Text = (zBar.Value + 1) +
"/" + (zBar.Maximum + 1) +
", " + (cBar.Value + 1) +
"/" + (cBar.Maximum + 1) +
", " + (tBar.Value + 1) +
"/" + (tBar.Maximum + 1) +
", " +
1007 mousePoint + mouseColor +
", " +
SelectedImage.Buffers[0].PixelFormat.ToString() +
", " + origin +
", " + location +
" " + res;
1011 statusLabel.Text = (zBar.Value + 1) +
"/" + (zBar.Maximum + 1) +
", " + (cBar.Value + 1) +
"/" + (cBar.Maximum + 1) +
", " + mousePoint + mouseColor +
", " +
1012 SelectedImage.Buffers[0].PixelFormat.ToString() +
", " + origin +
", " + location +
" " + res;
1022 UpdateImageSurface();
1299 bool updating =
false;
1304 private int zarrRgbRequest;
1310 UpdateImageSurface();
1314 if (!updatePyramidal || gl.Width <= 1 || gl.Height <= 1)
1318 SelectedImage.PyramidalSize =
new AForge.Size(gl.Width, gl.Height);
1321 if (slideRenderer ==
null)
1327 BioImage? directZarr =
null;
1328 int[]? directZarrChannels =
null;
1345 directZarrChannels =
new[] { channel, channel, channel };
1349 await slideRenderer.UpdateViewAsync(
1359 catch (Exception ex)
1361 System.Diagnostics.Trace.WriteLine($
"Could not update slide view: {ex}");
1372 var requestedMode =
Mode;
1373 int request = ++zarrRgbRequest;
1374 int width = image.Buffers[0].SizeX, height = image.Buffers[0].SizeY;
1378 if (requestedMode ==
ViewMode.RGBImage)
1380 channels = SelectedRgbChannels(image);
1385 Math.Max(0, image.SizeC - 1));
1386 channels =
new[] { channel, channel, channel };
1389 byte[] rgba = await ZarrChannelView.ReadRgbTileAsync(image, 0, 0, 0, width, height,
1391 if (request != zarrRgbRequest ||
SelectedImage != image ||
Mode != requestedMode)
1393 var frame =
new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
1394 var data = frame.LockBits(
new System.Drawing.Rectangle(0, 0, width, height),
1395 System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
1398 for (
int i = 0; i < rgba.Length; i += 4)
1399 (rgba[i], rgba[i + 2]) = (rgba[i + 2], rgba[i]);
1400 for (
int row = 0; row < height; row++)
1401 Marshal.Copy(rgba, row * width * 4, IntPtr.Add(data.Scan0, row * data.Stride), width * 4);
1403 finally { frame.UnlockBits(data); }
1404 foreach (var old
in Bitmaps) old?.Dispose();
1410 catch (Exception ex)
1412 System.Diagnostics.Trace.WriteLine($
"Could not render Zarr RGB channels: {ex.Message}");
1419 foreach (BioImage image
in Images)
1421 int index = image.GetFrameIndex(zBar.Value, cBar.Value, tBar.Value);
1422 bool unavailable = index < 0 || index >= image.Buffers.Count;
1425 var buffers =
Mode == ViewMode.Filtered ||
Mode == ViewMode.Raw
1426 ?
new[] { image.Buffers[index] }
1427 : image.Buffers.AsEnumerable();
1428 unavailable = buffers.Any(buffer =>
1429 buffer ==
null || buffer.Bytes ==
null || buffer.Bytes.Length == 0);
1433 System.Diagnostics.Trace.WriteLine($
"Image pixels are unavailable: {image.ID}");
1437 for (
int i = 0; i < Bitmaps.Count; i++)
1439 Bitmaps[i].Dispose();
1449 foreach (BioImage b
in Images)
1454 b.PyramidalSize =
new AForge.Size(gl.Width, gl.Height);
1455 ZCT coords =
new ZCT(zBar.Value, cBar.Value, tBar.Value);
1456 Bitmap bitmap =
null;
1458 int index = b.Coords[zBar.Value, cBar.Value, tBar.Value];
1461 bitmap = b.GetFiltered(coords, b.RChannel.RangeR, b.GChannel.RangeG, b.BChannel.RangeB);
1465 if (b.Buffers[0].RGBChannelsCount == 1)
1467 var planes =
new Bitmap[3];
1468 for (
int color = 0; color < 3; color++)
1470 int channel = Math.Clamp(b.rgbChannels[color], 0, b.SizeC - 1);
1471 planes[2 - color] = b.Buffers[b.GetFrameIndex(coords.Z, channel, coords.T)];
1473 bitmap = Bitmap.GetRGBBitmap(planes, b.RChannel.RangeR, b.GChannel.RangeG, b.BChannel.RangeB);
1476 bitmap = b.GetRGBBitmap(coords, b.RChannel.RangeR, b.GChannel.RangeG, b.BChannel.RangeB);
1480 bitmap = (Bitmap)b.Buffers[index].GetImageRGBA();
1484 bitmap = b.GetEmission(coords, b.RChannel.RangeR, b.GChannel.RangeG, b.BChannel.RangeB);
1486 var display = ToSysBitmap(bitmap);
1488 MaskRgbComponents(display, rgbEnabled);
1489 Bitmaps.Add(display);
1492 UpdateRegularOverview();
1496 bool drawing =
false;
1501 System.Threading.Thread.Sleep(50);
1503 }
while (drawing || updating);
1514 }
while (drawing || updating);
1515 for (
int i = 0; i <
Images.Count; i++)
1537 private void channelBoxR_SelectedIndexChanged(
object sender, EventArgs e)
1539 if (initializingRgbSelectors ||
SelectedImage ==
null || channelBoxR.SelectedIndex == -1)
1541 rgbEnabled[0] = channelBoxR.SelectedIndex > 0;
1542 if (rgbEnabled[0])
SelectedImage.rgbChannels[0] = channelBoxR.SelectedIndex - 1;
1553 private void channelBoxG_SelectedIndexChanged(
object sender, EventArgs e)
1555 if (initializingRgbSelectors ||
SelectedImage ==
null || channelBoxG.SelectedIndex == -1)
1557 rgbEnabled[1] = channelBoxG.SelectedIndex > 0;
1558 if (rgbEnabled[1])
SelectedImage.rgbChannels[1] = channelBoxG.SelectedIndex - 1;
1569 private void channelBoxB_SelectedIndexChanged(
object sender, EventArgs e)
1571 if (initializingRgbSelectors ||
SelectedImage ==
null || channelBoxB.SelectedIndex == -1)
1573 rgbEnabled[2] = channelBoxB.SelectedIndex > 0;
1574 if (rgbEnabled[2])
SelectedImage.rgbChannels[2] = channelBoxB.SelectedIndex - 1;
1585 private void showControlsToolStripMenuItem_Click(
object sender, EventArgs e)
1587 if (trackBarPanel.Visible)
1589 trackBarPanel.Hide();
1590 trackBarPanel.Height = 0;
1593 showControlsToolStripMenuItem.Text =
"Show Controls";
1594 gl.Dock = DockStyle.Fill;
1598 trackBarPanel.Show();
1601 trackBarPanel.Height = 75;
1602 showControlsToolStripMenuItem.Text =
"Hide Controls";
1603 gl.Dock = DockStyle.Fill;
1611 private void playZToolStripMenuItem_Click(
object sender, EventArgs e)
1613 if (playZToolStripMenuItem.Checked)
1616 playZToolStripMenuItem.Checked =
false;
1617 stopZToolStripMenuItem.Checked =
true;
1623 playZToolStripMenuItem.Checked =
true;
1624 stopZToolStripMenuItem.Checked =
false;
1632 private void stopZToolStripMenuItem_Click(
object sender, EventArgs e)
1634 if (stopZToolStripMenuItem.Checked)
1637 playZToolStripMenuItem.Checked =
true;
1638 stopZToolStripMenuItem.Checked =
false;
1645 playZToolStripMenuItem.Checked =
false;
1646 stopZToolStripMenuItem.Checked =
true;
1654 private void playTimeToolStripMenu_Click(
object sender, EventArgs e)
1656 if (playTimeToolStripMenu.Checked)
1659 playTimeToolStripMenu.Checked =
false;
1660 stopTimeToolStripMenu.Checked =
true;
1661 timelineTimer.Stop();
1666 playTimeToolStripMenu.Checked =
true;
1667 stopTimeToolStripMenu.Checked =
false;
1668 timelineTimer.Start();
1676 private void stopTimeToolStripMenu_Click(
object sender, EventArgs e)
1678 playTimeToolStripMenu.Checked =
false;
1679 stopTimeToolStripMenu.Checked =
true;
1680 timelineTimer.Stop();
1686 private void playCToolStripMenuItem_Click(
object sender, EventArgs e)
1688 if (playCToolStripMenuItem.Checked)
1691 playCToolStripMenuItem.Checked =
false;
1692 stopCToolStripMenuItem.Checked =
true;
1698 playCToolStripMenuItem.Checked =
true;
1699 stopCToolStripMenuItem.Checked =
false;
1708 private void stopCToolStripMenuItem_Click(
object sender, EventArgs e)
1710 stopCToolStripMenuItem.Checked =
false;
1711 playCToolStripMenuItem.Checked =
true;
1714 private string mousePoint =
"";
1715 private string mouseColor =
"";
1722 private void playSpeedToolStripMenuItem_Click(
object sender, EventArgs e)
1724 PlaySpeed sp =
null;
1729 if (sp.ShowDialog() != DialogResult.OK)
1731 zTimer.Interval = sp.TimePlayspeed;
1732 cTimer.Interval = sp.CPlayspeed;
1733 timelineTimer.Interval = sp.TimePlayspeed;
1741 private void playSpeedToolStripMenuItem1_Click(
object sender, EventArgs e)
1743 PlaySpeed sp =
null;
1748 if (sp.ShowDialog() != DialogResult.OK)
1750 zTimer.Interval = sp.TimePlayspeed;
1751 cTimer.Interval = sp.CPlayspeed;
1752 timelineTimer.Interval = sp.TimePlayspeed;
1761 private void CPlaySpeedToolStripMenuItem_Click(
object sender, EventArgs e)
1763 PlaySpeed sp =
null;
1768 if (sp.ShowDialog() != DialogResult.OK)
1770 zTimer.Interval = sp.TimePlayspeed;
1771 cTimer.Interval = sp.CPlayspeed;
1772 timelineTimer.Interval = sp.TimePlayspeed;
1797 t =
new RangeTool(timeEnabled,
true, zBar.Minimum, zBar.Maximum, tBar.Minimum, tBar.Maximum, cBar.Minimum, cBar.Maximum);
1799 t =
new RangeTool(timeEnabled,
false, zBar.Minimum, zBar.Maximum, tBar.Minimum, tBar.Maximum, cBar.Minimum, cBar.Maximum);
1800 if (t.ShowDialog() != DialogResult.OK)
1802 zBar.Minimum = t.
ZMin;
1803 zBar.Maximum = t.
ZMax;
1806 cBar.Minimum = t.
CMin;
1807 cBar.Maximum = t.
CMax;
1809 private void setValueRangeToolStripMenuItem_Click(
object sender, EventArgs e)
1813 private void setValueRangeToolStripMenuItem1_Click(
object sender, EventArgs e)
1817 private void setCValueRangeToolStripMenuItem_Click(
object sender, EventArgs e)
1825 private void ImageView_MouseWheel(
object sender, System.Windows.Forms.MouseEventArgs e)
1827 if (e is HandledMouseEventArgs handled && handled.Handled)
1829 var source = sender as System.Windows.Forms.Control ??
this;
1830 System.Drawing.Point cursor = source.Parent == viewport
1831 ?
new System.Drawing.Point(source.Left + e.X, source.Top + e.Y)
1832 : viewport.PointToClient(source.PointToScreen(e.Location));
1833 if (e.Delta == 0 || !viewport.ClientRectangle.Contains(cursor) ||
Images.Count == 0)
1837 Plugins.ScrollEvent(sender, e);
1838 if (e is HandledMouseEventArgs wheel)
1843 wheel.Handled =
true;
1846 const double minZoom = 0.000001;
1847 const double maxZoom = 1000000;
1848 double factor = Math.Pow(1.2, e.Delta / 120.0);
1856 Tools.selectBoxSize = (float)(ROI.selectBoxSize *
Resolution);
1862 factor = Math.Clamp(factor,
1863 minZoom / Math.Min(
Scale.Width,
Scale.Height),
1864 maxZoom / Math.Max(
Scale.Width,
Scale.Height));
1867 Origin =
new PointD(
Origin.X + shifted.X - anchor.X,
Origin.Y + shifted.Y - anchor.Y);
1876 private void ZTrackBar_MouseWheel(
object sender, System.Windows.Forms.MouseEventArgs e)
1880 if (zBar.Value + 1 <= zBar.Maximum)
1885 if (zBar.Value - 1 >= zBar.Minimum)
1897 private void TimeTrackBar_MouseWheel(
object sender, System.Windows.Forms.MouseEventArgs e)
1903 if (tBar.Value + 1 <= tBar.Maximum)
1908 if (tBar.Value - 1 >= tBar.Minimum)
1917 private void CTrackBar_MouseWheel(
object sender, System.Windows.Forms.MouseEventArgs e)
1921 if (cBar.Value + 1 <= cBar.Maximum)
1926 if (cBar.Value - 1 >= cBar.Minimum)
1937 private void cTimer_Tick(
object sender, EventArgs e)
1939 if (playCToolStripMenuItem.Checked)
1941 if (cBar.Maximum >= cBar.Value + 1)
1946 cBar.Value = cBar.Minimum;
1956 private void zTimer_Tick(
object sender, EventArgs e)
1958 if (playZToolStripMenuItem.Checked)
1960 if (zBar.Maximum >= zBar.Value + 1)
1965 zBar.Value = zBar.Minimum;
1976 private void timer_Tick(
object sender, EventArgs e)
1978 if (playTimeToolStripMenu.Checked)
1980 if (tBar.Maximum >= tBar.Value + 1)
1985 tBar.Value = tBar.Minimum;
1996 private void zBar_ValueChanged(
object sender, EventArgs e)
2011 private void timeBar_ValueChanged(
object sender, EventArgs e)
2027 private void cBar_ValueChanged(
object sender, EventArgs e)
2037 private void loopTimeToolStripMenuItem_Click(
object sender, EventArgs e)
2039 loopT = loopTimeToolStripMenuItem.Checked;
2041 private void loopZToolStripMenuItem_Click(
object sender, EventArgs e)
2043 loopZ = loopZToolStripMenuItem.Checked;
2045 private void loopCToolStripMenuItem_Click(
object sender, EventArgs e)
2047 loopC = loopCToolStripMenuItem.Checked;
2054 private List<ROI> annotationsR =
new List<ROI>();
2062 private List<ROI> annotationsG =
new List<ROI>();
2070 private List<ROI> annotationsB =
new List<ROI>();
2084 List<ROI> ans =
new List<ROI>();
2101 private System.Drawing.Point ToPoint(AForge.Point p)
2103 return new System.Drawing.Point((
int)p.X, (
int)p.Y);
2105 private System.Drawing.PointF ToPointF(PointD p)
2107 return new System.Drawing.PointF((
float)p.X, (
float)p.Y);
2114 private void DrawOverlay(System.Drawing.Graphics g)
2120 System.Drawing.Pen pen =
null;
2121 System.Drawing.Pen red =
null;
2122 System.Drawing.Pen green =
null;
2123 System.Drawing.Pen mag =
null;
2124 System.Drawing.Pen blue =
null;
2129 foreach (BioImage bi
in Images)
2131 if (!IsLayerEnabled(bi.PhysicalSizeX))
2133 foreach (ROI an
in bi.Annotations)
2144 else if (zBar.Value != an.coord.Z || cBar.Value != an.coord.C || tBar.Value != an.coord.T)
2146 float w = Math.Abs(
Scale.Width);
2147 pen =
new System.Drawing.Pen(
new SolidBrush(System.Drawing.Color.FromArgb(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B)), (
float)an.strokeWidth / w);
2148 red =
new System.Drawing.Pen(Brushes.Red, (
float)an.strokeWidth / w);
2149 mag =
new System.Drawing.Pen(Brushes.Magenta, (
float)an.strokeWidth / w);
2150 green =
new System.Drawing.Pen(Brushes.Green, (
float)an.strokeWidth / w);
2151 blue =
new System.Drawing.Pen(Brushes.Blue, (
float)an.strokeWidth / w);
2152 Font fo =
new Font(an.family, (
float)(an.strokeWidth / w) * an.fontSize);
2155 b =
new SolidBrush(System.Drawing.Color.Magenta);
2158 b =
new SolidBrush(System.Drawing.Color.FromArgb(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B));
2159 PointF pc =
new PointF((
float)(an.BoundingBox.X + (an.BoundingBox.W / 2)), (
float)(an.BoundingBox.Y + (an.BoundingBox.H / 2)));
2160 float width = (float)ToViewSizeW(ROI.selectBoxSize / w);
2163 width = (float)(ROI.selectBoxSize *
Resolution);
2165 if (an.type == ROI.Type.Point)
2168 foreach (var item
in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2170 g.DrawRectangle(red,
new System.Drawing.RectangleF((
float)item.X, (
float)item.Y, (
float)item.W, (
float)item.H));
2174 if (an.type == ROI.Type.Line)
2177 foreach (var item
in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2179 g.DrawRectangle(red,
new System.Drawing.RectangleF((
float)item.X, (
float)item.Y, (
float)item.W, (
float)item.H));
2183 if (an.type == ROI.Type.Rectangle && an.BoundingBox.W > 0 && an.BoundingBox.H > 0)
2185 g.DrawRectangle(pen,
new System.Drawing.RectangleF((
float)an.BoundingBox.X, (
float)an.BoundingBox.Y, (
float)an.W, (
float)an.H));
2186 foreach (var item
in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2188 g.DrawRectangle(red,
new System.Drawing.RectangleF((
float)item.X, (
float)item.Y, (
float)item.W, (
float)item.H));
2192 if (an.type == ROI.Type.Ellipse)
2195 g.DrawEllipse(pen, (
float)rec.X, (
float)rec.Y, (
float)rec.W, (
float)rec.H);
2196 foreach (var item
in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2198 g.DrawRectangle(red,
new System.Drawing.RectangleF((
float)item.X, (
float)item.Y, (
float)item.W, (
float)item.H));
2202 if (an.type == ROI.Type.Polygon && an.closed)
2204 if (an.Points.Count > 1)
2206 System.Drawing.Point[] pts =
new System.Drawing.Point[an.Points.Count];
2207 for (
int i = 0; i < an.Points.Count; i++)
2210 pts[i] =
new System.Drawing.Point((
int)p.X, (
int)p.Y);
2212 g.DrawLines(pen, pts);
2214 foreach (var item
in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2216 g.DrawRectangle(red,
new System.Drawing.RectangleF((
float)item.X, (
float)item.Y, (
float)item.W, (
float)item.H));
2220 if (an.type == ROI.Type.Polygon && !an.closed)
2222 if (an.Points.Count > 1)
2224 System.Drawing.Point[] pts =
new System.Drawing.Point[an.Points.Count - 1];
2225 for (
int i = 0; i < an.Points.Count - 1; i++)
2228 pts[i] =
new System.Drawing.Point((
int)p.X, (
int)p.Y);
2230 g.DrawLines(pen, pts);
2232 foreach (var item
in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2234 g.DrawRectangle(red,
new System.Drawing.RectangleF((
float)item.X, (
float)item.Y, (
float)item.W, (
float)item.H));
2238 if (an.type == ROI.Type.Polyline)
2240 if (an.Points.Count > 1)
2242 System.Drawing.Point[] pts =
new System.Drawing.Point[an.Points.Count - 1];
2243 for (
int i = 0; i < an.Points.Count - 1; i++)
2246 pts[i] =
new System.Drawing.Point((
int)p.X, (
int)p.Y);
2248 g.DrawLines(pen, pts);
2250 foreach (var item
in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2252 g.DrawRectangle(red,
new System.Drawing.RectangleF((
float)item.X, (
float)item.Y, (
float)item.W, (
float)item.H));
2257 if (an.type == ROI.Type.Freeform && an.closed)
2259 if (an.Points.Count > 1)
2261 System.Drawing.Point[] pts =
new System.Drawing.Point[an.Points.Count];
2262 for (
int i = 0; i < an.Points.Count; i++)
2265 pts[i] =
new System.Drawing.Point((
int)p.X, (
int)p.Y);
2267 g.DrawLines(pen, pts);
2271 if (an.type == ROI.Type.Freeform && !an.closed)
2273 if (an.Points.Count > 1)
2275 System.Drawing.Point[] pts =
new System.Drawing.Point[an.Points.Count - 1];
2276 for (
int i = 0; i < an.Points.Count - 1; i++)
2279 pts[i] =
new System.Drawing.Point((
int)p.X, (
int)p.Y);
2281 g.DrawLines(pen, pts);
2284 if (an.type == ROI.Type.Label)
2287 g.DrawString(an.Text, fo, b, (
float)v.X, (
float)v.Y);
2288 foreach (var item
in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2290 g.DrawRectangle(red,
new System.Drawing.RectangleF((
float)item.X, (
float)item.Y, (
float)item.W, (
float)item.H));
2295 System.Drawing.SizeF s = System.Windows.Forms.TextRenderer.MeasureText(an.Text,
new Font(an.family, an.fontSize));
2297 float fw = ((float)an.BoundingBox.X + ((float)an.BoundingBox.W / 2)) - ((
float)s.Width / 2);
2298 float fh = ((float)an.BoundingBox.Y + ((float)an.BoundingBox.H / 2)) - ((
float)s.Height / 2);
2300 g.DrawString(an.Text, fo, b, v.X, v.Y);
2305 g.DrawRectangles(green,
new System.Drawing.RectangleF[1] { new System.Drawing.RectangleF((float)v.X, (float)v.Y, (float)v.W, (float)v.H) });
2311 g.DrawRectangles(mag,
new System.Drawing.RectangleF[1] { new System.Drawing.RectangleF((float)v.X, (float)v.Y, (float)v.W, (float)v.H) });
2313 List<RectangleD> rects =
new List<RectangleD>();
2314 RectangleD[] sels = an.GetSelectBoxes(Tools.selectBoxSize);
2315 for (
int i = 0; i < an.selectedPoints.Count; i++)
2317 if (an.selectedPoints[i] < an.GetPointCount())
2319 rects.Add(sels[an.selectedPoints[i]]);
2322 for (
int i = 0; i < rects.Count; i++)
2325 g.DrawRectangle(blue,
new System.Drawing.RectangleF((
float)va[0].X, (
float)va[0].Y, (
float)va[0].W, (
float)va[0].H));
2330 System.Drawing.Size s = System.Windows.Forms.TextRenderer.MeasureText(an.Text,
new Font(an.family, an.fontSize));
2331 float fw = ((float)an.BoundingBox.X + ((float)an.BoundingBox.W / 2)) - ((
float)s.Width / 2);
2332 float fh = ((float)an.BoundingBox.Y + ((float)an.BoundingBox.H / 2)) - ((
float)s.Height / 2);
2334 g.DrawString(an.Text, fo, b, vv.X, vv.Y);
2349 bool updatePyr =
false;
2368 if (
Scale.Width == 0 ||
float.IsInfinity(
Scale.Width))
2371 if (Bitmaps.Count == 0)
2373 System.Drawing.RectangleF[] rf =
new System.Drawing.RectangleF[1];
2374 using System.Drawing.Pen blue =
new System.Drawing.Pen(Brushes.Blue, 1 /
Scale.Width);
2375 for (
int i = 0; i < Images.Count && i < Bitmaps.Count; i++)
2378 if (!IsLayerEnabled(im.PhysicalSizeX) && !im.isPyramidal)
2380 RectangleD r =
ToScreenRect(im.Volume.Location.X, im.Volume.Location.Y, im.Volume.Width, im.Volume.Height);
2383 RectangleF rg =
new RectangleF((
float)((-
Origin.X) - (w / 2)), (
float)((-
Origin.Y) - (h / 2)), (
float)(w), (
float)(h));
2384 RectangleF rec =
new RectangleF((
float)im.Volume.Location.X, (
float)im.Volume.Location.Y, (
float)im.Volume.Width, (
float)im.Volume.Height);
2387 var tr = g.Transform;
2389 g.DrawImage(Bitmaps[i], 0, 0);
2393 if (rg.IntersectsWith(rec))
2395 g.DrawImage(Bitmaps[i], (
float)r.X, (
float)r.Y, (
float)r.W, (
float)r.H);
2399 rf[0] =
new System.Drawing.RectangleF((
float)r.X, (
float)r.Y, (
float)r.W, (
float)r.H);
2400 g.DrawRectangles(blue, rf);
2407 Console.WriteLine(e.Message);
2414 private double scaleorig = 0;
2419 private void pictureBox_Paint(
object sender, PaintEventArgs e)
2421 var state = e.Graphics.Save();
2425 updateOverlay =
true;
2426 DrawOverlay(e.Graphics);
2430 e.Graphics.Restore(state);
2432 Plugins.Render(
this, e);
2433 Plugins.Paint(sender, e);
2440 return ToViewSizeW(ROI.selectBoxSize /
Scale.Width);
2442 private System.Drawing.Bitmap ToSysBitmap(Bitmap bm)
2446 using Bitmap rgba = bm.GetImageRGBA();
2447 var result =
new System.Drawing.Bitmap(rgba.Width, rgba.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
2448 var data = result.LockBits(
new System.Drawing.Rectangle(0, 0, result.Width, result.Height),
2449 System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
2452 int rowBytes = rgba.Width * 4;
2453 for (
int y = 0; y < rgba.Height; y++)
2454 Marshal.Copy(rgba.Bytes, y * rgba.Stride, IntPtr.Add(data.Scan0, y * data.Stride), rowBytes);
2458 result.UnlockBits(data);
2462 PointD mouseD =
new PointD(0, 0);
2463 PointD prevMove =
new PointD();
2471 private void rgbPictureBox_MouseMove(
object sender, MouseEventArgs e)
2482 mousePoint = $
"({p.X:0.##}, {p.Y:0.##})";
2484 if (e.Button == MouseButtons.XButton1 && !x1State && !
Ctrl &&
Mode !=
ViewMode.RGBImage)
2486 if (cBar.Value < cBar.Maximum)
2490 else if (e.Button == MouseButtons.XButton1 && !x1State &&
Ctrl)
2492 if (tBar.Value < tBar.Maximum)
2496 if (e.Button != MouseButtons.XButton1)
2499 if (e.Button == MouseButtons.XButton2 && !x2State && !
Ctrl &&
Mode !=
ViewMode.RGBImage)
2501 if (cBar.Value > cBar.Minimum)
2505 else if (e.Button == MouseButtons.XButton2 && !x2State &&
Ctrl)
2507 if (tBar.Value > tBar.Minimum)
2511 if (e.Button != MouseButtons.XButton2)
2514 if (Tools.currentTool.type == Tools.Tool.Type.move && e.Button == MouseButtons.Left)
2518 if (an.selectedPoints.Count > 0 && an.selectedPoints.Count < an.GetPointCount())
2520 if (an.type == ROI.Type.Rectangle || an.type == ROI.Type.Ellipse)
2523 if (an.selectedPoints[0] == 0)
2525 double dw = d.X - p.X;
2526 double dh = d.Y - p.Y;
2533 if (an.selectedPoints[0] == 1)
2535 double dw = p.X - (d.W + d.X);
2536 double dh = d.Y - p.Y;
2542 if (an.selectedPoints[0] == 2)
2544 double dw = d.X - p.X;
2545 double dh = p.Y - (d.Y + d.H);
2551 if (an.selectedPoints[0] == 3)
2553 double dw = d.X - p.X;
2554 double dh = d.Y - p.Y;
2562 PointD pod =
new PointD(p.X - pd.X, p.Y - pd.Y);
2563 for (
int i = 0; i < an.selectedPoints.Count; i++)
2565 PointD poid = an.GetPoint(an.selectedPoints[i]);
2566 an.UpdatePoint(
new PointD(poid.X + pod.X, poid.Y + pod.Y), an.selectedPoints[i]);
2572 PointD pod =
new PointD(p.X - pd.X, p.Y - pd.Y);
2573 for (
int i = 0; i < an.GetPointCount(); i++)
2575 PointD poid = an.Points[i];
2576 an.UpdatePoint(
new PointD(poid.X + pod.X, poid.Y + pod.Y), i);
2583 if (Tools.currentTool !=
null)
2584 if (Tools.currentTool.type == Tools.Tool.Type.pencil && e.Button == MouseButtons.Left)
2587 Tools.Tool tool = Tools.currentTool;
2589 Pen pen =
new Pen(Tools.DrawColor, (
int)Tools.StrokeWidth,
ImageView.SelectedImage.bitsPerPixel);
2590 g.FillEllipse(
new Rectangle((
int)ip.X, (
int)ip.Y, (
int)Tools.StrokeWidth, (
int)Tools.StrokeWidth), pen.color);
2605 private void pictureBox_MouseUp(
object sender, MouseEventArgs e)
2625 private void pictureBox_MouseDown(
object sender, MouseEventArgs e)
2632 pd =
new PointD(p.X, p.Y);
2634 mouseD =
new PointD(e.Location.X, e.Location.Y);
2642 if (e.Button == MouseButtons.Middle)
2648 tools.BringToFront();
2650 foreach (BioImage b
in Images)
2652 RectangleD r =
new RectangleD(b.Volume.Location.X, b.Volume.Location.Y, b.Volume.Width, b.Volume.Height);
2653 if (r.IntersectsWith(p))
2662 if (!
Ctrl && e.Button == MouseButtons.Left && Tools.currentTool.type != Tools.Tool.Type.rectSel)
2667 item.selectedPoints.Clear();
2672 if (Tools.currentTool.type == Tools.Tool.Type.move && e.Button == MouseButtons.Left)
2674 float width = (float)ToViewSizeW(ROI.selectBoxSize /
Scale.Width);
2678 width = Tools.selectBoxSize;
2679 height = Tools.selectBoxSize;
2681 foreach (BioImage bi
in Images)
2683 foreach (ROI an
in bi.Annotations)
2685 if (an.GetSelectBound(width, height).IntersectsWith(
new RectangleD(p.X, p.Y, 1, 1)))
2689 RectangleD[] sels = an.GetSelectBoxes(Tools.selectBoxSize);
2691 for (
int i = 0; i < sels.Length; i++)
2693 if (sels[i].IntersectsWith(r))
2695 an.selectedPoints.Add(i);
2701 an.Selected =
false;
2707 if (e.Button == MouseButtons.Left)
2710 if ((ip.X < s.X && ip.Y < s.Y) || (ip.X >= 0 && ip.Y >= 0))
2722 mouseColor =
", " + r +
"," + g +
"," + b;
2726 int r = (int)
SelectedImage.GetValueRGB(zc, 0, tc, e.X, e.Y, 0);
2727 mouseColor =
", " + r;
2737 mouseColor =
", " + r +
"," + g +
"," + b;
2741 int r = (int)
SelectedImage.GetValueRGB(zc, 0, tc, (
int)ip.X, (
int)ip.Y, 0);
2742 mouseColor =
", " + r;
2757 private void pictureBox_MouseDoubleClick(
object sender, MouseEventArgs e)
2762 PointD p =
ToViewSpace(e.Location.X, e.Location.Y);
2764 if (e.Button != MouseButtons.XButton1 && e.Button != MouseButtons.XButton2)
2765 Origin =
new PointD(-p.X, -p.Y);
2773 private void deleteROIToolStripMenuItem_Click(
object sender, EventArgs e)
2779 if (item.Selected && (item.selectedPoints.Count == 0 || item.selectedPoints.Count == item.GetPointCount() || item.type == ROI.Type.Ellipse || item.type == ROI.Type.Rectangle))
2785 if ((item.type == ROI.Type.Polygon || item.type == ROI.Type.Freeform || item.type == ROI.Type.Polyline) && item.selectedPoints.Count > 0)
2787 item.RemovePoints(item.selectedPoints.ToArray());
2790 item.selectedPoints.Clear();
2801 private void setTextSelectionToolStripMenuItem_Click(
object sender, EventArgs e)
2809 TextInput input =
new TextInput(item.Text);
2810 if (input.ShowDialog() != DialogResult.OK)
2812 item.Text = input.TextValue;
2813 item.family = input.font.FontFamily.Name;
2814 item.fontSize = input.font.Size;
2815 item.strokeColor = AForge.Color.FromArgb(input.color.R, input.color.G, input.color.B);
2825 private void copyViewToClipboardToolStripMenuItem_Click(
object sender, EventArgs e)
2828 using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
2833 System.Windows.Forms.Clipboard.SetImage(bmp);
2835 List<ROI> copys =
new List<ROI>();
2847 s += BioImage.ROIToString(item);
2850 System.Windows.Forms.Clipboard.SetText(s);
2856 string[] sts = System.Windows.Forms.Clipboard.GetText().Split(BioImage.NewLine);
2857 foreach (
string line
in sts)
2859 if (line.Length > 8)
2861 ROI an = BioImage.StringToROI(line);
2873 private void copyROIToolStripMenuItem_Click(
object sender, EventArgs e)
2883 private void pasteROIToolStripMenuItem_Click(
object sender, EventArgs e)
2892 private void hideControlsToolStripMenuItem_Click(
object sender, EventArgs e)
2904 private void showControlToolStripMenuItem_Click(
object sender, EventArgs e)
2916 private void HideStatusMenuItem_Click(
object sender, EventArgs e)
2924 private void rGBToolStripMenuItem_Click(
object sender, EventArgs e)
2933 private void filteredToolStripMenuItem_Click(
object sender, EventArgs e)
2942 private void rawToolStripMenuItem_Click(
object sender, EventArgs e)
2971 return new PointF((
float)d.X, (
float)d.Y);
2995 return new PointD(ddx, ddy);
3000 return new PointD(dx, dy);
3007 private double ToViewSizeW(
double d)
3039 double x = (double)(d /
PxWmicron) / scale.Width;
3049 double y = (double)(d /
PxHmicron) / scale.Height;
3062 return new PointD(fx, fy);
3081 return new PointF((
float)pd.X, (
float)pd.Y);
3090 PointF[] pf =
new PointF[p.Length];
3091 for (
int i = 0; i < p.Length; i++)
3105 return new PointF((
float)pd.X, (
float)pd.Y);
3134 return new PointF(x, y);
3155 double dw = ToViewSizeW(w);
3174 public SKRect
ToSKRect(
double x,
double y,
double w,
double h)
3176 double xd = gl.Width / 2;
3177 double yd = gl.Height / 2;
3178 return new SKRect((
float)(xd - x), (
float)(yd - y), (
float)(xd - (x + w)), (
float)(yd - (y + h)));
3206 for (
int i = 0; i < p.Length; i++)
3219 RectangleF[] rs =
new RectangleF[p.Length];
3220 for (
int i = 0; i < p.Length; i++)
3233 PointF[] rs =
new PointF[p.Length];
3234 for (
int i = 0; i < p.Length; i++)
3237 rs[i] =
new PointF((
float)pd.X, (
float)pd.Y);
3268 double moveAmount = 5 *
Scale.Width;
3270 if (e.KeyCode ==
Keys.C && e.Control)
3275 if (e.KeyCode ==
Keys.V && e.Control)
3280 if (e.KeyCode ==
Keys.Subtract || e.KeyCode ==
Keys.NumPad7)
3288 if (e.KeyCode ==
Keys.Add || e.KeyCode ==
Keys.NumPad9)
3296 if (e.KeyCode ==
Keys.W || e.KeyCode ==
Keys.NumPad8)
3304 if (e.KeyCode ==
Keys.S || e.KeyCode ==
Keys.NumPad2)
3312 if (e.KeyCode ==
Keys.A || e.KeyCode ==
Keys.NumPad4)
3320 if (e.KeyCode ==
Keys.D || e.KeyCode ==
Keys.NumPad6)
3345 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3351 PointD mouseDownInt =
new PointD(0, 0);
3352 PointD mouseUpInt =
new PointD(0, 0);
3353 PointD mouseMoveInt =
new PointD(0, 0);
3354 PointD mouseMove =
new PointD(0, 0);
3356 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3359 get {
return mouseDownInt; }
3360 set { mouseDownInt = value; }
3362 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3365 get {
return mouseUpInt; }
3366 set { mouseUpInt = value; }
3368 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3371 get {
return mouseMoveInt; }
3372 set { mouseMoveInt = value; }
3375 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3392 BioImage image =
Images[i];
3393 if (image.isPyramidal)
3397 RectangleD bounds = OverviewWorldBounds(image);
3398 if (bounds.W <= 0 || bounds.H <= 0 || !
double.IsFinite(bounds.W) || !
double.IsFinite(bounds.H))
3401 if (!
double.IsFinite(fit) || fit <= 0)
3405 (bounds.Y + bounds.H / 2) / fit -
ViewHeight / 2.0);
3409 double dx = image.Volume.Width / 2;
3410 double dy = image.Volume.Height / 2;
3411 Origin =
new PointD(-(image.Volume.Location.X + dx), -(image.Volume.Location.Y + dy));
3415 double fitScale = Math.Min(wx, wy);
3416 if (
double.IsFinite(fitScale) && fitScale > 0)
3417 Scale =
new SizeF((
float)fitScale, (
float)fitScale);
3425 private void goToImageToolStripMenuItem_Click(
object sender, EventArgs e)
3434 private void goToToolStripMenuItem1_Click(
object sender, EventArgs e)
3443 private void goToImageToolStripMenuItem_DropDownOpening(
object sender, EventArgs e)
3445 ToolStripMenuItem item = (ToolStripMenuItem)sender;
3446 item.DropDownItems.Clear();
3447 foreach (BioImage im
in Images)
3449 ToolStripMenuItem it =
new ToolStripMenuItem();
3450 it.Text = im.filename;
3451 item.DropDownItems.Add(it);
3461 private void goToImageToolStripMenuItem_DropDownItemClicked(
object sender, ToolStripItemClickedEventArgs e)
3464 foreach (var item
in Images)
3466 if (item.filename == e.ClickedItem.Text)
3476 for (
int i = 0; i < Bitmaps.Count; i++)
3478 if (Bitmaps[i] !=
null)
3479 Bitmaps[i].Dispose();
3481 for (
int i = 0; i < Bitmaps.Count; i++)
3483 if (Bitmaps[i] !=
null)
3484 Bitmaps[i].Dispose();
3493 private void goToToolStripMenuItem_Click_1(
object sender, EventArgs e)
3502 private void drawToolStripMenuItem_Click(
object sender, EventArgs e)
3511 if (item.type == ROI.Type.Line)
3513 g.DrawLine(
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(0)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(0)).Y),
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(1)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(1)).Y));
3516 if (item.type == ROI.Type.Rectangle)
3518 g.DrawRectangle(
SelectedImage.ToImageSpace(item.BoundingBox));
3521 if (item.type == ROI.Type.Ellipse)
3523 g.DrawEllipse(
SelectedImage.ToImageSpace(item.BoundingBox));
3526 if (item.type == ROI.Type.Freeform || item.type == ROI.Type.Polygon || item.type == ROI.Type.Polyline)
3530 for (
int i = 0; i < item.GetPointCount() - 1; i++)
3532 g.DrawLine(
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(i)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(i)).Y),
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(i + 1)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(i + 1)).Y));
3534 g.DrawLine(
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(0)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(0)).Y),
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(item.GetPointCount() - 1)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(item.GetPointCount() - 1)).Y));
3539 for (
int i = 0; i < item.GetPointCount() - 1; i++)
3541 g.DrawLine(
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(i)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(i)).Y),
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(i + 1)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(i + 1)).Y));
3555 private void fillToolStripMenuItem_Click(
object sender, EventArgs e)
3563 if (item.type == ROI.Type.Line)
3565 g.DrawLine(
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(0)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(0)).Y),
new PointF((
float)
SelectedImage.ToImageSpace(item.GetPoint(1)).X, (
float)
SelectedImage.ToImageSpace(item.GetPoint(1)).Y));
3568 if (item.type == ROI.Type.Rectangle)
3570 g.FillRectangle(
SelectedImage.ToImageSpace(item.BoundingBox), p.color);
3573 if (item.type == ROI.Type.Ellipse)
3575 g.FillEllipse(
SelectedImage.ToImageSpace(item.BoundingBox), p.color);
3578 if (item.type == ROI.Type.Freeform || item.type == ROI.Type.Polygon || item.type == ROI.Type.Polyline)
3615 private void moveStageToImageToolStripMenuItem_DropDownItemClicked(
object sender, ToolStripItemClickedEventArgs e)
3618 foreach (var item
in Images)
3620 if (item.ID.Contains(e.ClickedItem.Text))
3633 private void moveStageToImageToolStripMenuItem_Click(
object sender, EventArgs e)
3637 private void layersToolStripMenuItem_Click(
object sender, EventArgs e)
3639 if (layersTool ==
null)
3640 layersTool =
new Layers();
3647 private void pictureBox_SizeChanged(
object sender, EventArgs e)
3656 private void contextMenuStrip_Opening(
object sender, CancelEventArgs e)
3659 if (App.tabsView !=
null)
3660 Function.Initialize();
3662 private void hideOverviewToolStripMenuItem_Click(
object sender, EventArgs e)
3664 if (hideOverViewToolStripMenuItem.Text ==
"Hide Overview")
3667 hideOverViewToolStripMenuItem.Text =
"Show Overview";
3672 hideOverViewToolStripMenuItem.Text =
"Hide Overview";
3675 private void removeImageToolStripMenuItem_Click(
object sender, EventArgs e)
3680 private void removeImagesToolStripMenuItem_Click(
object sender, EventArgs e)
3685 private OpenSlideBase _openSlideBase;
3686 private SlideBase _slideBase;
3691 private void Initialize(
string file, BioImage bm)
3693 if (bm.Resolutions.Count == 1)
3695 if (bm.OpenSlideBase ==
null)
3697 _slideBase = bm.SlideBase;
3698 slideRenderer =
new SlideRenderer(gl);
3699 slideRenderer.SetSource(_slideBase);
3703 _openSlideBase = bm.OpenSlideBase;
3704 slideRenderer =
new SlideRenderer(gl);
3705 slideRenderer.SetSource(_openSlideBase);
3711 private void viewpanel_Paint(
object sender, PaintEventArgs e)
3713 pictureBox_Paint(sender, e);
3716 private void hideAllToolStripMenuItem_Click(
object sender, EventArgs e)
3724 private void showAllToolStripMenuItem_Click(
object sender, EventArgs e)
System.Drawing.Image Image
AForge.RectangleD RectangleD
System.Windows.Forms.Keys Keys
System.Windows.Forms.Application Application
System.Drawing.Graphics Graphics
static ChannelsTool channelsTool
int CFps
Setting the interval of the timer to the inverse of the fps. */.
bool ShowControls
Setting the visibility of the trackBarPanel. */.
RectangleD ToScreenRect(double x, double y, double w, double h)
System.Drawing.Bitmap overviewImage
RectangleD[] ToScreenSpace(RectangleD[] p)
PointD ToViewSpace(PointD p)
PointF ToScreenSpace(PointF p)
float ToScreenScaleW(double x)
override bool ProcessCmdKey(ref Message msg, Keys keyData)
void ImageView_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
RectangleD ToScreenSpace(RectangleD p)
new AForge.SizeF Scale
Scale when opening image stacks.
Channel GChannel
A property that returns the G channel of the image. */.
string Path
A property that returns the filepath. */.
bool ShowStatus
Setting the value of the property ShowStatus. */.
void ImageView_KeyUp(object sender, KeyEventArgs e)
PointD ToScreenSpace(PointD p)
PointD PyramidalOrigin
Setting the value of the pyramidalOrigin variable. */.
void AddImage(BioImage im)
double PxWmicron
Only used when opening stacks.
void MoveStageToImage(int i)
int ZFps
Setting the interval of the timer to the value of the fps. */.
RectangleF[] ToScreenSpace(RectangleF[] p)
PointF[] ToScreenSpace(PointF[] p)
static BioImage SelectedImage
Channel RChannel
A property that returns the R channel of the selected image. */.
static Bitmap SelectedBuffer
void SetCoordinate(int z, int c, int t)
override void OnLayout(LayoutEventArgs e)
PointF ToScreenScale(PointD p)
void UpdateSelectBoxSize(float size)
int Level
Current level when viewing whole-slide and pyramidal images.
void ImageView_KeyDown(object sender, KeyEventArgs e)
static List< ROI > selectedAnnotations
double ToViewSizeH(double d)
float ToScreenH(double y)
void UpdateView(bool refresh)
double Resolution
A property of the class ImageViewer. It is a getter and setter for the resolution of the image.
PointD PyramidalOriginTransformed
PointD ToScreenSpace(double x, double y)
ImageView(BioImage im, bool OpenWithOpenSlide=true)
Initializing the image viewer. */.
PointF ToViewSpace(PointF p)
void CopySelection()
It takes the selected ROIs and copies them to the clipboard.
ContextMenuStrip ViewContextMenu
A property that returns a ContextMenuStrip object. */.
PointF ToScreenSpace(Point3D p)
PointD Origin
A property of the class PointD. */.
PointF[] ToScreenSpace(PointD[] p)
ViewMode Mode
Setting the view mode of the application. */.
void DrawView(System.Drawing.Graphics g)
Draws the viewport when Hardware Acceleration is off.
List< ROI > AnnotationsRGB
int TimeFps
Setting the interval of the timer to the value of the timefps variable. */.
SKRect ToSKRect(double x, double y, double w, double h)
Channel BChannel
Getting the B channel of the image. */.
static MouseButtons mouseUpButtons
ImageView()
Initializing the ImageView class. */.
RectangleD ToScreenSpace(RectangleF p)
float ToScreenScaleH(double y)
async void UpdateImages(bool updatePyramidal=true)
double PxHmicron
Only used when opening stacks.
PointD ToViewSpace(double x, double y)
int SelectedIndex
A property that is used to set the selected index of the image. */.
float ToScreenW(double x)
PointD ImageToViewSpace(double x, double y)
static MouseButtons mouseDownButtons
static void Render(object o, PaintEventArgs e)
static void KeyPressEvent(object o, KeyPressEventArgs e)
static void KeyDownEvent(object o, KeyEventArgs e)
static void KeyUpEvent(object o, KeyEventArgs e)
void SetPosition(double px, double py)
void UpdateViewMode(ImageView.ViewMode v)
static bool GetKeyState(System.Windows.Forms.Keys vKey)
Layer(double d, bool enabled)