BioCore  5.0.0
A Windows .NET microscopy library and application for viewing, editing, and annotating images.
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;
16
17namespace BioCore
18{
19 public partial class Tools : Form
20 {
21 public static bool applyToStack = false;
22 public static ColorTool colorTool;
23 public static bool rEnabled = true;
24 public static bool gEnabled = true;
25 public static bool bEnabled = true;
26 private static ColorS drawColor = new ColorS(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
27 private static ColorS eraseColor = new ColorS(0, 0, 0);
28 private static int width = 1;
29
30 public static Rectangle selectionRectangle;
31 public static Hashtable tools = new Hashtable();
32 private AbstractFloodFiller floodFiller = null;
33 /* It's a class that contains a list of tools, and each tool has a type, a rectangle, a script,
34 and a tolerance. */
35 public class Tool
36 {
37 public enum ToolType
38 {
39 color,
41 select,
42 function
43 }
44 public enum Type
45 {
46 pencil,
47 brush,
48 bucket,
49 eraser,
50 move,
51 point,
52 line,
53 rect,
54 ellipse,
56 polygon,
57 text,
58 delete,
60 rectSel,
62 pan,
63 magic,
64 script,
66 }
67
68 public static void Init()
69 {
70 if (tools.Count == 0)
71 {
72 foreach (Tool.Type tool in (Tool.Type[])Enum.GetValues(typeof(Tool.Type)))
73 {
74 tools.Add(tool.ToString(), new Tool(tool, new ColorS(0, 0, 0)));
75 }
76 }
77 }
78 public List<System.Drawing.Point> Points;
80 private RectangleD rect;
82 {
83 get { return rect; }
84 set { rect = value; }
85 }
87 {
88 get { return new RectangleF((float)rect.X, (float)rect.Y, (float)rect.W, (float)rect.H); }
89 }
90 public string script;
91 public Type type;
92 public ColorS tolerance;
93 public Tool()
94 {
95 tolerance = new ColorS(0, 0, 0);
96 }
97 public Tool(Type t)
98 {
99 type = t;
100 tolerance = new ColorS(0, 0, 0);
101 }
102 public Tool(Type t, ColorS col)
103 {
104 type = t;
105 tolerance = new ColorS(0, 0, 0);
106 }
107 public Tool(Type t, RectangleD r)
108 {
109 type = t;
110 rect = r;
111 tolerance = new ColorS(0, 0, 0);
112 }
113 public Tool(Type t, string sc)
114 {
115 type = t;
116 script = sc;
117 tolerance = new ColorS(0, 0, 0);
118 }
119 public override string ToString()
120 {
121 return type.ToString();
122 }
123 }
124 public static Tool currentTool;
125 public static ColorS DrawColor
126 {
127 get
128 {
129 return drawColor;
130 }
131 set
132 {
133 drawColor = value;
134 }
135 }
136 public static ColorS EraseColor
137 {
138 get
139 {
140 return eraseColor;
141 }
142 set
143 {
144 eraseColor = value;
145 }
146 }
147
148 public static int StrokeWidth
149 {
150 get
151 {
152 return width;
153 }
154 set
155 {
156 width = value;
157 App.tools.UpdateGUI();
158 }
159 }
160
162 public Font font;
163 /* Initializing the tools. */
164 public Tools()
165 {
166 InitializeComponent();
167 Tool.Init();
168 ColorS col = new ColorS(ushort.MaxValue);
169 //We initialize the tools
171
172 floodFiller = null;
173 floodFiller = new QueueLinearFloodFiller(floodFiller);
174 }
175
176 public static Tool GetTool(string name)
177 {
178 return (Tool)tools[name];
179 }
180 public static Tool GetTool(Tool.Type typ)
181 {
182 return (Tool)tools[typ.ToString()];
183 }
184 public void UpdateOverlay()
185 {
187 }
188 public void UpdateView()
189 {
191 }
194 public void UpdateSelected()
195 {
196 foreach (Control item in this.Controls)
197 {
198 if(item.Tag != null)
199 if(item.Tag.ToString() == "tool")
200 item.BackColor = System.Drawing.Color.White;
201 }
202 }
204 private void UpdateGUI()
205 {
206 if (ImageView.SelectedImage != null)
207 {
208 color1Box.BackColor = System.Drawing.Color.FromArgb(DrawColor.R/ushort.MaxValue, DrawColor.G / ushort.MaxValue, DrawColor.B / ushort.MaxValue);
209 color2Box.BackColor = System.Drawing.Color.FromArgb(EraseColor.R / ushort.MaxValue, EraseColor.G / ushort.MaxValue, EraseColor.B / ushort.MaxValue);
210 }
211 widthBox.Value = width;
212 }
213 public static float selectBoxSize = ROI.selectBoxSize;
214 ROI anno = new ROI();
241 public void ToolDown(PointD e, MouseButtons buts)
242 {
243 if (App.viewer == null || currentTool == null || ImageView.SelectedImage == null)
244 return;
246 PointD p;
247 p = ImageView.SelectedImage.ToImageSpace(e);
248 if (currentTool.type == Tool.Type.line && buts == MouseButtons.Left)
249 {
250 if (anno.GetPointCount() == 0)
251 {
252 anno = new ROI();
253 anno.type = ROI.Type.Line;
254 anno.AddPoint(new PointD(e.X, e.Y));
255 anno.AddPoint(new PointD(e.X, e.Y));
256 anno.coord = App.viewer.GetCoordinate();
257 ImageView.SelectedImage.Annotations.Add(anno);
258 }
259 }
260 else
261 if (currentTool.type == Tool.Type.polygon && buts == MouseButtons.Left)
262 {
263 if (anno.GetPointCount() == 0)
264 {
265 anno = new ROI();
266 anno.type = ROI.Type.Polygon;
267 anno.AddPoint(new PointD(e.X, e.Y));
268 anno.coord = App.viewer.GetCoordinate();
269 ImageView.SelectedImage.Annotations.Add(anno);
270 }
271 else
272 {
273 //If we click on a point 1 we close this polygon
274 RectangleD d = new RectangleD(e.X, e.Y, ROI.selectBoxSize, ROI.selectBoxSize);
275 if (d.IntersectsWith(anno.Point))
276 {
277 anno.closed = true;
278 anno = new ROI();
279 }
280 else
281 {
282 anno.AddPoint(new PointD(e.X, e.Y));
283 }
284 }
285 }
286 else
287 if (currentTool.type == Tool.Type.freeform && buts == MouseButtons.Left)
288 {
289 if (anno.GetPointCount() == 0)
290 {
291 anno = new ROI();
292 anno.type = ROI.Type.Freeform;
293 anno.AddPoint(new PointD(e.X, e.Y));
294 anno.coord = App.viewer.GetCoordinate();
295 anno.closed = true;
296 ImageView.SelectedImage.Annotations.Add(anno);
297 }
298 else
299 {
300 anno.AddPoint(new PointD(e.X, e.Y));
301 }
302 }
303 else
304 if (currentTool.type == Tool.Type.rect && buts == MouseButtons.Left)
305 {
306 anno = ROI.CreateRectangle(App.viewer.GetCoordinate(),e.X,e.Y,1,1);
307 ImageView.SelectedImage.Annotations.Add(anno);
308 }
309 else
310 if (currentTool.type == Tool.Type.ellipse && buts == MouseButtons.Left)
311 {
312 anno = ROI.CreateRectangle(App.viewer.GetCoordinate(), e.X, e.Y, 1, 1);
313 ImageView.SelectedImage.Annotations.Add(anno);
314 }
315 else
316 if(currentTool.type == Tool.Type.delete && buts == MouseButtons.Left)
317 {
318 for (int i = 0; i < ImageView.SelectedImage.Annotations.Count; i++)
319 {
320 ROI an = ImageView.SelectedImage.Annotations[i];
321 if (an.BoundingBox.IntersectsWith(e.X,e.Y))
322 {
323 if (an.selectedPoints.Count == 0)
324 {
325 ImageView.SelectedImage.Annotations.Remove(an);
326 break;
327 }
328 else
329 if (an.selectedPoints.Count == 1 && !(an.type == ROI.Type.Polygon || an.type == ROI.Type.Polyline || an.type == ROI.Type.Freeform))
330 {
331 ImageView.SelectedImage.Annotations.Remove(an);
332 break;
333 }
334 else
335 {
336 if (an.type == ROI.Type.Polygon ||
337 an.type == ROI.Type.Polyline ||
338 an.type == ROI.Type.Freeform)
339 {
340 an.closed = false;
341 an.RemovePoints(an.selectedPoints.ToArray());
342 break;
343 }
344 }
345 }
346 }
348 }
349 else
350 if (currentTool.type == Tool.Type.text && buts == MouseButtons.Left)
351 {
352 ROI an = new ROI();
353 an.type = ROI.Type.Label;
354 an.AddPoint(new PointD(e.X, e.Y));
355 an.coord = App.viewer.GetCoordinate();
356 TextInput ti = new TextInput("");
357 if (ti.ShowDialog() != DialogResult.OK)
358 return;
359 an.family = ti.font.FontFamily.ToString();
360 an.fontSize = ti.font.Size;
361 an.strokeColor = AForge.Color.FromArgb(ti.color.A, ti.color.R, ti.color.G, ti.color.B);
362 an.Text = ti.TextValue;
363 ImageView.SelectedImage.Annotations.Add(an);
364 }
365 else
366 if (buts == MouseButtons.Middle || currentTool.type == Tool.Type.pan)
367 {
370 panPanel.BackColor = System.Drawing.Color.LightGray;
371 Cursor.Current = Cursors.Hand;
372 }
373
375 }
382 public void ToolUp(PointD e, MouseButtons buts)
383 {
384 PointD p;
385 p = ImageView.SelectedImage.ToImageSpace(e);
386 if (App.viewer == null || currentTool == null || ImageView.SelectedImage == null || anno == null)
387 return;
389 if (currentTool.type == Tool.Type.point && buts == MouseButtons.Left)
390 {
391 ROI an = new ROI();
392 an.AddPoint(new PointD(e.X, e.Y));
393 an.type = ROI.Type.Point;
394 an.coord = App.viewer.GetCoordinate();
395 ImageView.SelectedImage.Annotations.Add(an);
396 }
397 else
398 if (currentTool.type == Tool.Type.line && anno.type == ROI.Type.Line && buts == MouseButtons.Left)
399 {
400 if (anno.GetPointCount() > 0)
401 {
402 anno.UpdatePoint(new PointD(e.X, e.Y), 1);
403 anno = new ROI();
404 }
405 }
406 else
407 if (currentTool.type == Tool.Type.rect && anno.type == ROI.Type.Rectangle && buts == MouseButtons.Left)
408 {
409 if (anno.GetPointCount() == 4)
410 {
411 anno = new ROI();
412 }
413 }
414 else
415 if (currentTool.type == Tool.Type.ellipse && anno.type == ROI.Type.Ellipse && buts == MouseButtons.Left)
416 {
417 if (anno.GetPointCount() == 4)
418 {
419 anno = new ROI();
420 }
421 }
422 else
423 if (currentTool.type == Tool.Type.freeform && anno.type == ROI.Type.Freeform && buts == MouseButtons.Left)
424 {
425 anno = new ROI();
426 }
427 else
428 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left)
429 {
431 RectangleD r = GetTool(Tool.Type.rectSel).Rectangle;
432 foreach (ROI an in App.viewer.AnnotationsRGB)
433 {
434 if (an.GetSelectBound(App.viewer.GetScale(), App.viewer.GetScale()).ToRectangleF().IntersectsWith(r.ToRectangleF()))
435 {
436 an.selectedPoints.Clear();
438 an.Selected = true;
439 RectangleD[] sels = an.GetSelectBoxes(selectBoxSize);
440 for (int i = 0; i < sels.Length; i++)
441 {
442 if (sels[i].IntersectsWith(r))
443 {
444 an.selectedPoints.Add(i);
445 }
446 }
447 }
448 else
449 an.Selected = false;
450 }
451 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(0, 0, 0, 0);
452 }
453 else
454 if (Tools.currentTool.type == Tools.Tool.Type.magic && buts == MouseButtons.Left)
455 {
456 PointD pf = new PointD(ImageView.mouseUp.X - ImageView.mouseDown.X, ImageView.mouseUp.Y - ImageView.mouseDown.Y);
457 ZCT coord = App.viewer.GetCoordinate();
458
459 Rectangle r = new Rectangle((int)ImageView.mouseDown.X, (int)ImageView.mouseDown.Y, (int)(ImageView.mouseUp.X - ImageView.mouseDown.X), (int)(ImageView.mouseUp.Y - ImageView.mouseDown.Y));
460 if (r.Width <= 2 || r.Height <= 2)
461 return;
462 Bitmap bf = ImageView.SelectedImage.Buffers[ImageView.SelectedImage.Coords[coord.Z, coord.C, coord.T]];
463 bf.Crop(r);
464 Statistics[] sts = Statistics.FromBytes(bf);
465 Statistics st = sts[0];
466 Threshold th;
467 if (magicSel.Numeric)
468 {
469 th = new Threshold((int)magicSel.Threshold);
470 }
471 else
472 if (magicSel.Index == 2)
473 th = new Threshold((int)(st.Min + st.Mean));
474 else
475 if (magicSel.Index == 1)
476 th = new Threshold((int)st.Median);
477 else
478 th = new Threshold((int)st.Min);
479 th.ApplyInPlace((Bitmap)bf.Image);
480 Invert inv = new Invert();
481 Bitmap det;
482 if (bf.BitsPerPixel > 8)
483 det = AForge.Imaging.Image.Convert16bppTo8bpp((Bitmap)bf.Image);
484 else
485 det = (Bitmap)bf.Image;
486 BlobCounter blobCounter = new BlobCounter();
487 blobCounter.ProcessImage(det);
488 Blob[] blobs = blobCounter.GetObjectsInformation();
489 // create convex hull searching algorithm
490 GrahamConvexHull hullFinder = new GrahamConvexHull();
491 // lock image to draw on it
492 // process each blob
493 foreach (Blob blob in blobs)
494 {
495 if (blob.Rectangle.Width < magicSel.Max && blob.Rectangle.Height < magicSel.Max)
496 continue;
497 List<IntPoint> leftPoints = new List<IntPoint>();
498 List<IntPoint> rightPoints = new List<IntPoint>();
499 List<IntPoint> edgePoints = new List<IntPoint>();
500 List<IntPoint> hull = new List<IntPoint>();
501 // get blob's edge points
502 blobCounter.GetBlobsLeftAndRightEdges(blob,
503 out leftPoints, out rightPoints);
504 edgePoints.AddRange(leftPoints);
505 edgePoints.AddRange(rightPoints);
506 // blob's convex hull
507 hull = hullFinder.FindHull(edgePoints);
508 PointD[] pfs = new PointD[hull.Count];
509 for (int i = 0; i < hull.Count; i++)
510 {
511 pfs[i] = new PointD(r.X + hull[i].X, r.Y + hull[i].Y);
512 }
513 ROI an = ROI.CreateFreeform(coord, pfs);
514 ImageView.SelectedImage.Annotations.Add(an);
515 }
516 }
517 else
518 if (Tools.currentTool.type == Tools.Tool.Type.bucket && buts == MouseButtons.Left)
519 {
520 ZCT coord = App.viewer.GetCoordinate();
521 floodFiller.FillColor = DrawColor;
522 floodFiller.Tolerance = currentTool.tolerance;
523 floodFiller.Bitmap = ImageView.SelectedImage.Buffers[ImageView.SelectedImage.Coords[coord.C, coord.Z, coord.T]];
524 floodFiller.FloodFill(new AForge.Point((int)p.X, (int)p.Y));
526 }
527 else
528 if (Tools.currentTool.type == Tools.Tool.Type.dropper && buts == MouseButtons.Left)
529 {
530 DrawColor = ImageView.SelectedBuffer.GetPixel((int)p.X,(int)p.Y);
531 UpdateGUI();
532 }
534 }
535 public void ToolMove(PointD e, MouseButtons buts)
536 {
537 if (App.viewer == null)
538 return;
540 if (ImageView.SelectedImage == null)
541 return;
542 PointD p;
543 p = ImageView.SelectedImage.ToImageSpace(e);
544 if (currentTool.type == Tool.Type.line && ImageView.down)
545 {
546 anno.UpdatePoint(new PointD(e.X, e.Y), 1);
548 }
549 else
550 if (currentTool.type == Tool.Type.freeform && buts == MouseButtons.Left && ImageView.down)
551 {
552 if (anno.GetPointCount() == 0)
553 {
554 anno.type = ROI.Type.Freeform;
555 anno.AddPoint(new PointD(e.X, e.Y));
556 anno.coord = App.viewer.GetCoordinate();
557 anno.closed = true;
558 ImageView.SelectedImage.Annotations.Add(anno);
559 }
560 else
561 {
562 anno.AddPoint(new PointD(e.X, e.Y));
563 }
565 }else
566
567 if (currentTool.type == Tool.Type.rect && anno.type == ROI.Type.Rectangle)
568 {
569 if (anno.GetPointCount() == 4)
570 {
571 anno = ROI.CreateRectangle(App.viewer.GetCoordinate(),anno.X, anno.Y, e.X - anno.X, e.Y - anno.Y);
573 }
574 }
575 else
576 if (currentTool.type == Tool.Type.ellipse && anno.type == ROI.Type.Ellipse)
577 {
578 if (anno.GetPointCount() == 4)
579 {
580 anno = ROI.CreateEllipse(App.viewer.GetCoordinate(), anno.X, anno.Y, e.X - anno.X, e.Y - anno.Y);
582 }
583 }
584 else
585 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left && ImageView.down)
586 {
587 PointD d = new PointD(e.X - ImageView.mouseDown.X, e.Y - ImageView.mouseDown.Y);
590 foreach (ROI an in App.viewer.AnnotationsRGB)
591 {
592 if (an.GetSelectBound(App.viewer.GetScale(), App.viewer.GetScale()).IntersectsWith(r))
593 {
594 an.selectedPoints.Clear();
596 an.Selected = true;
597 RectangleD[] sels = an.GetSelectBoxes(selectBoxSize);
598 for (int i = 0; i < sels.Length; i++)
599 {
600 if (sels[i].IntersectsWith(r))
601 {
602 an.selectedPoints.Add(i);
603 }
604 }
605 }
606 else
607 an.Selected = false;
608 }
610 }
611 else
612 if (currentTool.type == Tool.Type.rectSel && ImageView.up)
613 {
614 Tools.GetTool(Tools.Tool.Type.rectSel).Rectangle = new RectangleD(0, 0, 0, 0);
615 }
616 else
617 if (Win32.GetKeyState(Keys.Delete))
618 {
619 foreach (ROI an in ImageView.selectedAnnotations)
620 {
621 if (an != null)
622 {
623 if (an.selectedPoints.Count == 0)
624 {
625 ImageView.SelectedImage.Annotations.Remove(an);
626 }
627 else
628 {
629 if (an.type == ROI.Type.Polygon ||
630 an.type == ROI.Type.Polyline ||
631 an.type == ROI.Type.Freeform)
632 {
633 an.closed = false;
634 an.RemovePoints(an.selectedPoints.ToArray());
635
636 }
637 }
638 }
639 }
641 }
642
643 if (Tools.currentTool.type == Tools.Tool.Type.magic && buts == MouseButtons.Left)
644 {
645 //First we draw the selection rectangle
646 PointD d = new PointD(e.X - ImageView.mouseDown.X, e.Y - ImageView.mouseDown.Y);
649 }
650
651 if (buts == MouseButtons.Left && currentTool.type == Tool.Type.eraser)
652 {
654 Pen pen = new Pen(Tools.EraseColor, (int)Tools.StrokeWidth,ImageView.SelectedBuffer.BitsPerPixel);
655 g.FillEllipse(new Rectangle((int)p.X, (int)p.Y, (int)width, (int)Tools.StrokeWidth), pen.color);
656 pen.Dispose();
658 }
659 if ((Tools.currentTool.type == Tools.Tool.Type.pan && (buts == MouseButtons.Middle || buts == MouseButtons.Left)))
660 {
661 if (ImageView.SelectedImage.isPyramidal)
662 {
663 if (ImageView.mouseDown.X - e.X != 0 || ImageView.mouseDown.Y - e.Y != 0)
664 {
665 App.viewer.PyramidalOriginTransformed = new PointD(App.viewer.PyramidalOriginTransformed.X + (ImageView.mouseDown.X - e.X), App.viewer.PyramidalOriginTransformed.Y + (ImageView.mouseDown.Y - e.Y));
666 }
667 }
668 else
669 {
670 // Screen-to-world conversion subtracts Origin. Moving the image
671 // toward the current pointer keeps the grabbed world point fixed.
672 App.viewer.Origin = new PointD(App.viewer.Origin.X + (e.X - ImageView.mouseDown.X), App.viewer.Origin.Y + (e.Y - ImageView.mouseDown.Y));
673 }
674 UpdateView();
675 }
676 }
677
683 private void movePanel_Click(object sender, EventArgs e)
684 {
685 currentTool = GetTool(Tool.Type.move);
687 movePanel.BackColor = System.Drawing.Color.LightGray;
688 Cursor.Current = Cursors.Arrow;
689 }
695 private void textPanel_Click(object sender, EventArgs e)
696 {
697 currentTool = GetTool(Tool.Type.text);
699 textPanel.BackColor = System.Drawing.Color.LightGray;
700 Cursor.Current = Cursors.Arrow;
701 }
711 private void textPanel_DoubleClick(object sender, EventArgs e)
712 {
713 currentTool = GetTool(Tool.Type.text);
715 textPanel.BackColor = System.Drawing.Color.LightGray;
716
717 if (fontDialog.ShowDialog() != DialogResult.OK)
718 return;
719 font = fontDialog.Font;
720 Cursor.Current = Cursors.Arrow;
721 }
727 private void pointPanel_Click(object sender, EventArgs e)
728 {
729 currentTool = GetTool(Tool.Type.point);
731 pointPanel.BackColor = System.Drawing.Color.LightGray;
732 Cursor.Current = Cursors.Arrow;
733 }
739 private void linePanel_Click(object sender, EventArgs e)
740 {
741 currentTool = GetTool(Tool.Type.line);
743 linePanel.BackColor = System.Drawing.Color.LightGray;
744 Cursor.Current = Cursors.Arrow;
745 }
752 private void rectPanel_Click(object sender, EventArgs e)
753 {
754 currentTool = GetTool(Tool.Type.rect);
756 rectPanel.BackColor = System.Drawing.Color.LightGray;
757 Cursor.Current = Cursors.Arrow;
758 }
765 private void ellipsePanel_Click(object sender, EventArgs e)
766 {
767 currentTool = GetTool(Tool.Type.ellipse);
769 ellipsePanel.BackColor = System.Drawing.Color.LightGray;
770 Cursor.Current = Cursors.Arrow;
771 }
778 private void polyPanel_Click(object sender, EventArgs e)
779 {
780 currentTool = GetTool(Tool.Type.polygon);
782 polyPanel.BackColor = System.Drawing.Color.LightGray;
783 Cursor.Current = Cursors.Arrow;
784 }
791 private void deletePanel_Click(object sender, EventArgs e)
792 {
793 currentTool = GetTool(Tool.Type.delete);
795 deletePanel.BackColor = System.Drawing.Color.LightGray;
796 Cursor.Current = Cursors.Arrow;
797 }
803 private void freeformPanel_Click(object sender, EventArgs e)
804 {
805 currentTool = GetTool(Tool.Type.freeform);
807 freeformPanel.BackColor = System.Drawing.Color.LightGray;
808 Cursor.Current = Cursors.Arrow;
809 }
816 private void rectSelPanel_Click(object sender, EventArgs e)
817 {
818 currentTool = GetTool(Tool.Type.rectSel);
820 rectSelPanel.BackColor = System.Drawing.Color.LightGray;
821 Cursor.Current = Cursors.Arrow;
822 }
829 private void panPanel_Click(object sender, EventArgs e)
830 {
831 currentTool = GetTool(Tool.Type.pan);
833 panPanel.BackColor = System.Drawing.Color.LightGray;
834 Cursor.Current = Cursors.Hand;
835 }
842 private void magicPanel_Click(object sender, EventArgs e)
843 {
844 currentTool = GetTool(Tool.Type.magic);
846 magicPanel.BackColor = System.Drawing.Color.LightGray;
847 Cursor.Current = Cursors.Arrow;
848 }
855 private void bucketPanel_Click(object sender, EventArgs e)
856 {
857 currentTool = GetTool(Tool.Type.bucket);
859 bucketPanel.BackColor = System.Drawing.Color.LightGray;
860 Cursor.Current = Cursors.Arrow;
861 }
868 private void pencilPanel_Click(object sender, EventArgs e)
869 {
870 currentTool = GetTool(Tool.Type.pencil);
872 pencilPanel.BackColor = System.Drawing.Color.LightGray;
873 Cursor.Current = Cursors.Arrow;
874 }
875 MagicSelect magicSel = new MagicSelect(2);
882 private void magicPanel_MouseDoubleClick(object sender, MouseEventArgs e)
883 {
884 if (magicSel.ShowDialog() != DialogResult.OK)
885 return;
886 }
892 private void Tools_FormClosing(object sender, FormClosingEventArgs e)
893 {
894 e.Cancel = true;
895 this.Hide();
896 }
897
905 private void pencilPanel_MouseDoubleClick(object sender, MouseEventArgs e)
906 {
907 currentTool = GetTool(Tool.Type.pencil);
909 pencilPanel.BackColor = System.Drawing.Color.LightGray;
910 Cursor.Current = Cursors.Arrow;
911 PenTool pt = new PenTool(new Pen(DrawColor, (int)Tools.StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel));
912 if (pt.ShowDialog() != DialogResult.OK)
913 return;
914 Tools.StrokeWidth = pt.Pen.width;
915 DrawColor = pt.Pen.color;
916 }
917
927 private void bucketPanel_MouseDoubleClick(object sender, MouseEventArgs e)
928 {
929 currentTool = GetTool(Tool.Type.bucket);
931 bucketPanel.BackColor = System.Drawing.Color.LightGray;
932 Cursor.Current = Cursors.Arrow;
933 FloodTool pt = new FloodTool(new Pen(DrawColor, (int)Tools.StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel),currentTool.tolerance, ImageView.SelectedBuffer.BitsPerPixel);
934 if (pt.ShowDialog() != DialogResult.OK)
935 return;
936 Tools.StrokeWidth = pt.Pen.width;
937 DrawColor = pt.Pen.color;
938 currentTool.tolerance = pt.Tolerance;
939 }
940
947 private void dropperPanel_MouseClick(object sender, MouseEventArgs e)
948 {
949 currentTool = GetTool(Tool.Type.dropper);
951 dropperPanel.BackColor = System.Drawing.Color.LightGray;
952 Cursor.Current = Cursors.Arrow;
953 }
954
962 private void color1Box_MouseClick(object sender, MouseEventArgs e)
963 {
964 ColorTool t = new ColorTool(DrawColor, ImageView.SelectedBuffer.BitsPerPixel);
965 if (t.ShowDialog() != DialogResult.OK)
966 return;
967 DrawColor = t.Color;
968 UpdateGUI();
969 }
970
978 private void color2Box_MouseClick(object sender, MouseEventArgs e)
979 {
980 ColorTool t = new ColorTool(EraseColor, ImageView.SelectedBuffer.BitsPerPixel);
981 if (t.ShowDialog() != DialogResult.OK)
982 return;
983 EraseColor = t.Color;
984 UpdateGUI();
985 }
986
992 private void widthBox_ValueChanged(object sender, EventArgs e)
993 {
994 width = (int)widthBox.Value;
995 }
996
1003 private void eraserPanel_MouseClick(object sender, MouseEventArgs e)
1004 {
1005 currentTool = GetTool(Tool.Type.eraser);
1007 eraserPanel.BackColor = System.Drawing.Color.LightGray;
1008 Cursor.Current = Cursors.Arrow;
1009 }
1010
1015 private void switchBox_MouseClick(object sender, MouseEventArgs e)
1016 {
1017 ColorS s = DrawColor;
1018 DrawColor = eraseColor;
1019 EraseColor = s;
1020 UpdateGUI();
1021 }
1022
1027 private void Tools_Activated(object sender, EventArgs e)
1028 {
1029 UpdateGUI();
1030 }
1031 }
1032}
System.Drawing.Pen Pen
AForge.RectangleD RectangleD
Definition ImageView.cs:17
System.Windows.Forms.Keys Keys
Definition ImageView.cs:16
The base class that the flood fill algorithms inherit from. Implements the basic flood filler functio...
static ImageView viewer
Definition App.cs:16
static Tools tools
Definition App.cs:14
void FillEllipse(float xx, float yy, int w, int h, ColorS c)
Definition Graphics.cs:174
static Graphics FromImage(Bitmap b)
Definition Graphics.cs:31
ImageView control for image stacks, pyramidal and whole-slide-images.
static PointD mouseDown
Definition ImageView.cs:335
static bool up
Definition ImageView.cs:338
static BioImage SelectedImage
Definition ImageView.cs:306
static Bitmap SelectedBuffer
Definition ImageView.cs:328
static List< ROI > selectedAnnotations
Definition ImageView.cs:303
static bool down
Definition ImageView.cs:336
PointD PyramidalOriginTransformed
PointD Origin
A property of the class PointD. *‍/.
Definition ImageView.cs:743
List< ROI > AnnotationsRGB
async void UpdateImages(bool updatePyramidal=true)
static PointD mouseUp
Definition ImageView.cs:337
Implements the QueueLinear flood fill algorithm using array-based pixel manipulation.
static State GetDown(PointD pf, MouseButtons mb)
Definition Scripting.cs:213
static State GetMove(PointD pf, MouseButtons mb)
Definition Scripting.cs:228
static State GetUp(PointD pf, MouseButtons mb)
Definition Scripting.cs:198
static void UpdateState(State s)
Definition Scripting.cs:288
static void Init()
Definition Tools.cs:68
Tool(Type t, ColorS col)
Definition Tools.cs:102
ToolType toolType
Definition Tools.cs:79
string script
Definition Tools.cs:90
RectangleF RectangleF
Definition Tools.cs:87
List< System.Drawing.Point > Points
Definition Tools.cs:78
RectangleD Rectangle
Definition Tools.cs:82
ColorS tolerance
Definition Tools.cs:92
override string ToString()
Definition Tools.cs:119
Tool(Type t)
Definition Tools.cs:97
Tool(Type t, string sc)
Definition Tools.cs:113
Tool(Type t, RectangleD r)
Definition Tools.cs:107
void UpdateOverlay()
Definition Tools.cs:184
static bool gEnabled
Definition Tools.cs:24
static ColorS EraseColor
Definition Tools.cs:137
static int StrokeWidth
Definition Tools.cs:149
void ToolDown(PointD e, MouseButtons buts)
Definition Tools.cs:241
static float selectBoxSize
Definition Tools.cs:213
void ToolUp(PointD e, MouseButtons buts)
Definition Tools.cs:382
void UpdateSelected()
Definition Tools.cs:194
static Tool GetTool(Tool.Type typ)
Definition Tools.cs:180
static bool rEnabled
Definition Tools.cs:23
void UpdateView()
Definition Tools.cs:188
static bool applyToStack
Definition Tools.cs:21
static Tool GetTool(string name)
Definition Tools.cs:176
Font font
Definition Tools.cs:162
static bool bEnabled
Definition Tools.cs:25
static ColorTool colorTool
Definition Tools.cs:22
static Tool currentTool
Definition Tools.cs:124
static Rectangle selectionRectangle
Definition Tools.cs:30
static ColorS DrawColor
Definition Tools.cs:126
void ToolMove(PointD e, MouseButtons buts)
Definition Tools.cs:535
static Hashtable tools
Definition Tools.cs:31
static RectangleD selectionRect
Definition Tools.cs:161
static bool GetKeyState(System.Windows.Forms.Keys vKey)
Definition Win32.cs:20
ColorS color
Definition Graphics.cs:6
void Dispose()
Definition Graphics.cs:21