BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
Tools.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.ComponentModel;
5using System.Data;
6using System.Drawing;
7using System.Linq;
8using System.Text;
9using System.Threading.Tasks;
10using System.Windows.Forms;
11using System.IO;
12using AForge.Imaging.Filters;
13using AForge.Imaging;
14using AForge.Math.Geometry;
15using AForge;
17using BioImager;
18using Rectangle = AForge.Rectangle;
19using Bitmap = AForge.Bitmap;
20using BioLib;
21using Gdk;
22using OpenSlideGTK;
23namespace BioImager
24{
25 public partial class Tools : Form
26 {
27 public static bool applyToStack = false;
28 public static ColorTool colorTool;
29 public static bool rEnabled = true;
30 public static bool gEnabled = true;
31 public static bool bEnabled = true;
32 private static ColorS drawColor = new ColorS(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
33 private static ColorS eraseColor = new ColorS(0, 0, 0);
34 private static int width = 1;
35
36 public static System.Drawing.Rectangle selectionRectangle;
37 public static Hashtable tools = new Hashtable();
38 private AbstractFloodFiller floodFiller = null;
39 /* It's a class that contains a list of tools, and each tool has a type, a rectangle, a script,
40 and a tolerance. */
41 public class Tool
42 {
43 public enum ToolType
44 {
45 color,
47 select,
48 function
49 }
50 public enum Type
51 {
52 pencil,
53 brush,
54 bucket,
55 eraser,
56 move,
57 point,
58 line,
59 rect,
60 select,
61 ellipse,
63 polygon,
64 text,
65 delete,
67 rectSel,
69 pan,
70 magic,
71 script,
73 }
74
75 public static void Init()
76 {
77 if (tools.Count == 0)
78 {
79 foreach (Tool.Type tool in (Tool.Type[])Enum.GetValues(typeof(Tool.Type)))
80 {
81 tools.Add(tool.ToString(), new Tool(tool, new ColorS(0, 0, 0)));
82 }
83 }
84 }
85 public List<AForge.Point> Points;
87 private RectangleD rect;
89 {
90 get { return rect; }
91 set { rect = value; }
92 }
93 public AForge.RectangleF RectangleF
94 {
95 get { return new AForge.RectangleF((float)rect.X, (float)rect.Y, (float)rect.W, (float)rect.H); }
96 }
97 public string script;
98 public Type type;
99 public ColorS tolerance;
100 public Tool()
101 {
102 tolerance = new ColorS(0, 0, 0);
103 }
104 public Tool(Type t)
105 {
106 type = t;
107 tolerance = new ColorS(0, 0, 0);
108 }
109 public Tool(Type t, ColorS col)
110 {
111 type = t;
112 tolerance = new ColorS(0, 0, 0);
113 }
114 public Tool(Type t, RectangleD r)
115 {
116 type = t;
117 rect = r;
118 tolerance = new ColorS(0, 0, 0);
119 }
120 public Tool(Type t, string sc)
121 {
122 type = t;
123 script = sc;
124 tolerance = new ColorS(0, 0, 0);
125 }
126 public override string ToString()
127 {
128 return type.ToString();
129 }
130 }
131 public static Tool currentTool;
132 public static ColorS DrawColor
133 {
134 get
135 {
136 return drawColor;
137 }
138 set
139 {
140 drawColor = value;
141 }
142 }
143 public static ColorS EraseColor
144 {
145 get
146 {
147 return eraseColor;
148 }
149 set
150 {
151 eraseColor = value;
152 }
153 }
154
155 public static int StrokeWidth
156 {
157 get
158 {
159 return width;
160 }
161 set
162 {
163 width = value;
164 App.tools.UpdateGUI();
165 }
166 }
167
169 public Font font;
170 /* Initializing the tools. */
171 public Tools()
172 {
173 InitializeComponent();
174 Tool.Init();
175 ColorS col = new ColorS(ushort.MaxValue);
176 //We initialize the tools
178 ROI.selectBoxSize = 1;
179 floodFiller = null;
180 floodFiller = new QueueLinearFloodFiller(floodFiller);
181 }
182
183 public static Tool GetTool(string name)
184 {
185 return (Tool)tools[name];
186 }
187 public static Tool GetTool(Tool.Type typ)
188 {
189 return (Tool)tools[typ.ToString()];
190 }
191 public void UpdateOverlay()
192 {
194 }
195 public void UpdateView()
196 {
198 }
201 public void UpdateSelected()
202 {
203 foreach (Control item in this.Controls)
204 {
205 if (item.Tag != null)
206 if (item.Tag.ToString() == "tool")
207 item.BackColor = System.Drawing.Color.White;
208 }
209 }
211 private void UpdateGUI()
212 {
213 if (ImageView.SelectedImage != null)
214 {
215 color1Box.BackColor = System.Drawing.Color.FromArgb((int)((float)DrawColor.R / (float)ushort.MaxValue) * 255,(int)((float)DrawColor.G / (float)ushort.MaxValue) * 255, (int)((float)DrawColor.B / (float)ushort.MaxValue) * 255);
216 color2Box.BackColor = System.Drawing.Color.FromArgb((int)(((float)EraseColor.R / (float)ushort.MaxValue) * 255), (int)(((float)EraseColor.G / (float)ushort.MaxValue) * 255), (int)(((float)EraseColor.B / (float)ushort.MaxValue) * 255));
217 }
218 widthBox.Value = width;
219 }
220 public static float selectBoxSize = 1;// ROI.selectBoxSize;
221 ROI anno = new ROI();
222 PointD rectStart = new PointD();
223
224 private void RefreshRoiManager()
225 {
227 }
228
229 private static PointD GetAnnotationPoint(PointD p)
230 {
231 return p;
232 }
259 public void ToolDown(PointD e, MouseButtons buts)
260 {
261 if (App.viewer == null || currentTool == null || ImageView.SelectedImage == null)
262 return;
264 PointD p = ImageView.SelectedImage.isPyramidal ? e : ImageView.SelectedImage.ToImageSpace(e);
265 PointD roiPoint = GetAnnotationPoint(e);
266 if (currentTool.type == Tool.Type.line && buts == MouseButtons.Left)
267 {
268 if (anno.type != ROI.Type.Line)
269 {
270 anno = new ROI();
271 anno.type = ROI.Type.Line;
272 anno.AddPoint(roiPoint);
273 anno.AddPoint(roiPoint);
274 anno.coord = App.viewer.GetCoordinate();
275 ImageView.SelectedImage.Annotations.Add(anno);
276 RefreshRoiManager();
277 }
278 }
279 else
280 if (currentTool.type == Tool.Type.polygon && buts == MouseButtons.Left)
281 {
282 if (anno.type != ROI.Type.Polygon)
283 {
284 anno = new ROI();
285 anno.type = ROI.Type.Polygon;
286 anno.closed = false;
287 anno.AddPoint(roiPoint);
288 anno.coord = App.viewer.GetCoordinate();
289 ImageView.SelectedImage.Annotations.Add(anno);
290 RefreshRoiManager();
291 }
292 else
293 {
294 //If we click on a point 1 we close this polygon
295 double hitSize = App.viewer.GetSelectionBoxHitSize();
296 PointD firstPoint = anno.Points[0];
297 double dx = roiPoint.X - firstPoint.X;
298 double dy = roiPoint.Y - firstPoint.Y;
299 if ((dx * dx) + (dy * dy) <= (hitSize * hitSize))
300 {
301 anno.closed = true;
302 anno.UpdateBoundingBox();
303 RefreshRoiManager();
304 anno = new ROI();
305 }
306 else
307 {
308 anno.AddPoint(roiPoint);
309 RefreshRoiManager();
310 }
311 }
312 }
313 else
314 if (currentTool.type == Tool.Type.freeform && buts == MouseButtons.Left)
315 {
316 if (anno.type != ROI.Type.Freeform)
317 {
318 anno = new ROI();
319 anno.type = ROI.Type.Freeform;
320 anno.closed = false;
321 anno.AddPoint(roiPoint);
322 anno.coord = App.viewer.GetCoordinate();
323 ImageView.SelectedImage.Annotations.Add(anno);
324 RefreshRoiManager();
325 }
326 else
327 {
328 anno.AddPoint(roiPoint);
329 RefreshRoiManager();
330 }
331 }
332 else
333 if (currentTool.type == Tool.Type.rect && buts == MouseButtons.Left)
334 {
335 anno = new ROI();
336 anno.type = ROI.Type.Rectangle;
337 rectStart = roiPoint;
338 anno.BoundingBox = new RectangleD(roiPoint.X, roiPoint.Y, 0, 0);
339 anno.Validate();
340 anno.coord = App.viewer.GetCoordinate();
341 ImageView.SelectedImage.Annotations.Add(anno);
342 currentTool.Rectangle = anno.BoundingBox;
343 }
344 else
345 if (currentTool.type == Tool.Type.ellipse && buts == MouseButtons.Left)
346 {
347 anno = new ROI();
348 anno.type = ROI.Type.Ellipse;
349 rectStart = roiPoint;
350 anno.BoundingBox = new RectangleD(roiPoint.X, roiPoint.Y, 0, 0);
351 anno.Validate();
352 anno.coord = App.viewer.GetCoordinate();
353 ImageView.SelectedImage.Annotations.Add(anno);
354 currentTool.Rectangle = anno.BoundingBox;
355 }
356 else
357 if (currentTool.type == Tool.Type.delete && buts == MouseButtons.Left)
358 {
359 for (int i = 0; i < ImageView.SelectedImage.Annotations.Count; i++)
360 {
361 ROI an = ImageView.SelectedImage.Annotations[i];
362 if (an.BoundingBox.IntersectsWith(new RectangleD(roiPoint.X, roiPoint.Y, 1, 1)))
363 {
364 if (an.selectedPoints.Count == 0)
365 {
366 ImageView.SelectedImage.Annotations.Remove(an);
367 RefreshRoiManager();
368 break;
369 }
370 else
371 if (an.selectedPoints.Count == 1 && !(an.type == ROI.Type.Polygon || an.type == ROI.Type.Polyline || an.type == ROI.Type.Freeform))
372 {
373 ImageView.SelectedImage.Annotations.Remove(an);
374 RefreshRoiManager();
375 break;
376 }
377 else
378 {
379 if (an.type == ROI.Type.Polygon ||
380 an.type == ROI.Type.Polyline ||
381 an.type == ROI.Type.Freeform)
382 {
383 an.closed = false;
384 an.RemovePoints(an.selectedPoints.ToArray());
385 break;
386 }
387 }
388 }
389 }
391 }
392 else
393 if (currentTool.type == Tool.Type.text && buts == MouseButtons.Left)
394 {
395 ROI an = new ROI();
396 an.type = ROI.Type.Label;
397 an.AddPoint(roiPoint);
398 an.coord = App.viewer.GetCoordinate();
399 TextInput ti = new TextInput("");
400 if (ti.ShowDialog() != DialogResult.OK)
401 return;
402 Font labelFont = ti.font ?? SystemFonts.DefaultFont;
403 string labelText = ti.TextValue ?? string.Empty;
404 System.Drawing.Size labelSize = TextRenderer.MeasureText(labelText, labelFont);
405 AForge.RectangleF labelBox = ImageView.SelectedImage.ToImageSpace(new RectangleD(0, 0, labelSize.Width, labelSize.Height));
406 an.family = labelFont.FontFamily.Name;
407 an.fontSize = labelFont.Size;
408 an.strokeColor = AForge.Color.FromArgb(ti.color.A, ti.color.R, ti.color.G, ti.color.B);
409 an.Text = labelText;
410 an.BoundingBox = new RectangleD(roiPoint.X, roiPoint.Y, labelBox.Width, labelBox.Height);
411 ImageView.SelectedImage.Annotations.Add(an);
412 RefreshRoiManager();
413 }
414
415 if (buts == MouseButtons.Middle)
416 {
419 panPanel.BackColor = System.Drawing.Color.LightGray;
420 }
421
422
424 }
431 public void ToolUp(PointD e, MouseButtons buts)
432 {
433 PointD p = new PointD();
434 if (ImageView.SelectedImage == null)
435 return;
436 p = ImageView.SelectedImage.isPyramidal ? e : ImageView.SelectedImage.ToImageSpace(e);
437 PointD roiPoint = GetAnnotationPoint(e);
438 if (App.viewer == null || currentTool == null || ImageView.SelectedImage == null || anno == null)
439 return;
441 if (currentTool.type == Tool.Type.point && buts == MouseButtons.Left)
442 {
443 ROI an = new ROI();
444 an.AddPoint(roiPoint);
445 an.type = ROI.Type.Point;
446 an.coord = App.viewer.GetCoordinate();
447 ImageView.SelectedImage.Annotations.Add(an);
448 }
449 else
450 if (currentTool.type == Tool.Type.line && anno.type == ROI.Type.Line && buts == MouseButtons.Left)
451 {
452 if (anno.GetPointCount() > 0)
453 {
454 anno.UpdatePoint(roiPoint, 1);
455 anno.UpdateBoundingBox();
456 RefreshRoiManager();
457 anno = new ROI();
458 }
459 }
460 else
461 if (currentTool.type == Tool.Type.rect && anno.type == ROI.Type.Rectangle && buts == MouseButtons.Left)
462 {
463 currentTool.Rectangle = new RectangleD(0, 0, 0, 0);
464 anno = new ROI();
465 rectStart = new PointD();
466 }
467 else
468 if (currentTool.type == Tool.Type.ellipse && anno.type == ROI.Type.Ellipse && buts == MouseButtons.Left)
469 {
470 currentTool.Rectangle = new RectangleD(0, 0, 0, 0);
471 anno = new ROI();
472 rectStart = new PointD();
473 }
474 else
475 if (currentTool.type == Tool.Type.freeform && anno.type == ROI.Type.Freeform && buts == MouseButtons.Left)
476 {
477 anno.closed = true;
478 anno.UpdateBoundingBox();
479 RefreshRoiManager();
480 anno = new ROI();
481 }
482 else
483 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left)
484 {
485 if (!Win32.GetKeyState(Keys.LControlKey))
487 RectangleD r = GetTool(Tool.Type.rectSel).Rectangle;
488 double hitSize = App.viewer.GetSelectionBoxHitSize();
489 foreach (ROI an in App.viewer.AnnotationsRGB)
490 {
491 if (an.GetSelectBound(hitSize, hitSize).ToRectangleF().IntersectsWith(r.ToRectangleF()))
492 {
493 if(!Win32.GetKeyState(Keys.LControlKey))
494 an.selectedPoints.Clear();
496 an.Selected = true;
497 RectangleD[] sels = an.GetSelectBoxes(selectBoxSize);
498 for (int i = 0; i < sels.Length; i++)
499 {
500 if (sels[i].IntersectsWith(r))
501 {
502 an.selectedPoints.Add(i);
503 }
504 }
505 }
506 else
507 an.Selected = false;
508 }
509 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(0, 0, 0, 0);
510 }
511 else
512 if (Tools.currentTool.type == Tools.Tool.Type.magic && buts == MouseButtons.Left)
513 {
515 AForge.RectangleF rr = ImageView.SelectedImage.ToImageSpace(r);
516 ZCT coord = App.viewer.GetCoordinate();
517 Bitmap bf;
518 if (ImageView.SelectedImage.Buffers[0].RGBChannelsCount > 1)
519 bf = ImageView.SelectedImage.GetFiltered(coord, ImageView.SelectedBuffer.Stats[0].Range, ImageView.SelectedBuffer.Stats[1].Range, ImageView.SelectedBuffer.Stats[2].Range);
520 else
521 bf = ImageView.SelectedImage.GetFiltered(coord, ImageView.SelectedBuffer.Stats[0].Range, ImageView.SelectedBuffer.Stats[0].Range, ImageView.SelectedBuffer.Stats[0].Range);
522 bf.Crop(rr.ToRectangleInt());
523 Statistics[] sts = Statistics.FromBytes(bf);
524 Statistics st = sts[0];
525 int th = 0;
526 if (magicSel.Numeric)
527 {
528 th = magicSel.Threshold;
529 }
530 else
531 if (magicSel.Index == 2)
532 th = (int)(st.Min + st.Mean);
533 else
534 if (magicSel.Index == 1)
535 th = (int)st.Median;
536 else
537 th = (int)st.Min;
538 Bitmap det;
539 if (bf.BitsPerPixel > 8)
540 {
541 bf.To8Bit();
542 det = bf;
543 //blobCounter.BackgroundThreshold = AForge.Color.FromArgb((int)(((float)th / (float)ushort.MaxValue) * 255), (int)(((float)th / (float)ushort.MaxValue) * 255), (int)(((float)th / (float)ushort.MaxValue) * 255));
544 }
545 else
546 {
547 //blobCounter.BackgroundThreshold = AForge.Color.FromArgb((int)th, (int)th, (int)th);
548 det = bf;
549 }
550 BlobCounter blobCounter = new BlobCounter(det);
551 blobCounter.FilterBlobs = true;
552 blobCounter.MinWidth = 2;
553 blobCounter.MinHeight = 2;
554 blobCounter.CoupledSizeFiltering = true;
555 Blob[] blobs = blobCounter.GetObjects(det, true);
556 double px = ImageView.SelectedImage.PhysicalSizeX;
557 double py = ImageView.SelectedImage.PhysicalSizeY;
558 foreach (Blob blob in blobs)
559 {
560 AForge.RectangleD rd = new RectangleD(blob.Rectangle.X * px, blob.Rectangle.Y * py, blob.Rectangle.Width * px, blob.Rectangle.Height * py);
561 PointD loc = new PointD(r.X + rd.X, r.Y + rd.Y);
562 ROI an = ROI.CreateRectangle(coord, loc.X, loc.Y, rd.W, rd.H);
563 ImageView.SelectedImage.Annotations.Add(an);
564 }
565 }
566 else
567 if (Tools.currentTool.type == Tools.Tool.Type.bucket && buts == MouseButtons.Left)
568 {
569 ZCT coord = App.viewer.GetCoordinate();
570 floodFiller.FillColor = DrawColor;
571 floodFiller.Tolerance = currentTool.tolerance;
572 floodFiller.Bitmap = ImageView.SelectedImage.Buffers[ImageView.SelectedImage.Coords[coord.C, coord.Z, coord.T]];
573 floodFiller.FloodFill(new AForge.Point((int)p.X, (int)p.Y));
575 }
576 else
577 if (Tools.currentTool.type == Tools.Tool.Type.dropper && buts == MouseButtons.Left)
578 {
579 DrawColor = ImageView.SelectedBuffer.GetPixel((int)p.X, (int)p.Y);
580 UpdateGUI();
581 }
583 }
584
585 public void ToolMove(PointD e, MouseButtons buts)
586 {
587 if (App.viewer == null)
588 return;
589 if (ImageView.SelectedImage == null)
590 return;
591 PointD p = ImageView.SelectedImage.isPyramidal ? e : ImageView.SelectedImage.ToImageSpace(e);
592 PointD roiPoint = GetAnnotationPoint(e);
593 if (Tools.currentTool.type == Tools.Tool.Type.pan && (buts.HasFlag(MouseButtons.Left) || buts.HasFlag(MouseButtons.Middle)))
594 {
595 if (ImageView.SelectedImage.isPyramidal)
596 {
597 if (App.viewer.MouseMoveInt.X != 0 || App.viewer.MouseMoveInt.Y != 0)
598 {
599 App.viewer.PyramidalOrigin = new PointD(
603 }
604 }
605 else
606 {
607 PointD pf = new PointD(e.X - ImageView.mouseDown.X, e.Y - ImageView.mouseDown.Y);
608 App.viewer.Origin = new PointD(App.viewer.Origin.X + pf.X, App.viewer.Origin.Y + pf.Y);
609 App.viewer.UpdateView(false);
610 }
612 return;
613 }
614
615 if (currentTool.type == Tool.Type.line && ImageView.down)
616 {
617 anno.UpdatePoint(roiPoint, 1);
619 }
620 else
621 if (currentTool.type == Tool.Type.freeform && ImageView.down)
622 {
623 if (anno.type != ROI.Type.Freeform)
624 {
625 anno = new ROI();
626 anno.type = ROI.Type.Freeform;
627 anno.closed = false;
628 anno.AddPoint(roiPoint);
629 anno.coord = App.viewer.GetCoordinate();
630 ImageView.SelectedImage.Annotations.Add(anno);
631 RefreshRoiManager();
632 }
633 else
634 {
635 anno.AddPoint(roiPoint);
636 RefreshRoiManager();
637 }
639 }
640 else
641
642 if (currentTool.type == Tool.Type.rect && anno.type == ROI.Type.Rectangle)
643 {
644 RectangleD rect;
645 double x = Math.Min(rectStart.X, roiPoint.X);
646 double y = Math.Min(rectStart.Y, roiPoint.Y);
647 double w = Math.Abs(roiPoint.X - rectStart.X);
648 double h = Math.Abs(roiPoint.Y - rectStart.Y);
649 rect = new RectangleD(x, y, w, h);
650 anno.BoundingBox = rect;
651 anno.Validate();
652 currentTool.Rectangle = rect;
654 }
655 else
656 if (currentTool.type == Tool.Type.ellipse && anno.type == ROI.Type.Ellipse)
657 {
658 RectangleD rect;
659 double x = Math.Min(rectStart.X, roiPoint.X);
660 double y = Math.Min(rectStart.Y, roiPoint.Y);
661 double w = Math.Abs(roiPoint.X - rectStart.X);
662 double h = Math.Abs(roiPoint.Y - rectStart.Y);
663 rect = new RectangleD(x, y, w, h);
664 anno.BoundingBox = rect;
665 anno.Validate();
666 currentTool.Rectangle = rect;
668 }
669 else
670 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left && ImageView.down)
671 {
672 PointD roiDown = GetAnnotationPoint(ImageView.mouseDown);
673 PointD d = new PointD(roiPoint.X - roiDown.X, roiPoint.Y - roiDown.Y);
674 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(roiDown.X, roiDown.Y, d.X, d.Y);
676 }
677 else
678 if (currentTool.type == Tool.Type.rectSel && ImageView.up)
679 {
680 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(0, 0, 0, 0);
681 }
682 else
683 if (Win32.GetKeyState(Keys.Delete))
684 {
685 foreach (ROI an in ImageView.selectedAnnotations)
686 {
687 if (an != null)
688 {
689 if (an.selectedPoints.Count == 0)
690 {
691 ImageView.SelectedImage.Annotations.Remove(an);
692 }
693 else
694 {
695 if (an.type == ROI.Type.Polygon ||
696 an.type == ROI.Type.Polyline ||
697 an.type == ROI.Type.Freeform)
698 {
699 an.closed = false;
700 an.RemovePoints(an.selectedPoints.ToArray());
701
702 }
703 }
704 }
705 }
707 }
708 /*
709 if (Tools.currentTool.type == Tools.Tool.Type.magic && buts == MouseButtons.Left)
710 {
711 //First we draw the selection rectangle
712 PointD d = new PointD(e.X - ImageView.mouseDown.X, e.Y - ImageView.mouseDown.Y);
713 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(ImageView.mouseDown.X, ImageView.mouseDown.Y, d.X, d.Y);
714 UpdateOverlay();
715 }
716 */
717 if (buts == MouseButtons.Left && currentTool.type == Tool.Type.eraser)
718 {
719 Graphics.Graphics g = Graphics.Graphics.FromImage(ImageView.SelectedBuffer);
720 Graphics.Pen pen = new Graphics.Pen(Tools.EraseColor, (int)Tools.StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel);
721 g.FillEllipse(new Rectangle((int)p.X, (int)p.Y, (int)width, (int)Tools.StrokeWidth), pen.color);
722 pen.Dispose();
724 }
725 }
726
732 private void movePanel_Click(object sender, EventArgs e)
733 {
734 currentTool = GetTool(Tool.Type.move);
736 movePanel.BackColor = System.Drawing.Color.LightGray;
737 }
743 private void textPanel_Click(object sender, EventArgs e)
744 {
745 currentTool = GetTool(Tool.Type.text);
747 textPanel.BackColor = System.Drawing.Color.LightGray;
748 }
758 private void textPanel_DoubleClick(object sender, EventArgs e)
759 {
760 currentTool = GetTool(Tool.Type.text);
762 textPanel.BackColor = System.Drawing.Color.LightGray;
763
764 if (fontDialog.ShowDialog() != DialogResult.OK)
765 return;
766 font = fontDialog.Font;
767 }
773 private void pointPanel_Click(object sender, EventArgs e)
774 {
775 currentTool = GetTool(Tool.Type.point);
777 pointPanel.BackColor = System.Drawing.Color.LightGray;
778 }
784 private void linePanel_Click(object sender, EventArgs e)
785 {
786 currentTool = GetTool(Tool.Type.line);
788 linePanel.BackColor = System.Drawing.Color.LightGray;
789 }
796 private void rectPanel_Click(object sender, EventArgs e)
797 {
798 currentTool = GetTool(Tool.Type.rect);
800 rectPanel.BackColor = System.Drawing.Color.LightGray;
801 }
808 private void ellipsePanel_Click(object sender, EventArgs e)
809 {
810 currentTool = GetTool(Tool.Type.ellipse);
812 ellipsePanel.BackColor = System.Drawing.Color.LightGray;
813 }
820 private void polyPanel_Click(object sender, EventArgs e)
821 {
822 currentTool = GetTool(Tool.Type.polygon);
824 polyPanel.BackColor = System.Drawing.Color.LightGray;
825 }
832 private void deletePanel_Click(object sender, EventArgs e)
833 {
834 currentTool = GetTool(Tool.Type.delete);
836 deletePanel.BackColor = System.Drawing.Color.LightGray;
837 }
843 private void freeformPanel_Click(object sender, EventArgs e)
844 {
845 currentTool = GetTool(Tool.Type.freeform);
847 freeformPanel.BackColor = System.Drawing.Color.LightGray;
848 }
855 private void rectSelPanel_Click(object sender, EventArgs e)
856 {
857 currentTool = GetTool(Tool.Type.rectSel);
859 rectSelPanel.BackColor = System.Drawing.Color.LightGray;
860 }
867 private void panPanel_Click(object sender, EventArgs e)
868 {
869 currentTool = GetTool(Tool.Type.pan);
871 panPanel.BackColor = System.Drawing.Color.LightGray;
872 }
879 private void magicPanel_Click(object sender, EventArgs e)
880 {
881 currentTool = GetTool(Tool.Type.magic);
883 magicPanel.BackColor = System.Drawing.Color.LightGray;
884 }
891 private void bucketPanel_Click(object sender, EventArgs e)
892 {
893 currentTool = GetTool(Tool.Type.bucket);
895 bucketPanel.BackColor = System.Drawing.Color.LightGray;
896 }
903 private void pencilPanel_Click(object sender, EventArgs e)
904 {
905 currentTool = GetTool(Tool.Type.pencil);
907 pencilPanel.BackColor = System.Drawing.Color.LightGray;
908 }
909 MagicSelect magicSel = new MagicSelect(2);
916 private void magicPanel_MouseDoubleClick(object sender, MouseEventArgs e)
917 {
918 if (magicSel.ShowDialog() != DialogResult.OK)
919 return;
920 }
926 private void Tools_FormClosing(object sender, FormClosingEventArgs e)
927 {
928 e.Cancel = true;
929 this.Hide();
930 }
931
939 private void pencilPanel_MouseDoubleClick(object sender, MouseEventArgs e)
940 {
941 currentTool = GetTool(Tool.Type.pencil);
943 pencilPanel.BackColor = System.Drawing.Color.LightGray;
944 PenTool pt = new PenTool(new Graphics.Pen(DrawColor, (int)Tools.StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel));
945 if (pt.ShowDialog() != DialogResult.OK)
946 return;
947 Tools.StrokeWidth = pt.Pen.width;
948 DrawColor = pt.Pen.color;
949 }
950
960 private void bucketPanel_MouseDoubleClick(object sender, MouseEventArgs e)
961 {
962 currentTool = GetTool(Tool.Type.bucket);
964 bucketPanel.BackColor = System.Drawing.Color.LightGray;
966 if (pt.ShowDialog() != DialogResult.OK)
967 return;
968 Tools.StrokeWidth = pt.Pen.width;
969 DrawColor = pt.Pen.color;
970 currentTool.tolerance = pt.Tolerance;
971 }
972
979 private void dropperPanel_MouseClick(object sender, MouseEventArgs e)
980 {
981 currentTool = GetTool(Tool.Type.dropper);
983 dropperPanel.BackColor = System.Drawing.Color.LightGray;
984 }
985
993 private void color1Box_MouseClick(object sender, MouseEventArgs e)
994 {
996 if (t.ShowDialog() != DialogResult.OK)
997 return;
998 DrawColor = t.Color;
999 UpdateGUI();
1000 }
1001
1009 private void color2Box_MouseClick(object sender, MouseEventArgs e)
1010 {
1011 ColorTool t = new ColorTool(EraseColor, ImageView.SelectedBuffer.BitsPerPixel);
1012 if (t.ShowDialog() != DialogResult.OK)
1013 return;
1014 EraseColor = t.Color;
1015 UpdateGUI();
1016 }
1017
1023 private void widthBox_ValueChanged(object sender, EventArgs e)
1024 {
1025 width = (int)widthBox.Value;
1026 }
1027
1034 private void eraserPanel_MouseClick(object sender, MouseEventArgs e)
1035 {
1036 currentTool = GetTool(Tool.Type.eraser);
1038 eraserPanel.BackColor = System.Drawing.Color.LightGray;
1039 }
1040
1045 private void switchBox_MouseClick(object sender, MouseEventArgs e)
1046 {
1047 ColorS s = DrawColor;
1048 DrawColor = eraseColor;
1049 EraseColor = s;
1050 UpdateGUI();
1051 }
1052
1057 private void Tools_Activated(object sender, EventArgs e)
1058 {
1059 UpdateGUI();
1060 }
1061 }
1062}
AForge.Bitmap Bitmap
AForge.RectangleD RectangleD
AForge.RectangleF RectangleF
AForge.Rectangle Rectangle
System.Windows.Forms.Keys Keys
Definition ImageView.cs:17
AForge.PointD PointD
AForge.ZCT ZCT
Definition TabsView.cs:17
The base class that the flood fill algorithms inherit from. Implements the basic flood filler functio...
static ROIManager manager
Definition App.cs:14
static Tools tools
Definition App.cs:21
static ImageView viewer
Definition App.cs:23
void FillEllipse(float xx, float yy, int w, int h, ColorS c)
Definition Graphics.cs:180
static Graphics FromImage(Bitmap b)
Definition Graphics.cs:37
ImageView control for image stacks, pyramidal and whole-slide-images.
static bool down
Definition ImageView.cs:303
List< ROI > AnnotationsRGB
PointD Origin
A property of the class PointD. *‍/.
Definition ImageView.cs:718
PointD PyramidalOrigin
Setting the value of the pyramidalOrigin variable. *‍/.
Definition ImageView.cs:730
void UpdateView(bool refreshImages=true)
static List< ROI > selectedAnnotations
Definition ImageView.cs:267
static PointD mouseDown
Definition ImageView.cs:302
static BioImage SelectedImage
Definition ImageView.cs:270
static PointD mouseUp
Definition ImageView.cs:304
static Bitmap SelectedBuffer
Definition ImageView.cs:295
double GetSelectionBoxHitSize()
async void UpdateImages(bool updatePyramidal=true)
Implements the QueueLinear flood fill algorithm using array-based pixel manipulation.
void UpdateAnnotationList()
Definition ROIManager.cs:26
static State GetDown(PointD pf, MouseButtons mb)
Definition Scripting.cs:186
static State GetUp(PointD pf, MouseButtons mb)
Definition Scripting.cs:171
static void UpdateState(State s)
Definition Scripting.cs:261
override string ToString()
Definition Tools.cs:126
ToolType toolType
Definition Tools.cs:86
Tool(Type t, string sc)
Definition Tools.cs:120
Tool(Type t, RectangleD r)
Definition Tools.cs:114
RectangleD Rectangle
Definition Tools.cs:89
List< AForge.Point > Points
Definition Tools.cs:85
static void Init()
Definition Tools.cs:75
Tool(Type t, ColorS col)
Definition Tools.cs:109
static bool bEnabled
Definition Tools.cs:31
void UpdateSelected()
Definition Tools.cs:201
static Tool GetTool(string name)
Definition Tools.cs:183
static bool applyToStack
Definition Tools.cs:27
static Tool currentTool
Definition Tools.cs:131
static System.Drawing.Rectangle selectionRectangle
Definition Tools.cs:36
static RectangleD selectionRect
Definition Tools.cs:168
static float selectBoxSize
Definition Tools.cs:220
static int StrokeWidth
Definition Tools.cs:156
void ToolMove(PointD e, MouseButtons buts)
Definition Tools.cs:585
void ToolUp(PointD e, MouseButtons buts)
Definition Tools.cs:431
static ColorS DrawColor
Definition Tools.cs:133
static Hashtable tools
Definition Tools.cs:37
static Tool GetTool(Tool.Type typ)
Definition Tools.cs:187
static bool gEnabled
Definition Tools.cs:30
static ColorS EraseColor
Definition Tools.cs:144
static bool rEnabled
Definition Tools.cs:29
void ToolDown(PointD e, MouseButtons buts)
Definition Tools.cs:259
void UpdateOverlay()
Definition Tools.cs:191
static ColorTool colorTool
Definition Tools.cs:28
void UpdateView()
Definition Tools.cs:195
static bool GetKeyState(System.Windows.Forms.Keys vKey)
Definition Win32.cs:24