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;
19using Bitmap = AForge.Bitmap;
25 public partial class Tools : Form
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;
37 public static Hashtable
tools =
new Hashtable();
81 tools.Add(tool.ToString(),
new Tool(tool,
new ColorS(0, 0, 0)));
95 get {
return new AForge.RectangleF((
float)rect.X, (
float)rect.Y, (
float)rect.W, (
float)rect.H); }
128 return type.ToString();
173 InitializeComponent();
175 ColorS col =
new ColorS(ushort.MaxValue);
178 ROI.selectBoxSize = 1;
203 foreach (Control item
in this.Controls)
205 if (item.Tag !=
null)
206 if (item.Tag.ToString() ==
"tool")
207 item.BackColor = System.Drawing.Color.White;
211 private void UpdateGUI()
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));
218 widthBox.Value = width;
221 ROI anno =
new ROI();
224 private void RefreshRoiManager()
265 PointD roiPoint = GetAnnotationPoint(e);
268 if (anno.type != ROI.Type.Line)
271 anno.type = ROI.Type.Line;
272 anno.AddPoint(roiPoint);
273 anno.AddPoint(roiPoint);
282 if (anno.type != ROI.Type.Polygon)
285 anno.type = ROI.Type.Polygon;
287 anno.AddPoint(roiPoint);
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))
302 anno.UpdateBoundingBox();
308 anno.AddPoint(roiPoint);
316 if (anno.type != ROI.Type.Freeform)
319 anno.type = ROI.Type.Freeform;
321 anno.AddPoint(roiPoint);
328 anno.AddPoint(roiPoint);
336 anno.type = ROI.Type.Rectangle;
337 rectStart = roiPoint;
338 anno.BoundingBox =
new RectangleD(roiPoint.X, roiPoint.Y, 0, 0);
342 currentTool.Rectangle = anno.BoundingBox;
348 anno.type = ROI.Type.Ellipse;
349 rectStart = roiPoint;
350 anno.BoundingBox =
new RectangleD(roiPoint.X, roiPoint.Y, 0, 0);
354 currentTool.Rectangle = anno.BoundingBox;
362 if (an.BoundingBox.IntersectsWith(
new RectangleD(roiPoint.X, roiPoint.Y, 1, 1)))
364 if (an.selectedPoints.Count == 0)
371 if (an.selectedPoints.Count == 1 && !(an.type == ROI.Type.Polygon || an.type == ROI.Type.Polyline || an.type == ROI.Type.Freeform))
379 if (an.type == ROI.Type.Polygon ||
380 an.type == ROI.Type.Polyline ||
381 an.type == ROI.Type.Freeform)
384 an.RemovePoints(an.selectedPoints.ToArray());
396 an.type = ROI.Type.Label;
397 an.AddPoint(roiPoint);
400 if (ti.ShowDialog() != DialogResult.OK)
402 Font labelFont = ti.font ?? SystemFonts.DefaultFont;
403 string labelText = ti.TextValue ??
string.Empty;
404 System.Drawing.Size labelSize = TextRenderer.MeasureText(labelText, labelFont);
406 an.family = labelFont.FontFamily.Name;
407 an.fontSize = labelFont.Size;
410 an.BoundingBox =
new RectangleD(roiPoint.X, roiPoint.Y, labelBox.Width, labelBox.Height);
415 if (buts == MouseButtons.Middle)
419 panPanel.BackColor = System.Drawing.Color.LightGray;
437 PointD roiPoint = GetAnnotationPoint(e);
444 an.AddPoint(roiPoint);
445 an.type = ROI.Type.Point;
452 if (anno.GetPointCount() > 0)
454 anno.UpdatePoint(roiPoint, 1);
455 anno.UpdateBoundingBox();
463 currentTool.Rectangle =
new RectangleD(0, 0, 0, 0);
470 currentTool.Rectangle =
new RectangleD(0, 0, 0, 0);
478 anno.UpdateBoundingBox();
491 if (an.GetSelectBound(hitSize, hitSize).ToRectangleF().IntersectsWith(r.ToRectangleF()))
494 an.selectedPoints.Clear();
498 for (
int i = 0; i < sels.Length; i++)
500 if (sels[i].IntersectsWith(r))
502 an.selectedPoints.Add(i);
522 bf.Crop(rr.ToRectangleInt());
523 Statistics[] sts = Statistics.FromBytes(bf);
524 Statistics st = sts[0];
531 if (magicSel.
Index == 2)
532 th = (int)(st.Min + st.Mean);
534 if (magicSel.
Index == 1)
539 if (bf.BitsPerPixel > 8)
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);
558 foreach (Blob blob
in blobs)
560 AForge.RectangleD rd =
new RectangleD(blob.Rectangle.X * px, blob.Rectangle.Y * py, blob.Rectangle.Width * px, blob.Rectangle.Height * py);
562 ROI an = ROI.CreateRectangle(coord, loc.X, loc.Y, rd.W, rd.H);
573 floodFiller.
FloodFill(
new AForge.Point((
int)p.X, (
int)p.Y));
592 PointD roiPoint = GetAnnotationPoint(e);
599 App.viewer.PyramidalOrigin =
new PointD(
617 anno.UpdatePoint(roiPoint, 1);
623 if (anno.type != ROI.Type.Freeform)
626 anno.type = ROI.Type.Freeform;
628 anno.AddPoint(roiPoint);
635 anno.AddPoint(roiPoint);
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);
650 anno.BoundingBox = rect;
652 currentTool.Rectangle = 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);
664 anno.BoundingBox = rect;
666 currentTool.Rectangle = rect;
673 PointD d =
new PointD(roiPoint.X - roiDown.X, roiPoint.Y - roiDown.Y);
689 if (an.selectedPoints.Count == 0)
695 if (an.type == ROI.Type.Polygon ||
696 an.type == ROI.Type.Polyline ||
697 an.type == ROI.Type.Freeform)
700 an.RemovePoints(an.selectedPoints.ToArray());
732 private void movePanel_Click(
object sender, EventArgs e)
736 movePanel.BackColor = System.Drawing.Color.LightGray;
743 private void textPanel_Click(
object sender, EventArgs e)
747 textPanel.BackColor = System.Drawing.Color.LightGray;
758 private void textPanel_DoubleClick(
object sender, EventArgs e)
762 textPanel.BackColor = System.Drawing.Color.LightGray;
764 if (fontDialog.ShowDialog() != DialogResult.OK)
766 font = fontDialog.Font;
773 private void pointPanel_Click(
object sender, EventArgs e)
777 pointPanel.BackColor = System.Drawing.Color.LightGray;
784 private void linePanel_Click(
object sender, EventArgs e)
788 linePanel.BackColor = System.Drawing.Color.LightGray;
796 private void rectPanel_Click(
object sender, EventArgs e)
800 rectPanel.BackColor = System.Drawing.Color.LightGray;
808 private void ellipsePanel_Click(
object sender, EventArgs e)
812 ellipsePanel.BackColor = System.Drawing.Color.LightGray;
820 private void polyPanel_Click(
object sender, EventArgs e)
824 polyPanel.BackColor = System.Drawing.Color.LightGray;
832 private void deletePanel_Click(
object sender, EventArgs e)
836 deletePanel.BackColor = System.Drawing.Color.LightGray;
843 private void freeformPanel_Click(
object sender, EventArgs e)
847 freeformPanel.BackColor = System.Drawing.Color.LightGray;
855 private void rectSelPanel_Click(
object sender, EventArgs e)
859 rectSelPanel.BackColor = System.Drawing.Color.LightGray;
867 private void panPanel_Click(
object sender, EventArgs e)
871 panPanel.BackColor = System.Drawing.Color.LightGray;
879 private void magicPanel_Click(
object sender, EventArgs e)
883 magicPanel.BackColor = System.Drawing.Color.LightGray;
891 private void bucketPanel_Click(
object sender, EventArgs e)
895 bucketPanel.BackColor = System.Drawing.Color.LightGray;
903 private void pencilPanel_Click(
object sender, EventArgs e)
907 pencilPanel.BackColor = System.Drawing.Color.LightGray;
916 private void magicPanel_MouseDoubleClick(
object sender, MouseEventArgs e)
918 if (magicSel.ShowDialog() != DialogResult.OK)
926 private void Tools_FormClosing(
object sender, FormClosingEventArgs e)
939 private void pencilPanel_MouseDoubleClick(
object sender, MouseEventArgs e)
943 pencilPanel.BackColor = System.Drawing.Color.LightGray;
945 if (pt.ShowDialog() != DialogResult.OK)
960 private void bucketPanel_MouseDoubleClick(
object sender, MouseEventArgs e)
964 bucketPanel.BackColor = System.Drawing.Color.LightGray;
966 if (pt.ShowDialog() != DialogResult.OK)
979 private void dropperPanel_MouseClick(
object sender, MouseEventArgs e)
983 dropperPanel.BackColor = System.Drawing.Color.LightGray;
993 private void color1Box_MouseClick(
object sender, MouseEventArgs e)
996 if (t.ShowDialog() != DialogResult.OK)
1009 private void color2Box_MouseClick(
object sender, MouseEventArgs e)
1012 if (t.ShowDialog() != DialogResult.OK)
1023 private void widthBox_ValueChanged(
object sender, EventArgs e)
1025 width = (int)widthBox.Value;
1034 private void eraserPanel_MouseClick(
object sender, MouseEventArgs e)
1038 eraserPanel.BackColor = System.Drawing.Color.LightGray;
1045 private void switchBox_MouseClick(
object sender, MouseEventArgs e)
1057 private void Tools_Activated(
object sender, EventArgs e)
AForge.RectangleD RectangleD
AForge.RectangleF RectangleF
AForge.Rectangle Rectangle
System.Windows.Forms.Keys Keys
The base class that the flood fill algorithms inherit from. Implements the basic flood filler functio...
static ROIManager manager
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.
List< ROI > AnnotationsRGB
PointD Origin
A property of the class PointD. */.
PointD PyramidalOrigin
Setting the value of the pyramidalOrigin variable. */.
void UpdateView(bool refreshImages=true)
static List< ROI > selectedAnnotations
static BioImage SelectedImage
static Bitmap SelectedBuffer
double GetSelectionBoxHitSize()
async void UpdateImages(bool updatePyramidal=true)
Implements the QueueLinear flood fill algorithm using array-based pixel manipulation.
void UpdateAnnotationList()
static State GetDown(PointD pf, MouseButtons mb)
static State GetUp(PointD pf, MouseButtons mb)
static void UpdateState(State s)
static bool GetKeyState(System.Windows.Forms.Keys vKey)