BioImager  4.9.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.cs
1using AForge;
2using AForge.Imaging.Filters;
3using BioLib;
4using CSScripting;
5using Gtk;
6using OpenSlideGTK;
7using OpenTK.Mathematics;
8using OpenTK.Windowing.Common;
9using OpenTK.Windowing.Desktop;
10using OpenTK.Windowing.GraphicsLibraryFramework;
11using org.checkerframework.checker.units.qual;
12using SkiaSharp;
13using SkiaSharp.Views.Gtk;
14using System.ComponentModel;
15using System.Runtime.InteropServices;
16using Application = System.Windows.Forms.Application;
17using Bitmap = AForge.Bitmap;
18using Image = System.Drawing.Image;
19using Keys = System.Windows.Forms.Keys;
20using PointF = AForge.PointF;
21using Rectangle = AForge.Rectangle;
22using RectangleD = AForge.RectangleD;
23using RectangleF = AForge.RectangleF;
24using SizeF = AForge.SizeF;
25
26namespace BioImager
27{
28
32 public partial class ImageView : UserControl, IDisposable
33 {
34 GLWindow window;
35 SlideGLArea gl = new SlideGLArea();
36 SlideRenderer slideRenderer;
38 public ImageView(BioImage im, bool OpenWithOpenSlide = true)
39 {
40 string file = im.ID.Replace("\\", "/");
41 InitializeComponent();
42
43 if (im.isPyramidal)
44 {
45 gl.Size = new System.Drawing.Size(800, 600);
46 if (im.openSlideImage != null && OpenWithOpenSlide)
47 {
48 openSlide = true;
49 Initialize(im.file, im);
50 }
51 else
52 Initialize(im.file, im);
53 hScrollBar.Maximum = im.Resolutions[Level].SizeX;
54 vScrollBar.Maximum = im.Resolutions[Level].SizeY;
55 hScrollBar.Visible = true;
56 vScrollBar.Visible = true;
57 }
58 else
59 {
60 hScrollBar.Visible = false;
61 vScrollBar.Visible = false;
62 gl.Width += 18;
63 gl.Height += 18;
64 Tools.selectBoxSize = ROI.selectBoxSize;
65 }
66 App.viewer = this;
67 if (im.SlideBase != null && im.isPyramidal && OpenSlide)
68 openSlide = true;
69 serie = im.series;
70 gl.Dock = DockStyle.Fill;
71 viewpanel.Controls.Add(gl);
72 Dock = DockStyle.Fill;
73 AddImage(im);
74 App.viewer = this;
75 if (file == "" || file == null)
76 return;
77 SetCoordinate(0, 0, 0);
78 InitGUI();
79 gl.Paint += Gl_Paint;
80 MouseWheel += new System.Windows.Forms.MouseEventHandler(ImageView_MouseWheel);
81 zBar.MouseWheel += new System.Windows.Forms.MouseEventHandler(ZTrackBar_MouseWheel);
82 cBar.MouseWheel += new System.Windows.Forms.MouseEventHandler(CTrackBar_MouseWheel);
83 tBar.MouseWheel += new System.Windows.Forms.MouseEventHandler(TimeTrackBar_MouseWheel);
84 //We set the trackbar event to handled so that it only scrolls one tick not the default multiple.
85 zBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled = true;
86 tBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled = true;
87 cBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled = true;
88 this.SizeChanged += ImageView_SizeChanged;
89 this.KeyDown += ImageView_KeyDown;
90 this.KeyPress += ImageView_KeyPress;
91 this.KeyUp += ImageView_KeyUp;
92 TimeFps = 60;
93 ZFps = 60;
94 CFps = 1;
95 resolutions = im.Resolutions;
96 if (im.isPyramidal)
97 {
98 // Set the source based on image type
99 if (im.OpenSlideBase != null)
100 {
101 slideRenderer.SetSource(im.OpenSlideBase);
102 }
103 else if (im.SlideBase != null)
104 {
105 slideRenderer.SetSource(im.SlideBase);
106 }
107 }
108 InitGL();
109 update = true;
110 InitPreview();
111 GoToImage();
112 UpdateImages();
113 Mode = ViewMode.Filtered;
114 UpdateView();
115
116 }
118 public ImageView()
119 {
120 InitializeComponent();
121 InitGL();
122 Dock = DockStyle.Fill;
123 App.viewer = this;
124 SetCoordinate(0, 0, 0);
125 InitGUI();
126 gl.Paint += Gl_Paint;
127 //Buf = image.GetBufByCoord(GetCoordinate());
128 MouseWheel += new System.Windows.Forms.MouseEventHandler(ImageView_MouseWheel);
129 zBar.MouseWheel += new System.Windows.Forms.MouseEventHandler(ZTrackBar_MouseWheel);
130 cBar.MouseWheel += new System.Windows.Forms.MouseEventHandler(CTrackBar_MouseWheel);
131 tBar.MouseWheel += new System.Windows.Forms.MouseEventHandler(TimeTrackBar_MouseWheel);
132 this.SizeChanged += ImageView_SizeChanged;
133 //We set the trackbar event to handled so that it only scrolls one tick not the default multiple.
134 zBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled = true;
135 tBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled = true;
136 cBar.MouseWheel += (sender, e) => ((HandledMouseEventArgs)e).Handled = true;
137 TimeFps = 60;
138 ZFps = 60;
139 CFps = 1;
140 update = true;
141 UpdateImages();
142 GoToImage();
143 UpdateView();
144 }
145 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
146 {
147 const int WM_KEYDOWN = 0x0100;
148 const int WM_KEYUP = 0x0101;
149 const int WM_CHAR = 0x0102;
150
151 switch (msg.Msg)
152 {
153 case WM_KEYDOWN:
154 ImageView_KeyDown(this, new KeyEventArgs(keyData));
155 break;
156
157 case WM_KEYUP:
158 ImageView_KeyUp(this, new KeyEventArgs(keyData));
159 break;
160
161 case WM_CHAR:
162 char ch = (char)msg.WParam;
163 ImageView_KeyPress(this, new System.Windows.Forms.KeyPressEventArgs(ch));
164 break;
165 }
166
167 return base.ProcessCmdKey(ref msg, keyData);
168 }
169
170 private void ImageView_SizeChanged(object? sender, EventArgs e)
171 {
172 if (SelectedImage != null)
173 if (SelectedImage.isPyramidal)
174 SelectedImage.PyramidalSize = new AForge.Size(gl.Width, gl.Height);
175 }
176
177 private void InitGL()
178 {
179 var gameWindowSettings = new GameWindowSettings()
180 {
181 UpdateFrequency = 60,
182 };
183 NativeWindowSettings nativeSettings;
184
185 nativeSettings = new NativeWindowSettings()
186 {
187 ClientSize = new Vector2i(600, 400),
188 Location = new Vector2i(0, 0),
189 Title = "OpenGL Context",
190 StartVisible = false, // Window starts hidden
191 API = ContextAPI.OpenGL,
192 Profile = ContextProfile.Core,
193 APIVersion = new Version(3, 3)
194 };
195 window = new GLWindow(gameWindowSettings, nativeSettings);
196 GLFWProvider.SetErrorCallback((error, description) =>
197 {
198 Console.WriteLine($"BioImager GLFW Error {error}: {description}");
199 });
200 }
201
202 private void Gl_Paint(object? sender, PaintEventArgs e)
203 {
204 Render(e.Graphics);
205 }
206
207 ~ImageView()
208 {
209
210 }
211 public struct Layer
212 {
213 public double Resolution
214 {
215 get; set;
216 }
217 public bool Enabled { get; set; }
218 public Layer(double d)
219 {
220 Enabled = true;
221 Resolution = d;
222 }
223 public Layer(double d, bool enabled)
224 {
225 Enabled = enabled;
226 Resolution = d;
227 }
228 }
229
230 public List<Layer> Layers = new List<Layer>();
231 private Layers layersTool = new Layers();
232 private bool IsLayerEnabled(double d)
233 {
234 foreach (Layer item in Layers)
235 {
236 if (d == item.Resolution && item.Enabled)
237 return true;
238 }
239 return false;
240 }
241 List<System.Drawing.Bitmap> Bitmaps = new List<System.Drawing.Bitmap>();
242 List<Resolution> resolutions = new List<Resolution>();
243 public static List<ROI> selectedAnnotations = new List<ROI>();
244 private static int selectedIndex = 0;
245 public static BioImage SelectedImage
246 {
247 get
248 {
249 if (App.viewer != null)
250 {
251 if (App.viewer.Images.Count > 0)
252 return App.viewer.Images[selectedIndex];
253 else
254 return null;
255 }
256 else
257 return null;
258 }
259 set
260 {
261 if (App.viewer != null)
262 {
263 if (App.viewer.Images.Count > 0)
264 App.viewer.Images[selectedIndex] = value;
265 }
266 }
267 }
268 public static Bitmap SelectedBuffer
269 {
270 get
271 {
272 int ind = SelectedImage.Coords[SelectedImage.Coordinate.Z, SelectedImage.Coordinate.C, SelectedImage.Coordinate.T];
273 return SelectedImage.Buffers[ind];
274 }
275 }
276 public static PointD mouseDown;
277 public static bool down;
278 public static PointD mouseUp;
279 public static bool up;
280 public static bool Ctrl
281 {
282 get
283 {
284 return Win32.GetKeyState(Keys.LControlKey);
285 }
286 }
287 private bool x1State = false;
288 private bool x2State = false;
289 public static MouseButtons mouseUpButtons;
290 public static MouseButtons mouseDownButtons;
291 private PointD pd;
292 public static bool showBounds = true;
293 public static bool showText = true;
294 public Image Buf = null;
295 public bool init = false;
296 private bool update = false;
297 private bool updateOverlay = false;
298 public List<BioImage> Images = new List<BioImage>();
299 private Bitmap overviewImage;
304 private void Render(System.Drawing.Graphics canvas)
305 {
306 try
307 {
308 // Draw annotations (ROIs) - keep existing annotation drawing code
309 int i = 0;
310 foreach (BioImage im in Images)
311 {
312 List<ROI> rois = new List<ROI>();
313 rois.AddRange(im.Annotations);
314 int ri = 0;
315 ZCT co = GetCoordinate();
316 canvas.TranslateTransform((float)gl.Width / 2f, (float)gl.Height / 2f);
317 RectangleD rp = ToScreenSpace(new RectangleD(im.StageSizeX * im.PhysicalSizeX, im.StageSizeX * im.PhysicalSizeY, im.SizeX * im.PhysicalSizeX, im.SizeY * im.PhysicalSizeY));
318 //if (!im.isPyramidal)
319 // canvas.DrawImage(Bitmaps[i],new System.Drawing.PointF((float)rp.X, (float)rp.Y));
320 i++;
321 }
322 if (overviewImage != null && ShowOverview)
323 {
324 var g = canvas;
325 g.ResetTransform();
326 g.DrawImage(ToSysBitmap(overviewBitmap), new System.Drawing.Point(0, 0));
327 g.DrawRectangle(Pens.Gray, overview.X, overview.Y, overview.Width, overview.Height);
328 double dsx = _slideBase.Schema.Resolutions[Level].UnitsPerPixel / Resolution;
329 Resolution rs = SelectedImage.Resolutions[Level];
330 double dx = ((double)PyramidalOrigin.X / (rs.SizeX * dsx)) * overview.Width;
331 double dy = ((double)PyramidalOrigin.Y / (rs.SizeY * dsx)) * overview.Height;
332 double dw = ((double)ViewWidth / (rs.SizeX)) * overview.Width * dsx;
333 double dh = ((double)ViewHeight / (rs.SizeY)) * overview.Height * dsx;
334 g.DrawRectangle(Pens.Red, (int)dx, (int)dy, (int)dw, (int)dh);
335 g.ResetTransform();
336 }
337 System.Drawing.Rectangle rf = new System.Drawing.Rectangle((int)canvas.Clip.GetBounds(canvas).X, (int)canvas.Clip.GetBounds(canvas).Y,
338 (int)canvas.Clip.GetBounds(canvas).Width, (int)canvas.Clip.GetBounds(canvas).Height);
339 // Plugin rendering hook
340 Plugins.Render(this, new PaintEventArgs(canvas, rf));
341 }
342 catch (Exception ex)
343 {
344 Console.WriteLine($"Annotation render error: {ex.Message}");
345 }
346 }
347
349 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
350 public int SelectedIndex
351 {
352 get;
353 set
354 {
355 if (value >= 0 && Images.Count > 0)
356 {
357 field = value;
358 selectedIndex = field;
359 InitGUI();
360 }
361 }
362 } = 0;
363 public Tools tools { get { return App.tools; } }
364 public string filepath = "";
365 public int serie = 0;
366 public int minSizeX = 50;
367 public int minSizeY = 20;
368 public bool loopZ = true;
369 public bool loopT = true;
370 public bool loopC = true;
371 private AForge.Rectangle overview;
372 private Bitmap overviewBitmap;
373 public Rectangle OverView
374 {
375 get { return overview; }
376 }
377 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
378 public bool ShowStage { get; set; }
379 private double pxWmicron = 0.004;
380 private double pxHmicron = 0.004;
381 AForge.SizeF scale = new AForge.SizeF(1, 1);
389 public void SetCoordinate(int z, int c, int t)
390 {
391 System.Threading.Tasks.Task.Run(() =>
392 {
393 try
394 {
395 App.viewer.Invoke((MethodInvoker)delegate
396 {
397 if (SelectedImage == null)
398 return;
399 if (z >= SelectedImage.SizeZ)
400 zBar.Value = zBar.Maximum;
401 if (c >= SelectedImage.SizeC)
402 cBar.Value = cBar.Maximum;
403 if (t >= SelectedImage.SizeT)
404 tBar.Value = tBar.Maximum;
405 zBar.Value = z;
406 cBar.Value = c;
407 tBar.Value = t;
408 });
409 }
410 catch (Exception e)
411 {
412 Console.WriteLine(e.Message);
413 }
414
415 });
416 }
420 public ZCT GetCoordinate()
421 {
422 return SelectedImage.Coordinate;
423 }
429 public void AddImage(BioImage im)
430 {
431 Images.Add(im);
432 SelectedIndex = Images.Count - 1;
433 bool c = false;
434 foreach (var item in Layers)
435 {
436 if (item.Resolution == im.PhysicalSizeX)
437 c = true;
438 }
439 if (!c)
440 Layers.Add(new Layer(im.PhysicalSizeX));
441 if (im.isPyramidal)
442 {
443 hScrollBar.Maximum = im.Resolutions[Level].SizeX;
444 vScrollBar.Maximum = im.Resolutions[Level].SizeY;
445 hScrollBar.Visible = true;
446 vScrollBar.Visible = true;
447 }
448 else
449 {
450 hScrollBar.Visible = false;
451 vScrollBar.Visible = false;
452 gl.Width += 18;
453 gl.Height += 18;
454 Tools.selectBoxSize = ROI.selectBoxSize;
455 }
456 InitGUI();
457 UpdateImages();
458
459 GoToImage(Images.Count - 1);
460 }
464 private async void InitPreview()
465 {
466 if (!SelectedImage.isPyramidal)
467 return;
468 overview = new Rectangle(0, 0, 120, 120);
469 if (SelectedImage.Resolutions.Count == 1)
470 {
471 ShowOverview = false;
472 return;
473 }
474 if (MacroResolution.HasValue)
475 {
476 double aspx = (double)SelectedImage.Resolutions[MacroResolution.Value - 2].SizeX / (double)SelectedImage.Resolutions[MacroResolution.Value - 2].SizeY;
477 double aspy = (double)SelectedImage.Resolutions[MacroResolution.Value - 2].SizeY / (double)SelectedImage.Resolutions[MacroResolution.Value - 2].SizeX;
478 overview = new Rectangle(0, 0, (int)(aspx * 120), (int)(aspy * 120));
479 if (SelectedImage.Resolutions[MacroResolution.Value - 2].SizeInBytes > 1000000000)
480 {
481 return;
482 }
483 ZCT coord = GetCoordinate();
484 Bitmap bm = SelectedImage.GetTile(SelectedImage, SelectedImage.GetFrameIndex(coord.Z, coord.C, coord.T), MacroResolution.Value - 2, 0, 0, SelectedImage.Resolutions[MacroResolution.Value - 2].SizeX, SelectedImage.Resolutions[MacroResolution.Value - 2].SizeY);
485 ResizeNearestNeighbor re = new ResizeNearestNeighbor(overview.Width, overview.Height);
486 Bitmap bmp = re.Apply(bm);
487 overviewBitmap = bmp;
488 }
489 else
490 {
491 ZCT coord = GetCoordinate();
492 int lev = SelectedImage.Resolutions.Count - 1;
493 double aspx = (double)SelectedImage.Resolutions[lev].SizeX / (double)SelectedImage.Resolutions[lev].SizeY;
494 double aspy = (double)SelectedImage.Resolutions[lev].SizeY / (double)SelectedImage.Resolutions[lev].SizeX;
495 overview = new Rectangle(0, 0, (int)(aspx * 120), (int)(aspy * 120));
496 Bitmap bm = SelectedImage.GetTile(SelectedImage, SelectedImage.GetFrameIndex(coord.Z, coord.C, coord.T), lev, 0, 0, SelectedImage.Resolutions[lev].SizeX, SelectedImage.Resolutions[lev].SizeY);
497 ResizeNearestNeighbor re = new ResizeNearestNeighbor(overview.Width, overview.Height);
498 Bitmap bmp = re.Apply(bm);
499 overviewBitmap = bmp;
500 }
501 ShowOverview = true;
502 Console.WriteLine("Preview Initialized.");
503 }
504 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
505 public bool ShowOverview { get; set; }
507 private bool showControls = true;
509 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
510 public bool ShowControls
511 {
512 get { return trackBarPanel.Visible; }
513 set
514 {
515 showControls = value;
516 if (!value)
517 {
518 trackBarPanel.Hide();
519 if (ShowStatus)
520 {
521 gl.Top = 25;
522 gl.Height += 75;
523 }
524 else
525 {
526 gl.Top = 0;
527 gl.Height += 75;
528 }
529 hideControlsToolStripMenuItem1.Text = "Show Controls";
530 }
531 else
532 {
533 trackBarPanel.Show();
534 if (ShowStatus)
535 {
536 gl.Top = 25;
537 gl.Height -= 75;
538 }
539 else
540 {
541 gl.Top = 0;
542 gl.Height += 75;
543 }
544
545 //panel.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
546 hideControlsToolStripMenuItem1.Text = "Hide Controls";
547 }
548 UpdateView();
549 }
550 }
552 private bool showStatus = true;
554 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
555 public bool ShowStatus
556 {
557 get { return showStatus; }
558 set
559 {
560 showStatus = true;
561 if (!value)
562 {
563 statusPanel.Hide();
564 gl.Top = 0;
565 gl.Height += 25;
566 showControlsToolStripMenuItem.Visible = true;
567 hideControlsToolStripMenuItem.Text = "Show Status";
568 }
569 else
570 {
571 statusPanel.Show();
572 statusPanel.Visible = value;
573 gl.Top = 25;
574 showControlsToolStripMenuItem.Visible = false;
575 hideControlsToolStripMenuItem.Text = "Hide Status";
576 }
577 }
578 }
582
583 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
584 public double PxWmicron
585 {
586 get
587 {
588 return pxWmicron;
589 }
590 set
591 {
592 pxWmicron = value;
593 }
594 }
598 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
599 public double PxHmicron
600 {
601 get
602 {
603 return pxHmicron;
604 }
605 set
606 {
607 pxHmicron = value;
608 }
609 }
610 public enum ViewMode
611 {
612 Raw,
613 Filtered,
614 RGBImage,
615 Emission,
616 }
617 private ViewMode viewMode = ViewMode.Filtered;
619 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
620 public ViewMode Mode
621 {
622 get
623 {
624 return viewMode;
625 }
626 set
627 {
628 viewMode = value;
629 //If view mode is changed we update.
630 update = true;
631 UpdateImages();
632 App.tabsView.UpdateViewMode(viewMode);
633 UpdateView();
635 if (viewMode == ViewMode.RGBImage)
636 {
637 cBar.Value = 0;
638 rgbBoxsPanel.BringToFront();
639 cBar.SendToBack();
640 cLabel.SendToBack();
641 gl.BringToFront();
642 }
643 else
644 if (viewMode == ViewMode.Filtered)
645 {
646 rgbBoxsPanel.SendToBack();
647 cBar.BringToFront();
648 cLabel.BringToFront();
649 gl.BringToFront();
650 }
651 else
652 if (viewMode == ViewMode.Raw)
653 {
654 rgbBoxsPanel.SendToBack();
655 cBar.BringToFront();
656 cLabel.BringToFront();
657 gl.BringToFront();
658 }
659 else
660 {
661 cBar.Value = 0;
662 rgbBoxsPanel.BringToFront();
663 cBar.SendToBack();
664 cLabel.SendToBack();
665 gl.BringToFront();
666 }
667 }
668 }
670 public string Path
671 {
672 get
673 {
674 return filepath;
675 }
676 }
678 public Channel RChannel
679 {
680 get
681 {
682 return SelectedImage.Channels[SelectedImage.rgbChannels[0]];
683 }
684 }
686 public Channel GChannel
687 {
688 get
689 {
690 return SelectedImage.Channels[SelectedImage.rgbChannels[1]];
691 }
692 }
694 public Channel BChannel
695 {
696 get
697 {
698 return SelectedImage.Channels[SelectedImage.rgbChannels[2]];
699 }
700 }
701 PointD origin = new PointD(0, 0);
702 bool hardwareAcceleration = true;
703 bool openSlide = false;
704 public bool OpenSlide
705 {
706 get { return openSlide; }
707 }
708 public int? MacroResolution { get { return SelectedImage.MacroResolution; } }
709 public int? LabelResolution { get { return SelectedImage.LabelResolution; } }
710 public int ViewWidth
711 {
712 get
713 {
714 return gl.Width;
715 }
716 }
717 public int ViewHeight
718 {
719 get
720 {
721 return gl.Height;
722 }
723 }
725 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
726 public PointD Origin
727 {
728 get { return origin; }
729 set
730 {
731 origin = value;
732 update = true;
733 UpdateView();
734 }
735 }
737 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
738 public PointD PyramidalOrigin
739 {
740 get
741 {
742 return SelectedImage.PyramidalOrigin;
743 }
744 set
745 {
746 SelectedImage.PyramidalOrigin = value;
747 }
748 }
750 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
751 public double Resolution
752 {
753 get
754 {
755 if (SelectedImage == null)
756 return 1;
757 return SelectedImage.Resolution;
758 }
759 set
760 {
761 double dp = Resolution / value;
762 SelectedImage.PyramidalOrigin = new PointD((dp * PyramidalOrigin.X), (dp * PyramidalOrigin.Y));
763 SelectedImage.Resolution = value;
764 if (SelectedImage.Type == BioImage.ImageType.well)
765 SelectedImage.Level = (int)value;
766 updatePyr = true;
767 }
768 }
769 private void UpdateScrollBars()
770 {
771 double dsx = SelectedImage.OpenSlideBase.Schema.Resolutions[Level].UnitsPerPixel / Resolution;
772 hScrollBar.Maximum = (int)(SelectedImage.Resolutions[Level].SizeX * dsx);
773 vScrollBar.Maximum = (int)(SelectedImage.Resolutions[Level].SizeY * dsx);
774 if (PyramidalOrigin.X >= hScrollBar.Maximum)
775 hScrollBar.Maximum = (int)PyramidalOrigin.X;
776 if (PyramidalOrigin.Y >= vScrollBar.Maximum)
777 vScrollBar.Maximum = (int)PyramidalOrigin.Y;
778 try
779 {
780 hScrollBar.Value = (int)PyramidalOrigin.X;
781 vScrollBar.Value = (int)PyramidalOrigin.Y;
782 hScrollBar.Update();
783 vScrollBar.Update();
784 }
785 catch (Exception)
786 {
787
788 }
789
790 }
791
795 public int Level
796 {
797 get
798 {
799 if (SelectedImage != null)
800 return SelectedImage.Level;
801 else
802 return 0;
803 }
804 }
808 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
809 public new AForge.SizeF Scale
810 {
811 get
812 {
813 return scale;
814 }
815 set
816 {
817 scale = value;
818 update = true;
819 UpdateView();
820 if (SelectedImage != null)
821 if (SelectedImage.isPyramidal)
822 {
823 Tools.selectBoxSize = (float)(ROI.selectBoxSize * Resolution);
824 }
825 else
826 Tools.selectBoxSize = ROI.selectBoxSize;
827 }
828 }
830 public ContextMenuStrip ViewContextMenu
831 {
832 get
833 {
834 return contextMenuStrip;
835 }
836 }
841 public void UpdateRGBChannels()
842 {
843 //Buf = image.GetBufByCoord(GetCoordinate());
844 if (channelBoxR.SelectedIndex == -1)
845 SelectedImage.rgbChannels[0] = 0;
846 else
847 SelectedImage.rgbChannels[1] = channelBoxR.SelectedIndex;
848 if (channelBoxG.SelectedIndex == -1)
849 SelectedImage.rgbChannels[1] = 0;
850 else
851 SelectedImage.rgbChannels[1] = channelBoxG.SelectedIndex;
852 if (channelBoxB.SelectedIndex == -1)
853 SelectedImage.rgbChannels[2] = 0;
854 else
855 SelectedImage.rgbChannels[2] = channelBoxB.SelectedIndex;
856
857 }
858 private bool timeEnabled = false;
859 private int zfps;
861 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
862 public int ZFps
863 {
864 get
865 {
866 return zfps;
867 }
868 set
869 {
870 zfps = value;
871 float f = value;
872 zTimer.Interval = (int)Math.Floor(1000 / f);
873 }
874 }
875 private int timefps;
877 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
878 public int TimeFps
879 {
880 get
881 {
882 return timefps;
883 }
884 set
885 {
886 timefps = value;
887 float f = value;
888 timelineTimer.Interval = (int)Math.Floor(1000 / f);
889 }
890 }
891 private int cfps;
893 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
894 public int CFps
895 {
896 get
897 {
898 return cfps;
899 }
900 set
901 {
902 cfps = value;
903 float f = value;
904 cTimer.Interval = (int)Math.Floor(1000 / f);
905 }
906 }
910 public void InitGUI()
911 {
912 if (SelectedImage == null)
913 return;
914 zBar.Maximum = SelectedImage.SizeZ - 1;
915 if (SelectedImage.Buffers[0].RGBChannelsCount == 3)
916 cBar.Maximum = 0;
917 else
918 cBar.Maximum = SelectedImage.SizeC - 1;
919 if (SelectedImage.SizeT > 1)
920 {
921 tBar.Maximum = SelectedImage.SizeT - 1;
922 timeEnabled = true;
923 }
924 else
925 {
926 tBar.Enabled = false;
927 timeEnabled = false;
928 tBar.Maximum = SelectedImage.SizeT - 1;
929 }
930 //rgbPictureBox.Image = image.plane.GetBitmap();
931 //we clear the channel comboboxes incase we have channels from previous loaded image.
932 channelBoxR.Items.Clear();
933 channelBoxG.Items.Clear();
934 channelBoxB.Items.Clear();
935
936 foreach (Channel ch in SelectedImage.Channels)
937 {
938 channelBoxR.Items.Add(ch);
939 channelBoxG.Items.Add(ch);
940 channelBoxB.Items.Add(ch);
941 }
942 if (SelectedImage.Channels.Count > 2)
943 {
944 channelBoxR.SelectedIndex = 0;
945 channelBoxG.SelectedIndex = 1;
946 channelBoxB.SelectedIndex = 2;
947 }
948 else
949 if (SelectedImage.Channels.Count == 2)
950 {
951 channelBoxR.SelectedIndex = 0;
952 channelBoxG.SelectedIndex = 1;
953 }
955
956 init = true;
957 }
962 public void UpdateSelectBoxSize(float size)
963 {
964 ROI.selectBoxSize = size;
965 }
970 public void UpdateOverlay()
971 {
972 gl.Invalidate();
973 updateOverlay = true;
974 }
978 public void UpdateStatus()
979 {
980 if (SelectedImage == null)
981 return;
982 string res = "";
983 if (SelectedImage.Type == BioImage.ImageType.well)
984 res = "Well:" + SelectedImage.Level;
985 else if (SelectedImage.Type == BioImage.ImageType.pyramidal)
986 {
987 res = "Res.:" + Resolution + " Level:" + Level;
988 }
989 if (Mode == ViewMode.RGBImage)
990 {
991 if (timeEnabled)
992 {
993 statusLabel.Text = (zBar.Value + 1) + "/" + (zBar.Maximum + 1) + ", " + (tBar.Value + 1) + "/" + (tBar.Maximum + 1) + ", " +
994 mousePoint + mouseColor + ", " + SelectedImage.Buffers[0].PixelFormat.ToString() + ", (" + -Origin.X + ", " + -Origin.Y + "), (" + SelectedImage.Volume.Location.X + ", " + SelectedImage.Volume.Location.Y + ") " + res;
995 }
996 else
997 {
998 statusLabel.Text = (zBar.Value + 1) + "/" + (cBar.Maximum + 1) + ", " + mousePoint + mouseColor + ", " + SelectedImage.Buffers[0].PixelFormat.ToString()
999 + ", (" + -Origin.X + ", " + -Origin.Y + "), (" + SelectedImage.Volume.Location.X + ", " + SelectedImage.Volume.Location.Y + ") " + res;
1000 }
1001
1002 }
1003 else
1004 {
1005 if (timeEnabled)
1006 {
1007 statusLabel.Text = (zBar.Value + 1) + "/" + (zBar.Maximum + 1) + ", " + (cBar.Value + 1) + "/" + (cBar.Maximum + 1) + ", " + (tBar.Value + 1) + "/" + (tBar.Maximum + 1) + ", " +
1008 mousePoint + mouseColor + ", " + SelectedImage.Buffers[0].PixelFormat.ToString() + ", (" + -Origin.X + ", " + -Origin.Y + "), (" + SelectedImage.Volume.Location.X + ", " + SelectedImage.Volume.Location.Y + ") " + res;
1009 }
1010 else
1011 {
1012 statusLabel.Text = (zBar.Value + 1) + "/" + (zBar.Maximum + 1) + ", " + (cBar.Value + 1) + "/" + (cBar.Maximum + 1) + ", " + mousePoint + mouseColor + ", " +
1013 SelectedImage.Buffers[0].PixelFormat.ToString() + ", (" + -Origin.X + ", " + -Origin.Y + "), (" + SelectedImage.Volume.Location.X + ", " + SelectedImage.Volume.Location.Y + ") " + res;
1014 }
1015 }
1016 }
1021 public void UpdateView()
1022 {
1023 UpdateStatus();
1024 update = true;
1025 UpdateImages();
1026 gl.Invalidate();
1027 }
1031 /*
1032 public void RenderFrame()
1033 {
1034 if (!update)
1035 return;
1036 drawing = true;
1037 if (dBitmaps.Count != Images.Count)
1038 UpdateImages();
1039 if (HardwareAcceleration && sk != null)
1040 {
1041 Plugins.Render(this, sk);
1042 sk.BeginDraw();
1043 sk.RenderTarget2D.Clear(new RawColor4(1.0f, 1.0f, 1.0f, 1.0f));
1044 RectangleF rg = ToScreenRect(PointD.MinX, PointD.MinY, PointD.MaxX - PointD.MinX, PointD.MaxY - PointD.MinY);
1045 //dx.RenderTarget2D.Transform = SharpDX.Matrix3x2.Rotation((float)Math.PI);
1046 SharpDX.Direct2D1.SolidColorBrush pen = new SharpDX.Direct2D1.SolidColorBrush(sk.RenderTarget2D, new RawColor4(1.0f, 0.0f, 0.0f, 1.0f));
1047 SharpDX.Direct2D1.SolidColorBrush red = new SharpDX.Direct2D1.SolidColorBrush(sk.RenderTarget2D, new RawColor4(1.0f, 0.0f, 0.0f, 1.0f));
1048 SharpDX.Direct2D1.SolidColorBrush green = new SharpDX.Direct2D1.SolidColorBrush(sk.RenderTarget2D, new RawColor4(0.0f, 1.0f, 0.0f, 1.0f));
1049 SharpDX.Direct2D1.SolidColorBrush mag = new SharpDX.Direct2D1.SolidColorBrush(sk.RenderTarget2D, new RawColor4(1.0f, 0.0f, 1.0f, 1.0f));
1050 SharpDX.Direct2D1.SolidColorBrush blue = new SharpDX.Direct2D1.SolidColorBrush(sk.RenderTarget2D, new RawColor4(0.0f, 0.0f, 1.0f, 1.0f));
1051 SharpDX.Direct2D1.SolidColorBrush b = new SharpDX.Direct2D1.SolidColorBrush(sk.RenderTarget2D, new RawColor4(1.0f, 1.0f, 0.0f, 1.0f));
1052 SharpDX.Direct2D1.SolidColorBrush gray = new SharpDX.Direct2D1.SolidColorBrush(sk.RenderTarget2D, new RawColor4(0.5f, 0.5f, 0.5f, 1.0f));
1053
1054 sk.RenderTarget2D.FillRectangle(ToSKRect(rg.X, rg.Y, rg.Width, rg.Height), gray);
1055 for (int x = 0; x < Images.Count; x++)
1056 {
1057 if (!IsLayerEnabled(Images[x].PhysicalSizeX) && !Images[x].isPyramidal)
1058 continue;
1059 RectangleF r = ToScreenRect(Images[x].Volume.Location.X, Images[x].Volume.Location.Y, Images[x].Volume.Width, Images[x].Volume.Height);
1060 double w = ToViewW(ViewWidth);
1061 double h = ToViewH(ViewHeight);
1062 RectangleF rge = new RectangleF((float)((-Origin.X) - (w / 2)), (float)((-Origin.Y) - (h / 2)), (float)(Math.Abs(w)), (float)(Math.Abs(h)));
1063 RectangleF rec = new RectangleF((float)Images[x].Volume.Location.X, (float)Images[x].Volume.Location.Y, (float)Images[x].Volume.Width, (float)Images[x].Volume.Height);
1064 //if (rge.IntersectsWith(rec))
1065 sk.RenderTarget2D.DrawBitmap(dBitmaps[x], ToSKRect(r.X, r.Y, r.Width, r.Height), 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
1066 if (x == selectedIndex)
1067 sk.RenderTarget2D.DrawRectangle(ToSKRect(r.X, r.Y, r.Width, r.Height), blue);
1068 }
1069 bool bounds = showBounds;
1070 bool labels = showText;
1071 foreach (BioImage bi in Images)
1072 {
1073 if (!IsLayerEnabled(bi.PhysicalSizeX) && !bi.isPyramidal)
1074 continue;
1075 foreach (ROI an in bi.Annotations)
1076 {
1077 if (zBar.Value != an.coord.Z || cBar.Value != an.coord.C || tBar.Value != an.coord.T)
1078 continue;
1079 float w = Math.Abs(Scale.Width);
1080 Font fo = new Font(new FontFamily(an.family), (float)((an.strokeWidth / w) * an.fontSize));
1081 PointF pc = new PointF((float)(an.BoundingBox.X + (an.BoundingBox.W / 2)), (float)(an.BoundingBox.Y + (an.BoundingBox.H / 2)));
1082 float width = 1;
1083 sk.RenderTarget2D.StrokeWidth = width;
1084 if (an.type == ROI.Type.Point)
1085 {
1086 PointF pf = ToScreenSpace(new PointF((float)an.Points[0].X + 1, (float)an.Points[0].Y + 1));
1087 sk.RenderTarget2D.DrawLine(new RawVector2((float)an.Points[0].X, (float)an.Points[0].Y), new RawVector2(pf.X, pf.Y), b);
1088 RectangleF[] rfs = ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize));
1089 for (int i = 0; i < rfs.Length; i++)
1090 {
1091 sk.RenderTarget2D.DrawRectangle(ToSKRect(rfs[i].X, rfs[i].Y, rfs[i].Width, rfs[i].Height), red);
1092 }
1093 }
1094 else
1095 if (an.type == ROI.Type.Line)
1096 {
1097 PointD pf = ToScreenSpace(an.GetPoint(0));
1098 PointD pf2 = ToScreenSpace(an.GetPoint(1));
1099 sk.RenderTarget2D.DrawLine(new RawVector2((float)pf.X, (float)pf.Y), new RawVector2((float)pf2.X, (float)pf2.Y), b);
1100 RectangleF[] rfs = ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize));
1101 for (int i = 0; i < rfs.Length; i++)
1102 {
1103 sk.RenderTarget2D.DrawRectangle(ToSKRect(rfs[i].X, rfs[i].Y, rfs[i].Width, rfs[i].Height), red);
1104 }
1105 }
1106 else
1107 if (an.type == ROI.Type.Rectangle && an.BoundingBox.W > 0 && an.BoundingBox.H > 0)
1108 {
1109 RectangleF rec = ToScreenSpace(an.BoundingBox);
1110 sk.RenderTarget2D.DrawRectangle(ToSKRect(rec.X, rec.Y, rec.Width, rec.Height), red);
1111 RectangleF[] rfs = ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize));
1112 for (int i = 0; i < rfs.Length; i++)
1113 {
1114 sk.RenderTarget2D.DrawRectangle(ToSKRect(rfs[i].X, rfs[i].Y, rfs[i].Width, rfs[i].Height), red);
1115 }
1116 }
1117 else
1118 if (an.type == ROI.Type.Ellipse)
1119 {
1120 RectangleF r = ToScreenSpace(an.BoundingBox);
1121 RectangleF[] rfs = ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize));
1122 RawRectangleF rf = ToSKRect(rfs[0].X, rfs[0].Y, rfs[0].Width, rfs[0].Height);
1123 SharpDX.Direct2D1.Ellipse e = new SharpDX.Direct2D1.Ellipse(new RawVector2(rf.Left + (Math.Abs(r.Width) / 2) - (rfs[0].Width / 2), rf.Top + (Math.Abs(r.Height) / 2) - (rfs[0].Height / 2)), -r.Width / 2, -r.Height / 2);
1124 sk.RenderTarget2D.DrawEllipse(e, b);
1125 for (int i = 0; i < rfs.Length; i++)
1126 {
1127 sk.RenderTarget2D.DrawRectangle(ToSKRect(rfs[i].X, rfs[i].Y, rfs[i].Width, rfs[i].Height), red);
1128 }
1129 }
1130 else
1131 if (an.type == ROI.Type.Polygon && an.closed)
1132 {
1133 RawVector2 pf;
1134 RawVector2 pf2;
1135 for (int i = 0; i < an.Points.Count - 1; i++)
1136 {
1137 pf = new RawVector2((float)ToScreenSpace(an.GetPoint(i).X, an.GetPoint(i).Y).X, (float)ToScreenSpace(an.GetPoint(i).X, an.GetPoint(i).Y).Y);
1138 pf2 = new RawVector2((float)ToScreenSpace(an.GetPoint(i + 1).X, an.GetPoint(i + 1).Y).X, (float)ToScreenSpace(an.GetPoint(i + 1).X, an.GetPoint(i + 1).Y).Y);
1139 sk.RenderTarget2D.DrawLine(pf, pf2, b);
1140 }
1141 pf = new RawVector2((float)ToScreenSpace(an.GetPoint(0)).X, (float)ToScreenSpace(an.GetPoint(0)).Y);
1142 pf2 = new RawVector2((float)ToScreenSpace(an.GetPoint(an.Points.Count - 1)).X, (float)ToScreenSpace(an.GetPoint(an.Points.Count - 1)).Y);
1143 sk.RenderTarget2D.DrawLine(pf, pf2, b);
1144
1145 RectangleF[] rfs = ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize));
1146 for (int i = 0; i < rfs.Length; i++)
1147 {
1148 sk.RenderTarget2D.DrawRectangle(ToSKRect(rfs[i].X, rfs[i].Y, rfs[i].Width, rfs[i].Height), red);
1149 }
1150 }
1151 else
1152 if (an.type == ROI.Type.Polygon && !an.closed || an.type == ROI.Type.Polyline)
1153 {
1154 RawVector2 pf;
1155 RawVector2 pf2;
1156 for (int i = 0; i < an.Points.Count - 1; i++)
1157 {
1158 pf = new RawVector2((float)ToScreenSpace(an.GetPoint(i).X, an.GetPoint(i).Y).X, (float)ToScreenSpace(an.GetPoint(i).X, an.GetPoint(i).Y).Y);
1159 pf2 = new RawVector2((float)ToScreenSpace(an.GetPoint(i + 1).X, an.GetPoint(i + 1).Y).X, (float)ToScreenSpace(an.GetPoint(i + 1).X, an.GetPoint(i + 1).Y).Y);
1160 sk.RenderTarget2D.DrawLine(pf, pf2, b);
1161 sk.RenderTarget2D.DrawLine(pf, pf2, b);
1162 }
1163
1164 RectangleF[] rfs = ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize));
1165 for (int i = 0; i < rfs.Length; i++)
1166 {
1167 sk.RenderTarget2D.DrawRectangle(ToSKRect(rfs[i].X, rfs[i].Y, rfs[i].Width, rfs[i].Height), red);
1168 }
1169
1170 }
1171 else
1172 if (an.type == ROI.Type.Freeform && an.closed)
1173 {
1174 RawVector2 pf;
1175 RawVector2 pf2;
1176 for (int i = 0; i < an.Points.Count - 1; i++)
1177 {
1178 pf = new RawVector2((float)ToScreenSpace(an.GetPoint(i).X, an.GetPoint(i).Y).X, (float)ToScreenSpace(an.GetPoint(i).X, an.GetPoint(i).Y).Y);
1179 pf2 = new RawVector2((float)ToScreenSpace(an.GetPoint(i + 1).X, an.GetPoint(i + 1).Y).X, (float)ToScreenSpace(an.GetPoint(i + 1).X, an.GetPoint(i + 1).Y).Y);
1180 sk.RenderTarget2D.DrawLine(pf, pf2, b);
1181 sk.RenderTarget2D.DrawLine(pf, pf2, b);
1182 }
1183 pf = new RawVector2((float)ToScreenSpace(an.GetPoint(0)).X, (float)ToScreenSpace(an.GetPoint(0)).Y);
1184 pf2 = new RawVector2((float)ToScreenSpace(an.GetPoint(an.Points.Count - 1)).X, (float)ToScreenSpace(an.GetPoint(an.Points.Count - 1)).Y);
1185 sk.RenderTarget2D.DrawLine(pf, pf2, b);
1186 }
1187 if (an.type == ROI.Type.Label)
1188 {
1189 RectangleF rec = ToScreenSpace(an.BoundingBox);
1190 RawRectangleF r = ToSKRect(rec.X, rec.Y, rec.Width, rec.Height);
1191 SharpDX.DirectWrite.TextFormat tex = new SharpDX.DirectWrite.TextFormat(sk.FactoryDWrite, an.family.ToString(), an.fontSize);
1192 sk.RenderTarget2D.DrawText(an.Text, tex, r, b);
1193 tex.Dispose();
1194 RectangleF[] rfs = ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize));
1195 for (int i = 0; i < rfs.Length; i++)
1196 {
1197 sk.RenderTarget2D.DrawRectangle(ToSKRect(rfs[i].X, rfs[i].Y, rfs[i].Width, rfs[i].Height), red);
1198 }
1199 }
1200 if (labels)
1201 {
1202 if (an.Text != null)
1203 {
1204 System.Drawing.Size s = TextRenderer.MeasureText(an.Text, new Font(an.family, an.fontSize));
1205 //Lets draw the text of this ROI in the middle of the ROI.
1206 float fw = ((float)an.BoundingBox.X + ((float)an.BoundingBox.W / 2)) - ((float)s.Width / 2);
1207 float fh = ((float)an.BoundingBox.Y + ((float)an.BoundingBox.H / 2)) - ((float)s.Height / 2);
1208 RawRectangleF r = ToSKRect(fw, fh, s.Width, s.Height);
1209 SharpDX.DirectWrite.TextFormat tex = new SharpDX.DirectWrite.TextFormat(sk.FactoryDWrite, an.family.ToString(), an.fontSize);
1210 sk.RenderTarget2D.DrawText(an.Text, tex, r, b);
1211 tex.Dispose();
1212 }
1213 }
1214 if (bounds)
1215 {
1216 RectangleF r = ToScreenSpace(an.BoundingBox);
1217 sk.RenderTarget2D.DrawRectangle(ToSKRect(r.X, r.Y, r.Width, r.Height), green);
1218 }
1219 if (an.Selected)
1220 {
1221 //Lets draw the selected bounding box.
1222 RectangleF r = ToScreenSpace(an.BoundingBox);
1223 sk.RenderTarget2D.DrawRectangle(ToSKRect(r.X, r.Y, r.Width, r.Height), mag);
1224
1225 //Lets draw the selectBoxes.
1226 List<RectangleD> rects = new List<RectangleD>();
1227 RectangleD[] sels = an.GetSelectBoxes(Tools.selectBoxSize);
1228 for (int i = 0; i < an.selectedPoints.Count; i++)
1229 {
1230 if (an.selectedPoints[i] < an.GetPointCount())
1231 {
1232 rects.Add(sels[an.selectedPoints[i]]);
1233 }
1234 }
1235 if (rects.Count > 0)
1236 {
1237 for (int i = 0; i < rects.Count; i++)
1238 {
1239 RectangleF ri = ToScreenSpace(rects[i]);
1240 sk.RenderTarget2D.DrawRectangle(ToSKRect(ri.X, ri.Y, ri.Width, ri.Height), blue);
1241 }
1242 }
1243 rects.Clear();
1244 }
1245
1246 }
1247 }
1248 if (ShowStage)
1249 {
1250 AForge.RectangleD re = Microscope.GetViewRectangle(false);
1251 RectangleF vr = ToScreenRect(re.X, re.Y, re.W, re.H);
1252 RawRectangleF rr = ToSKRect(vr.X, vr.Y, vr.Width, vr.Height);
1253 sk.RenderTarget2D.DrawRectangle(rr, red);
1254 }
1255
1256 if(Tools.currentTool!=null)
1257 if (Tools.currentTool.type == Tools.Tool.Type.rectSel)// && Modifiers == ModifierType.Button1Mask)
1258 {
1259 var recd = ToScreenRect(Tools.currentTool.Rectangle.X, Tools.currentTool.Rectangle.Y, Tools.currentTool.Rectangle.W, Tools.currentTool.Rectangle.H);
1260 sk.RenderTarget2D.DrawRectangle(ToSKRect((float)recd.X, (float)recd.Y, (float)recd.Width, (float)recd.Height), blue);
1261 }
1262 pen.Dispose();
1263 red.Dispose();
1264 mag.Dispose();
1265 green.Dispose();
1266 blue.Dispose();
1267 gray.Dispose();
1268 b.Dispose();
1269 sk.EndDraw();
1270 }
1271 drawing = false;
1272 }
1273 */
1277 public void UpdateView(bool refresh)
1278 {
1279 UpdateStatus();
1280 update = refresh;
1281 if (update)
1282 {
1283 gl.Invalidate();
1284 }
1285 }
1286 bool updating = false;
1291 public async void UpdateImages(bool updatePyramidal = false)
1292 {
1293 if (SelectedImage == null)
1294 return;
1295 if (SelectedImage.isPyramidal && gl.Width > 1 && gl.Height > 1)
1296 {
1297 if (SelectedImage.isPyramidal)
1298 updatePyr = true;
1299 SelectedImage.PyramidalOrigin = PyramidalOrigin;
1300 SelectedImage.PyramidalSize = new AForge.Size(gl.Width, gl.Height);
1301 // Use the new renderer - no more ReadPixels!
1302 _ = slideRenderer.UpdateViewAsync(
1304 gl.Width,
1305 gl.Height,
1306 Resolution,
1308 );
1309 return;
1310 }
1311 for (int i = 0; i < Bitmaps.Count; i++)
1312 {
1313 Bitmaps[i].Dispose();
1314 Bitmaps[i] = null;
1315 }
1316 Bitmaps.Clear();
1317 if (zBar.Maximum != SelectedImage.SizeZ - 1 || tBar.Maximum != SelectedImage.SizeT - 1)
1318 {
1319 InitGUI();
1320 }
1321
1322 int bi = 0;
1323 foreach (BioImage b in Images)
1324 {
1325 if (b.isPyramidal)
1326 updatePyr = true;
1327 b.PyramidalOrigin = PyramidalOrigin;
1328 b.PyramidalSize = new AForge.Size(gl.Width, gl.Height);
1329 ZCT coords = new ZCT(zBar.Value, cBar.Value, tBar.Value);
1330 Bitmap bitmap = null;
1331
1332 int index = b.Coords[zBar.Value, cBar.Value, tBar.Value];
1333 if (Mode == ViewMode.Filtered)
1334 {
1335 bitmap = b.GetFiltered(coords, b.RChannel.RangeR, b.GChannel.RangeG, b.BChannel.RangeB);
1336 }
1337 else if (Mode == ViewMode.RGBImage)
1338 {
1339 bitmap = b.GetRGBBitmap(coords, b.RChannel.RangeR, b.GChannel.RangeG, b.BChannel.RangeB);
1340 }
1341 else if (Mode == ViewMode.Raw)
1342 {
1343 bitmap = (Bitmap)b.Buffers[index].GetImageRGBA();
1344 }
1345 else
1346 {
1347 bitmap = b.GetEmission(coords, b.RChannel.RangeR, b.GChannel.RangeG, b.BChannel.RangeB);
1348 }
1349 Bitmaps.Add(ToSysBitmap(bitmap));
1350 bi++;
1351 }
1352 update = true;
1353 }
1354 bool drawing = false;
1355 public void RemoveImage(int i)
1356 {
1357 do
1358 {
1359 System.Threading.Thread.Sleep(50);
1360 Application.DoEvents();
1361 } while (drawing || updating);
1362 Images[i].Dispose();
1363 Images.RemoveAt(i);
1364 UpdateImages();
1365 }
1366 public void RemoveImages()
1367 {
1368 do
1369 {
1370 Thread.Sleep(50);
1371 Application.DoEvents();
1372 } while (drawing || updating);
1373 for (int i = 0; i < Images.Count; i++)
1374 {
1375 Images[i].Dispose();
1376 }
1377 Images.Clear();
1378 UpdateImages();
1379 }
1380 Bitmap bitmap;
1384 public void UpdateImage()
1385 {
1386 UpdateImages();
1387 }
1395 private void channelBoxR_SelectedIndexChanged(object sender, EventArgs e)
1396 {
1397 if (channelBoxR.SelectedIndex == -1)
1398 return;
1399 SelectedImage.rgbChannels[0] = channelBoxR.SelectedIndex;
1400 update = true;
1401 UpdateView();
1402 }
1410 private void channelBoxG_SelectedIndexChanged(object sender, EventArgs e)
1411 {
1412 if (channelBoxG.SelectedIndex == -1)
1413 return;
1414 SelectedImage.rgbChannels[1] = channelBoxG.SelectedIndex;
1415 update = true;
1416 UpdateView();
1417 }
1425 private void channelBoxB_SelectedIndexChanged(object sender, EventArgs e)
1426 {
1427 if (channelBoxB.SelectedIndex == -1)
1428 return;
1429 SelectedImage.rgbChannels[2] = channelBoxB.SelectedIndex;
1430 update = true;
1431 UpdateView();
1432 }
1440 private void showControlsToolStripMenuItem_Click(object sender, EventArgs e)
1441 {
1442 if (trackBarPanel.Visible)
1443 {
1444 trackBarPanel.Hide();
1445 trackBarPanel.Height = 0;
1446 Application.DoEvents();
1447 gl.Height += 75;
1448 showControlsToolStripMenuItem.Text = "Show Controls";
1449 gl.Dock = DockStyle.Fill;
1450 }
1451 else
1452 {
1453 trackBarPanel.Show();
1454 gl.Height -= 75;
1455 Application.DoEvents();
1456 trackBarPanel.Height = 75;
1457 showControlsToolStripMenuItem.Text = "Hide Controls";
1458 gl.Dock = DockStyle.Fill;
1459 }
1460
1461 }
1466 private void playZToolStripMenuItem_Click(object sender, EventArgs e)
1467 {
1468 if (playZToolStripMenuItem.Checked)
1469 {
1470 //We stop
1471 playZToolStripMenuItem.Checked = false;
1472 stopZToolStripMenuItem.Checked = true;
1473 zTimer.Stop();
1474 }
1475 else
1476 {
1477 //We start
1478 playZToolStripMenuItem.Checked = true;
1479 stopZToolStripMenuItem.Checked = false;
1480 zTimer.Start();
1481 }
1482 }
1487 private void stopZToolStripMenuItem_Click(object sender, EventArgs e)
1488 {
1489 if (stopZToolStripMenuItem.Checked)
1490 {
1491 //We start
1492 playZToolStripMenuItem.Checked = true;
1493 stopZToolStripMenuItem.Checked = false;
1494 zTimer.Start();
1495
1496 }
1497 else
1498 {
1499 //We stop
1500 playZToolStripMenuItem.Checked = false;
1501 stopZToolStripMenuItem.Checked = true;
1502 zTimer.Stop();
1503 }
1504 }
1509 private void playTimeToolStripMenu_Click(object sender, EventArgs e)
1510 {
1511 if (playTimeToolStripMenu.Checked)
1512 {
1513 //We stop
1514 playTimeToolStripMenu.Checked = false;
1515 stopTimeToolStripMenu.Checked = true;
1516 timelineTimer.Stop();
1517 }
1518 else
1519 {
1520 //We start
1521 playTimeToolStripMenu.Checked = true;
1522 stopTimeToolStripMenu.Checked = false;
1523 timelineTimer.Start();
1524 }
1525 }
1531 private void stopTimeToolStripMenu_Click(object sender, EventArgs e)
1532 {
1533 playTimeToolStripMenu.Checked = false;
1534 stopTimeToolStripMenu.Checked = true;
1535 timelineTimer.Stop();
1536 }
1541 private void playCToolStripMenuItem_Click(object sender, EventArgs e)
1542 {
1543 if (playCToolStripMenuItem.Checked)
1544 {
1545 //We stop
1546 playCToolStripMenuItem.Checked = false;
1547 stopCToolStripMenuItem.Checked = true;
1548 cTimer.Stop();
1549 }
1550 else
1551 {
1552 //We start
1553 playCToolStripMenuItem.Checked = true;
1554 stopCToolStripMenuItem.Checked = false;
1555 cTimer.Start();
1556 }
1557 }
1563 private void stopCToolStripMenuItem_Click(object sender, EventArgs e)
1564 {
1565 stopCToolStripMenuItem.Checked = false;
1566 playCToolStripMenuItem.Checked = true;
1567 cTimer.Stop();
1568 }
1569 private string mousePoint = "";
1570 private string mouseColor = "";
1577 private void playSpeedToolStripMenuItem_Click(object sender, EventArgs e)
1578 {
1579 PlaySpeed sp = null;
1580 if (Mode == ViewMode.RGBImage)
1581 sp = new PlaySpeed(timeEnabled, false, ZFps, TimeFps, CFps);
1582 else
1583 sp = new PlaySpeed(timeEnabled, true, ZFps, TimeFps, CFps);
1584 if (sp.ShowDialog() != DialogResult.OK)
1585 return;
1586 zTimer.Interval = sp.TimePlayspeed;
1587 cTimer.Interval = sp.CPlayspeed;
1588 timelineTimer.Interval = sp.TimePlayspeed;
1589 }
1596 private void playSpeedToolStripMenuItem1_Click(object sender, EventArgs e)
1597 {
1598 PlaySpeed sp = null;
1599 if (Mode == ViewMode.RGBImage)
1600 sp = new PlaySpeed(timeEnabled, false, ZFps, TimeFps, CFps);
1601 else
1602 sp = new PlaySpeed(timeEnabled, true, ZFps, TimeFps, CFps);
1603 if (sp.ShowDialog() != DialogResult.OK)
1604 return;
1605 zTimer.Interval = sp.TimePlayspeed;
1606 cTimer.Interval = sp.CPlayspeed;
1607 timelineTimer.Interval = sp.TimePlayspeed;
1608 }
1616 private void CPlaySpeedToolStripMenuItem_Click(object sender, EventArgs e)
1617 {
1618 PlaySpeed sp = null;
1619 if (Mode == ViewMode.RGBImage)
1620 sp = new PlaySpeed(timeEnabled, false, ZFps, TimeFps, CFps);
1621 else
1622 sp = new PlaySpeed(timeEnabled, true, ZFps, TimeFps, CFps);
1623 if (sp.ShowDialog() != DialogResult.OK)
1624 return;
1625 zTimer.Interval = sp.TimePlayspeed;
1626 cTimer.Interval = sp.CPlayspeed;
1627 timelineTimer.Interval = sp.TimePlayspeed;
1628 }
1648 public void GetRange()
1649 {
1650 RangeTool t;
1651 if (Mode == ViewMode.Filtered)
1652 t = new RangeTool(timeEnabled, true, zBar.Minimum, zBar.Maximum, tBar.Minimum, tBar.Maximum, cBar.Minimum, cBar.Maximum);
1653 else
1654 t = new RangeTool(timeEnabled, false, zBar.Minimum, zBar.Maximum, tBar.Minimum, tBar.Maximum, cBar.Minimum, cBar.Maximum);
1655 if (t.ShowDialog() != DialogResult.OK)
1656 return;
1657 zBar.Minimum = t.ZMin;
1658 zBar.Maximum = t.ZMax;
1659 tBar.Minimum = t.TimeMin;
1660 tBar.Maximum = t.TimeMax;
1661 cBar.Minimum = t.CMin;
1662 cBar.Maximum = t.CMax;
1663 }
1664 private void setValueRangeToolStripMenuItem_Click(object sender, EventArgs e)
1665 {
1666 GetRange();
1667 }
1668 private void setValueRangeToolStripMenuItem1_Click(object sender, EventArgs e)
1669 {
1670 GetRange();
1671 }
1672 private void setCValueRangeToolStripMenuItem_Click(object sender, EventArgs e)
1673 {
1674 GetRange();
1675 }
1680 private void ImageView_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
1681 {
1682 Plugins.ScrollEvent(sender, e);
1683 if (SelectedImage != null)
1684 if (SelectedImage.isPyramidal)
1685 {
1686 if (Ctrl)
1687 if (e.Delta > 0)
1688 {
1689 Resolution *= 0.95;
1690 }
1691 else
1692 {
1693 Resolution *= 1.05;
1694 }
1695 }
1696 float dx = Scale.Width / 50;
1697 float dy = Scale.Height / 50;
1698 if (Ctrl)
1699 {
1700 float dsx = dSize.Width / 50;
1701 float dsy = dSize.Height / 50;
1702 if (e.Delta > 0)
1703 {
1704 Scale = new SizeF(Scale.Width + dx, Scale.Height + dy);
1705 dSize.Width += dsx;
1706 dSize.Height += dsy;
1707 }
1708 else
1709 {
1710 Scale = new SizeF(Scale.Width - dx, Scale.Height - dy);
1711 dSize.Width -= dsx;
1712 dSize.Height -= dsy;
1713 }
1714 UpdateView();
1715 }
1716 else
1717 if (e.Delta > 0)
1718 {
1719 if (zBar.Value + 1 <= zBar.Maximum)
1720 zBar.Value += 1;
1721 }
1722 else
1723 {
1724 if (zBar.Value - 1 >= zBar.Minimum)
1725 zBar.Value -= 1;
1726 }
1727
1728 }
1734 private void ZTrackBar_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
1735 {
1736 if (e.Delta > 0)
1737 {
1738 if (zBar.Value + 1 <= zBar.Maximum)
1739 zBar.Value += 1;
1740 }
1741 else
1742 {
1743 if (zBar.Value - 1 >= zBar.Minimum)
1744 zBar.Value -= 1;
1745 }
1746
1747 }
1755 private void TimeTrackBar_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
1756 {
1757 if (!timeEnabled)
1758 return;
1759 if (e.Delta > 0)
1760 {
1761 if (tBar.Value + 1 <= tBar.Maximum)
1762 tBar.Value += 1;
1763 }
1764 else
1765 {
1766 if (tBar.Value - 1 >= tBar.Minimum)
1767 tBar.Value -= 1;
1768 }
1769 }
1775 private void CTrackBar_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
1776 {
1777 if (e.Delta > 0)
1778 {
1779 if (cBar.Value + 1 <= cBar.Maximum)
1780 cBar.Value += 1;
1781 }
1782 else
1783 {
1784 if (cBar.Value - 1 >= cBar.Minimum)
1785 cBar.Value -= 1;
1786 }
1787 }
1788
1795 private void cTimer_Tick(object sender, EventArgs e)
1796 {
1797 if (playCToolStripMenuItem.Checked)
1798 {
1799 if (cBar.Maximum >= cBar.Value + 1)
1800 cBar.Value++;
1801 else
1802 {
1803 if (loopC)
1804 cBar.Value = cBar.Minimum;
1805 }
1806 }
1807 }
1814 private void zTimer_Tick(object sender, EventArgs e)
1815 {
1816 if (playZToolStripMenuItem.Checked)
1817 {
1818 if (zBar.Maximum >= zBar.Value + 1)
1819 zBar.Value++;
1820 else
1821 {
1822 if (loopZ)
1823 zBar.Value = zBar.Minimum;
1824 }
1825 }
1826 }
1834 private void timer_Tick(object sender, EventArgs e)
1835 {
1836 if (playTimeToolStripMenu.Checked)
1837 {
1838 if (tBar.Maximum >= tBar.Value + 1)
1839 tBar.Value++;
1840 else
1841 {
1842 if (loopT)
1843 tBar.Value = tBar.Minimum;
1844 }
1845 }
1846 }
1854 private void zBar_ValueChanged(object sender, EventArgs e)
1855 {
1856 if (SelectedImage == null)
1857 return;
1858 SelectedImage.Coordinate = new ZCT(zBar.Value, SelectedImage.Coordinate.C, SelectedImage.Coordinate.T);
1859 update = true;
1860 UpdateImage();
1861 UpdateView();
1862 }
1869 private void timeBar_ValueChanged(object sender, EventArgs e)
1870 {
1871 if (SelectedImage == null)
1872 return;
1873 SelectedImage.Coordinate = new ZCT(SelectedImage.Coordinate.Z, SelectedImage.Coordinate.C, tBar.Value);
1874 update = true;
1875 UpdateImage();
1876 UpdateView();
1877 }
1885 private void cBar_ValueChanged(object sender, EventArgs e)
1886 {
1887 if (SelectedImage == null)
1888 return;
1889 SelectedImage.Coordinate = new ZCT(SelectedImage.Coordinate.Z, cBar.Value, SelectedImage.Coordinate.T);
1890 update = true;
1891 UpdateImage();
1892 UpdateView();
1893 }
1894
1895 private void loopTimeToolStripMenuItem_Click(object sender, EventArgs e)
1896 {
1897 loopT = loopTimeToolStripMenuItem.Checked;
1898 }
1899 private void loopZToolStripMenuItem_Click(object sender, EventArgs e)
1900 {
1901 loopZ = loopZToolStripMenuItem.Checked;
1902 }
1903 private void loopCToolStripMenuItem_Click(object sender, EventArgs e)
1904 {
1905 loopC = loopCToolStripMenuItem.Checked;
1906 }
1907
1908 public bool showRROIs = true;
1909 public bool showGROIs = true;
1910 public bool showBROIs = true;
1911
1912 private List<ROI> annotationsR = new List<ROI>();
1913 public List<ROI> AnnotationsR
1914 {
1915 get
1916 {
1917 return SelectedImage.GetAnnotations(SelectedImage.Coordinate.Z, SelectedImage.RChannel.Index, SelectedImage.Coordinate.T);
1918 }
1919 }
1920 private List<ROI> annotationsG = new List<ROI>();
1921 public List<ROI> AnnotationsG
1922 {
1923 get
1924 {
1925 return SelectedImage.GetAnnotations(SelectedImage.Coordinate.Z, SelectedImage.GChannel.Index, SelectedImage.Coordinate.T);
1926 }
1927 }
1928 private List<ROI> annotationsB = new List<ROI>();
1929 public List<ROI> AnnotationsB
1930 {
1931 get
1932 {
1933 return SelectedImage.GetAnnotations(SelectedImage.Coordinate.Z, SelectedImage.BChannel.Index, SelectedImage.Coordinate.T);
1934 }
1935 }
1936 public List<ROI> AnnotationsRGB
1937 {
1938 get
1939 {
1940 if (SelectedImage == null)
1941 return null;
1942 List<ROI> ans = new List<ROI>();
1943 if (Mode == ViewMode.RGBImage)
1944 {
1945 if (showRROIs)
1946 ans.AddRange(AnnotationsR);
1947 if (showGROIs)
1948 ans.AddRange(AnnotationsG);
1949 if (showBROIs)
1950 ans.AddRange(AnnotationsB);
1951 }
1952 else
1953 {
1954 ans.AddRange(SelectedImage.GetAnnotations(SelectedImage.Coordinate));
1955 }
1956 return ans;
1957 }
1958 }
1959 private System.Drawing.Point ToPoint(AForge.Point p)
1960 {
1961 return new System.Drawing.Point((int)p.X, (int)p.Y);
1962 }
1963 private System.Drawing.PointF ToPointF(PointD p)
1964 {
1965 return new System.Drawing.PointF((float)p.X, (float)p.Y);
1966 }
1972 private void DrawOverlay(System.Drawing.Graphics g)
1973 {
1974 if (SelectedImage == null)
1975 return;
1976 if (!updateOverlay)
1977 return;
1978 SetCoordinate(zBar.Value, cBar.Value, tBar.Value);
1979 System.Drawing.Pen pen = null;
1980 System.Drawing.Pen red = null;
1981 System.Drawing.Pen green = null;
1982 System.Drawing.Pen mag = null;
1983 System.Drawing.Pen blue = null;
1984 Brush b = null;
1985 bool bounds = showBounds;
1986 bool labels = showText;
1987 ZCT cor = GetCoordinate();
1988 foreach (BioImage bi in Images)
1989 {
1990 if (!IsLayerEnabled(bi.PhysicalSizeX))
1991 continue;
1992 foreach (ROI an in bi.Annotations)
1993 {
1994 if (Mode == ViewMode.RGBImage)
1995 {
1996 if (!showRROIs && an.coord.C == 0)
1997 continue;
1998 if (!showGROIs && an.coord.C == 1)
1999 continue;
2000 if (!showBROIs && an.coord.C == 2)
2001 continue;
2002 }
2003 else if (zBar.Value != an.coord.Z || cBar.Value != an.coord.C || tBar.Value != an.coord.T)
2004 continue;
2005 float w = Math.Abs(Scale.Width);
2006 pen = new System.Drawing.Pen(new SolidBrush(System.Drawing.Color.FromArgb(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B)), (float)an.strokeWidth / w);
2007 red = new System.Drawing.Pen(Brushes.Red, (float)an.strokeWidth / w);
2008 mag = new System.Drawing.Pen(Brushes.Magenta, (float)an.strokeWidth / w);
2009 green = new System.Drawing.Pen(Brushes.Green, (float)an.strokeWidth / w);
2010 blue = new System.Drawing.Pen(Brushes.Blue, (float)an.strokeWidth / w);
2011 Font fo = new Font(an.family, (float)(an.strokeWidth / w) * an.fontSize);
2012 if (an.Selected)
2013 {
2014 b = new SolidBrush(System.Drawing.Color.Magenta);
2015 }
2016 else
2017 b = new SolidBrush(System.Drawing.Color.FromArgb(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B));
2018 PointF pc = new PointF((float)(an.BoundingBox.X + (an.BoundingBox.W / 2)), (float)(an.BoundingBox.Y + (an.BoundingBox.H / 2)));
2019 float width = (float)ToViewSizeW(ROI.selectBoxSize / w);
2020 if (SelectedImage.isPyramidal)
2021 {
2022 width = (float)(ROI.selectBoxSize * Resolution);
2023 }
2024 if (an.type == ROI.Type.Point)
2025 {
2026 g.DrawLine(pen, ToPointF(ToScreenSpace(an.Points[0])), ToPointF(ToScreenSpace(an.Points[0].X + 1, an.Points[0].Y + 1)));
2027 foreach (var item in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2028 {
2029 g.DrawRectangle(red, new System.Drawing.RectangleF((float)item.X, (float)item.Y, (float)item.W, (float)item.H));
2030 }
2031 }
2032 else
2033 if (an.type == ROI.Type.Line)
2034 {
2035 g.DrawLine(pen, ToPointF(ToScreenSpace(an.Points[0])), ToPointF(ToScreenSpace(an.GetPoint(1))));
2036 foreach (var item in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2037 {
2038 g.DrawRectangle(red, new System.Drawing.RectangleF((float)item.X, (float)item.Y, (float)item.W, (float)item.H));
2039 }
2040 }
2041 else
2042 if (an.type == ROI.Type.Rectangle && an.BoundingBox.W > 0 && an.BoundingBox.H > 0)
2043 {
2044 g.DrawRectangle(pen, new System.Drawing.RectangleF((float)an.BoundingBox.X, (float)an.BoundingBox.Y, (float)an.W, (float)an.H));
2045 foreach (var item in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2046 {
2047 g.DrawRectangle(red, new System.Drawing.RectangleF((float)item.X, (float)item.Y, (float)item.W, (float)item.H));
2048 }
2049 }
2050 else
2051 if (an.type == ROI.Type.Ellipse)
2052 {
2053 RectangleD rec = ToScreenSpace(an.BoundingBox);
2054 g.DrawEllipse(pen, (float)rec.X, (float)rec.Y, (float)rec.W, (float)rec.H);
2055 foreach (var item in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2056 {
2057 g.DrawRectangle(red, new System.Drawing.RectangleF((float)item.X, (float)item.Y, (float)item.W, (float)item.H));
2058 }
2059 }
2060 else
2061 if (an.type == ROI.Type.Polygon && an.closed)
2062 {
2063 if (an.Points.Count > 1)
2064 {
2065 System.Drawing.Point[] pts = new System.Drawing.Point[an.Points.Count];
2066 for (int i = 0; i < an.Points.Count; i++)
2067 {
2068 var p = ToScreenSpace(an.Points[i].X, an.Points[i].Y);
2069 pts[i] = new System.Drawing.Point((int)p.X, (int)p.Y);
2070 }
2071 g.DrawLines(pen, pts);
2072 }
2073 foreach (var item in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2074 {
2075 g.DrawRectangle(red, new System.Drawing.RectangleF((float)item.X, (float)item.Y, (float)item.W, (float)item.H));
2076 }
2077 }
2078 else
2079 if (an.type == ROI.Type.Polygon && !an.closed)
2080 {
2081 if (an.Points.Count > 1)
2082 {
2083 System.Drawing.Point[] pts = new System.Drawing.Point[an.Points.Count - 1];
2084 for (int i = 0; i < an.Points.Count - 1; i++)
2085 {
2086 var p = ToScreenSpace(an.Points[i].X, an.Points[i].Y);
2087 pts[i] = new System.Drawing.Point((int)p.X, (int)p.Y);
2088 }
2089 g.DrawLines(pen, pts);
2090 }
2091 foreach (var item in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2092 {
2093 g.DrawRectangle(red, new System.Drawing.RectangleF((float)item.X, (float)item.Y, (float)item.W, (float)item.H));
2094 }
2095 }
2096 else
2097 if (an.type == ROI.Type.Polyline)
2098 {
2099 if (an.Points.Count > 1)
2100 {
2101 System.Drawing.Point[] pts = new System.Drawing.Point[an.Points.Count - 1];
2102 for (int i = 0; i < an.Points.Count - 1; i++)
2103 {
2104 var p = ToScreenSpace(an.Points[i].X, an.Points[i].Y);
2105 pts[i] = new System.Drawing.Point((int)p.X, (int)p.Y);
2106 }
2107 g.DrawLines(pen, pts);
2108 }
2109 foreach (var item in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2110 {
2111 g.DrawRectangle(red, new System.Drawing.RectangleF((float)item.X, (float)item.Y, (float)item.W, (float)item.H));
2112 }
2113 }
2114
2115 else
2116 if (an.type == ROI.Type.Freeform && an.closed)
2117 {
2118 if (an.Points.Count > 1)
2119 {
2120 System.Drawing.Point[] pts = new System.Drawing.Point[an.Points.Count];
2121 for (int i = 0; i < an.Points.Count; i++)
2122 {
2123 var p = ToScreenSpace(an.Points[i].X, an.Points[i].Y);
2124 pts[i] = new System.Drawing.Point((int)p.X, (int)p.Y);
2125 }
2126 g.DrawLines(pen, pts);
2127 }
2128 }
2129 else
2130 if (an.type == ROI.Type.Freeform && !an.closed)
2131 {
2132 if (an.Points.Count > 1)
2133 {
2134 System.Drawing.Point[] pts = new System.Drawing.Point[an.Points.Count - 1];
2135 for (int i = 0; i < an.Points.Count - 1; i++)
2136 {
2137 var p = ToScreenSpace(an.Points[i].X, an.Points[i].Y);
2138 pts[i] = new System.Drawing.Point((int)p.X, (int)p.Y);
2139 }
2140 g.DrawLines(pen, pts);
2141 }
2142 }
2143 if (an.type == ROI.Type.Label)
2144 {
2145 var v = ToScreenSpace(an.Points[0]);
2146 g.DrawString(an.Text, fo, b, (float)v.X, (float)v.Y);
2147 foreach (var item in ToScreenSpace(an.GetSelectBoxes(Tools.selectBoxSize)))
2148 {
2149 g.DrawRectangle(red, new System.Drawing.RectangleF((float)item.X, (float)item.Y, (float)item.W, (float)item.H));
2150 }
2151 }
2152 if (labels)
2153 {
2154 System.Drawing.SizeF s = System.Windows.Forms.TextRenderer.MeasureText(an.Text, new Font(an.family, an.fontSize));
2155 //Lets draw the text of this ROI in the middle of the RO
2156 float fw = ((float)an.BoundingBox.X + ((float)an.BoundingBox.W / 2)) - ((float)s.Width / 2);
2157 float fh = ((float)an.BoundingBox.Y + ((float)an.BoundingBox.H / 2)) - ((float)s.Height / 2);
2158 var v = ToScreenSpace(new PointF(fw, fh));
2159 g.DrawString(an.Text, fo, b, v.X, v.Y);
2160 }
2161 if (bounds)
2162 {
2163 var v = ToScreenSpace(an.BoundingBox);
2164 g.DrawRectangles(green, new System.Drawing.RectangleF[1] { new System.Drawing.RectangleF((float)v.X, (float)v.Y, (float)v.W, (float)v.H) });
2165 }
2166 if (an.Selected)
2167 {
2168 //Lets draw the bounding box.
2169 var v = ToScreenSpace(an.BoundingBox);
2170 g.DrawRectangles(mag, new System.Drawing.RectangleF[1] { new System.Drawing.RectangleF((float)v.X, (float)v.Y, (float)v.W, (float)v.H) });
2171 //Lets draw the selectBoxes.
2172 List<RectangleD> rects = new List<RectangleD>();
2173 RectangleD[] sels = an.GetSelectBoxes(Tools.selectBoxSize);
2174 for (int i = 0; i < an.selectedPoints.Count; i++)
2175 {
2176 if (an.selectedPoints[i] < an.GetPointCount())
2177 {
2178 rects.Add(sels[an.selectedPoints[i]]);
2179 }
2180 }
2181 for (int i = 0; i < rects.Count; i++)
2182 {
2183 var va = ToScreenSpace(rects.ToArray());
2184 g.DrawRectangle(blue, new System.Drawing.RectangleF((float)va[0].X, (float)va[0].Y, (float)va[0].W, (float)va[0].H));
2185 }
2186
2187 rects.Clear();
2188 //Lets draw the text of this ROI in the middle of the ROI
2189 System.Drawing.Size s = System.Windows.Forms.TextRenderer.MeasureText(an.Text, new Font(an.family, an.fontSize));
2190 float fw = ((float)an.BoundingBox.X + ((float)an.BoundingBox.W / 2)) - ((float)s.Width / 2);
2191 float fh = ((float)an.BoundingBox.Y + ((float)an.BoundingBox.H / 2)) - ((float)s.Height / 2);
2192 var vv = ToScreenSpace(new PointF(fw, fh));
2193 g.DrawString(an.Text, fo, b, vv.X, vv.Y);
2194 }
2195 pen.Dispose();
2196 red.Dispose();
2197 mag.Dispose();
2198 green.Dispose();
2199 blue.Dispose();
2200 b.Dispose();
2201 }
2202 }
2203 }
2208 AForge.SizeF dSize = new AForge.SizeF(1, 1);
2209 bool updatePyr = false;
2214 public void DrawView(System.Drawing.Graphics g)
2215 {
2216 try
2217 {
2218 drawing = true;
2219 if (SelectedImage == null)
2220 return;
2221 if (SelectedImage.isPyramidal)
2222 {
2223 UpdateImages(true);
2224 updatePyr = false;
2225 return;
2226 }
2227 g.TranslateTransform(ViewWidth / 2, ViewHeight / 2);
2228 if (Scale.Width == 0 || float.IsInfinity(Scale.Width))
2229 Scale = new SizeF(1, 1);
2230 g.ScaleTransform(Scale.Width, Scale.Height);
2231 if (Bitmaps.Count == 0)
2232 return;
2233 System.Drawing.RectangleF[] rf = new System.Drawing.RectangleF[1];
2234 System.Drawing.Pen blue = new System.Drawing.Pen(Brushes.Blue, 1 / Scale.Width);
2235 int i = 0;
2236 foreach (BioImage im in Images)
2237 {
2238 if (!IsLayerEnabled(im.PhysicalSizeX) && !im.isPyramidal)
2239 continue;
2240 RectangleD r = ToScreenRect(im.Volume.Location.X, im.Volume.Location.Y, im.Volume.Width, im.Volume.Height);
2241 double w = ToViewW(ViewWidth);
2242 double h = ToViewH(ViewHeight);
2243 RectangleF rg = new RectangleF((float)((-Origin.X) - (w / 2)), (float)((-Origin.Y) - (h / 2)), (float)(w), (float)(h));
2244 RectangleF rec = new RectangleF((float)im.Volume.Location.X, (float)im.Volume.Location.Y, (float)im.Volume.Width, (float)im.Volume.Height);
2245 if (SelectedImage.isPyramidal)
2246 {
2247 var tr = g.Transform;
2248 g.ResetTransform();
2249 g.DrawImage(Bitmaps[i], 0, 0);
2250 g.Transform = tr;
2251 }
2252 else
2253 if (rg.IntersectsWith(rec))
2254 {
2255 g.DrawImage(Bitmaps[i], (float)r.X, (float)r.Y, (float)r.W, (float)r.H);
2256 }
2257 if (i == SelectedIndex && !SelectedImage.isPyramidal)
2258 {
2259 rf[0] = new System.Drawing.RectangleF((float)r.X, (float)r.Y, (float)r.W, (float)r.H);
2260 g.DrawRectangles(blue, rf);
2261 }
2262 i++;
2263 }
2264 if (ShowOverview)
2265 {
2266 g.ResetTransform();
2267 g.DrawImage(ToSysBitmap(overviewBitmap), new System.Drawing.Point(0, 0));
2268 g.DrawRectangle(Pens.Gray, overview.X, overview.Y, overview.Width, overview.Height);
2269 if (!openSlide)
2270 {
2271 double dsx = _slideBase.Schema.Resolutions[Level].UnitsPerPixel / Resolution;
2272 Resolution rs = SelectedImage.Resolutions[Level];
2273 double dx = ((double)PyramidalOrigin.X / (rs.SizeX * dsx)) * overview.Width;
2274 double dy = ((double)PyramidalOrigin.Y / (rs.SizeY * dsx)) * overview.Height;
2275 double dw = ((double)ViewWidth / (rs.SizeX)) * overview.Width * dsx;
2276 double dh = ((double)ViewHeight / (rs.SizeY)) * overview.Height * dsx;
2277 g.DrawRectangle(Pens.Red, (int)dx, (int)dy, (int)dw, (int)dh);
2278 }
2279 else
2280 {
2281 double dsx = _openSlideBase.Schema.Resolutions[Level].UnitsPerPixel / Resolution;
2282 var rs = _openSlideBase.Schema.Resolutions.Last();
2283 Resolution rss = SelectedImage.Resolutions[Level];
2284 double dx = ((double)PyramidalOrigin.X / (rss.SizeX * dsx)) * overview.Width;
2285 double dy = ((double)PyramidalOrigin.Y / (rss.SizeY * dsx)) * overview.Height;
2286 double dw = ((double)ViewWidth / (rss.SizeX * dsx)) * overview.Width;
2287 double dh = ((double)ViewHeight / (rss.SizeY * dsx)) * overview.Height;
2288 g.DrawRectangle(Pens.Red, (int)dx, (int)dy, (int)dw, (int)dh);
2289 }
2290 }
2291 if (ShowStage)
2292 {
2293 RectangleD d = Microscope.GetViewRectangle(false);
2294 RectangleF[] rfs = new RectangleF[1] { new RectangleF((float)d.X, (float)d.Y, (float)d.W, (float)d.H) };
2295 var v = ToScreenSpace(rfs);
2296 System.Drawing.Pen red = new System.Drawing.Pen(Brushes.Red, 1 / Scale.Width);
2297 g.DrawRectangle(red, v[0].X, v[0].Y, v[0].Width, v[0].Height);
2298 }
2299 blue.Dispose();
2300 update = false;
2301 drawing = false;
2302 }
2303 catch (Exception e)
2304 {
2305 Console.WriteLine(e.Message);
2306 }
2307 }
2308 private double scaleorig = 0;
2313 private void pictureBox_Paint(object sender, PaintEventArgs e)
2314 {
2315 update = true;
2316 //
2317 gl.BringToFront();
2318 //Render(gl.CreateGraphics());
2319 DrawView(gl.CreateGraphics());
2320 Plugins.Paint(sender, e);
2321 }
2325 public double GetScale()
2326 {
2327 return ToViewSizeW(ROI.selectBoxSize / Scale.Width);
2328 }
2329 private System.Drawing.Bitmap ToSysBitmap(Bitmap bm)
2330 {
2331 return new System.Drawing.Bitmap(bm.Width, bm.Height, bm.Width * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, bm.GetImageRGBA().Data);
2332 }
2333 PointD mouseD = new PointD(0, 0);
2334 PointD prevMove = new PointD();
2342 private void rgbPictureBox_MouseMove(object sender, MouseEventArgs e)
2343 {
2344 PointD p = ImageToViewSpace(e.Location.X, e.Location.Y);
2345 tools.ToolMove(p, e.Button);
2346 mouseMove = p;
2347 MouseMoveInt = new PointD(e.X, e.Y);
2348 if (SelectedImage == null)
2349 return;
2350 if (SelectedImage.isPyramidal && overview.IntersectsWith(e.X, e.Y) && e.Button.HasFlag(MouseButtons.Left))
2351 {
2352 if (!OpenSlide)
2353 {
2354 double dsx = _slideBase.Schema.Resolutions[Level].UnitsPerPixel / Resolution;
2355 Resolution rs = SelectedImage.Resolutions[(int)Level];
2356 double dx = ((double)e.X / overview.Width) * (rs.SizeX * dsx);
2357 double dy = ((double)e.Y / overview.Height) * (rs.SizeY * dsx);
2358 double w = (double)gl.Width / 2;
2359 double h = (double)gl.Height / 2;
2360 PyramidalOrigin = new PointD(dx - w, dy - h);
2361 }
2362 else
2363 {
2364 double dsx = _openSlideBase.Schema.Resolutions[Level].UnitsPerPixel / Resolution;
2365 Resolution rs = SelectedImage.Resolutions[(int)Level];
2366 double dx = ((double)e.X / overview.Width) * (rs.SizeX * dsx);
2367 double dy = ((double)e.Y / overview.Height) * (rs.SizeY * dsx);
2368 double w = (double)gl.Width / 2;
2369 double h = (double)gl.Height / 2;
2370 PyramidalOrigin = new PointD(dx - w, dy - h);
2371 }
2372 }
2373 if (SelectedImage != null)
2374 {
2375 PointD ip = SelectedImage.ToImageSpace(p);
2376 mousePoint = "(" + (p.X) + ", " + (p.Y) + ")";
2377 }
2378 if (e.Button == MouseButtons.XButton1 && !x1State && !Ctrl && Mode != ViewMode.RGBImage)
2379 {
2380 if (cBar.Value < cBar.Maximum)
2381 cBar.Value++;
2382 x1State = true;
2383 }
2384 else if (e.Button == MouseButtons.XButton1 && !x1State && Ctrl)
2385 {
2386 if (tBar.Value < tBar.Maximum)
2387 tBar.Value++;
2388 x1State = true;
2389 }
2390 if (e.Button != MouseButtons.XButton1)
2391 x1State = false;
2392
2393 if (e.Button == MouseButtons.XButton2 && !x2State && !Ctrl && Mode != ViewMode.RGBImage)
2394 {
2395 if (cBar.Value > cBar.Minimum)
2396 cBar.Value--;
2397 x2State = true;
2398 }
2399 else if (e.Button == MouseButtons.XButton2 && !x2State && Ctrl)
2400 {
2401 if (tBar.Value > tBar.Minimum)
2402 tBar.Value--;
2403 x2State = true;
2404 }
2405 if (e.Button != MouseButtons.XButton2)
2406 x2State = false;
2407
2408 if (Tools.currentTool.type == Tools.Tool.Type.move && e.Button == MouseButtons.Left)
2409 {
2410 foreach (ROI an in selectedAnnotations)
2411 {
2412 if (an.selectedPoints.Count > 0 && an.selectedPoints.Count < an.GetPointCount())
2413 {
2414 if (an.type == ROI.Type.Rectangle || an.type == ROI.Type.Ellipse)
2415 {
2416 RectangleD d = an.BoundingBox;
2417 if (an.selectedPoints[0] == 0)
2418 {
2419 double dw = d.X - p.X;
2420 double dh = d.Y - p.Y;
2421 d.X = p.X;
2422 d.Y = p.Y;
2423 d.W += dw;
2424 d.H += dh;
2425 }
2426 else
2427 if (an.selectedPoints[0] == 1)
2428 {
2429 double dw = p.X - (d.W + d.X);
2430 double dh = d.Y - p.Y;
2431 d.W += dw;
2432 d.H += dh;
2433 d.Y -= dh;
2434 }
2435 else
2436 if (an.selectedPoints[0] == 2)
2437 {
2438 double dw = d.X - p.X;
2439 double dh = p.Y - (d.Y + d.H);
2440 d.W += dw;
2441 d.H += dh;
2442 d.X -= dw;
2443 }
2444 else
2445 if (an.selectedPoints[0] == 3)
2446 {
2447 double dw = d.X - p.X;
2448 double dh = d.Y - p.Y;
2449 d.W = p.X - an.X;
2450 d.H = p.Y - an.Y;
2451 }
2452 an.BoundingBox = d;
2453 }
2454 else
2455 {
2456 PointD pod = new PointD(p.X - pd.X, p.Y - pd.Y);
2457 for (int i = 0; i < an.selectedPoints.Count; i++)
2458 {
2459 PointD poid = an.GetPoint(an.selectedPoints[i]);
2460 an.UpdatePoint(new PointD(poid.X + pod.X, poid.Y + pod.Y), an.selectedPoints[i]);
2461 }
2462 }
2463 }
2464 else
2465 {
2466 PointD pod = new PointD(p.X - pd.X, p.Y - pd.Y);
2467 for (int i = 0; i < an.GetPointCount(); i++)
2468 {
2469 PointD poid = an.Points[i];
2470 an.UpdatePoint(new PointD(poid.X + pod.X, poid.Y + pod.Y), i);
2471 }
2472 }
2473 }
2474 UpdateOverlay();
2475 }
2476
2477 if (Tools.currentTool != null)
2478 if (Tools.currentTool.type == Tools.Tool.Type.pencil && e.Button == MouseButtons.Left)
2479 {
2480 PointD ip = SelectedImage.ToImageSpace(p);
2481 Tools.Tool tool = Tools.currentTool;
2482 Graphics.Graphics g = Graphics.Graphics.FromImage(SelectedBuffer);
2483 Graphics.Pen pen = new Graphics.Pen(Tools.DrawColor, (int)Tools.StrokeWidth, ImageView.SelectedImage.bitsPerPixel);
2484 g.FillEllipse(new Rectangle((int)ip.X, (int)ip.Y, (int)Tools.StrokeWidth, (int)Tools.StrokeWidth), pen.color);
2485 UpdateImage();
2486 }
2487
2488
2489 UpdateStatus();
2490 prevMove = p;
2491 pd = p;
2492 }
2499 private void pictureBox_MouseUp(object sender, MouseEventArgs e)
2500 {
2501 PointD p = ImageToViewSpace(e.Location.X, e.Location.Y);
2502 mouseUpButtons = e.Button;
2503 mouseDownButtons = MouseButtons.None;
2504 MouseUpInt = new PointD(e.X, e.Y);
2505 mouseUp = p;
2506 down = false;
2507 up = true;
2508 if (SelectedImage == null)
2509 return;
2510 App.viewer = this;
2511 tools.ToolUp(p, e.Button);
2512 }
2519 private void pictureBox_MouseDown(object sender, MouseEventArgs e)
2520 {
2521 App.viewer = this;
2522 MouseDownInt = new PointD(e.X, e.Y);
2523 mouseDownButtons = e.Button;
2524 mouseUpButtons = MouseButtons.None;
2525 PointD p = ImageToViewSpace(e.Location.X, e.Location.Y);
2526 pd = new PointD(p.X, p.Y);
2527 mouseDown = pd;
2528 mouseD = new PointD(e.Location.X, e.Location.Y);
2529 down = true;
2530 up = false;
2531 PointD ip;
2532 if (SelectedImage == null)
2533 return;
2534 ip = SelectedImage.ToImageSpace(p);
2535 tools.BringToFront();
2536 int ind = 0;
2537 if (ShowOverview && overview.IntersectsWith(new RectangleD(e.X, e.Y, 1, 1)))
2538 {
2539 if (!OpenSlide)
2540 {
2541 double dsx = _slideBase.Schema.Resolutions[Level].UnitsPerPixel / Resolution;
2542 Resolution rs = SelectedImage.Resolutions[(int)Level];
2543 double dx = ((double)e.X / overview.Width) * (rs.SizeX * dsx);
2544 double dy = ((double)e.Y / overview.Height) * (rs.SizeY * dsx);
2545 double w = (double)ViewWidth / 2;
2546 double h = (double)ViewHeight / 2;
2547 PyramidalOrigin = new PointD(dx - w, dy - h);
2548 }
2549 else
2550 {
2551 double dsx = _openSlideBase.Schema.Resolutions[Level].UnitsPerPixel / Resolution;
2552 Resolution rs = SelectedImage.Resolutions[(int)Level];
2553 double dx = ((double)e.X / overview.Width) * (rs.SizeX * dsx);
2554 double dy = ((double)e.Y / overview.Height) * (rs.SizeY * dsx);
2555 double w = (double)ViewWidth / 2;
2556 double h = (double)ViewHeight / 2;
2557 PyramidalOrigin = new PointD(dx - w, dy - h);
2558 }
2559 return;
2560 }
2561 foreach (BioImage b in Images)
2562 {
2563 RectangleD r = new RectangleD(b.Volume.Location.X, b.Volume.Location.Y, b.Volume.Width, b.Volume.Height);
2564 if (r.IntersectsWith(p))
2565 {
2566 b.selected = true;
2567 SelectedIndex = ind;
2568 }
2569 else
2570 b.selected = false;
2571 ind++;
2572 }
2573 if (!Ctrl && e.Button == MouseButtons.Left && Tools.currentTool.type != Tools.Tool.Type.rectSel)
2574 {
2575 foreach (ROI item in selectedAnnotations)
2576 {
2577 if (item.Selected)
2578 item.selectedPoints.Clear();
2579 }
2580 selectedAnnotations.Clear();
2581 }
2582
2583 if (Tools.currentTool.type == Tools.Tool.Type.move && e.Button == MouseButtons.Left)
2584 {
2585 float width = (float)ToViewSizeW(ROI.selectBoxSize / Scale.Width);
2586 float height = (float)ToViewSizeH(ROI.selectBoxSize / Scale.Height);
2587 if (openSlide)
2588 {
2589 width = Tools.selectBoxSize;
2590 height = Tools.selectBoxSize;
2591 }
2592 foreach (BioImage bi in Images)
2593 {
2594 foreach (ROI an in bi.Annotations)
2595 {
2596 if (an.GetSelectBound(width, height).IntersectsWith(new RectangleD(p.X, p.Y, 1, 1)))
2597 {
2598 selectedAnnotations.Add(an);
2599 an.Selected = true;
2600 RectangleD[] sels = an.GetSelectBoxes(Tools.selectBoxSize);
2601 RectangleD r = new RectangleD(p.X, p.Y, sels[0].W, sels[0].H);
2602 for (int i = 0; i < sels.Length; i++)
2603 {
2604 if (sels[i].IntersectsWith(r))
2605 {
2606 an.selectedPoints.Add(i);
2607 }
2608 }
2609 }
2610 else
2611 if (!Ctrl)
2612 an.Selected = false;
2613 }
2614 }
2615 UpdateOverlay();
2616 }
2617
2618 if (e.Button == MouseButtons.Left)
2619 {
2620 AForge.Point s = new AForge.Point(SelectedImage.SizeX, SelectedImage.SizeY);
2621 if ((ip.X < s.X && ip.Y < s.Y) || (ip.X >= 0 && ip.Y >= 0))
2622 {
2623 int zc = SelectedImage.Coordinate.Z;
2624 int cc = SelectedImage.Coordinate.C;
2625 int tc = SelectedImage.Coordinate.T;
2626 if (SelectedImage.isPyramidal)
2627 {
2628 if (SelectedImage.isRGB)
2629 {
2630 int r = (int)SelectedImage.GetValueRGB(zc, RChannel.Index, tc, e.X, e.Y, 0);
2631 int g = (int)SelectedImage.GetValueRGB(zc, GChannel.Index, tc, e.X, e.Y, 1);
2632 int b = (int)SelectedImage.GetValueRGB(zc, BChannel.Index, tc, e.X, e.Y, 2);
2633 mouseColor = ", " + r + "," + g + "," + b;
2634 }
2635 else
2636 {
2637 int r = (int)SelectedImage.GetValueRGB(zc, 0, tc, e.X, e.Y, 0);
2638 mouseColor = ", " + r;
2639 }
2640 }
2641 else
2642 {
2643 if (SelectedImage.isRGB)
2644 {
2645 int r = (int)SelectedImage.GetValueRGB(zc, RChannel.Index, tc, (int)ip.X, (int)ip.Y, 0);
2646 int g = (int)SelectedImage.GetValueRGB(zc, GChannel.Index, tc, (int)ip.X, (int)ip.Y, 1);
2647 int b = (int)SelectedImage.GetValueRGB(zc, BChannel.Index, tc, (int)ip.X, (int)ip.Y, 2);
2648 mouseColor = ", " + r + "," + g + "," + b;
2649 }
2650 else
2651 {
2652 int r = (int)SelectedImage.GetValueRGB(zc, 0, tc, (int)ip.X, (int)ip.Y, 0);
2653 mouseColor = ", " + r;
2654 }
2655 }
2656 }
2657 }
2658 UpdateStatus();
2659 tools.ToolDown(mouseDown, e.Button);
2660 }
2668 private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e)
2669 {
2670 if (SelectedImage == null)
2671 return;
2672 App.viewer = this;
2673 PointD p = ToViewSpace(e.Location.X, e.Location.Y);
2674 tools.ToolDown(p, e.Button);
2675 if (e.Button != MouseButtons.XButton1 && e.Button != MouseButtons.XButton2)
2676 Origin = new PointD(-p.X, -p.Y);
2677 }
2684 private void deleteROIToolStripMenuItem_Click(object sender, EventArgs e)
2685 {
2686 if (SelectedImage == null)
2687 return;
2688 foreach (ROI item in AnnotationsRGB)
2689 {
2690 if (item.Selected && (item.selectedPoints.Count == 0 || item.selectedPoints.Count == item.GetPointCount() || item.type == ROI.Type.Ellipse || item.type == ROI.Type.Rectangle))
2691 {
2692 SelectedImage.Annotations.Remove(item);
2693 }
2694 else
2695 {
2696 if ((item.type == ROI.Type.Polygon || item.type == ROI.Type.Freeform || item.type == ROI.Type.Polyline) && item.selectedPoints.Count > 0)
2697 {
2698 item.RemovePoints(item.selectedPoints.ToArray());
2699
2700 }
2701 item.selectedPoints.Clear();
2702 }
2703 }
2704 UpdateOverlay();
2705 }
2712 private void setTextSelectionToolStripMenuItem_Click(object sender, EventArgs e)
2713 {
2714 if (SelectedImage == null)
2715 return;
2716 foreach (ROI item in AnnotationsRGB)
2717 {
2718 if (item.Selected)
2719 {
2720 TextInput input = new TextInput(item.Text);
2721 if (input.ShowDialog() != DialogResult.OK)
2722 return;
2723 item.Text = input.TextValue;
2724 item.family = input.font.FontFamily.Name;
2725 item.fontSize = input.font.Size;
2726 item.strokeColor = AForge.Color.FromArgb(input.color.R, input.color.G, input.color.B);
2727 UpdateOverlay();
2728 }
2729 }
2730 }
2731
2736 private void copyViewToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
2737 {
2738 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ViewWidth, ViewHeight);
2739 using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
2740 {
2741 DrawView(g);
2742 DrawOverlay(g);
2743 }
2744 System.Windows.Forms.Clipboard.SetImage(bmp);
2745 }
2746 List<ROI> copys = new List<ROI>();
2747
2749 public void CopySelection()
2750 {
2751 copys.Clear();
2752 string s = "";
2753 foreach (ROI item in AnnotationsRGB)
2754 {
2755 if (item.Selected)
2756 {
2757 copys.Add(item);
2758 s += BioImage.ROIToString(item);
2759 }
2760 }
2761 System.Windows.Forms.Clipboard.SetText(s);
2762 }
2765 public void PasteSelection()
2766 {
2767 string[] sts = System.Windows.Forms.Clipboard.GetText().Split(BioImage.NewLine);
2768 foreach (string line in sts)
2769 {
2770 if (line.Length > 8)
2771 {
2772 ROI an = BioImage.StringToROI(line);
2773 //We set the coordinates of the ROI's we are pasting
2774 an.coord = GetCoordinate();
2775 SelectedImage.Annotations.Add(an);
2776 }
2777 }
2778 UpdateOverlay();
2779 }
2784 private void copyROIToolStripMenuItem_Click(object sender, EventArgs e)
2785 {
2786 CopySelection();
2787 }
2788
2794 private void pasteROIToolStripMenuItem_Click(object sender, EventArgs e)
2795 {
2797 }
2798
2803 private void hideControlsToolStripMenuItem_Click(object sender, EventArgs e)
2804 {
2805 if (ShowControls)
2806 ShowControls = false;
2807 else
2808 ShowControls = true;
2809 }
2810
2815 private void showControlToolStripMenuItem_Click(object sender, EventArgs e)
2816 {
2817 if (ShowControls)
2818 ShowControls = false;
2819 else
2820 ShowControls = true;
2821 }
2822
2827 private void HideStatusMenuItem_Click(object sender, EventArgs e)
2828 {
2829 ShowStatus = false;
2830 }
2835 private void rGBToolStripMenuItem_Click(object sender, EventArgs e)
2836 {
2837 Mode = ViewMode.RGBImage;
2838 }
2839
2844 private void filteredToolStripMenuItem_Click(object sender, EventArgs e)
2845 {
2846 Mode = ViewMode.Filtered;
2847 }
2848
2853 private void rawToolStripMenuItem_Click(object sender, EventArgs e)
2854 {
2855 Mode = ViewMode.Raw;
2856 }
2863 public PointD ImageToViewSpace(double x, double y)
2864 {
2865 if (SelectedImage == null)
2866 return ToViewSpace(x, y);
2867 if (SelectedImage.isPyramidal)
2868 {
2869 return new PointD((PyramidalOrigin.X + x) * Resolution, (PyramidalOrigin.Y + y) * Resolution);
2870 }
2871 else
2872 return ToViewSpace(x, y);
2873 }
2879 public PointF ToViewSpace(PointF p)
2880 {
2881 PointD d = ToViewSpace(p.X, p.Y);
2882 return new PointF((float)d.X, (float)d.Y);
2883 }
2889 public PointD ToViewSpace(PointD p)
2890 {
2891 return ToViewSpace(p.X, p.Y); ;
2892 }
2899 public PointD ToViewSpace(double x, double y)
2900 {
2901 if (SelectedImage != null)
2902 if (SelectedImage.isPyramidal)
2903 {
2904 double ddx = x / Resolution;
2905 double ddy = y / Resolution;
2906 return new PointD(ddx, ddy);
2907 }
2908 double dx, dy;
2909 dx = (ToViewSizeW(x - (ViewWidth / 2)) / Scale.Width) - Origin.X;
2910 dy = (ToViewSizeH(y - (ViewHeight / 2)) / Scale.Height) - Origin.Y;
2911 return new PointD(dx, dy);
2912 }
2918 private double ToViewSizeW(double d)
2919 {
2920 if (SelectedImage != null)
2921 if (SelectedImage.isPyramidal)
2922 {
2923 return d / Resolution;
2924 }
2925 double x = (double)(d / PxWmicron);
2926 return x;
2927 }
2933 public double ToViewSizeH(double d)
2934 {
2935 if (SelectedImage != null)
2936 if (SelectedImage.isPyramidal)
2937 {
2938 return d / Resolution;
2939 }
2940 double y = (double)(d / PxHmicron);
2941 return y;
2942 }
2948 public double ToViewW(double d)
2949 {
2950 double x = (double)(d / PxWmicron) / scale.Width;
2951 return x;
2952 }
2958 public double ToViewH(double d)
2959 {
2960 double y = (double)(d / PxHmicron) / scale.Height;
2961 return y;
2962 }
2969 public PointD ToScreenSpace(double x, double y)
2970 {
2971 double fx = ToScreenScaleW(Origin.X + x);
2972 double fy = ToScreenScaleH(Origin.Y + y);
2973 return new PointD(fx, fy);
2974 }
2980 public PointD ToScreenSpace(PointD p)
2981 {
2982 return ToScreenSpace(p.X, p.Y);
2983 }
2989 public PointF ToScreenSpace(PointF p)
2990 {
2991 PointD pd = ToScreenSpace(p.X, p.Y);
2992 return new PointF((float)pd.X, (float)pd.Y);
2993 }
2999 public PointF[] ToScreenSpace(PointF[] p)
3000 {
3001 PointF[] pf = new PointF[p.Length];
3002 for (int i = 0; i < p.Length; i++)
3003 {
3004 pf[i] = ToScreenSpace(p[i]);
3005 }
3006 return pf;
3007 }
3013 public PointF ToScreenSpace(Point3D p)
3014 {
3015 PointD pd = ToScreenSpace(p.X, p.Y);
3016 return new PointF((float)pd.X, (float)pd.Y);
3017 }
3023 public float ToScreenScaleW(double x)
3024 {
3025 return (float)(x * PxWmicron);
3026 }
3032 public float ToScreenScaleH(double y)
3033 {
3034 return (float)(y * PxHmicron);
3035 }
3041 public PointF ToScreenScale(PointD p)
3042 {
3043 float x = ToScreenScaleW((float)p.X);
3044 float y = ToScreenScaleH((float)p.Y);
3045 return new PointF(x, y);
3046 }
3055 public RectangleD ToScreenRect(double x, double y, double w, double h)
3056 {
3057 if (SelectedImage == null)
3058 {
3059 PointD pf;
3060 pf = ToScreenSpace(x, y);
3061 return new RectangleD(pf.X, pf.Y, ToScreenScaleW(w), ToScreenScaleH(h));
3062 }
3063 if (SelectedImage.isPyramidal)
3064 {
3065 PointD d = ToViewSpace(x, y);
3066 double dw = ToViewSizeW(w);
3067 double dh = ToViewSizeH(h);
3068 return new RectangleD((d.X - PyramidalOrigin.X), (d.Y - PyramidalOrigin.Y), dw, dh);
3069 }
3070 else
3071 {
3072 PointD pf = ToScreenSpace(x, y);
3073 return new RectangleD(pf.X, pf.Y, ToScreenScaleW(w), ToScreenScaleH(h));
3074 }
3075 }
3085 public SKRect ToSKRect(double x, double y, double w, double h)
3086 {
3087 double xd = gl.Width / 2;
3088 double yd = gl.Height / 2;
3089 return new SKRect((float)(xd - x), (float)(yd - y), (float)(xd - (x + w)), (float)(yd - (y + h)));
3090 }
3096 public RectangleD ToScreenSpace(RectangleD p)
3097 {
3098 return ToScreenRect(p.X, p.Y, p.W, p.H);
3099 }
3105 public RectangleD ToScreenSpace(RectangleF p)
3106 {
3107 return ToScreenRect(p.X, p.Y, p.Width, p.Height);
3108 }
3114 public RectangleD[] ToScreenSpace(RectangleD[] p)
3115 {
3116 RectangleD[] rs = new RectangleD[p.Length];
3117 for (int i = 0; i < p.Length; i++)
3118 {
3119 rs[i] = ToScreenSpace(p[i]);
3120 }
3121 return rs;
3122 }
3128 public RectangleF[] ToScreenSpace(RectangleF[] p)
3129 {
3130 RectangleF[] rs = new RectangleF[p.Length];
3131 for (int i = 0; i < p.Length; i++)
3132 {
3133 rs[i] = ToScreenSpace(p[i]).ToRectangleF();
3134 }
3135 return rs;
3136 }
3142 public PointF[] ToScreenSpace(PointD[] p)
3143 {
3144 PointF[] rs = new PointF[p.Length];
3145 for (int i = 0; i < p.Length; i++)
3146 {
3147 PointD pd = ToScreenSpace(p[i]);
3148 rs[i] = new PointF((float)pd.X, (float)pd.Y);
3149 }
3150 return rs;
3151 }
3157 public float ToScreenW(double x)
3158 {
3159 return (float)(x * PxWmicron);
3160 }
3166 public float ToScreenH(double y)
3167 {
3168 return (float)(y * PxHmicron);
3169 }
3177 public void ImageView_KeyDown(object sender, KeyEventArgs e)
3178 {
3179 double moveAmount = 5 * Scale.Width;
3180 Plugins.KeyDownEvent(sender, e);
3181 if (e.KeyCode == Keys.C && e.Control)
3182 {
3183 CopySelection();
3184 return;
3185 }
3186 if (e.KeyCode == Keys.V && e.Control)
3187 {
3189 return;
3190 }
3191 if (e.KeyCode == Keys.Subtract || e.KeyCode == Keys.NumPad7)
3192 {
3193 if (SelectedImage.isPyramidal)
3194 Resolution *= 0.9f;
3195 else
3196 Scale = new SizeF(Scale.Width - 0.1f, Scale.Height - 0.1f);
3197 UpdateView();
3198 }
3199 if (e.KeyCode == Keys.Add || e.KeyCode == Keys.NumPad9)
3200 {
3201 if (SelectedImage.isPyramidal)
3202 Resolution *= 1.1f;
3203 else
3204 Scale = new SizeF(Scale.Width + 0.1f, Scale.Height + 0.1f);
3205 UpdateView();
3206 }
3207 if (e.KeyCode == Keys.W || e.KeyCode == Keys.NumPad8)
3208 {
3209 if (SelectedImage.isPyramidal)
3210 PyramidalOrigin = new PointD(PyramidalOrigin.X, PyramidalOrigin.Y - moveAmount);
3211 else
3212 Origin = new PointD(Origin.X, Origin.Y + moveAmount);
3213 UpdateView();
3214 }
3215 if (e.KeyCode == Keys.S || e.KeyCode == Keys.NumPad2)
3216 {
3217 if (SelectedImage.isPyramidal)
3218 PyramidalOrigin = new PointD(PyramidalOrigin.X, PyramidalOrigin.Y + moveAmount);
3219 else
3220 Origin = new PointD(Origin.X, Origin.Y - moveAmount);
3221 UpdateView();
3222 }
3223 if (e.KeyCode == Keys.A || e.KeyCode == Keys.NumPad4)
3224 {
3225 if (SelectedImage.isPyramidal)
3226 PyramidalOrigin = new PointD(PyramidalOrigin.X - moveAmount, PyramidalOrigin.Y);
3227 else
3228 Origin = new PointD(Origin.X + moveAmount, Origin.Y);
3229 UpdateView();
3230 }
3231 if (e.KeyCode == Keys.D || e.KeyCode == Keys.NumPad6)
3232 {
3233 if (SelectedImage.isPyramidal)
3234 PyramidalOrigin = new PointD(PyramidalOrigin.X + moveAmount, PyramidalOrigin.Y);
3235 else
3236 Origin = new PointD(Origin.X - moveAmount, Origin.Y);
3237 UpdateView();
3238 }
3239 }
3240 private void ImageView_KeyUp(object sender, KeyEventArgs e)
3241 {
3242 Plugins.KeyUpEvent(sender, e);
3243 }
3244 private void ImageView_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
3245 {
3246 Plugins.KeyPressEvent(sender, e);
3247 }
3252 public void GoToImage()
3253 {
3254 GoToImage(0);
3255 }
3256 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3257 public PointD PyramidalOriginTransformed
3258 {
3259 get { return new PointD(PyramidalOrigin.X * Resolution, PyramidalOrigin.Y * Resolution); }
3260 set { PyramidalOrigin = new PointD(value.X / Resolution, value.Y / Resolution); }
3261 }
3262 PointD mouseDownInt = new PointD(0, 0);
3263 PointD mouseUpInt = new PointD(0, 0);
3264 PointD mouseMoveInt = new PointD(0, 0);
3265 PointD mouseMove = new PointD(0, 0);
3266 /* A property that returns the value of the mouseDownInt variable. */
3267 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3268 public PointD MouseDownInt
3269 {
3270 get { return mouseDownInt; }
3271 set { mouseDownInt = value; }
3272 }
3273 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3274 public PointD MouseUpInt
3275 {
3276 get { return mouseUpInt; }
3277 set { mouseUpInt = value; }
3278 }
3279 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3280 public PointD MouseMoveInt
3281 {
3282 get { return mouseMoveInt; }
3283 set { mouseMoveInt = value; }
3284 }
3285
3286 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3287 public bool ShowMasks { get; set; } = true;
3288
3294 public void GoToImage(int i)
3295 {
3296 if (Images.Count <= i)
3297 return;
3298 if (SelectedImage.Type == BioImage.ImageType.pyramidal)
3299 {
3300 if (SelectedImage.OpenSlideBase != null)
3301 {
3302 if (MacroResolution.HasValue)
3303 {
3304 int lev = MacroResolution.Value - 2;
3305 Resolution = _openSlideBase.Schema.Resolutions[lev].UnitsPerPixel * 0.98;
3306 }
3307 else
3308 {
3309 int lev = 0;
3310 Resolution = _openSlideBase.Schema.Resolutions[lev].UnitsPerPixel * 0.98;
3311 }
3312 }
3313 else
3314 {
3315 if (MacroResolution.HasValue)
3316 {
3317 int lev = MacroResolution.Value - 1;
3318 Resolution = SelectedImage.SlideBase.Schema.Resolutions[lev].UnitsPerPixel * 0.98;
3319 PyramidalOrigin = new PointD(0, 0);
3320 }
3321 else
3322 {
3323 Resolution = SelectedImage.GetUnitPerPixel(SelectedImage.Resolutions.Count - 1) * 0.98;
3324 }
3325 }
3326 }
3327 double dx = Images[i].Volume.Width / 2;
3328 double dy = Images[i].Volume.Height / 2;
3329 Origin = new PointD(-(Images[i].Volume.Location.X + dx), -(Images[i].Volume.Location.Y + dy));
3330 double wx, wy;
3331 wx = ViewWidth / ToScreenScaleW(SelectedImage.Volume.Width);
3332 wy = ViewHeight / ToScreenScaleH(SelectedImage.Volume.Height);
3333 Scale = new SizeF((float)wy, (float)wy);
3334 UpdateView();
3335 }
3336
3341 private void goToImageToolStripMenuItem_Click(object sender, EventArgs e)
3342 {
3343 GoToImage();
3344 }
3350 private void goToToolStripMenuItem1_Click(object sender, EventArgs e)
3351 {
3352 Origin = new PointD(mouseDown.X, mouseDown.Y);
3353 }
3359 private void goToImageToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
3360 {
3361 ToolStripMenuItem item = (ToolStripMenuItem)sender;
3362 item.DropDownItems.Clear();
3363 foreach (BioImage im in Images)
3364 {
3365 ToolStripMenuItem it = new ToolStripMenuItem();
3366 it.Text = im.filename;
3367 item.DropDownItems.Add(it);
3368 }
3369 }
3377 private void goToImageToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
3378 {
3379 int i = 0;
3380 foreach (var item in Images)
3381 {
3382 if (item.filename == e.ClickedItem.Text)
3383 {
3384 GoToImage(i);
3385 return;
3386 }
3387 i++;
3388 }
3389 }
3390 public new void Dispose()
3391 {
3392 for (int i = 0; i < Bitmaps.Count; i++)
3393 {
3394 if (Bitmaps[i] != null)
3395 Bitmaps[i].Dispose();
3396 }
3397 for (int i = 0; i < Bitmaps.Count; i++)
3398 {
3399 if (Bitmaps[i] != null)
3400 Bitmaps[i].Dispose();
3401 }
3402 }
3403
3409 private void goToToolStripMenuItem_Click_1(object sender, EventArgs e)
3410 {
3411 Microscope.Stage.SetPosition(mouseDown.X, mouseDown.Y);
3412 }
3413
3418 private void drawToolStripMenuItem_Click(object sender, EventArgs e)
3419 {
3420 Graphics.Graphics g = Graphics.Graphics.FromImage(SelectedBuffer);
3421 foreach (ROI item in AnnotationsRGB)
3422 {
3423 Graphics.Pen p = new Graphics.Pen(Tools.DrawColor, (int)Tools.StrokeWidth, SelectedBuffer.BitsPerPixel);
3424 g.pen = p;
3425 if (item.Selected)
3426 {
3427 if (item.type == ROI.Type.Line)
3428 {
3429 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));
3430 }
3431 else
3432 if (item.type == ROI.Type.Rectangle)
3433 {
3434 g.DrawRectangle(SelectedImage.ToImageSpace(item.BoundingBox));
3435 }
3436 else
3437 if (item.type == ROI.Type.Ellipse)
3438 {
3439 g.DrawEllipse(SelectedImage.ToImageSpace(item.BoundingBox));
3440 }
3441 else
3442 if (item.type == ROI.Type.Freeform || item.type == ROI.Type.Polygon || item.type == ROI.Type.Polyline)
3443 {
3444 if (item.closed)
3445 {
3446 for (int i = 0; i < item.GetPointCount() - 1; i++)
3447 {
3448 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));
3449 }
3450 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));
3451
3452 }
3453 else
3454 {
3455 for (int i = 0; i < item.GetPointCount() - 1; i++)
3456 {
3457 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));
3458 }
3459 }
3460 }
3461 }
3462 }
3463 update = true;
3464 UpdateImage();
3465 }
3466
3471 private void fillToolStripMenuItem_Click(object sender, EventArgs e)
3472 {
3473 Graphics.Graphics g = Graphics.Graphics.FromImage(SelectedBuffer);
3474 foreach (ROI item in AnnotationsRGB)
3475 {
3476 Graphics.Pen p = new Graphics.Pen(Tools.DrawColor, (int)Tools.StrokeWidth, SelectedBuffer.BitsPerPixel);
3477 if (item.Selected)
3478 {
3479 if (item.type == ROI.Type.Line)
3480 {
3481 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));
3482 }
3483 else
3484 if (item.type == ROI.Type.Rectangle)
3485 {
3486 g.FillRectangle(SelectedImage.ToImageSpace(item.BoundingBox), p.color);
3487 }
3488 else
3489 if (item.type == ROI.Type.Ellipse)
3490 {
3491 g.FillEllipse(SelectedImage.ToImageSpace(item.BoundingBox), p.color);
3492 }
3493 else
3494 if (item.type == ROI.Type.Freeform || item.type == ROI.Type.Polygon || item.type == ROI.Type.Polyline)
3495 {
3496 g.FillPolygon(SelectedImage.ToImageSpace(item.GetPointsF()), SelectedImage.ToImageSpace(item.BoundingBox), p.color);
3497 }
3498 }
3499 }
3500 update = true;
3501 UpdateImage();
3502 }
3503
3504 public void GoToStage()
3505 {
3506 RectangleD d = Microscope.GetViewRectangle(false);
3507 double dx = d.W / 2;
3508 double dy = d.H / 2;
3509 Origin = new PointD(-(d.X + dx), -(d.Y + dy));
3510 double wx, wy;
3511 wx = Math.Abs(ViewWidth / ToScreenScaleW(d.W));
3512 wy = Math.Abs(ViewHeight / ToScreenScaleH(d.H));
3513 scale.Width = (float)wy;
3514 scale.Height = (float)wy;
3515 update = true;
3516 UpdateView();
3517 }
3521 public void MoveStageToImage()
3522 {
3523 if (SelectedImage == null)
3524 return;
3525 Microscope.Stage.SetPosition(SelectedImage.Volume.Location.X, SelectedImage.Volume.Location.Y);
3526 update = true;
3527 UpdateView();
3528 }
3532 public void MoveStageToImage(int i)
3533 {
3534 update = true;
3535 Microscope.Stage.SetPosition(Images[i].Volume.Location.X, Images[i].Volume.Location.Y);
3536 UpdateView();
3537 }
3543 private void goToStageToolStripMenuItem_Click(object sender, EventArgs e)
3544 {
3545 update = true;
3546 GoToStage();
3547 }
3554 private void moveStageToImageToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
3555 {
3556 int i = 0;
3557 foreach (var item in Images)
3558 {
3559 if (item.ID.Contains(e.ClickedItem.Text))
3560 {
3562 return;
3563 }
3564 i++;
3565 }
3566 }
3567
3572 private void moveStageToImageToolStripMenuItem_Click(object sender, EventArgs e)
3573 {
3575 }
3576 private void layersToolStripMenuItem_Click(object sender, EventArgs e)
3577 {
3578 if (layersTool == null)
3579 layersTool = new Layers();
3580 layersTool.Show();
3581 }
3586 private void pictureBox_SizeChanged(object sender, EventArgs e)
3587 {
3588 if (ViewWidth < 2 || ViewHeight < 2) return;
3589 if (SelectedImage.isPyramidal)
3590 {
3591 if (SelectedImage.isPyramidal)
3592 UpdateImages();
3593 }
3594 }
3595 private void contextMenuStrip_Opening(object sender, CancelEventArgs e)
3596 {
3597 Function.Initialize();
3598 }
3599 private void hideOverviewToolStripMenuItem_Click(object sender, EventArgs e)
3600 {
3601 if (hideOverViewToolStripMenuItem.Text == "Hide Overview")
3602 {
3603 ShowOverview = false;
3604 hideOverViewToolStripMenuItem.Text = "Show Overview";
3605 }
3606 else
3607 {
3608 ShowOverview = true;
3609 hideOverViewToolStripMenuItem.Text = "Hide Overview";
3610 }
3611 }
3612 private void removeImageToolStripMenuItem_Click(object sender, EventArgs e)
3613 {
3614 RemoveImage(SelectedIndex);
3615 }
3616
3617 private void removeImagesToolStripMenuItem_Click(object sender, EventArgs e)
3618 {
3619 RemoveImages();
3620 }
3621 #region OpenSlide
3622 private OpenSlideBase _openSlideBase;
3623 private SlideBase _slideBase;
3624
3628 private void Initialize(string file, BioImage bm)
3629 {
3630 if (bm.Type != BioImage.ImageType.pyramidal)
3631 return;
3632 if (bm.OpenSlideBase == null)
3633 {
3634 _slideBase = bm.SlideBase;
3635 slideRenderer = new SlideRenderer(gl);
3636 slideRenderer.SetSource(_slideBase);
3637 }
3638 else
3639 {
3640 _openSlideBase = bm.OpenSlideBase;
3641 slideRenderer = new SlideRenderer(gl);
3642 slideRenderer.SetSource(_openSlideBase);
3643 }
3644 }
3645
3646 #endregion
3647
3648 private void vScrollBar_ValueChanged(object sender, EventArgs e)
3649 {
3650 SelectedImage.PyramidalOrigin = new PointD(hScrollBar.Value, vScrollBar.Value);
3651 UpdateImages(true);
3652 }
3653 }
3654}
float ToScreenScaleH(double y)
new AForge.SizeF Scale
Scale when opening image stacks.
Definition ImageView.cs:810
void UpdateView(bool refresh)
PointD ImageToViewSpace(double x, double y)
bool ShowControls
Setting the visibility of the trackBarPanel. *‍/.
Definition ImageView.cs:511
Channel RChannel
A property that returns the R channel of the selected image. *‍/.
Definition ImageView.cs:679
float ToScreenH(double y)
PointD Origin
A property of the class PointD. *‍/.
Definition ImageView.cs:727
void DrawView(System.Drawing.Graphics g)
Draws the viewport when Hardware Acceleration is off.
PointF[] ToScreenSpace(PointD[] p)
PointF ToScreenScale(PointD p)
PointD PyramidalOrigin
Setting the value of the pyramidalOrigin variable. *‍/.
Definition ImageView.cs:739
void SetCoordinate(int z, int c, int t)
Definition ImageView.cs:389
PointD ToScreenSpace(double x, double y)
float ToScreenW(double x)
PointD ToViewSpace(PointD p)
RectangleD[] ToScreenSpace(RectangleD[] p)
ImageView(BioImage im, bool OpenWithOpenSlide=true)
Initializing the image viewer. *‍/.
Definition ImageView.cs:38
async void UpdateImages(bool updatePyramidal=false)
SKRect ToSKRect(double x, double y, double w, double h)
ViewMode Mode
Setting the view mode of the application. *‍/.
Definition ImageView.cs:621
double PxHmicron
Only used when opening stacks.
Definition ImageView.cs:600
PointF[] ToScreenSpace(PointF[] p)
int TimeFps
Setting the interval of the timer to the value of the timefps variable. *‍/.
Definition ImageView.cs:879
int CFps
Setting the interval of the timer to the inverse of the fps. *‍/.
Definition ImageView.cs:895
PointF ToViewSpace(PointF p)
PointF ToScreenSpace(PointF p)
RectangleD ToScreenSpace(RectangleD p)
double ToViewW(double d)
void UpdateSelectBoxSize(float size)
Definition ImageView.cs:962
void CopySelection()
It takes the selected ROIs and copies them to the clipboard.
void GoToImage(int i)
Channel GChannel
A property that returns the G channel of the image. *‍/.
Definition ImageView.cs:687
bool ShowStatus
Setting the value of the property ShowStatus. *‍/.
Definition ImageView.cs:556
ImageView()
Initializing the ImageView class. *‍/.
Definition ImageView.cs:118
Channel BChannel
Getting the B channel of the image. *‍/.
Definition ImageView.cs:695
string Path
A property that returns the filepath. *‍/.
Definition ImageView.cs:671
int ZFps
Setting the interval of the timer to the value of the fps. *‍/.
Definition ImageView.cs:863
double PxWmicron
Only used when opening stacks.
Definition ImageView.cs:585
void ImageView_KeyDown(object sender, KeyEventArgs e)
RectangleF[] ToScreenSpace(RectangleF[] p)
float ToScreenScaleW(double x)
RectangleD ToScreenRect(double x, double y, double w, double h)
int SelectedIndex
A property that is used to set the selected index of the image. *‍/.
Definition ImageView.cs:351
RectangleD ToScreenSpace(RectangleF p)
int Level
Current level when viewing whole-slide and pyramidal images.
Definition ImageView.cs:796
PointD ToViewSpace(double x, double y)
void AddImage(BioImage im)
Definition ImageView.cs:429
PointF ToScreenSpace(Point3D p)
void MoveStageToImage(int i)
PointD ToScreenSpace(PointD p)
double ToViewH(double d)
ContextMenuStrip ViewContextMenu
A property that returns a ContextMenuStrip object. *‍/.
Definition ImageView.cs:831
double Resolution
A property of the class ImageViewer. It is a getter and setter for the resolution of the image.
Definition ImageView.cs:752
double ToViewSizeH(double d)
void UpdateViewMode(ImageView.ViewMode v)
Definition TabsView.cs:609
void ToolUp(PointD e, MouseButtons buts)
Definition Tools.cs:394
void ToolDown(PointD e, MouseButtons buts)
Definition Tools.cs:248