2using System.Collections;
3using System.Collections.Generic;
4using System.ComponentModel;
9using System.Threading.Tasks;
10using System.Windows.Forms;
12using AForge.Imaging.Filters;
14using AForge.Math.Geometry;
19 public partial class Tools : Form
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;
31 public static Hashtable
tools =
new Hashtable();
74 tools.Add(tool.ToString(),
new Tool(tool,
new ColorS(0, 0, 0)));
78 public List<System.Drawing.Point>
Points;
88 get {
return new RectangleF((
float)rect.X, (
float)rect.Y, (
float)rect.W, (
float)rect.H); }
121 return type.ToString();
166 InitializeComponent();
168 ColorS col =
new ColorS(ushort.MaxValue);
196 foreach (Control item
in this.Controls)
199 if(item.Tag.ToString() ==
"tool")
200 item.BackColor = System.Drawing.Color.White;
204 private void UpdateGUI()
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);
211 widthBox.Value = width;
214 ROI anno =
new ROI();
250 if (anno.GetPointCount() == 0)
253 anno.type = ROI.Type.Line;
254 anno.AddPoint(
new PointD(e.X, e.Y));
255 anno.AddPoint(
new PointD(e.X, e.Y));
263 if (anno.GetPointCount() == 0)
266 anno.type = ROI.Type.Polygon;
267 anno.AddPoint(
new PointD(e.X, e.Y));
275 if (d.IntersectsWith(anno.Point))
282 anno.AddPoint(
new PointD(e.X, e.Y));
289 if (anno.GetPointCount() == 0)
292 anno.type = ROI.Type.Freeform;
293 anno.AddPoint(
new PointD(e.X, e.Y));
300 anno.AddPoint(
new PointD(e.X, e.Y));
321 if (an.BoundingBox.IntersectsWith(e.X,e.Y))
323 if (an.selectedPoints.Count == 0)
329 if (an.selectedPoints.Count == 1 && !(an.type == ROI.Type.Polygon || an.type == ROI.Type.Polyline || an.type == ROI.Type.Freeform))
336 if (an.type == ROI.Type.Polygon ||
337 an.type == ROI.Type.Polyline ||
338 an.type == ROI.Type.Freeform)
341 an.RemovePoints(an.selectedPoints.ToArray());
353 an.type = ROI.Type.Label;
354 an.AddPoint(
new PointD(e.X, e.Y));
357 if (ti.ShowDialog() != DialogResult.OK)
359 an.family = ti.
font.FontFamily.ToString();
360 an.fontSize = ti.
font.Size;
370 panPanel.BackColor = System.Drawing.Color.LightGray;
371 Cursor.Current = Cursors.Hand;
382 public void ToolUp(PointD e, MouseButtons buts)
392 an.AddPoint(
new PointD(e.X, e.Y));
393 an.type = ROI.Type.Point;
400 if (anno.GetPointCount() > 0)
402 anno.UpdatePoint(
new PointD(e.X, e.Y), 1);
409 if (anno.GetPointCount() == 4)
417 if (anno.GetPointCount() == 4)
436 an.selectedPoints.Clear();
440 for (
int i = 0; i < sels.Length; i++)
442 if (sels[i].IntersectsWith(r))
444 an.selectedPoints.Add(i);
460 if (r.Width <= 2 || r.Height <= 2)
464 Statistics[] sts = Statistics.FromBytes(bf);
465 Statistics st = sts[0];
469 th =
new Threshold((
int)magicSel.
Threshold);
472 if (magicSel.
Index == 2)
473 th =
new Threshold((
int)(st.Min + st.Mean));
475 if (magicSel.
Index == 1)
476 th =
new Threshold((
int)st.Median);
478 th =
new Threshold((
int)st.Min);
479 th.ApplyInPlace((Bitmap)bf.Image);
480 Invert inv =
new Invert();
482 if (bf.BitsPerPixel > 8)
483 det = AForge.Imaging.Image.Convert16bppTo8bpp((Bitmap)bf.Image);
485 det = (Bitmap)bf.Image;
486 BlobCounter blobCounter =
new BlobCounter();
487 blobCounter.ProcessImage(det);
488 Blob[] blobs = blobCounter.GetObjectsInformation();
490 GrahamConvexHull hullFinder =
new GrahamConvexHull();
493 foreach (Blob blob
in blobs)
495 if (blob.Rectangle.Width < magicSel.
Max && blob.Rectangle.Height < magicSel.
Max)
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>();
502 blobCounter.GetBlobsLeftAndRightEdges(blob,
503 out leftPoints, out rightPoints);
504 edgePoints.AddRange(leftPoints);
505 edgePoints.AddRange(rightPoints);
507 hull = hullFinder.FindHull(edgePoints);
508 PointD[] pfs =
new PointD[hull.Count];
509 for (
int i = 0; i < hull.Count; i++)
511 pfs[i] =
new PointD(r.X + hull[i].X, r.Y + hull[i].Y);
513 ROI an = ROI.CreateFreeform(coord, pfs);
524 floodFiller.
FloodFill(
new AForge.Point((
int)p.X, (
int)p.Y));
546 anno.UpdatePoint(
new PointD(e.X, e.Y), 1);
552 if (anno.GetPointCount() == 0)
554 anno.type = ROI.Type.Freeform;
555 anno.AddPoint(
new PointD(e.X, e.Y));
562 anno.AddPoint(
new PointD(e.X, e.Y));
569 if (anno.GetPointCount() == 4)
578 if (anno.GetPointCount() == 4)
594 an.selectedPoints.Clear();
598 for (
int i = 0; i < sels.Length; i++)
600 if (sels[i].IntersectsWith(r))
602 an.selectedPoints.Add(i);
623 if (an.selectedPoints.Count == 0)
629 if (an.type == ROI.Type.Polygon ||
630 an.type == ROI.Type.Polyline ||
631 an.type == ROI.Type.Freeform)
634 an.RemovePoints(an.selectedPoints.ToArray());
683 private void movePanel_Click(
object sender, EventArgs e)
687 movePanel.BackColor = System.Drawing.Color.LightGray;
688 Cursor.Current = Cursors.Arrow;
695 private void textPanel_Click(
object sender, EventArgs e)
699 textPanel.BackColor = System.Drawing.Color.LightGray;
700 Cursor.Current = Cursors.Arrow;
711 private void textPanel_DoubleClick(
object sender, EventArgs e)
715 textPanel.BackColor = System.Drawing.Color.LightGray;
717 if (fontDialog.ShowDialog() != DialogResult.OK)
719 font = fontDialog.Font;
720 Cursor.Current = Cursors.Arrow;
727 private void pointPanel_Click(
object sender, EventArgs e)
731 pointPanel.BackColor = System.Drawing.Color.LightGray;
732 Cursor.Current = Cursors.Arrow;
739 private void linePanel_Click(
object sender, EventArgs e)
743 linePanel.BackColor = System.Drawing.Color.LightGray;
744 Cursor.Current = Cursors.Arrow;
752 private void rectPanel_Click(
object sender, EventArgs e)
756 rectPanel.BackColor = System.Drawing.Color.LightGray;
757 Cursor.Current = Cursors.Arrow;
765 private void ellipsePanel_Click(
object sender, EventArgs e)
769 ellipsePanel.BackColor = System.Drawing.Color.LightGray;
770 Cursor.Current = Cursors.Arrow;
778 private void polyPanel_Click(
object sender, EventArgs e)
782 polyPanel.BackColor = System.Drawing.Color.LightGray;
783 Cursor.Current = Cursors.Arrow;
791 private void deletePanel_Click(
object sender, EventArgs e)
795 deletePanel.BackColor = System.Drawing.Color.LightGray;
796 Cursor.Current = Cursors.Arrow;
803 private void freeformPanel_Click(
object sender, EventArgs e)
807 freeformPanel.BackColor = System.Drawing.Color.LightGray;
808 Cursor.Current = Cursors.Arrow;
816 private void rectSelPanel_Click(
object sender, EventArgs e)
820 rectSelPanel.BackColor = System.Drawing.Color.LightGray;
821 Cursor.Current = Cursors.Arrow;
829 private void panPanel_Click(
object sender, EventArgs e)
833 panPanel.BackColor = System.Drawing.Color.LightGray;
834 Cursor.Current = Cursors.Hand;
842 private void magicPanel_Click(
object sender, EventArgs e)
846 magicPanel.BackColor = System.Drawing.Color.LightGray;
847 Cursor.Current = Cursors.Arrow;
855 private void bucketPanel_Click(
object sender, EventArgs e)
859 bucketPanel.BackColor = System.Drawing.Color.LightGray;
860 Cursor.Current = Cursors.Arrow;
868 private void pencilPanel_Click(
object sender, EventArgs e)
872 pencilPanel.BackColor = System.Drawing.Color.LightGray;
873 Cursor.Current = Cursors.Arrow;
875 MagicSelect magicSel =
new MagicSelect(2);
882 private void magicPanel_MouseDoubleClick(
object sender, MouseEventArgs e)
884 if (magicSel.ShowDialog() != DialogResult.OK)
892 private void Tools_FormClosing(
object sender, FormClosingEventArgs e)
905 private void pencilPanel_MouseDoubleClick(
object sender, MouseEventArgs e)
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)
914 Tools.StrokeWidth = pt.Pen.width;
927 private void bucketPanel_MouseDoubleClick(
object sender, MouseEventArgs e)
931 bucketPanel.BackColor = System.Drawing.Color.LightGray;
932 Cursor.Current = Cursors.Arrow;
934 if (pt.ShowDialog() != DialogResult.OK)
936 Tools.StrokeWidth = pt.Pen.width;
938 currentTool.tolerance = pt.Tolerance;
947 private void dropperPanel_MouseClick(
object sender, MouseEventArgs e)
951 dropperPanel.BackColor = System.Drawing.Color.LightGray;
952 Cursor.Current = Cursors.Arrow;
962 private void color1Box_MouseClick(
object sender, MouseEventArgs e)
964 ColorTool t =
new ColorTool(
DrawColor, ImageView.SelectedBuffer.BitsPerPixel);
965 if (t.ShowDialog() != DialogResult.OK)
978 private void color2Box_MouseClick(
object sender, MouseEventArgs e)
980 ColorTool t =
new ColorTool(
EraseColor, ImageView.SelectedBuffer.BitsPerPixel);
981 if (t.ShowDialog() != DialogResult.OK)
992 private void widthBox_ValueChanged(
object sender, EventArgs e)
994 width = (int)widthBox.Value;
1003 private void eraserPanel_MouseClick(
object sender, MouseEventArgs e)
1007 eraserPanel.BackColor = System.Drawing.Color.LightGray;
1008 Cursor.Current = Cursors.Arrow;
1015 private void switchBox_MouseClick(
object sender, MouseEventArgs e)
1027 private void Tools_Activated(
object sender, EventArgs e)
AForge.RectangleD RectangleD
System.Windows.Forms.Keys Keys
The base class that the flood fill algorithms inherit from. Implements the basic flood filler functio...
void FillEllipse(float xx, float yy, int w, int h, ColorS c)
static Graphics FromImage(Bitmap b)
ImageView control for image stacks, pyramidal and whole-slide-images.
static BioImage SelectedImage
static Bitmap SelectedBuffer
static List< ROI > selectedAnnotations
PointD PyramidalOriginTransformed
PointD Origin
A property of the class PointD. */.
List< ROI > AnnotationsRGB
async void UpdateImages(bool updatePyramidal=true)
Implements the QueueLinear flood fill algorithm using array-based pixel manipulation.
static State GetDown(PointD pf, MouseButtons mb)
static State GetMove(PointD pf, MouseButtons mb)
static State GetUp(PointD pf, MouseButtons mb)
static void UpdateState(State s)
static bool GetKeyState(System.Windows.Forms.Keys vKey)