21 private Builder _builder;
23#pragma warning disable 649
25 private TreeView roiView;
27 private SpinButton xBox;
29 private SpinButton yBox;
31 private SpinButton wBox;
33 private SpinButton hBox;
35 private SpinButton zBox;
37 private SpinButton cBox;
39 private SpinButton tBox;
41 private SpinButton widthBox;
43 private SpinButton rBox;
45 private SpinButton gBox;
47 private SpinButton bBox;
49 private Label typeLabel;
51 private Entry textBox;
55 private SpinButton pointBox;
57 private SpinButton pointXBox;
59 private SpinButton pointYBox;
61 private SpinButton selBox;
63 private FontButton fontBut;
65 private CheckButton boundsBox;
67 private CheckButton showTextBox;
69 private CheckButton showRBox;
71 private CheckButton showGBox;
73 private CheckButton showBBox;
75 private Label imageNameLabel;
77 private CheckButton showMasksBox;
81 private MenuItem menuDelete;
83 private MenuItem menuCopy;
85 private MenuItem menuPaste;
86#pragma warning restore 649
89 private static Random rng =
new Random();
90 #region Constructors / Destructors
91 public BioImage image;
92 private static Dictionary<string, ROI> rts =
new Dictionary<string, ROI>();
93 public static Dictionary<string, ROI> rois
97 foreach (var item
in ImageView.SelectedImage.Annotations)
99 if(!rts.ContainsKey(item.id))
101 if (item.id ==
"" || item.id ==
null)
102 item.id = rng.Next(0,999999).ToString();
103 rts.Add(item.id, item);
115 Builder builder =
new Builder(
new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) +
"/" +
"Glade/ROIManager.glade", FileMode.Open));
116 return new ROIManager(builder, builder.GetObject(
"roiManager").Handle);
119 protected ROIManager(Builder builder, IntPtr handle) : base(handle)
122 builder.Autoconnect(
this);
123 xBox.ValueChanged += xBox_ValueChanged;
124 yBox.ValueChanged += yBox_ValueChanged;
125 wBox.ValueChanged += wBox_ValueChanged;
126 hBox.ValueChanged += hBox_ValueChanged;
127 rBox.ValueChanged += rBox_ValueChanged;
128 gBox.ValueChanged += gBox_ValueChanged;
129 bBox.ValueChanged += bBox_ValueChanged;
130 zBox.ValueChanged += zBox_ValueChanged;
131 cBox.ValueChanged += cBox_ValueChanged;
132 tBox.ValueChanged += tBox_ValueChanged;
133 widthBox.ValueChanged += strokeWBox_ValueChanged;
134 pointXBox.ValueChanged += pointXBox_ValueChanged;
135 pointYBox.ValueChanged += pointYBox_ValueChanged;
136 pointBox.ValueChanged += pointBox_ValueChanged;
137 selBox.ValueChanged += selectBoxSize_ValueChanged;
138 widthBox.ValueChanged += strokeWBox_ValueChanged;
139 textBox.Changed += textBox_TextChanged;
140 idBox.Changed += idBox_TextChanged;
141 boundsBox.Clicked += showBoundsBox_ActiveChanged;
142 showTextBox.Clicked += showTextBox_ActiveChanged;
143 showRBox.Clicked += showRBox_ActiveChanged;
144 showGBox.Clicked += showGBox_ActiveChanged;
145 showBBox.Clicked += showBBox_ActiveChanged;
146 showMasksBox.Clicked += ShowMasksBox_Clicked;
147 this.DeleteEvent += ROIManager_DeleteEvent;
148 menuDelete.ButtonPressEvent += MenuDelete_ButtonPressEvent;
149 menuCopy.ButtonPressEvent += MenuCopy_ButtonPressEvent;
150 menuPaste.ButtonPressEvent += MenuPaste_ButtonPressEvent;
153 roiView.RowActivated += RoiView_RowActivated;
154 this.FocusInEvent += ROIManager_FocusInEvent;
155 this.FocusActivated += ROIManager_Activated;
156 roiView.ButtonPressEvent += RoiView_ButtonPressEvent;
158 xBox.Adjustment.Upper = PointD.MaxX;
159 xBox.Adjustment.StepIncrement= 0.1;
160 xBox.Adjustment.PageIncrement= 1;
161 yBox.Adjustment.Upper = PointD.MaxY;
162 yBox.Adjustment.StepIncrement = 0.1;
163 yBox.Adjustment.PageIncrement = 1;
164 wBox.Adjustment.Upper = PointD.MaxX;
165 wBox.Adjustment.StepIncrement = 0.1;
166 wBox.Adjustment.PageIncrement = 1;
167 hBox.Adjustment.Upper = PointD.MaxY;
168 xBox.Adjustment.StepIncrement = 0.1;
169 xBox.Adjustment.PageIncrement = 1;
170 rBox.Adjustment.Upper =
byte.MaxValue;
171 rBox.Adjustment.StepIncrement = 1;
172 rBox.Adjustment.PageIncrement = 1;
173 gBox.Adjustment.Upper =
byte.MaxValue;
174 gBox.Adjustment.StepIncrement = 1;
175 gBox.Adjustment.PageIncrement = 1;
176 bBox.Adjustment.Upper =
byte.MaxValue;
177 bBox.Adjustment.StepIncrement = 1;
178 bBox.Adjustment.PageIncrement = 1;
179 zBox.Adjustment.Upper = 10000;
180 zBox.Adjustment.StepIncrement = 1;
181 zBox.Adjustment.PageIncrement = 1;
182 cBox.Adjustment.Upper = 10000;
183 cBox.Adjustment.StepIncrement = 1;
184 cBox.Adjustment.PageIncrement = 1;
185 tBox.Adjustment.Upper = 10000;
186 tBox.Adjustment.StepIncrement = 1;
187 tBox.Adjustment.PageIncrement = 1;
188 widthBox.Adjustment.Upper = 100;
189 widthBox.Adjustment.StepIncrement = 1;
190 widthBox.Adjustment.PageIncrement = 1;
191 pointBox.Adjustment.Upper = 100000;
192 pointBox.Adjustment.StepIncrement = 1;
193 pointBox.Adjustment.PageIncrement = 1;
194 pointXBox.Adjustment.Upper = PointD.MaxX;
195 pointXBox.Adjustment.StepIncrement = 0.1;
196 pointXBox.Adjustment.PageIncrement = 1;
197 pointYBox.Adjustment.Upper = PointD.MaxY;
198 pointYBox.Adjustment.StepIncrement = 0.1;
199 pointYBox.Adjustment.PageIncrement = 1;
200 selBox.Value = ROI.selectBoxSize;
201 selBox.Adjustment.Upper = 100;
202 selBox.Adjustment.StepIncrement = 1;
203 roiView.ActivateOnSingleClick =
true;
205 App.ApplyStyles(
this);
208 private void RoiView_ButtonPressEvent(
object o, ButtonPressEventArgs args)
210 if (args.Event.Button == 3)
214 private List<ROI> copys =
new List<ROI>();
220 List<ROI> rois =
new List<ROI>();
221 rois.AddRange(
ImageView.SelectedImage.AnnotationsR);
222 rois.AddRange(
ImageView.SelectedImage.AnnotationsG);
223 rois.AddRange(
ImageView.SelectedImage.AnnotationsB);
224 foreach (ROI item
in rois)
229 s += BioImage.ROIToString(item);
232 Clipboard clipboard = Clipboard.Get(Gdk.Selection.Clipboard);
239 Clipboard clipboard = Clipboard.Get(Gdk.Selection.Clipboard);
240 string text = clipboard.WaitForText();
241 string[] sts = text.Split(BioImage.NewLine);
242 foreach (
string line
in sts)
246 ROI an = BioImage.StringToROI(line);
248 an.coord = App.viewer.GetCoordinate();
249 ImageView.SelectedImage.Annotations.Add(an);
256 private void MenuPaste_ButtonPressEvent(
object o, ButtonPressEventArgs args)
261 private void MenuCopy_ButtonPressEvent(
object o, ButtonPressEventArgs args)
266 private void MenuDelete_ButtonPressEvent(
object o, ButtonPressEventArgs args)
268 if (anno !=
null &&
ImageView.SelectedImage !=
null)
271 ImageView.SelectedImage.Annotations.Remove(anno);
276 private void ShowMasksBox_Clicked(
object sender, EventArgs e)
278 App.viewer.ShowMasks = showMasksBox.Active;
282 private void ROIManager_DeleteEvent(
object o, DeleteEventArgs args)
293 private void ROIManager_FocusInEvent(
object o, FocusInEventArgs args)
301 public ROI anno =
new ROI();
311 private void RoiView_RowActivated(
object o, RowActivatedArgs args)
314 if (roiView.Model.GetIter(out iter, args.Path))
316 string type = (string)roiView.Model.GetValue(iter, 0);
318 if (Enum.TryParse<ROI.Type>(type,out t))
320 string id = (string)roiView.Model.GetValue(iter, 1);
321 string text = (string)roiView.Model.GetValue(iter, 2);
322 string bounds = (string)roiView.Model.GetValue(iter, 3);
323 if (rois.ContainsKey(
id))
326 if (App.viewer !=
null)
327 App.viewer.SetCoordinate(anno.coord.Z, anno.coord.C, anno.coord.T);
332 zBox.Value = anno.coord.Z;
333 cBox.Value = anno.coord.C;
334 tBox.Value = anno.coord.T;
335 rBox.Value = anno.strokeColor.R;
336 gBox.Value = anno.strokeColor.G;
337 bBox.Value = anno.strokeColor.B;
338 widthBox.Value = anno.strokeWidth;
339 idBox.Text = anno.id;
340 textBox.Text = anno.Text;
341 typeLabel.Text = anno.type.ToString();
342 imageNameLabel.Text =
ImageView.SelectedImage.Filename;
346 App.viewer.PyramidalOrigin =
new PointD((
int)(anno.X), (
int)(anno.Y));
347 App.viewer.UpdateView(
true);
361 Gtk.TreeViewColumn typeCol =
new Gtk.TreeViewColumn();
362 typeCol.Title =
"Type";
363 Gtk.CellRendererText typeCell =
new Gtk.CellRendererText();
364 typeCol.PackStart(typeCell,
true);
366 Gtk.TreeViewColumn idCol =
new Gtk.TreeViewColumn();
368 Gtk.CellRendererText idCell =
new Gtk.CellRendererText();
369 idCol.PackStart(idCell,
true);
371 Gtk.TreeViewColumn textCol =
new Gtk.TreeViewColumn();
372 textCol.Title =
"Text";
373 Gtk.CellRendererText textCell =
new Gtk.CellRendererText();
374 textCol.PackStart(textCell,
true);
376 Gtk.TreeViewColumn rectCol =
new Gtk.TreeViewColumn();
377 rectCol.Title =
"Bounds";
378 Gtk.CellRendererText rectCell =
new Gtk.CellRendererText();
379 rectCol.PackStart(rectCell,
true);
382 roiView.AppendColumn(typeCol);
383 roiView.AppendColumn(idCol);
384 roiView.AppendColumn(textCol);
385 roiView.AppendColumn(rectCol);
387 typeCol.AddAttribute(typeCell,
"text", 0);
388 idCol.AddAttribute(idCell,
"text", 1);
389 textCol.AddAttribute(textCell,
"text", 2);
390 rectCol.AddAttribute(rectCell,
"text", 3);
392 Gtk.TreeStore store =
new Gtk.TreeStore(typeof(
string), typeof(
string), typeof(
string), typeof(
string));
394 foreach (BioImage b
in Images.images)
396 Gtk.TreeIter iter = store.AppendValues(System.IO.Path.GetFileName(b.Filename));
397 foreach (ROI r
in b.Annotations)
399 store.AppendValues(iter, r.type.ToString(), r.id, r.Text, r.BoundingBox.ToString());
402 roiView.Model = store;
411 Gtk.TreeStore store =
new Gtk.TreeStore(typeof(
string), typeof(
string), typeof(
string), typeof(
string));
412 foreach (BioImage b
in Images.images)
414 Gtk.TreeIter iter = store.AppendValues(System.IO.Path.GetFileName(b.Filename));
415 foreach (ROI r
in b.Annotations)
419 store.AppendValues(iter, r.type.ToString(), rng.Next(), r.Text, r.BoundingBox.ToString());
423 if(!rois.ContainsKey(r.id))
425 store.AppendValues(iter, r.type.ToString(), r.id, r.Text, r.BoundingBox.ToString());
429 roiView.Model = store;
433 private void UpdateView()
435 App.viewer.UpdateView();
447 ImageView.SelectedImage.Annotations[index] = an;
456 private void xBox_ValueChanged(
object sender, EventArgs e)
460 anno.BoundingBox =
new RectangleD(xBox.Value, anno.Y, anno.W, anno.H);
470 private void yBox_ValueChanged(
object sender, EventArgs e)
474 anno.BoundingBox =
new RectangleD(anno.X, yBox.Value, anno.W, anno.H);
483 private void wBox_ValueChanged(
object sender, EventArgs e)
487 if(anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
488 anno.BoundingBox =
new RectangleD(anno.X, anno.Y, wBox.Value, anno.H);
497 private void hBox_ValueChanged(
object sender, EventArgs e)
501 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
502 anno.BoundingBox =
new RectangleD(anno.X, anno.Y, anno.W, hBox.Value);
511 private void sBox_ValueChanged(
object sender, EventArgs e)
525 private void zBox_ValueChanged(
object sender, EventArgs e)
529 anno.coord.Z = (int)zBox.Value;
539 private void cBox_ValueChanged(
object sender, EventArgs e)
543 anno.coord.C = (int)cBox.Value;
553 private void tBox_ValueChanged(
object sender, EventArgs e)
557 anno.coord.T = (int)cBox.Value;
567 private void rBox_ValueChanged(
object sender, EventArgs e)
571 anno.strokeColor = Color.FromArgb((
byte)rBox.Value, anno.strokeColor.G, anno.strokeColor.B);
581 private void gBox_ValueChanged(
object sender, EventArgs e)
585 anno.strokeColor = Color.FromArgb(anno.strokeColor.R, (
byte)gBox.Value, anno.strokeColor.B);
595 private void bBox_ValueChanged(
object sender, EventArgs e)
599 anno.strokeColor = Color.FromArgb(anno.strokeColor.R, anno.strokeColor.G, (
byte)bBox.Value);
609 private void textBox_TextChanged(
object sender, EventArgs e)
613 anno.Text = textBox.Text;
623 private void idBox_TextChanged(
object sender, EventArgs e)
627 anno.id = idBox.Text;
637 private void ROIManager_Activated(
object sender, EventArgs e)
641 string n = System.IO.Path.GetFileName(
ImageView.SelectedImage.ID);
642 if (imageNameLabel.Text != n)
643 imageNameLabel.Text = n;
651 private void addButton_Click(
object sender, EventArgs e)
653 ImageView.SelectedImage.Annotations.Add(anno);
656 public static bool showBounds =
true;
657 public static bool showText =
false;
658 public static bool showR =
true;
659 public static bool showG =
true;
660 public static bool showB =
true;
665 private void showBoundsBox_ActiveChanged(
object sender, EventArgs e)
667 showBounds = boundsBox.Active;
674 private void showTextBox_ActiveChanged(
object sender, EventArgs e)
676 showText = showTextBox.Active;
687 private void pointXBox_ValueChanged(
object sender, EventArgs e)
691 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
693 anno.UpdatePoint(
new PointD((
double)pointXBox.Value, (
double)pointYBox.Value),(
int)pointBox.Value);
703 private void pointYBox_ValueChanged(
object sender, EventArgs e)
707 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
709 anno.UpdatePoint(
new PointD((
double)pointXBox.Value, (
double)pointYBox.Value), (
int)pointBox.Value);
712 public bool autoUpdate =
true;
720 PointD d = anno.GetPoint((
int)pointBox.Value);
721 pointXBox.Value = (int)d.X;
722 pointYBox.Value = (int)d.Y;
728 private void pointBox_ValueChanged(
object sender, EventArgs e)
739 private void strokeWBox_ValueChanged(
object sender, EventArgs e)
743 anno.strokeWidth = (int)widthBox.Value;
751 private void selectBoxSize_ValueChanged(
object sender, EventArgs e)
753 ROI.selectBoxSize = (int)widthBox.Value;
762 private void showRBox_ActiveChanged(
object sender, EventArgs e)
764 if (App.viewer ==
null)
766 App.viewer.showRROIs = showRBox.Active;
775 private void showGBox_ActiveChanged(
object sender, EventArgs e)
777 if (App.viewer ==
null)
779 App.viewer.showGROIs = showGBox.Active;
789 private void showBBox_ActiveChanged(
object sender, EventArgs e)
791 if (App.viewer ==
null)
793 App.viewer.showBROIs = showBBox.Active;
801 private void saveToolStripMenuItem_Click(
object sender, EventArgs e)