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
Tools.cs
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,
46 annotation,
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,
62 polyline,
63 polygon,
64 text,
65 delete,
66 freeform,
67 rectSel,
68 pointSel,
69 pan,
70 magic,
71 script,
72 dropper
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;
86 public ToolType toolType;
87 private RectangleD rect;
88 public RectangleD Rectangle
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
168 public static RectangleD selectionRect;
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
177 currentTool = GetTool(Tool.Type.move);
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 {
193 App.viewer.UpdateOverlay();
194 }
195 public void UpdateView()
196 {
197 App.viewer.UpdateView();
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();
248 public void ToolDown(PointD e, MouseButtons buts)
249 {
250 if (App.viewer == null || currentTool == null || ImageView.SelectedImage == null)
251 return;
253 PointD p;
254 if(ImageView.SelectedImage!=null)
255 p = ImageView.SelectedImage.ToImageSpace(e);
256 if (currentTool.type == Tool.Type.line && buts == MouseButtons.Left)
257 {
258 if (anno.GetPointCount() == 0)
259 {
260 anno = new ROI();
261 anno.type = ROI.Type.Line;
262 anno.AddPoint(new PointD(e.X, e.Y));
263 anno.AddPoint(new PointD(e.X, e.Y));
264 anno.coord = App.viewer.GetCoordinate();
265 ImageView.SelectedImage.Annotations.Add(anno);
266 }
267 }
268 else
269 if (currentTool.type == Tool.Type.polygon && buts == MouseButtons.Left)
270 {
271 if (anno.GetPointCount() == 0)
272 {
273 anno = new ROI();
274 anno.type = ROI.Type.Polygon;
275 anno.AddPoint(new PointD(e.X, e.Y));
276 anno.coord = App.viewer.GetCoordinate();
277 ImageView.SelectedImage.Annotations.Add(anno);
278 }
279 else
280 {
281 //If we click on a point 1 we close this polygon
282 RectangleD d = new RectangleD(e.X, e.Y, ROI.selectBoxSize, ROI.selectBoxSize);
283 if (d.IntersectsWith(anno.Points[0]))
284 {
285 anno.closed = true;
286 anno = new ROI();
287 }
288 else
289 {
290 anno.AddPoint(new PointD(e.X, e.Y));
291 }
292 }
293 }
294 else
295 if (currentTool.type == Tool.Type.freeform && buts == MouseButtons.Left)
296 {
297 if (anno.GetPointCount() == 0)
298 {
299 anno = new ROI();
300 anno.type = ROI.Type.Freeform;
301 anno.AddPoint(new PointD(e.X, e.Y));
302 anno.coord = App.viewer.GetCoordinate();
303 anno.closed = true;
304 ImageView.SelectedImage.Annotations.Add(anno);
305 }
306 else
307 {
308 anno.AddPoint(new PointD(e.X, e.Y));
309 }
310 }
311 else
312 if (currentTool.type == Tool.Type.rect && buts == MouseButtons.Left)
313 {
314 anno.type = ROI.Type.Rectangle;
315 anno.BoundingBox = new RectangleD(e.X, e.Y, 1, 1);
316 anno.coord = App.viewer.GetCoordinate();
317 ImageView.SelectedImage.Annotations.Add(anno);
318 }
319 else
320 if (currentTool.type == Tool.Type.ellipse && buts == MouseButtons.Left)
321 {
322 anno.type = ROI.Type.Ellipse;
323 anno.BoundingBox = new RectangleD(e.X, e.Y, 1, 1);
324 anno.coord = App.viewer.GetCoordinate();
325 ImageView.SelectedImage.Annotations.Add(anno);
326 }
327 else
328 if (currentTool.type == Tool.Type.delete && buts == MouseButtons.Left)
329 {
330 for (int i = 0; i < ImageView.SelectedImage.Annotations.Count; i++)
331 {
332 ROI an = ImageView.SelectedImage.Annotations[i];
333 if (an.BoundingBox.IntersectsWith(new RectangleD(e.X, e.Y, 1, 1)))
334 {
335 if (an.selectedPoints.Count == 0)
336 {
337 ImageView.SelectedImage.Annotations.Remove(an);
338 break;
339 }
340 else
341 if (an.selectedPoints.Count == 1 && !(an.type == ROI.Type.Polygon || an.type == ROI.Type.Polyline || an.type == ROI.Type.Freeform))
342 {
343 ImageView.SelectedImage.Annotations.Remove(an);
344 break;
345 }
346 else
347 {
348 if (an.type == ROI.Type.Polygon ||
349 an.type == ROI.Type.Polyline ||
350 an.type == ROI.Type.Freeform)
351 {
352 an.closed = false;
353 an.RemovePoints(an.selectedPoints.ToArray());
354 break;
355 }
356 }
357 }
358 }
359 UpdateOverlay();
360 }
361 else
362 if (currentTool.type == Tool.Type.text && buts == MouseButtons.Left)
363 {
364 ROI an = new ROI();
365 an.type = ROI.Type.Label;
366 an.AddPoint(new PointD(e.X, e.Y));
367 an.coord = App.viewer.GetCoordinate();
368 TextInput ti = new TextInput("");
369 if (ti.ShowDialog() != DialogResult.OK)
370 return;
371 an.family = font.FontFamily.Name;
372 an.fontSize = ti.font.Size;
373 an.strokeColor = AForge.Color.FromArgb(ti.color.A, ti.color.R, ti.color.G, ti.color.B);
374 an.Text = ti.TextValue;
375 ImageView.SelectedImage.Annotations.Add(an);
376 }
377
378 if (buts == MouseButtons.Middle)
379 {
380 currentTool = GetTool(Tool.Type.pan);
382 panPanel.BackColor = System.Drawing.Color.LightGray;
383 }
384
385
386 UpdateOverlay();
387 }
394 public void ToolUp(PointD e, MouseButtons buts)
395 {
396 PointD p = new PointD();
397 if (ImageView.SelectedImage == null)
398 return;
399 p = ImageView.SelectedImage.ToImageSpace(e);
400 if (App.viewer == null || currentTool == null || ImageView.SelectedImage == null || anno == null)
401 return;
403 if (currentTool.type == Tool.Type.point && buts == MouseButtons.Left)
404 {
405 ROI an = new ROI();
406 an.AddPoint(new PointD(e.X, e.Y));
407 an.type = ROI.Type.Point;
408 an.coord = App.viewer.GetCoordinate();
409 ImageView.SelectedImage.Annotations.Add(an);
410 }
411 else
412 if (currentTool.type == Tool.Type.line && anno.type == ROI.Type.Line && buts == MouseButtons.Left)
413 {
414 if (anno.GetPointCount() > 0)
415 {
416 anno.UpdatePoint(new PointD(e.X, e.Y), 1);
417 anno = new ROI();
418 }
419 }
420 else
421 if (currentTool.type == Tool.Type.rect && anno.type == ROI.Type.Rectangle && buts == MouseButtons.Left)
422 {
423 if (anno.GetPointCount() == 4)
424 {
425 anno = new ROI();
426 }
427 }
428 else
429 if (currentTool.type == Tool.Type.ellipse && anno.type == ROI.Type.Ellipse && buts == MouseButtons.Left)
430 {
431 if (anno.GetPointCount() == 4)
432 {
433 anno = new ROI();
434 }
435 }
436 else
437 if (currentTool.type == Tool.Type.freeform && anno.type == ROI.Type.Freeform && buts == MouseButtons.Left)
438 {
439 anno = new ROI();
440 }
441 else
442 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left)
443 {
444 if (!Win32.GetKeyState(Keys.LControlKey))
445 ImageView.selectedAnnotations.Clear();
446 RectangleD r = GetTool(Tool.Type.rectSel).Rectangle;
447 foreach (ROI an in App.viewer.AnnotationsRGB)
448 {
449 if (an.GetSelectBound(App.viewer.GetScale(), App.viewer.GetScale()).ToRectangleF().IntersectsWith(r.ToRectangleF()))
450 {
451 if(!Win32.GetKeyState(Keys.LControlKey))
452 an.selectedPoints.Clear();
453 ImageView.selectedAnnotations.Add(an);
454 an.Selected = true;
455 RectangleD[] sels = an.GetSelectBoxes(selectBoxSize);
456 for (int i = 0; i < sels.Length; i++)
457 {
458 if (sels[i].IntersectsWith(r))
459 {
460 an.selectedPoints.Add(i);
461 }
462 }
463 }
464 else
465 an.Selected = false;
466 }
467 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(0, 0, 0, 0);
468 }
469 else
470 if (Tools.currentTool.type == Tools.Tool.Type.magic && buts == MouseButtons.Left)
471 {
472 RectangleD r = new RectangleD(ImageView.mouseDown.X, ImageView.mouseDown.Y, Math.Abs(ImageView.mouseUp.X - ImageView.mouseDown.X), Math.Abs(ImageView.mouseUp.Y - ImageView.mouseDown.Y));
473 AForge.RectangleF rr = ImageView.SelectedImage.ToImageSpace(r);
474 ZCT coord = App.viewer.GetCoordinate();
475 Bitmap bf;
476 if (ImageView.SelectedImage.Buffers[0].RGBChannelsCount > 1)
477 bf = ImageView.SelectedImage.GetFiltered(coord, ImageView.SelectedBuffer.Stats[0].Range, ImageView.SelectedBuffer.Stats[1].Range, ImageView.SelectedBuffer.Stats[2].Range);
478 else
479 bf = ImageView.SelectedImage.GetFiltered(coord, ImageView.SelectedBuffer.Stats[0].Range, ImageView.SelectedBuffer.Stats[0].Range, ImageView.SelectedBuffer.Stats[0].Range);
480 bf.Crop(rr.ToRectangleInt());
481 Statistics[] sts = Statistics.FromBytes(bf);
482 Statistics st = sts[0];
483 int th = 0;
484 if (magicSel.Numeric)
485 {
486 th = magicSel.Threshold;
487 }
488 else
489 if (magicSel.Index == 2)
490 th = (int)(st.Min + st.Mean);
491 else
492 if (magicSel.Index == 1)
493 th = (int)st.Median;
494 else
495 th = (int)st.Min;
496 Bitmap det;
497 if (bf.BitsPerPixel > 8)
498 {
499 bf.To8Bit();
500 det = bf;
501 //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));
502 }
503 else
504 {
505 //blobCounter.BackgroundThreshold = AForge.Color.FromArgb((int)th, (int)th, (int)th);
506 det = bf;
507 }
508 BlobCounter blobCounter = new BlobCounter(det);
509 blobCounter.FilterBlobs = true;
510 blobCounter.MinWidth = 2;
511 blobCounter.MinHeight = 2;
512 blobCounter.CoupledSizeFiltering = true;
513 Blob[] blobs = blobCounter.GetObjects(det, true);
514 double px = ImageView.SelectedImage.PhysicalSizeX;
515 double py = ImageView.SelectedImage.PhysicalSizeY;
516 foreach (Blob blob in blobs)
517 {
518 AForge.RectangleD rd = new RectangleD(blob.Rectangle.X * px, blob.Rectangle.Y * py, blob.Rectangle.Width * px, blob.Rectangle.Height * py);
519 PointD loc = new PointD(r.X + rd.X, r.Y + rd.Y);
520 ROI an = ROI.CreateRectangle(coord, loc.X, loc.Y, rd.W, rd.H);
521 ImageView.SelectedImage.Annotations.Add(an);
522 }
523 }
524 else
525 if (Tools.currentTool.type == Tools.Tool.Type.bucket && buts == MouseButtons.Left)
526 {
527 ZCT coord = App.viewer.GetCoordinate();
528 floodFiller.FillColor = DrawColor;
529 floodFiller.Tolerance = currentTool.tolerance;
530 floodFiller.Bitmap = ImageView.SelectedImage.Buffers[ImageView.SelectedImage.Coords[coord.C, coord.Z, coord.T]];
531 floodFiller.FloodFill(new AForge.Point((int)p.X, (int)p.Y));
532 App.viewer.UpdateImages();
533 }
534 else
535 if (Tools.currentTool.type == Tools.Tool.Type.dropper && buts == MouseButtons.Left)
536 {
537 DrawColor = ImageView.SelectedBuffer.GetPixel((int)p.X, (int)p.Y);
538 UpdateGUI();
539 }
540 UpdateOverlay();
541 }
542
543 public void ToolMove(PointD e, MouseButtons buts)
544 {
545 if (App.viewer == null)
546 return;
547 if (ImageView.SelectedImage == null)
548 return;
549 PointD p = ImageView.SelectedImage.ToImageSpace(e);
550 if (Tools.currentTool.type == Tools.Tool.Type.pan && (buts.HasFlag(MouseButtons.Left) || buts.HasFlag(MouseButtons.Middle)))
551 {
552 if (ImageView.SelectedImage.isPyramidal)
553 {
554 if (App.viewer.MouseMoveInt.X != 0 || App.viewer.MouseMoveInt.Y != 0)
555 {
556 App.viewer.PyramidalOriginTransformed = new PointD(App.viewer.PyramidalOriginTransformed.X + (ImageView.mouseDown.X - e.X), App.viewer.PyramidalOriginTransformed.Y + (ImageView.mouseDown.Y - e.Y));
557 App.viewer.UpdateImages();
558 }
559 }
560 else
561 {
562 PointD pf = new PointD(e.X - ImageView.mouseDown.X, e.Y - ImageView.mouseDown.Y);
563 App.viewer.Origin = new PointD(App.viewer.Origin.X + pf.X, App.viewer.Origin.Y + pf.Y);
564 }
565 UpdateView();
566 }
567
568
569 if (currentTool.type == Tool.Type.line && ImageView.down)
570 {
571 anno.UpdatePoint(new PointD(e.X, e.Y), 1);
572 UpdateOverlay();
573 }
574 else
575 if (currentTool.type == Tool.Type.freeform && buts == MouseButtons.Left && ImageView.down)
576 {
577 if (anno.GetPointCount() == 0)
578 {
579 anno.type = ROI.Type.Freeform;
580 anno.AddPoint(new PointD(e.X, e.Y));
581 anno.coord = App.viewer.GetCoordinate();
582 anno.closed = true;
583 ImageView.SelectedImage.Annotations.Add(anno);
584 }
585 else
586 {
587 anno.AddPoint(new PointD(e.X, e.Y));
588 }
589 UpdateOverlay();
590 }
591 else
592
593 if (currentTool.type == Tool.Type.rect && anno.type == ROI.Type.Rectangle)
594 {
595 if (anno.GetPointCount() == 4)
596 {
597 anno.BoundingBox = new RectangleD(anno.X, anno.Y, e.X - anno.X, e.Y - anno.Y);
598 UpdateOverlay();
599 }
600 }
601 else
602 if (currentTool.type == Tool.Type.ellipse && anno.type == ROI.Type.Ellipse)
603 {
604 if (anno.GetPointCount() == 4)
605 {
606 anno.BoundingBox = new RectangleD(anno.X, anno.Y, e.X - anno.X, e.Y - anno.Y);
607 UpdateOverlay();
608 }
609 }
610 else
611 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left && ImageView.down)
612 {
613 PointD d = new PointD(e.X - ImageView.mouseDown.X, e.Y - ImageView.mouseDown.Y);
614 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(ImageView.mouseDown.X, ImageView.mouseDown.Y, d.X, d.Y);
615 RectangleD r = Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle;
616 foreach (ROI an in App.viewer.AnnotationsRGB)
617 {
618 if (an.GetSelectBound(App.viewer.GetScale(), App.viewer.GetScale()).IntersectsWith(r))
619 {
620 if (!Win32.GetKeyState(Keys.LControlKey))
621 an.selectedPoints.Clear();
622 ImageView.selectedAnnotations.Add(an);
623 an.Selected = true;
624 RectangleD[] sels = an.GetSelectBoxes(selectBoxSize);
625 for (int i = 0; i < sels.Length; i++)
626 {
627 if (sels[i].IntersectsWith(r))
628 {
629 an.selectedPoints.Add(i);
630 }
631 }
632 }
633 else if (!Win32.GetKeyState(Keys.LControlKey))
634 an.Selected = false;
635 }
636 UpdateOverlay();
637 }
638 else
639 if (currentTool.type == Tool.Type.rectSel && ImageView.up)
640 {
641 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(0, 0, 0, 0);
642 }
643 else
644 if (Win32.GetKeyState(Keys.Delete))
645 {
646 foreach (ROI an in ImageView.selectedAnnotations)
647 {
648 if (an != null)
649 {
650 if (an.selectedPoints.Count == 0)
651 {
652 ImageView.SelectedImage.Annotations.Remove(an);
653 }
654 else
655 {
656 if (an.type == ROI.Type.Polygon ||
657 an.type == ROI.Type.Polyline ||
658 an.type == ROI.Type.Freeform)
659 {
660 an.closed = false;
661 an.RemovePoints(an.selectedPoints.ToArray());
662
663 }
664 }
665 }
666 }
667 UpdateOverlay();
668 }
669 if (currentTool.type == Tool.Type.rectSel && buts.HasFlag(MouseButtons.Left))
670 {
671 PointD d = new PointD(e.X - ImageView.mouseDown.X, e.Y - ImageView.mouseDown.Y);
672 Tools.GetTool(Tools.Tool.Type.select).Rectangle = new RectangleD(ImageView.mouseDown.X, ImageView.mouseDown.Y, Math.Abs(d.X), Math.Abs(d.Y));
673 RectangleD r = Tools.GetTool(Tools.Tool.Type.select).Rectangle;
674 List<ROI> rois = ImageView.SelectedImage.Annotations;
675 foreach (ROI an in rois)
676 {
677 if (an.GetSelectBound(ROI.selectBoxSize * ImageView.SelectedImage.PhysicalSizeX, ROI.selectBoxSize * ImageView.SelectedImage.PhysicalSizeY).IntersectsWith(r))
678 {
679 if(!Win32.GetKeyState(Keys.LControlKey))
680 an.selectedPoints.Clear();
681 an.Selected = true;
682 RectangleD[] sels = an.GetSelectBoxes();
683 for (int i = 0; i < sels.Length; i++)
684 {
685 if (sels[i].IntersectsWith(r))
686 {
687 an.selectedPoints.Add(i);
688 }
689 }
690 }
691 }
692 App.viewer.UpdateView();
693 }
694 /*
695 if (Tools.currentTool.type == Tools.Tool.Type.magic && buts == MouseButtons.Left)
696 {
697 //First we draw the selection rectangle
698 PointD d = new PointD(e.X - ImageView.mouseDown.X, e.Y - ImageView.mouseDown.Y);
699 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(ImageView.mouseDown.X, ImageView.mouseDown.Y, d.X, d.Y);
700 UpdateOverlay();
701 }
702 */
703 if (buts == MouseButtons.Left && currentTool.type == Tool.Type.eraser)
704 {
705 Graphics.Graphics g = Graphics.Graphics.FromImage(ImageView.SelectedBuffer);
706 Graphics.Pen pen = new Graphics.Pen(Tools.EraseColor, (int)Tools.StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel);
707 g.FillEllipse(new Rectangle((int)p.X, (int)p.Y, (int)width, (int)Tools.StrokeWidth), pen.color);
708 pen.Dispose();
709 App.viewer.UpdateImage();
710 }
711 }
712
718 private void movePanel_Click(object sender, EventArgs e)
719 {
720 currentTool = GetTool(Tool.Type.move);
722 movePanel.BackColor = System.Drawing.Color.LightGray;
723 }
729 private void textPanel_Click(object sender, EventArgs e)
730 {
731 currentTool = GetTool(Tool.Type.text);
733 textPanel.BackColor = System.Drawing.Color.LightGray;
734 }
744 private void textPanel_DoubleClick(object sender, EventArgs e)
745 {
746 currentTool = GetTool(Tool.Type.text);
748 textPanel.BackColor = System.Drawing.Color.LightGray;
749
750 if (fontDialog.ShowDialog() != DialogResult.OK)
751 return;
752 font = fontDialog.Font;
753 }
759 private void pointPanel_Click(object sender, EventArgs e)
760 {
761 currentTool = GetTool(Tool.Type.point);
763 pointPanel.BackColor = System.Drawing.Color.LightGray;
764 }
770 private void linePanel_Click(object sender, EventArgs e)
771 {
772 currentTool = GetTool(Tool.Type.line);
774 linePanel.BackColor = System.Drawing.Color.LightGray;
775 }
782 private void rectPanel_Click(object sender, EventArgs e)
783 {
784 currentTool = GetTool(Tool.Type.rect);
786 rectPanel.BackColor = System.Drawing.Color.LightGray;
787 }
794 private void ellipsePanel_Click(object sender, EventArgs e)
795 {
796 currentTool = GetTool(Tool.Type.ellipse);
798 ellipsePanel.BackColor = System.Drawing.Color.LightGray;
799 }
806 private void polyPanel_Click(object sender, EventArgs e)
807 {
808 currentTool = GetTool(Tool.Type.polygon);
810 polyPanel.BackColor = System.Drawing.Color.LightGray;
811 }
818 private void deletePanel_Click(object sender, EventArgs e)
819 {
820 currentTool = GetTool(Tool.Type.delete);
822 deletePanel.BackColor = System.Drawing.Color.LightGray;
823 }
829 private void freeformPanel_Click(object sender, EventArgs e)
830 {
831 currentTool = GetTool(Tool.Type.freeform);
833 freeformPanel.BackColor = System.Drawing.Color.LightGray;
834 }
841 private void rectSelPanel_Click(object sender, EventArgs e)
842 {
843 currentTool = GetTool(Tool.Type.rectSel);
845 rectSelPanel.BackColor = System.Drawing.Color.LightGray;
846 }
853 private void panPanel_Click(object sender, EventArgs e)
854 {
855 currentTool = GetTool(Tool.Type.pan);
857 panPanel.BackColor = System.Drawing.Color.LightGray;
858 }
865 private void magicPanel_Click(object sender, EventArgs e)
866 {
867 currentTool = GetTool(Tool.Type.magic);
869 magicPanel.BackColor = System.Drawing.Color.LightGray;
870 }
877 private void bucketPanel_Click(object sender, EventArgs e)
878 {
879 currentTool = GetTool(Tool.Type.bucket);
881 bucketPanel.BackColor = System.Drawing.Color.LightGray;
882 }
889 private void pencilPanel_Click(object sender, EventArgs e)
890 {
891 currentTool = GetTool(Tool.Type.pencil);
893 pencilPanel.BackColor = System.Drawing.Color.LightGray;
894 }
895 MagicSelect magicSel = new MagicSelect(2);
902 private void magicPanel_MouseDoubleClick(object sender, MouseEventArgs e)
903 {
904 if (magicSel.ShowDialog() != DialogResult.OK)
905 return;
906 }
912 private void Tools_FormClosing(object sender, FormClosingEventArgs e)
913 {
914 e.Cancel = true;
915 this.Hide();
916 }
917
925 private void pencilPanel_MouseDoubleClick(object sender, MouseEventArgs e)
926 {
927 currentTool = GetTool(Tool.Type.pencil);
929 pencilPanel.BackColor = System.Drawing.Color.LightGray;
930 PenTool pt = new PenTool(new Graphics.Pen(DrawColor, (int)Tools.StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel));
931 if (pt.ShowDialog() != DialogResult.OK)
932 return;
933 Tools.StrokeWidth = pt.Pen.width;
934 DrawColor = pt.Pen.color;
935 }
936
946 private void bucketPanel_MouseDoubleClick(object sender, MouseEventArgs e)
947 {
948 currentTool = GetTool(Tool.Type.bucket);
950 bucketPanel.BackColor = System.Drawing.Color.LightGray;
951 FloodTool pt = new FloodTool(new Graphics.Pen(DrawColor, (int)Tools.StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel), currentTool.tolerance, ImageView.SelectedBuffer.BitsPerPixel);
952 if (pt.ShowDialog() != DialogResult.OK)
953 return;
954 Tools.StrokeWidth = pt.Pen.width;
955 DrawColor = pt.Pen.color;
956 currentTool.tolerance = pt.Tolerance;
957 }
958
965 private void dropperPanel_MouseClick(object sender, MouseEventArgs e)
966 {
967 currentTool = GetTool(Tool.Type.dropper);
969 dropperPanel.BackColor = System.Drawing.Color.LightGray;
970 }
971
979 private void color1Box_MouseClick(object sender, MouseEventArgs e)
980 {
981 ColorTool t = new ColorTool(DrawColor, ImageView.SelectedBuffer.BitsPerPixel);
982 if (t.ShowDialog() != DialogResult.OK)
983 return;
984 DrawColor = t.Color;
985 UpdateGUI();
986 }
987
995 private void color2Box_MouseClick(object sender, MouseEventArgs e)
996 {
997 ColorTool t = new ColorTool(EraseColor, ImageView.SelectedBuffer.BitsPerPixel);
998 if (t.ShowDialog() != DialogResult.OK)
999 return;
1000 EraseColor = t.Color;
1001 UpdateGUI();
1002 }
1003
1009 private void widthBox_ValueChanged(object sender, EventArgs e)
1010 {
1011 width = (int)widthBox.Value;
1012 }
1013
1020 private void eraserPanel_MouseClick(object sender, MouseEventArgs e)
1021 {
1022 currentTool = GetTool(Tool.Type.eraser);
1024 eraserPanel.BackColor = System.Drawing.Color.LightGray;
1025 }
1026
1031 private void switchBox_MouseClick(object sender, MouseEventArgs e)
1032 {
1033 ColorS s = DrawColor;
1034 DrawColor = eraseColor;
1035 EraseColor = s;
1036 UpdateGUI();
1037 }
1038
1043 private void Tools_Activated(object sender, EventArgs e)
1044 {
1045 UpdateGUI();
1046 }
1047 }
1048}
The base class that the flood fill algorithms inherit from. Implements the basic flood filler functio...
ImageView control for image stacks, pyramidal and whole-slide-images.
PointD Origin
A property of the class PointD. *‍/.
Definition ImageView.cs:727
async void UpdateImages(bool updatePyramidal=false)
Implements the QueueLinear flood fill algorithm using array-based pixel manipulation.
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
void UpdateSelected()
Definition Tools.cs:201
void ToolUp(PointD e, MouseButtons buts)
Definition Tools.cs:394
void ToolDown(PointD e, MouseButtons buts)
Definition Tools.cs:248
static bool GetKeyState(System.Windows.Forms.Keys vKey)
Definition Win32.cs:24