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
Bio.ROIManager Class Reference
Inheritance diagram for Bio.ROIManager:

Public Member Functions

void CopySelection ()
 It takes the selected ROIs and copies them to the clipboard.
 
void PasteSelection ()
 
void InitItems ()
 
void UpdateAnnotationList ()
 
void updateROI (int index, ROI an)
 
void UpdatePointBox ()
 

Static Public Member Functions

static ROIManager Create ()
 

Public Attributes

BioImage image
 
ROI anno = new ROI()
 
bool autoUpdate = true
 

Static Public Attributes

static bool showBounds = true
 
static bool showText = false
 
static bool showR = true
 
static bool showG = true
 
static bool showB = true
 

Protected Member Functions

 ROIManager (Builder builder, IntPtr handle)
 

Properties

static Dictionary< string, ROI > rois [get, set]
 

Detailed Description

Definition at line 16 of file ROIManager.cs.

Constructor & Destructor Documentation

◆ ROIManager()

Bio.ROIManager.ROIManager ( Builder builder,
IntPtr handle )
protected

Definition at line 137 of file ROIManager.cs.

137 : base(handle)
138 {
139 _builder = builder;
140 builder.Autoconnect(this);
141 xBox.ValueChanged += xBox_ValueChanged;
142 yBox.ValueChanged += yBox_ValueChanged;
143 wBox.ValueChanged += wBox_ValueChanged;
144 hBox.ValueChanged += hBox_ValueChanged;
145 rBox.ValueChanged += rBox_ValueChanged;
146 gBox.ValueChanged += gBox_ValueChanged;
147 bBox.ValueChanged += bBox_ValueChanged;
148 zBox.ValueChanged += zBox_ValueChanged;
149 cBox.ValueChanged += cBox_ValueChanged;
150 tBox.ValueChanged += tBox_ValueChanged;
151 widthBox.ValueChanged += strokeWBox_ValueChanged;
152 pointXBox.ValueChanged += pointXBox_ValueChanged;
153 pointYBox.ValueChanged += pointYBox_ValueChanged;
154 pointBox.ValueChanged += pointBox_ValueChanged;
155 selBox.ValueChanged += selectBoxSize_ValueChanged;
156 widthBox.ValueChanged += strokeWBox_ValueChanged;
157 textBox.Changed += textBox_TextChanged;
158 idBox.Changed += idBox_TextChanged;
159 boundsBox.Clicked += showBoundsBox_ActiveChanged;
160 showTextBox.Clicked += showTextBox_ActiveChanged;
161 showRBox.Clicked += showRBox_ActiveChanged;
162 showGBox.Clicked += showGBox_ActiveChanged;
163 showBBox.Clicked += showBBox_ActiveChanged;
164 showMasksBox.Clicked += ShowMasksBox_Clicked;
165 this.DeleteEvent += ROIManager_DeleteEvent;
166 menuDelete.ButtonPressEvent += MenuDelete_ButtonPressEvent;
167 menuCopy.ButtonPressEvent += MenuCopy_ButtonPressEvent;
168 menuPaste.ButtonPressEvent += MenuPaste_ButtonPressEvent;
169
170 //roiView.Selection.Changed += roiView_SelectedIndexChanged;
171 roiView.RowActivated += RoiView_RowActivated;
172 this.FocusInEvent += ROIManager_FocusInEvent;
173 this.FocusActivated += ROIManager_Activated;
174 roiView.ButtonPressEvent += RoiView_ButtonPressEvent;
175
176 xBox.Adjustment.Upper = PointD.MaxX;
177 xBox.Adjustment.StepIncrement= 0.1;
178 xBox.Adjustment.PageIncrement= 1;
179 yBox.Adjustment.Upper = PointD.MaxY;
180 yBox.Adjustment.StepIncrement = 0.1;
181 yBox.Adjustment.PageIncrement = 1;
182 wBox.Adjustment.Upper = PointD.MaxX;
183 wBox.Adjustment.StepIncrement = 0.1;
184 wBox.Adjustment.PageIncrement = 1;
185 hBox.Adjustment.Upper = PointD.MaxY;
186 xBox.Adjustment.StepIncrement = 0.1;
187 xBox.Adjustment.PageIncrement = 1;
188 rBox.Adjustment.Upper = byte.MaxValue;
189 rBox.Adjustment.StepIncrement = 1;
190 rBox.Adjustment.PageIncrement = 1;
191 gBox.Adjustment.Upper = byte.MaxValue;
192 gBox.Adjustment.StepIncrement = 1;
193 gBox.Adjustment.PageIncrement = 1;
194 bBox.Adjustment.Upper = byte.MaxValue;
195 bBox.Adjustment.StepIncrement = 1;
196 bBox.Adjustment.PageIncrement = 1;
197 zBox.Adjustment.Upper = 10000;
198 zBox.Adjustment.StepIncrement = 1;
199 zBox.Adjustment.PageIncrement = 1;
200 cBox.Adjustment.Upper = 10000;
201 cBox.Adjustment.StepIncrement = 1;
202 cBox.Adjustment.PageIncrement = 1;
203 tBox.Adjustment.Upper = 10000;
204 tBox.Adjustment.StepIncrement = 1;
205 tBox.Adjustment.PageIncrement = 1;
206 widthBox.Adjustment.Upper = 100;
207 widthBox.Adjustment.StepIncrement = 1;
208 widthBox.Adjustment.PageIncrement = 1;
209 pointBox.Adjustment.Upper = 100000;
210 pointBox.Adjustment.StepIncrement = 1;
211 pointBox.Adjustment.PageIncrement = 1;
212 pointXBox.Adjustment.Upper = PointD.MaxX;
213 pointXBox.Adjustment.StepIncrement = 0.1;
214 pointXBox.Adjustment.PageIncrement = 1;
215 pointYBox.Adjustment.Upper = PointD.MaxY;
216 pointYBox.Adjustment.StepIncrement = 0.1;
217 pointYBox.Adjustment.PageIncrement = 1;
218 selBox.Value = ROI.selectBoxSize;
219 selBox.Adjustment.Upper = 100;
220 selBox.Adjustment.StepIncrement = 1;
221 roiView.ActivateOnSingleClick = true;
222 InitItems();
223 if (ImageView.SelectedImage != null)
225 App.ApplyStyles(this);
226 }
void UpdateAnnotationList()

Member Function Documentation

◆ CopySelection()

void Bio.ROIManager.CopySelection ( )

It takes the selected ROIs and copies them to the clipboard.

Definition at line 236 of file ROIManager.cs.

237 {
238 copys.Clear();
239 string s = "";
240 List<ROI> rois = new List<ROI>();
241 rois.AddRange(ImageView.SelectedImage.AnnotationsR);
242 rois.AddRange(ImageView.SelectedImage.AnnotationsG);
243 rois.AddRange(ImageView.SelectedImage.AnnotationsB);
244 foreach (ROI item in rois)
245 {
246 if (item.Selected)
247 {
248 copys.Add(item);
249 s += BioImage.ROIToString(item);
250 }
251 }
252 Clipboard clipboard = Clipboard.Get(Gdk.Selection.Clipboard);
253 clipboard.Text = s;
254 }

◆ Create()

static ROIManager Bio.ROIManager.Create ( )
static

Definition at line 131 of file ROIManager.cs.

132 {
133 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/ROIManager.glade", FileMode.Open));
134 return new ROIManager(builder, builder.GetObject("roiManager").Handle);
135 }

◆ InitItems()

void Bio.ROIManager.InitItems ( )

It creates a treeview with 4 columns, and then populates the treeview with the data from the Images class

Definition at line 379 of file ROIManager.cs.

380 {
381 Gtk.TreeViewColumn typeCol = new Gtk.TreeViewColumn();
382 typeCol.Title = "Type";
383 Gtk.CellRendererText typeCell = new Gtk.CellRendererText();
384 typeCol.PackStart(typeCell, true);
385
386 Gtk.TreeViewColumn idCol = new Gtk.TreeViewColumn();
387 idCol.Title = "ID";
388 Gtk.CellRendererText idCell = new Gtk.CellRendererText();
389 idCol.PackStart(idCell, true);
390
391 Gtk.TreeViewColumn textCol = new Gtk.TreeViewColumn();
392 textCol.Title = "Text";
393 Gtk.CellRendererText textCell = new Gtk.CellRendererText();
394 textCol.PackStart(textCell, true);
395
396 Gtk.TreeViewColumn rectCol = new Gtk.TreeViewColumn();
397 rectCol.Title = "Bounds";
398 Gtk.CellRendererText rectCell = new Gtk.CellRendererText();
399 rectCol.PackStart(rectCell, true);
400
401
402 roiView.AppendColumn(typeCol);
403 roiView.AppendColumn(idCol);
404 roiView.AppendColumn(textCol);
405 roiView.AppendColumn(rectCol);
406
407 typeCol.AddAttribute(typeCell, "text", 0);
408 idCol.AddAttribute(idCell, "text", 1);
409 textCol.AddAttribute(textCell, "text", 2);
410 rectCol.AddAttribute(rectCell, "text", 3);
411
412 Gtk.TreeStore store = new Gtk.TreeStore(typeof(string), typeof(string), typeof(string), typeof(string));
413
414 foreach (BioImage b in Images.images)
415 {
416 Gtk.TreeIter iter = store.AppendValues(System.IO.Path.GetFileName(b.Filename));
417 foreach (ROI r in b.Annotations)
418 {
419 store.AppendValues(iter, r.type.ToString(), r.id, r.Text, r.BoundingBox.ToString());
420 }
421 if (App.viewer != null)
422 {
423 foreach (ROI r in App.viewer.GetZarrLabelOverlaysForImage(b))
424 {
425 if (r == null || b.Annotations.Contains(r))
426 continue;
427 store.AppendValues(iter, r.type.ToString(), r.id, r.Text, r.BoundingBox.ToString());
428 }
429 }
430 }
431 roiView.Model = store;
432
433 }

◆ PasteSelection()

void Bio.ROIManager.PasteSelection ( )

The function takes the text from the clipboard and splits it into lines. Each line is then converted into an ROI object and added to the list of annotations

Definition at line 257 of file ROIManager.cs.

258 {
259 Clipboard clipboard = Clipboard.Get(Gdk.Selection.Clipboard);
260 string text = clipboard.WaitForText();
261 string[] sts = text.Split(BioImage.NewLine);
262 foreach (string line in sts)
263 {
264 if (line.Length > 8)
265 {
266 ROI an = BioImage.StringToROI(line);
267 //We set the coordinates of the ROI's we are pasting
268 an.coord = App.viewer.GetCoordinate();
269 ImageView.SelectedImage.Annotations.Add(an);
270 }
271 }
272 UpdateView();
273 }

◆ UpdateAnnotationList()

void Bio.ROIManager.UpdateAnnotationList ( )

It takes a list of images, and for each image, it takes a list of annotations, and for each annotation, it adds the annotation to a dictionary, and then adds the annotation to a treeview

Definition at line 437 of file ROIManager.cs.

438 {
439 rois.Clear();
440 Gtk.TreeStore store = new Gtk.TreeStore(typeof(string), typeof(string), typeof(string), typeof(string));
441 List<BioImage> sourceImages = new List<BioImage>(Images.images);
442 if (ImageView.SelectedImage != null && !sourceImages.Contains(ImageView.SelectedImage))
443 sourceImages.Insert(0, ImageView.SelectedImage);
444
445 foreach (BioImage b in sourceImages)
446 {
447 Gtk.TreeIter iter = store.AppendValues(System.IO.Path.GetFileName(b.Filename));
448 ROI[] annotations = b.Annotations?.ToArray() ?? Array.Empty<ROI>();
449 HashSet<ROI> annotationSet = new HashSet<ROI>(annotations.Where(r => r != null));
450 foreach (ROI r in annotations)
451 {
452 if (r == null)
453 continue;
454 if (r.id == "")
455 {
456 store.AppendValues(iter, r.type.ToString(), rng.Next(), r.Text, r.BoundingBox.ToString());
457 }
458 else
459 {
460 if(!rois.ContainsKey(r.id))
461 rois.Add(r.id, r);
462 store.AppendValues(iter, r.type.ToString(), r.id, r.Text, r.BoundingBox.ToString());
463 }
464 }
465 if (App.viewer != null)
466 {
467 ROI[] overlays = App.viewer.GetZarrLabelOverlaysForImage(b).ToArray();
468 foreach (ROI r in overlays)
469 {
470 if (r == null || annotationSet.Contains(r))
471 continue;
472 if (r.id == "")
473 {
474 store.AppendValues(iter, r.type.ToString(), rng.Next(), r.Text, r.BoundingBox.ToString());
475 }
476 else
477 {
478 if (!rois.ContainsKey(r.id))
479 rois.Add(r.id, r);
480 store.AppendValues(iter, r.type.ToString(), r.id, r.Text, r.BoundingBox.ToString());
481 }
482 }
483 }
484 }
485 roiView.Model = store;
486 }

◆ UpdatePointBox()

void Bio.ROIManager.UpdatePointBox ( )

This function updates the point box with the current point

Returns
The point of the annotation.

Definition at line 772 of file ROIManager.cs.

773 {
774 if (anno == null)
775 return;
776 PointD d = anno.GetPoint((int)pointBox.Value);
777 pointXBox.Value = (int)d.X;
778 pointYBox.Value = (int)d.Y;
779 }

◆ updateROI()

void Bio.ROIManager.updateROI ( int index,
ROI an )

‍Update the ROI at the specified index with the specified ROI

Parameters
indexthe index of the annotation to be updated
ROIThe ROI object to be updated
Returns
The ROI object is being returned.

Definition at line 499 of file ROIManager.cs.

500 {
501 if (ImageView.SelectedImage == null)
502 return;
503 ImageView.SelectedImage.Annotations[index] = an;
504 UpdateView();
505 }

Member Data Documentation

◆ anno

ROI Bio.ROIManager.anno = new ROI()

Definition at line 321 of file ROIManager.cs.

◆ autoUpdate

bool Bio.ROIManager.autoUpdate = true

Definition at line 768 of file ROIManager.cs.

◆ image

BioImage Bio.ROIManager.image

Definition at line 91 of file ROIManager.cs.

◆ showB

bool Bio.ROIManager.showB = true
static

Definition at line 716 of file ROIManager.cs.

◆ showBounds

bool Bio.ROIManager.showBounds = true
static

Definition at line 712 of file ROIManager.cs.

◆ showG

bool Bio.ROIManager.showG = true
static

Definition at line 715 of file ROIManager.cs.

◆ showR

bool Bio.ROIManager.showR = true
static

Definition at line 714 of file ROIManager.cs.

◆ showText

bool Bio.ROIManager.showText = false
static

Definition at line 713 of file ROIManager.cs.

Property Documentation

◆ rois

Dictionary<string, ROI> Bio.ROIManager.rois
staticgetset

Definition at line 93 of file ROIManager.cs.

94 {
95 get
96 {
97 ROI[] selectedAnnotations = ImageView.SelectedImage?.Annotations?.ToArray() ?? Array.Empty<ROI>();
98 foreach (var item in selectedAnnotations)
99 {
100 if (item == null)
101 continue;
102 if(!rts.ContainsKey(item.id))
103 {
104 if (item.id == "" || item.id == null)
105 item.id = rng.Next(0,999999999).ToString();
106 rts.Add(item.id, item);
107 }
108 }
109 if (App.viewer != null && ImageView.SelectedImage != null)
110 {
111 ROI[] overlays = App.viewer.GetZarrLabelOverlaysForImage(ImageView.SelectedImage).ToArray();
112 foreach (var item in overlays)
113 {
114 if (item == null)
115 continue;
116 if (!rts.ContainsKey(item.id))
117 {
118 if (item.id == "" || item.id == null)
119 item.id = rng.Next(0, 999999999).ToString();
120 rts.Add(item.id, item);
121 }
122 }
123 }
124 return rts;
125 }
126 set
127 {
128 rts = value;
129 }
130 }

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