BioGTK  6.5.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
Loading...
Searching...
No Matches
BioGTK.Tools Class Reference

Implementations for all tool types defined in Tools.cs. More...

Inheritance diagram for BioGTK.Tools:

Classes

class  Tool
 

Public Member Functions

void ToolDown (PointD e, ButtonPressEventArgs buts)
 
void ToolUp (PointD e, ButtonReleaseEventArgs buts)
 
void ToolMove (PointD e, MotionNotifyEventArgs buts)
 
void ToolDown_Move (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Move (PointD e, MotionNotifyEventArgs buts)
 
void ToolUp_Move (PointD e, ButtonReleaseEventArgs buts)
 
void ToolDown_Point (PointD e, ButtonPressEventArgs buts)
 
void ToolDown_Line (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Line (PointD e, MotionNotifyEventArgs buts)
 
void ToolUp_Line (PointD e, ButtonReleaseEventArgs buts)
 
void ToolDown_Rectangle (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Rectangle (PointD e, MotionNotifyEventArgs buts)
 
void ToolUp_Rectangle (PointD e, ButtonReleaseEventArgs buts)
 
void ToolDown_Ellipse (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Ellipse (PointD e, MotionNotifyEventArgs buts)
 
void ToolUp_Ellipse (PointD e, ButtonReleaseEventArgs buts)
 
void ToolDown_Polygon (PointD e, ButtonPressEventArgs buts)
 
void ToolDown_Freeform (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Freeform (PointD e, MotionNotifyEventArgs buts)
 
void ToolUp_Freeform (PointD e, ButtonReleaseEventArgs buts)
 
void ToolDown_Text (PointD e, ButtonPressEventArgs buts)
 
void ToolDown_Delete (PointD e, ButtonPressEventArgs buts)
 
void ToolDown_Brush (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Brush (PointD e, MotionNotifyEventArgs buts)
 
void ToolDown_Eraser (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Eraser (PointD e, MotionNotifyEventArgs buts)
 
void ToolUp_Bucket (PointD e, ButtonReleaseEventArgs buts)
 
void ToolUp_Dropper (PointD e, ButtonReleaseEventArgs buts)
 
void ToolDown_Pan (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Pan (PointD e, MotionNotifyEventArgs buts)
 
void ToolUp_Pan (PointD e, ButtonReleaseEventArgs buts)
 
void ToolDown_Magic (PointD e, ButtonPressEventArgs buts)
 
void ToolMove_Magic (PointD e, MotionNotifyEventArgs buts)
 
void ToolUp_Magic (PointD e, ButtonReleaseEventArgs buts)
 

Static Public Member Functions

static Tools Create ()
 
static Tool GetTool (string name)
 
static Tool GetTool (Tool.Type t)
 
static int CalculateThreshold (int index, Statistics stat)
 Helper method to calculate threshold for magic select.
 

Static Public Attributes

static bool applyToStack = false
 
static ColorTool colorTool
 
static bool rEnabled = true
 
static bool gEnabled = true
 
static bool bEnabled = true
 
static ColorS drawColor = new ColorS(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue)
 
static ColorS eraseColor = new ColorS(0, 0, 0)
 
static ColorS tolerance = new ColorS(0, 0, 0)
 
static Rectangle selectionRectangle
 
static Dictionary< string, Tooltools = new Dictionary<string, Tool>()
 
static bool colorOne = true
 
static double PanSpeed = 0.75
 
static Tool currentTool
 
static RectangleD selectionRect
 
static TextInput ti = null
 

Protected Member Functions

 Tools (Builder builder, IntPtr handle)
 
void SetupHandlers ()
 Sets up the handlers.
 

Properties

static ROI selectedROI [get, set]
 
static List< ROI > selectedROIs [get, set]
 
static ColorS DrawColor [get, set]
 
static ColorS EraseColor [get, set]
 
static int StrokeWidth [get, set]
 
bool IsPanning [get, set]
 

Detailed Description

Implementations for all tool types defined in Tools.cs.

Definition at line 22 of file Tools.cs.

Constructor & Destructor Documentation

◆ Tools()

BioGTK.Tools.Tools ( Builder builder,
IntPtr handle )
protected

Definition at line 42 of file Tools.cs.

42 : base(handle)
43 {
44 selectColor = AForge.Color.FromArgb(0, 0, 150, 255);
45 AForge.Color white = AForge.Color.FromArgb(255, 255, 255, 255);
46 _builder = builder;
47 builder.Autoconnect(this);
49 Tool.Init();
50 ColorS col = new ColorS(ushort.MaxValue);
51 //We initialize the tools
52 currentTool = GetTool(Tool.Type.move.ToString());
53 floodFiller = new QueueLinearFloodFiller(floodFiller);
54 magicSelect = MagicSelect.Create(0);
55 App.ApplyStyles(this);
56 }
static MagicSelect Create(int index)
static Tool GetTool(string name)
Definition Tools.cs:1738
void SetupHandlers()
Sets up the handlers.
Definition Tools.cs:124

Member Function Documentation

◆ CalculateThreshold()

static int BioGTK.Tools.CalculateThreshold ( int index,
Statistics stat )
static

Helper method to calculate threshold for magic select.

Definition at line 1753 of file Tools.cs.

1754 {
1755 return index switch
1756 {
1757 2 => (int)(stat.Min + stat.Mean),
1758 1 => (int)stat.Median,
1759 _ => (int)stat.Min
1760 };
1761 }

◆ Create()

static Tools BioGTK.Tools.Create ( )
static

It creates a new instance of the Tools class, which is a class that inherits from the Gtk.Window class

Returns
A new instance of the Tools class.

Definition at line 36 of file Tools.cs.

37 {
38 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/Tools.glade", FileMode.Open));
39 return new Tools(builder, builder.GetObject("tools").Handle);
40 }

◆ GetTool() [1/2]

static Tool BioGTK.Tools.GetTool ( string name)
static

If the tools dictionary contains the name of the tool, return the tool, otherwise return the move tool

Parameters
nameThe name of the tool to get.
Returns
The tool that is being returned is the tool that is being used.

Definition at line 1738 of file Tools.cs.

1739 {
1740 if (tools.ContainsKey(name))
1741 return (Tool)tools[name];
1742 else return tools[Tool.Type.move.ToString()];
1743 }

◆ GetTool() [2/2]

static Tool BioGTK.Tools.GetTool ( Tool.Type t)
static

Definition at line 1744 of file Tools.cs.

1745 {
1746 if (tools.ContainsKey(t.ToString()))
1747 return (Tool)tools[t.ToString()];
1748 else return tools.FirstOrDefault().Value;
1749 }

◆ SetupHandlers()

void BioGTK.Tools.SetupHandlers ( )
protected

Sets up the handlers.

It sets up the handlers for the buttons

Definition at line 124 of file Tools.cs.

125 {
126 this.ButtonPressEvent += Tools_ButtonPressEvent;
127 ti = TextInput.Create();
128 view.Drawn += View_Drawn;
129 view.DeleteEvent += View_DeleteEvent;
130 }
static TextInput Create(bool ROItype=true)
Definition TextInput.cs:36

◆ ToolDown()

void BioGTK.Tools.ToolDown ( PointD e,
ButtonPressEventArgs buts )

Definition at line 313 of file Tools.cs.

314 {
315 if (App.viewer == null || currentTool == null || ImageView.SelectedImage == null)
316 return;
317
318 Plugins.MouseDown(ImageView.SelectedImage, e, buts);
319 Scripting.UpdateState(Scripting.State.GetDown(e, buts.Event.Button));
320
321 switch (currentTool.type)
322 {
323 case Tool.Type.pan:
324 ToolDown_Pan(e, buts);
325 break;
326 case Tool.Type.magic:
327 ToolDown_Magic(e, buts);
328 break;
329 case Tool.Type.point:
330 ToolDown_Point(e, buts);
331 break;
332 case Tool.Type.move:
333 ToolDown_Move(e, buts);
334 break;
335 case Tool.Type.line:
336 ToolDown_Line(e, buts);
337 break;
338 case Tool.Type.rect:
339 ToolDown_Rectangle(e, buts);
340 break;
341 case Tool.Type.ellipse:
342 ToolDown_Ellipse(e, buts);
343 break;
344 case Tool.Type.polygon:
345 ToolDown_Polygon(e, buts);
346 break;
347 case Tool.Type.text:
348 ToolDown_Text(e, buts);
349 break;
350 case Tool.Type.delete:
351 ToolDown_Delete(e, buts);
352 break;
353 case Tool.Type.freeform:
354 ToolDown_Freeform(e, buts);
355 break;
356 default:
357 break;
358 }
359 }

◆ ToolDown_Brush()

void BioGTK.Tools.ToolDown_Brush ( PointD e,
ButtonPressEventArgs buts )

Definition at line 1168 of file Tools.cs.

1169 {
1170 if (currentTool.type != Tool.Type.brush || buts.Event.Button != 1)
1171 return;
1172
1173 PointD ip = ImageView.SelectedImage.ToImageSpace(e);
1174 if (ImageView.SelectedImage.isPyramidal)
1175 ip = new PointD(e.X, e.Y);
1176
1177 Bio.Graphics.Graphics g = Bio.Graphics.Graphics.FromImage(ImageView.SelectedBuffer);
1178 g.pen = new Bio.Graphics.Pen(DrawColor, (int)StrokeWidth, ImageView.SelectedImage.bitsPerPixel);
1179 g.FillEllipse(new Rectangle((int)ip.X, (int)ip.Y, (int)StrokeWidth, (int)StrokeWidth), g.pen.color);
1180
1181 App.viewer.UpdateImage();
1182 App.viewer.UpdateView();
1183 }

◆ ToolDown_Delete()

void BioGTK.Tools.ToolDown_Delete ( PointD e,
ButtonPressEventArgs buts )

Definition at line 1120 of file Tools.cs.

1121 {
1122 if (currentTool.type != Tool.Type.delete || buts.Event.Button != 1)
1123 return;
1124
1125 for (int i = ImageView.SelectedImage.Annotations.Count - 1; i >= 0; i--)
1126 {
1127 ROI an = ImageView.SelectedImage.Annotations[i];
1128 if (an == null) continue;
1129
1130 if (an.BoundingBox.IntersectsWith(new RectangleD(e.X, e.Y, 1, 1)))
1131 {
1132 if (an.selectedPoints == null || an.selectedPoints.Count == 0)
1133 {
1134 // Delete entire ROI
1135 ImageView.SelectedImage.Annotations.RemoveAt(i);
1136 break;
1137 }
1138 else if (an.selectedPoints.Count == 1 &&
1139 !(an.type == ROI.Type.Polygon ||
1140 an.type == ROI.Type.Polyline ||
1141 an.type == ROI.Type.Freeform))
1142 {
1143 // Delete ROI with single selected point (for non multi-point types)
1144 ImageView.SelectedImage.Annotations.RemoveAt(i);
1145 break;
1146 }
1147 else
1148 {
1149 // Delete selected points from polygon/polyline/freeform
1150 if (an.type == ROI.Type.Polygon ||
1151 an.type == ROI.Type.Polyline ||
1152 an.type == ROI.Type.Freeform)
1153 {
1154 an.closed = false;
1155 an.RemovePoints(an.selectedPoints.ToArray());
1156 an.UpdateBoundingBox();
1157 break;
1158 }
1159 }
1160 }
1161 }
1162 UpdateView();
1163 }

◆ ToolDown_Ellipse()

void BioGTK.Tools.ToolDown_Ellipse ( PointD e,
ButtonPressEventArgs buts )

Definition at line 903 of file Tools.cs.

904 {
905 if (currentTool.type != Tool.Type.ellipse || buts.Event.Button != 1)
906 return;
907
908 selectedROI = new ROI();
909 selectedROI.type = ROI.Type.Ellipse;
910 selectedROI.BoundingBox = new RectangleD(e.X, e.Y, 0, 0); // Start with 0 size
911 selectedROI.coord = App.viewer.GetCoordinate();
912 selectedROI.serie = ImageView.SelectedImage.isPyramidal ? App.viewer.Level : ImageView.SelectedImage.series;
913 AddROI(selectedROI);
914 }

◆ ToolDown_Eraser()

void BioGTK.Tools.ToolDown_Eraser ( PointD e,
ButtonPressEventArgs buts )

Definition at line 1206 of file Tools.cs.

1207 {
1208 if (currentTool.type != Tool.Type.eraser || buts.Event.Button != 1)
1209 return;
1210
1211 PointD ip = ImageView.SelectedImage.ToImageSpace(e);
1212 if (ImageView.SelectedImage.isPyramidal)
1213 ip = new PointD(e.X, e.Y);
1214
1215 Bio.Graphics.Graphics g = Bio.Graphics.Graphics.FromImage(ImageView.SelectedBuffer);
1216 Bio.Graphics.Pen pen = new Bio.Graphics.Pen(EraseColor, (int)StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel);
1217 g.FillEllipse(new Rectangle((int)ip.X, (int)ip.Y, (int)StrokeWidth, (int)StrokeWidth), pen.color);
1218
1219 App.viewer.UpdateImages();
1220 App.viewer.UpdateView();
1221 }

◆ ToolDown_Freeform()

void BioGTK.Tools.ToolDown_Freeform ( PointD e,
ButtonPressEventArgs buts )

Definition at line 1022 of file Tools.cs.

1023 {
1024 if (currentTool.type != Tool.Type.freeform || buts.Event.Button != 1)
1025 return;
1026
1027 if (selectedROI == null || selectedROI.type != ROI.Type.Polygon)
1028 {
1029 // Start new freeform
1030 selectedROI = new ROI();
1031 selectedROI.type = ROI.Type.Polygon;
1032 selectedROI.closed = false;
1033 selectedROI.AddPoint(new PointD(e.X, e.Y));
1034 selectedROI.coord = App.viewer.GetCoordinate();
1035 selectedROI.serie = ImageView.SelectedImage.isPyramidal ? App.viewer.Level : ImageView.SelectedImage.series;
1036 AddROI(selectedROI);
1037 UpdateView();
1038 }
1039 else if (!selectedROI.closed)
1040 {
1041 // Check if clicking near first point to close freeform
1042 if (selectedROI.Points.Count >= 3)
1043 {
1044 PointD firstPoint = selectedROI.Points[0];
1045 double distance = Math.Sqrt(Math.Pow(e.X - firstPoint.X, 2) + Math.Pow(e.Y - firstPoint.Y, 2));
1046 double threshold = 10.0; // Adjust based on your zoom/scale
1047
1048 if (distance < threshold)
1049 {
1050 // Close freeform
1051 selectedROI.closed = true;
1052 selectedROI.Selected = false;
1053 selectedROI.UpdateBoundingBox();
1054 selectedROI.Validate();
1055 selectedROI = null;
1056 UpdateView();
1057 return;
1058 }
1059 }
1060
1061
1062 }
1063 // Add new point to polygon
1064 selectedROI.AddPoint(new PointD(e.X, e.Y));
1065 selectedROI.UpdateBoundingBox();
1066 UpdateView();
1067 }

◆ ToolDown_Line()

void BioGTK.Tools.ToolDown_Line ( PointD e,
ButtonPressEventArgs buts )

Definition at line 801 of file Tools.cs.

802 {
803 if (currentTool.type != Tool.Type.line || buts.Event.Button != 1)
804 return;
805
806 selectedROI = new ROI();
807 selectedROI.type = ROI.Type.Line;
808 selectedROI.AddPoint(new PointD(e.X, e.Y));
809 selectedROI.AddPoint(new PointD(e.X + ImageView.SelectedImage.PhysicalSizeX * ROI.selectBoxSize,
810 e.Y + ImageView.SelectedImage.PhysicalSizeX * ROI.selectBoxSize));
811 selectedROI.coord = App.viewer.GetCoordinate();
812 selectedROI.serie = ImageView.SelectedImage.isPyramidal ? App.viewer.Level : ImageView.SelectedImage.series;
813 AddROI(selectedROI);
814 }

◆ ToolDown_Magic()

void BioGTK.Tools.ToolDown_Magic ( PointD e,
ButtonPressEventArgs buts )

Definition at line 1461 of file Tools.cs.

1462 {
1463 if (selectedROI == null)
1464 {
1465 selectedROI = new ROI();
1466 selectedROI.type = ROI.Type.Freeform;
1467 selectedROI.AddPoint(new PointD(e.X, e.Y));
1468 selectedROI.coord = App.viewer.GetCoordinate();
1469 if (ImageView.SelectedImage.isPyramidal)
1470 selectedROI.serie = App.viewer.Level;
1471 else
1472 selectedROI.serie = ImageView.SelectedImage.series;
1473 AddROI(selectedROI);
1474 }
1475 else
1476 {
1477 selectedROI.AddPoint(new PointD(e.X, e.Y));
1478 }
1479 }

◆ ToolDown_Move()

void BioGTK.Tools.ToolDown_Move ( PointD e,
ButtonPressEventArgs buts )

Definition at line 476 of file Tools.cs.

477 {
478 if (currentTool.type != Tool.Type.move || buts.Event.Button != 1)
479 return;
480
481 App.viewer.MouseDown = e;
482 bool ctrl = buts.Event.State.HasFlag(ModifierType.ControlMask);
483
484 selectedROI = null;
485
486 // 1 — Vertex hit test on selected ROIs
487 foreach (var ann in ImageView.SelectedImage.Annotations)
488 {
489 if (ann == null || !ann.Selected) continue;
490
491 var boxes = ann.GetSelectBoxes(ROI.selectBoxSize * ImageView.SelectedImage.PhysicalSizeX);
492 if (boxes == null) continue;
493
494 for (int i = 0; i < boxes.Length; i++)
495 {
496 if (boxes[i].Contains(ann.coord, e))
497 {
498 selectedROI = ann;
499 if (ctrl)
500 {
501 if (ann.selectedPoints.Contains(i)) ann.selectedPoints.Remove(i);
502 else ann.selectedPoints.Add(i);
503 }
504 else
505 {
506 ann.selectedPoints.Clear();
507 ann.selectedPoints.Add(i);
508 }
509 UpdateView();
510 return;
511 }
512 }
513 }
514
515 // 2 — Click on body of already-selected ROI
516 foreach (var ann in ImageView.SelectedImage.Annotations)
517 {
518 if (ann != null && ann.Selected && ann.BoundingBox.Contains(ann.coord, e))
519 {
520 selectedROI = ann;
521 UpdateView();
522 return;
523 }
524 }
525
526 // 3 — Click on any ROI (select it)
527 foreach (var ann in ImageView.SelectedImage.Annotations)
528 {
529 if (ann != null && ann.BoundingBox.Contains(ann.coord, e))
530 {
531 if (!ctrl)
532 {
533 foreach (var other in ImageView.SelectedImage.Annotations)
534 {
535 if (other != ann)
536 {
537 other.Selected = false;
538 other.selectedPoints?.Clear();
539 }
540 }
541 }
542
543 ann.Selected = true;
544 ann.selectedPoints?.Clear();
545 selectedROI = ann;
546 UpdateView();
547 return;
548 }
549 }
550
551 // 4 — Start selection rectangle
552 if (!ctrl)
553 {
554 foreach (var ann in ImageView.SelectedImage.Annotations)
555 {
556 if (ann != null)
557 {
558 ann.Selected = false;
559 ann.selectedPoints?.Clear();
560 }
561 }
562 selectedROI = null;
563 }
564
565 Tools.GetTool(Tools.Tool.Type.move).Rectangle = new RectangleD(e.X, e.Y, 0, 0);
566 UpdateView();
567 }

◆ ToolDown_Pan()

void BioGTK.Tools.ToolDown_Pan ( PointD e,
ButtonPressEventArgs buts )

Definition at line 1312 of file Tools.cs.

1313 {
1314 if (buts.Event.Button != 1 && buts.Event.Button != 2)
1315 return;
1316
1317 currentTool = GetTool(Tool.Type.pan);
1318 panStartX = buts.Event.X;
1319 panStartY = buts.Event.Y;
1320 initialPanScale = App.viewer.Resolution;
1321
1322 if (ImageView.SelectedImage.isPyramidal)
1323 {
1324 initialPanOrigin = new PointD(
1325 App.viewer.PyramidalOrigin.X,
1326 App.viewer.PyramidalOrigin.Y);
1327 }
1328 else
1329 {
1330 initialPanOrigin = new PointD(
1331 App.viewer.Origin.X,
1332 App.viewer.Origin.Y);
1333 }
1334 }

◆ ToolDown_Point()

void BioGTK.Tools.ToolDown_Point ( PointD e,
ButtonPressEventArgs buts )

Definition at line 781 of file Tools.cs.

782 {
783 if (currentTool.type != Tool.Type.point || buts.Event.Button != 1)
784 return;
785
786 ROI an = new ROI();
787 an.type = ROI.Type.Point;
788 an.Points.Clear();
789 an.Points.Add(new PointD(e.X, e.Y));
790 an.coord = App.viewer.GetCoordinate();
791 an.serie = ImageView.SelectedImage.isPyramidal ? App.viewer.Level : ImageView.SelectedImage.series;
792 an.Selected = true;
793 selectedROI = an;
794 AddROI(selectedROI);
795 UpdateView();
796 }

◆ ToolDown_Polygon()

void BioGTK.Tools.ToolDown_Polygon ( PointD e,
ButtonPressEventArgs buts )

Definition at line 953 of file Tools.cs.

954 {
955 if (currentTool.type != Tool.Type.polygon || buts.Event.Button != 1)
956 return;
957
958 if (selectedROI == null || selectedROI.type != ROI.Type.Polygon)
959 {
960 // Start new polygon
961 selectedROI = new ROI();
962 selectedROI.type = ROI.Type.Polygon;
963 selectedROI.closed = false;
964 selectedROI.AddPoint(new PointD(e.X, e.Y));
965 selectedROI.coord = App.viewer.GetCoordinate();
966 selectedROI.serie = ImageView.SelectedImage.isPyramidal ? App.viewer.Level : ImageView.SelectedImage.series;
967 AddROI(selectedROI);
968 UpdateView();
969 }
970 else if (!selectedROI.closed)
971 {
972 // Check if clicking near first point to close polygon
973 if (selectedROI.Points.Count >= 3)
974 {
975 PointD firstPoint = selectedROI.Points[0];
976 double distance = Math.Sqrt(Math.Pow(e.X - firstPoint.X, 2) + Math.Pow(e.Y - firstPoint.Y, 2));
977 double threshold = 10.0; // Adjust based on your zoom/scale
978
979 if (distance < threshold)
980 {
981 // Close polygon
982 selectedROI.closed = true;
983 selectedROI.Selected = false;
984 selectedROI.UpdateBoundingBox();
985 selectedROI.Validate();
986 selectedROI = null;
987 UpdateView();
988 return;
989 }
990 }
991
992
993 }
994 // Add new point to polygon
995 selectedROI.AddPoint(new PointD(e.X, e.Y));
996 selectedROI.UpdateBoundingBox();
997 UpdateView();
998 }

◆ ToolDown_Rectangle()

void BioGTK.Tools.ToolDown_Rectangle ( PointD e,
ButtonPressEventArgs buts )

Definition at line 853 of file Tools.cs.

854 {
855 if (currentTool.type != Tool.Type.rect || buts.Event.Button != 1)
856 return;
857
858 selectedROI = new ROI();
859 selectedROI.type = ROI.Type.Rectangle;
860 selectedROI.BoundingBox = new RectangleD(e.X, e.Y, 0, 0); // Start with 0 size
861 selectedROI.coord = App.viewer.GetCoordinate();
862 selectedROI.serie = ImageView.SelectedImage.isPyramidal ? App.viewer.Level : ImageView.SelectedImage.series;
863 AddROI(selectedROI);
864 }

◆ ToolDown_Text()

void BioGTK.Tools.ToolDown_Text ( PointD e,
ButtonPressEventArgs buts )

Definition at line 1096 of file Tools.cs.

1097 {
1098 if (currentTool.type != Tool.Type.text || buts.Event.Button != 1)
1099 return;
1100
1101 selectedROI = new ROI();
1102 selectedROI.type = ROI.Type.Label;
1103 selectedROI.AddPoint(new PointD(e.X, e.Y));
1104 selectedROI.coord = App.viewer.GetCoordinate();
1105 selectedROI.serie = ImageView.SelectedImage.isPyramidal ? App.viewer.Level : ImageView.SelectedImage.series;
1106
1107 // Show text input dialog
1108 ti = TextInput.Create();
1109 ti.ShowAll();
1110 ti.Run();
1111
1112 AddROI(selectedROI);
1113 selectedROI.UpdateBoundingBox();
1114 UpdateView();
1115 }

◆ ToolMove()

void BioGTK.Tools.ToolMove ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 412 of file Tools.cs.

413 {
414 if (App.viewer == null)
415 return;
416
417 Plugins.MouseMove(ImageView.SelectedImage, e, buts);
418
419 // Update scripting state using available button masks
420 if (buts.Event.State.HasFlag(ModifierType.Button1Mask))
421 Scripting.UpdateState(Scripting.State.GetMove(e, 1));
422 else if (buts.Event.State.HasFlag(ModifierType.Button2Mask))
423 Scripting.UpdateState(Scripting.State.GetMove(e, 2));
424 else if (buts.Event.State.HasFlag(ModifierType.Button3Mask))
425 Scripting.UpdateState(Scripting.State.GetMove(e, 3));
426 else if (buts.Event.State.HasFlag(ModifierType.Button4Mask))
427 Scripting.UpdateState(Scripting.State.GetMove(e, 4));
428 else if (buts.Event.State.HasFlag(ModifierType.Button5Mask))
429 Scripting.UpdateState(Scripting.State.GetMove(e, 5));
430 else
431 Scripting.UpdateState(Scripting.State.GetMove(e, 0));
432
433 switch (currentTool.type)
434 {
435 case Tool.Type.pan:
436 ToolMove_Pan(e, buts);
437 break;
438 case Tool.Type.move:
439 ToolMove_Move(e, buts);
440 break;
441 case Tool.Type.magic:
442 ToolMove_Magic(e, buts);
443 break;
444 case Tool.Type.line:
445 ToolMove_Line(e, buts);
446 break;
447 case Tool.Type.rect:
448 ToolMove_Rectangle(e, buts);
449 break;
450 case Tool.Type.ellipse:
451 ToolMove_Ellipse(e, buts);
452 break;
453 case Tool.Type.polygon:
454 ToolMove_Polygon(e, buts);
455 break;
456 case Tool.Type.text:
457 //ToolMove_Text(e, buts);
458 break;
459 case Tool.Type.freeform:
460 ToolMove_Freeform(e, buts);
461 break;
462 case Tool.Type.brush:
463 ToolMove_Brush(e, buts);
464 break;
465 case Tool.Type.eraser:
466 ToolMove_Eraser(e, buts);
467 break;
468 default:
469 break;
470 }
471 }

◆ ToolMove_Brush()

void BioGTK.Tools.ToolMove_Brush ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 1185 of file Tools.cs.

1186 {
1187 if (currentTool.type != Tool.Type.brush ||
1188 !buts.Event.State.HasFlag(ModifierType.Button1Mask))
1189 return;
1190
1191 PointD ip = ImageView.SelectedImage.ToImageSpace(e);
1192 if (ImageView.SelectedImage.isPyramidal)
1193 ip = new PointD(e.X, e.Y);
1194
1195 Bio.Graphics.Graphics g = Bio.Graphics.Graphics.FromImage(ImageView.SelectedBuffer);
1196 g.pen = new Bio.Graphics.Pen(DrawColor, (int)StrokeWidth, ImageView.SelectedImage.bitsPerPixel);
1197 g.FillEllipse(new Rectangle((int)ip.X, (int)ip.Y, (int)StrokeWidth, (int)StrokeWidth), g.pen.color);
1198
1199 App.viewer.UpdateImages();
1200 App.viewer.UpdateView();
1201 }

◆ ToolMove_Ellipse()

void BioGTK.Tools.ToolMove_Ellipse ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 916 of file Tools.cs.

917 {
918 if (currentTool.type != Tool.Type.ellipse ||
919 !buts.Event.State.HasFlag(ModifierType.Button1Mask))
920 return;
921
922 if (selectedROI != null && selectedROI.type == ROI.Type.Ellipse)
923 {
924 selectedROI.BoundingBox = RectangleDExtensions.FromCorners(
925 new PointD(selectedROI.BoundingBox.X, selectedROI.BoundingBox.Y),
926 new PointD(e.X, e.Y));
927 UpdateView();
928 }
929 }

◆ ToolMove_Eraser()

void BioGTK.Tools.ToolMove_Eraser ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 1223 of file Tools.cs.

1224 {
1225 if (currentTool.type != Tool.Type.eraser ||
1226 !buts.Event.State.HasFlag(ModifierType.Button1Mask))
1227 return;
1228
1229 PointD ip = ImageView.SelectedImage.ToImageSpace(e);
1230 if (ImageView.SelectedImage.isPyramidal)
1231 ip = new PointD(e.X, e.Y);
1232
1233 Bio.Graphics.Graphics g = Bio.Graphics.Graphics.FromImage(ImageView.SelectedBuffer);
1234 Bio.Graphics.Pen pen = new Bio.Graphics.Pen(EraseColor, (int)StrokeWidth, ImageView.SelectedBuffer.BitsPerPixel);
1235 g.FillEllipse(new Rectangle((int)ip.X, (int)ip.Y, (int)StrokeWidth, (int)StrokeWidth), pen.color);
1236
1237 App.viewer.UpdateImages();
1238 App.viewer.UpdateView();
1239 }

◆ ToolMove_Freeform()

void BioGTK.Tools.ToolMove_Freeform ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 1069 of file Tools.cs.

1070 {
1071 if (selectedROI != null)
1072 if (currentTool.type == Tool.Type.freeform && buts.Event.State.HasFlag(ModifierType.Button1Mask))
1073 {
1074 selectedROI.AddPoint(new PointD(e.X, e.Y));
1075 selectedROI.coord = App.viewer.GetCoordinate();
1076 selectedROI.serie = ImageView.SelectedImage.isPyramidal ? App.viewer.Level : ImageView.SelectedImage.series;
1077 }
1078 }

◆ ToolMove_Line()

void BioGTK.Tools.ToolMove_Line ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 816 of file Tools.cs.

817 {
818 if (currentTool.type != Tool.Type.line ||
819 !buts.Event.State.HasFlag(ModifierType.Button1Mask))
820 return;
821
822 if (selectedROI != null)
823 {
824 if (selectedROI.selectedPoints.Count == 1)
825 {
826 selectedROI.UpdatePoint(new PointD(e.X, e.Y), selectedROI.selectedPoints[0]);
827 selectedROI.UpdateBoundingBox();
828 UpdateView();
829 }
830 else
831 {
832 selectedROI.UpdatePoint(new PointD(e.X, e.Y), 1);
833 selectedROI.UpdateBoundingBox();
834 UpdateView();
835 }
836 }
837 }

◆ ToolMove_Magic()

void BioGTK.Tools.ToolMove_Magic ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 1481 of file Tools.cs.

1482 {
1483 //First we draw the selection rectangle
1484 PointD d = new PointD(e.X - App.viewer.MouseDown.X, e.Y - App.viewer.MouseDown.Y);
1485 Tools.GetTool(Tools.Tool.Type.move).Rectangle = new RectangleD(App.viewer.MouseDown.X, App.viewer.MouseDown.Y, d.X, d.Y);
1486 UpdateView();
1487 }

◆ ToolMove_Move()

void BioGTK.Tools.ToolMove_Move ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 568 of file Tools.cs.

569 {
570 if (currentTool.type != Tool.Type.move ||
571 !buts.Event.State.HasFlag(ModifierType.Button1Mask))
572 return;
573
574 // Moving selected vertices/control points or ROIs
575 if (selectedROI != null && selectedROI.Selected && selectedROI.selectedPoints != null)
576 {
577 PointD delta = new PointD(e.X - App.viewer.MouseDown.X, e.Y - App.viewer.MouseDown.Y);
578
579 // Rectangle / Ellipse special handling
580 if (selectedROI.type == ROI.Type.Rectangle || selectedROI.type == ROI.Type.Ellipse)
581 {
582 // If exactly one corner is selected -> resize by that corner
583 if (selectedROI.selectedPoints.Count == 1)
584 {
585 int pointIndex = selectedROI.selectedPoints[0];
586 RectangleD rect = selectedROI.BoundingBox;
587
588 // Work with normalized copy to make logic clearer
589 double left = rect.X;
590 double top = rect.Y;
591 double right = rect.X + rect.W;
592 double bottom = rect.Y + rect.H;
593
594 switch (pointIndex)
595 {
596 case 0: // Top-Left
597 left += delta.X;
598 top += delta.Y;
599 break;
600 case 1: // Top-Right
601 right += delta.X;
602 top += delta.Y;
603 break;
604 case 2: // Bottom-Right
605 right += delta.X;
606 bottom += delta.Y;
607 break;
608 case 3: // Bottom-Left
609 left += delta.X;
610 bottom += delta.Y;
611 break;
612 default:
613 break;
614 }
615
616 // Build and assign normalized bounding box
617 RectangleD newRect = new RectangleD(
618 Math.Min(left, right),
619 Math.Min(top, bottom),
620 Math.Abs(right - left),
621 Math.Abs(bottom - top)
622 );
623
624 selectedROI.BoundingBox = newRect;
625
626 // Important: keep points and bbox in sync
627 SyncPointsFromBoundingBox(selectedROI);
628 selectedROI.UpdateBoundingBox(); // if your ROI uses this to recalc derived fields
629
630 App.viewer.MouseDown = new PointD(e.X, e.Y);
631 App.viewer.UpdateView();
632 return;
633 }
634 else
635 {
636 // No corner selected -> move entire ROI by delta
637 for (int i = 0; i < selectedROI.Points.Count; i++)
638 {
639 selectedROI.UpdatePoint(
640 new PointD(selectedROI.Points[i].X + delta.X,
641 selectedROI.Points[i].Y + delta.Y), i);
642 }
643
644 // Keep bounding box in sync with points
645 SyncBoundingBoxFromPoints(selectedROI);
646 selectedROI.UpdateBoundingBox();
647
648 App.viewer.MouseDown = new PointD(e.X, e.Y);
649 App.viewer.UpdateView();
650 return;
651 }
652 }
653 else
654 {
655 // Other shapes: polygons, polylines, freeforms, lines, points
656 if (selectedROI.selectedPoints.Count == 0)
657 {
658 // Move all points
659 for (int i = 0; i < selectedROI.Points.Count; i++)
660 {
661 selectedROI.UpdatePoint(
662 new PointD(selectedROI.Points[i].X + delta.X,
663 selectedROI.Points[i].Y + delta.Y), i);
664 }
665 }
666 else
667 {
668 // Move only selected points
669 foreach (int pointIndex in selectedROI.selectedPoints.ToArray())
670 {
671 if (pointIndex >= 0 && pointIndex < selectedROI.Points.Count)
672 {
673 PointD pt = selectedROI.Points[pointIndex];
674 selectedROI.UpdatePoint(
675 new PointD(pt.X + delta.X, pt.Y + delta.Y), pointIndex);
676 }
677 }
678 }
679
680 // Keep bbox updated
681 SyncBoundingBoxFromPoints(selectedROI);
682 selectedROI.UpdateBoundingBox();
683
684 App.viewer.MouseDown = new PointD(e.X, e.Y);
685 App.viewer.UpdateView();
686 return;
687 }
688 }
689 // Dragging entire selected ROI (no selectedPoints list)
690 else if (selectedROI != null && selectedROI.Selected)
691 {
692 PointD delta = new PointD(e.X - App.viewer.MouseDown.X, e.Y - App.viewer.MouseDown.Y);
693
694 for (int i = 0; i < selectedROI.Points.Count; i++)
695 {
696 selectedROI.UpdatePoint(
697 new PointD(selectedROI.Points[i].X + delta.X,
698 selectedROI.Points[i].Y + delta.Y), i);
699 }
700
701 SyncBoundingBoxFromPoints(selectedROI);
702 selectedROI.UpdateBoundingBox();
703
704 App.viewer.MouseDown = new PointD(e.X, e.Y);
705 App.viewer.UpdateView();
706 return;
707 }
708 // Drawing / updating selection rectangle
709 else
710 {
711 PointD d = new PointD(e.X - App.viewer.MouseDown.X, e.Y - App.viewer.MouseDown.Y);
712 RectangleD selRect = new RectangleD(
713 Math.Min(App.viewer.MouseDown.X, e.X),
714 Math.Min(App.viewer.MouseDown.Y, e.Y),
715 Math.Abs(d.X), Math.Abs(d.Y));
716
717 Tools.GetTool(Tools.Tool.Type.move).Rectangle = selRect;
718
719 bool controlHeld = buts.Event.State.HasFlag(ModifierType.ControlMask);
720
721 // Select ROIs intersecting with rectangle
722 foreach (ROI an in ImageView.SelectedImage.Annotations)
723 {
724 if (an == null) continue;
725
726 RectangleD selBound = an.GetSelectBound(
727 ROI.selectBoxSize * ImageView.SelectedImage.PhysicalSizeX,
728 ROI.selectBoxSize * ImageView.SelectedImage.PhysicalSizeY);
729
730 if (selBound.IntersectsWith(selRect))
731 {
732 an.Selected = true;
733
734 if (!controlHeld)
735 an.selectedPoints?.Clear();
736
737 // Select points within rectangle
738 RectangleD[] sels = an.GetSelectBoxes(
739 ROI.selectBoxSize * ImageView.SelectedImage.PhysicalSizeX);
740 if (sels != null)
741 {
742 for (int i = 0; i < sels.Length; i++)
743 {
744 if (sels[i].IntersectsWith(selRect))
745 {
746 if (an.selectedPoints == null) an.selectedPoints = new List<int>();
747 if (!an.selectedPoints.Contains(i))
748 an.selectedPoints.Add(i);
749 }
750 }
751 }
752 }
753 else if (!controlHeld)
754 {
755 an.Selected = false;
756 an.selectedPoints?.Clear();
757 }
758 }
759
760 if (selectedROI != null)
761 selectedROI.UpdateBoundingBox();
762
763 App.viewer.UpdateView();
764 }
765 }

◆ ToolMove_Pan()

void BioGTK.Tools.ToolMove_Pan ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 1339 of file Tools.cs.

1340 {
1341 if (currentTool.type != Tool.Type.pan)
1342 return;
1343
1344 if (!buts.Event.State.HasFlag(ModifierType.Button1Mask) &&
1345 !buts.Event.State.HasFlag(ModifierType.Button2Mask))
1346 return;
1347
1348 double dx = buts.Event.X - panStartX;
1349 double dy = buts.Event.Y - panStartY;
1350 // Apply pan speed multiplier for user-controlled panning sensitivity
1351
1352 double deltaX = (dx / initialPanScale) * PanSpeed;
1353 double deltaY = (dy / initialPanScale) * PanSpeed;
1354
1355 if (ImageView.SelectedImage.isPyramidal)
1356 {
1357 App.viewer.PyramidalOrigin = new PointD(
1358 initialPanOrigin.X - deltaX,
1359 initialPanOrigin.Y - deltaY);
1360 App.viewer.UpdateView(true);
1361 }
1362 else
1363 {
1364 App.viewer.Origin = new PointD(
1365 initialPanOrigin.X - deltaX,
1366 initialPanOrigin.Y - deltaY);
1367 // Non-pyramidal can still use normal update
1368 App.viewer.UpdateView();
1369 }
1370 }

◆ ToolMove_Rectangle()

void BioGTK.Tools.ToolMove_Rectangle ( PointD e,
MotionNotifyEventArgs buts )

Definition at line 866 of file Tools.cs.

867 {
868 if (currentTool.type != Tool.Type.rect ||
869 !buts.Event.State.HasFlag(ModifierType.Button1Mask))
870 return;
871
872 if (selectedROI != null && selectedROI.type == ROI.Type.Rectangle)
873 {
874 selectedROI.BoundingBox = RectangleDExtensions.FromCorners(
875 new PointD(selectedROI.BoundingBox.X, selectedROI.BoundingBox.Y),
876 new PointD(e.X, e.Y));
877 UpdateView();
878 }
879 }

◆ ToolUp()

void BioGTK.Tools.ToolUp ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 361 of file Tools.cs.

362 {
363 if (App.viewer == null || currentTool == null || ImageView.SelectedImage == null)
364 return;
365
366 Plugins.MouseUp(ImageView.SelectedImage, e, buts);
367 Scripting.UpdateState(Scripting.State.GetUp(e, buts.Event.Button));
368
369 switch (currentTool.type)
370 {
371 case Tool.Type.pan:
372 ToolUp_Pan(e, buts);
373 break;
374 case Tool.Type.move:
375 ToolUp_Move(e, buts);
376 break;
377 case Tool.Type.magic:
378 ToolUp_Magic(e, buts);
379 break;
380 case Tool.Type.line:
381 ToolUp_Line(e, buts);
382 break;
383 case Tool.Type.rect:
384 ToolUp_Rectangle(e, buts);
385 break;
386 case Tool.Type.ellipse:
387 ToolUp_Ellipse(e, buts);
388 break;
389 case Tool.Type.polygon:
390 ToolUp_Polygon(e, buts);
391 break;
392 case Tool.Type.text:
393 //ToolUp_Text(e, buts);
394 break;
395 case Tool.Type.delete:
396 //
397 break;
398 case Tool.Type.freeform:
399 ToolUp_Freeform(e, buts);
400 break;
401 case Tool.Type.bucket:
402 ToolUp_Bucket(e, buts);
403 break;
404 case Tool.Type.dropper:
405 ToolUp_Dropper(e, buts);
406 break;
407 default:
408 break;
409 }
410 }

◆ ToolUp_Bucket()

void BioGTK.Tools.ToolUp_Bucket ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 1244 of file Tools.cs.

1245 {
1246 if (currentTool.type != Tool.Type.bucket || buts.Event.Button != 1)
1247 return;
1248
1249 PointD ip = ImageView.SelectedImage.ToImageSpace(e);
1250
1251 if (ip.X >= ImageView.SelectedImage.SizeX || ip.Y >= ImageView.SelectedImage.SizeY)
1252 return;
1253
1254 floodFiller.FillColor = DrawColor;
1255 floodFiller.Tolerance = tolerance;
1256 floodFiller.Bitmap = ImageView.SelectedBuffer;
1257 floodFiller.FloodFill(new AForge.Point((int)ip.X, (int)ip.Y));
1258
1259 App.viewer.UpdateImages();
1260 App.viewer.UpdateView();
1261 }

◆ ToolUp_Dropper()

void BioGTK.Tools.ToolUp_Dropper ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 1266 of file Tools.cs.

1267 {
1268 if (currentTool.type != Tool.Type.dropper || buts.Event.Button != 1)
1269 return;
1270
1271 PointD ip = ImageView.SelectedImage.ToImageSpace(e);
1272
1273 if (ip.X >= 0 && ip.Y >= 0 && ip.X < ImageView.SelectedImage.SizeX && ip.Y < ImageView.SelectedImage.SizeY)
1274 {
1275 DrawColor = ImageView.SelectedBuffer.GetPixel((int)ip.X, (int)ip.Y);
1276 App.viewer.UpdateView();
1277 }
1278 }

◆ ToolUp_Ellipse()

void BioGTK.Tools.ToolUp_Ellipse ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 931 of file Tools.cs.

932 {
933 if (currentTool.type != Tool.Type.ellipse || buts.Event.Button != 1)
934 return;
935
936 if (selectedROI != null && selectedROI.type == ROI.Type.Ellipse)
937 {
938 // Update final ellipse bounds
939 selectedROI.BoundingBox = RectangleDExtensions.FromCorners(
940 new PointD(selectedROI.BoundingBox.X, selectedROI.BoundingBox.Y),
941 new PointD(e.X, e.Y));
942
943 // Validate the ROI (might reject if too small)
944 selectedROI.Validate();
945 selectedROI = null;
946 UpdateView();
947 }
948 }

◆ ToolUp_Freeform()

void BioGTK.Tools.ToolUp_Freeform ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 1080 of file Tools.cs.

1081 {
1082 if (currentTool.type != Tool.Type.freeform || buts.Event.Button != 1)
1083 return;
1084
1085 if (selectedROI != null)
1086 {
1087 selectedROI.UpdateBoundingBox();
1088 //selectedROI = null;
1089 UpdateView();
1090 }
1091 }

◆ ToolUp_Line()

void BioGTK.Tools.ToolUp_Line ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 839 of file Tools.cs.

840 {
841 if (currentTool.type != Tool.Type.line || buts.Event.Button != 1)
842 return;
843
844 if (selectedROI != null && selectedROI.GetPointCount() >= 2)
845 {
846 selectedROI.UpdatePoint(new PointD(e.X, e.Y), 1);
847 selectedROI.UpdateBoundingBox();
848 selectedROI = null;
849 UpdateView();
850 }
851 }

◆ ToolUp_Magic()

void BioGTK.Tools.ToolUp_Magic ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 1489 of file Tools.cs.

1490 {
1491 if (!buts.Event.State.HasFlag(ModifierType.Button1Mask))
1492 return;
1493 // Define the rectangle from mouse coordinates
1494 RectangleD rectangle = new RectangleD(
1495 App.viewer.MouseDown.X,
1496 App.viewer.MouseDown.Y,
1497 Math.Abs(App.viewer.MouseUp.X - App.viewer.MouseDown.X),
1498 Math.Abs(App.viewer.MouseUp.Y - App.viewer.MouseDown.Y)
1499 );
1500
1501 // Convert to image space coordinates
1502 AForge.RectangleF rectInImageSpace = ImageView.SelectedImage.ToImageSpace(rectangle);
1503 ZCT coord = App.viewer.GetCoordinate();
1504 Bitmap bitmap;
1505
1506 // Check the number of RGB channels to choose filtering method
1507 if (ImageView.SelectedImage.Buffers[0].RGBChannelsCount > 1)
1508 {
1509 bitmap = ImageView.SelectedImage.GetFiltered(
1510 coord,
1511 new IntRange((int)ImageView.SelectedBuffer.Stats[0].Min, (int)ImageView.SelectedBuffer.Stats[0].Max),
1512 new IntRange((int)ImageView.SelectedBuffer.Stats[1].Min, (int)ImageView.SelectedBuffer.Stats[1].Max),
1513 new IntRange((int)ImageView.SelectedBuffer.Stats[2].Min, (int)ImageView.SelectedBuffer.Stats[2].Max)
1514 );
1515 }
1516 else
1517 {
1518 bitmap = ImageView.SelectedImage.GetFiltered(
1519 coord,
1520 new IntRange((int)ImageView.SelectedBuffer.Stats[0].Min, (int)ImageView.SelectedBuffer.Stats[0].Max),
1521 new IntRange((int)ImageView.SelectedBuffer.Stats[0].Min, (int)ImageView.SelectedBuffer.Stats[0].Max),
1522 new IntRange((int)ImageView.SelectedBuffer.Stats[0].Min, (int)ImageView.SelectedBuffer.Stats[0].Max)
1523 );
1524 }
1525
1526 // Crop the image to the selected rectangle
1527 bitmap.Crop(rectInImageSpace.ToRectangleInt());
1528 // Determine the threshold based on magicSelect settings
1529 Statistics[] st = Statistics.FromBytes(bitmap.Bytes, bitmap.SizeX, bitmap.Height, bitmap.RGBChannelsCount, bitmap.BitsPerPixel, bitmap.Stride, bitmap.PixelFormat);
1530 int threshold = magicSelect.Numeric ? magicSelect.Threshold : CalculateThreshold(magicSelect.Index, st[0]);
1531 BlobCounter blobCounter = new BlobCounter();
1532 OtsuThreshold th = new OtsuThreshold();
1533 bitmap.To8Bit();
1534 th.ApplyInPlace(bitmap);
1535 blobCounter.FilterBlobs = true;
1536 blobCounter.MinWidth = 2;
1537 blobCounter.MinHeight = 2;
1538 blobCounter.ProcessImage(bitmap);
1539 // Retrieve detected blobs
1540 Blob[] blobs = blobCounter.GetObjectsInformation();
1541 double pixelSizeX = ImageView.SelectedImage.PhysicalSizeX;
1542 double pixelSizeY = ImageView.SelectedImage.PhysicalSizeY;
1543 // Annotate detected blobs in the original image
1544 foreach (Blob blob in blobs)
1545 {
1546 AForge.RectangleD blobRectangle = new AForge.RectangleD(
1547 blob.Rectangle.X * pixelSizeX,
1548 blob.Rectangle.Y * pixelSizeY,
1549 blob.Rectangle.Width * pixelSizeX,
1550 blob.Rectangle.Height * pixelSizeY
1551 );
1552 // Calculate the location of the detected blob
1553 PointD location = new PointD(rectangle.X + blobRectangle.X, rectangle.Y + blobRectangle.Y);
1554 // Create and add ROI annotation
1555 ROI annotation = ROI.CreateRectangle(coord, location.X, location.Y, blobRectangle.W, blobRectangle.H);
1556 ImageView.SelectedImage.Annotations.Add(annotation);
1557 }
1558 App.viewer.UpdateView(true);
1559 }
static int CalculateThreshold(int index, Statistics stat)
Helper method to calculate threshold for magic select.
Definition Tools.cs:1753

◆ ToolUp_Move()

void BioGTK.Tools.ToolUp_Move ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 766 of file Tools.cs.

767 {
768 if (currentTool.type != Tool.Type.move || buts.Event.Button != 1)
769 return;
770
771 // Clear selection rectangle
772 Tools.GetTool(Tools.Tool.Type.move).Rectangle = new RectangleD(0, 0, 0, 0);
773 selectedROI?.UpdateBoundingBox();
774 App.viewer.UpdateView();
775 }

◆ ToolUp_Pan()

void BioGTK.Tools.ToolUp_Pan ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 1376 of file Tools.cs.

1377 {
1378 if (currentTool.type == Tool.Type.pan &&
1379 (buts.Event.Button == 1 || buts.Event.Button == 2))
1380 {
1381 currentTool = GetTool(Tool.Type.move);
1382 }
1383 }

◆ ToolUp_Rectangle()

void BioGTK.Tools.ToolUp_Rectangle ( PointD e,
ButtonReleaseEventArgs buts )

Definition at line 881 of file Tools.cs.

882 {
883 if (currentTool.type != Tool.Type.rect || buts.Event.Button != 1)
884 return;
885
886 if (selectedROI != null && selectedROI.type == ROI.Type.Rectangle)
887 {
888 // Update final rectangle bounds
889 selectedROI.BoundingBox = RectangleDExtensions.FromCorners(
890 new PointD(selectedROI.BoundingBox.X, selectedROI.BoundingBox.Y),
891 new PointD(e.X, e.Y));
892
893 // Validate the ROI (might reject if too small)
894 selectedROI.Validate();
895 selectedROI = null;
896 UpdateView();
897 }
898 }

Member Data Documentation

◆ applyToStack

bool BioGTK.Tools.applyToStack = false
static

Definition at line 57 of file Tools.cs.

◆ bEnabled

bool BioGTK.Tools.bEnabled = true
static

Definition at line 61 of file Tools.cs.

◆ colorOne

bool BioGTK.Tools.colorOne = true
static

Definition at line 220 of file Tools.cs.

◆ colorTool

ColorTool BioGTK.Tools.colorTool
static

Definition at line 58 of file Tools.cs.

◆ currentTool

Tool BioGTK.Tools.currentTool
static

Definition at line 1686 of file Tools.cs.

◆ drawColor

ColorS BioGTK.Tools.drawColor = new ColorS(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue)
static

Definition at line 62 of file Tools.cs.

◆ eraseColor

ColorS BioGTK.Tools.eraseColor = new ColorS(0, 0, 0)
static

Definition at line 63 of file Tools.cs.

◆ gEnabled

bool BioGTK.Tools.gEnabled = true
static

Definition at line 60 of file Tools.cs.

◆ PanSpeed

double BioGTK.Tools.PanSpeed = 0.75
static

Definition at line 1308 of file Tools.cs.

◆ rEnabled

bool BioGTK.Tools.rEnabled = true
static

Definition at line 59 of file Tools.cs.

◆ selectionRect

RectangleD BioGTK.Tools.selectionRect
static

Definition at line 1729 of file Tools.cs.

◆ selectionRectangle

Rectangle BioGTK.Tools.selectionRectangle
static

Definition at line 87 of file Tools.cs.

◆ ti

TextInput BioGTK.Tools.ti = null
static

Definition at line 1730 of file Tools.cs.

◆ tolerance

ColorS BioGTK.Tools.tolerance = new ColorS(0, 0, 0)
static

Definition at line 64 of file Tools.cs.

◆ tools

Dictionary<string, Tool> BioGTK.Tools.tools = new Dictionary<string, Tool>()
static

Definition at line 88 of file Tools.cs.

Property Documentation

◆ DrawColor

ColorS BioGTK.Tools.DrawColor
staticgetset

Definition at line 1688 of file Tools.cs.

1689 {
1690 get
1691 {
1692 return drawColor;
1693 }
1694 set
1695 {
1696 drawColor = value;
1697 tools[Tool.Type.color1.ToString()].color = drawColor;
1698 }
1699 }

◆ EraseColor

ColorS BioGTK.Tools.EraseColor
staticgetset

Definition at line 1701 of file Tools.cs.

1702 {
1703 get
1704 {
1705 return eraseColor;
1706 }
1707 set
1708 {
1709 eraseColor = value;
1710 tools[Tool.Type.color2.ToString()].color = eraseColor;
1711 }
1712 }

◆ IsPanning

bool BioGTK.Tools.IsPanning
getset

Definition at line 1727 of file Tools.cs.

1727{ get; set; }

◆ selectedROI

ROI BioGTK.Tools.selectedROI
staticgetset

Definition at line 68 of file Tools.cs.

69 {
70 get
71 {
72 List<ROI> rs = new List<ROI>();
73 foreach (var item in ImageView.SelectedImage.Annotations)
74 {
75 if (item.Selected)
76 rs.Add(item);
77 }
78 if (rs.Count > 0)
79 roi = rs[0];
80 return roi;
81 }
82 set
83 {
84 roi = value;
85 }
86 }

◆ selectedROIs

List<ROI> BioGTK.Tools.selectedROIs
staticgetset

Definition at line 92 of file Tools.cs.

93 {
94 get
95 {
96 rois.Clear();
97 for (int i = 0; i < Images.images.Count; i++)
98 {
99 for (int r = 0; r < Images.images[i].Annotations.Count; r++)
100 {
101 if (Images.images[i].Annotations[r].Selected)
102 rois.Add(Images.images[i].Annotations[r]);
103 }
104 }
105 return rois;
106 }
107 set
108 {
109 rois.Clear();
110 rois.AddRange(value);
111 }
112 }

◆ StrokeWidth

int BioGTK.Tools.StrokeWidth
staticgetset

Definition at line 1715 of file Tools.cs.

1716 {
1717 get
1718 {
1719 return width;
1720 }
1721 set
1722 {
1723 width = value;
1724 }
1725 }

The documentation for this class was generated from the following file: