BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
ROIManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using AForge;
11using BioLib;
12using Color = AForge.Color;
13namespace BioImager
14{
15 public partial class ROIManager : Form
16 {
17 public ROIManager()
18 {
19 InitializeComponent();
20 foreach (ROI.Type item in Enum.GetValues(typeof(ROI.Type)))
21 {
22 typeBox.Items.Add(item);
23 }
24 }
25 public ROI anno = new ROI();
27 {
28 if (ImageView.SelectedImage == null)
29 return;
30 roiView.Items.Clear();
31 foreach (ROI an in ImageView.SelectedImage.Annotations)
32 {
33 ListViewItem it = new ListViewItem();
34 it.Tag = an;
35 it.Text = an.ToString();
36 roiView.Items.Add(it);
37 }
38 }
39 public void UpdateOverlay()
40 {
41 if(App.viewer != null)
43 }
44 public void updateROI(int index, ROI an)
45 {
46 if (ImageView.SelectedImage == null)
47 return;
48 ImageView.SelectedImage.Annotations[index] = an;
50 }
51 private void xBox_ValueChanged(object sender, EventArgs e)
52 {
53 if (roiView.SelectedItems.Count == 0)
54 return;
55 anno.BoundingBox = new RectangleD((double)xBox.Value, anno.BoundingBox.Y, anno.BoundingBox.W, anno.BoundingBox.H);
56 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
57 anno.Validate();
58
60 }
61 private void yBox_ValueChanged(object sender, EventArgs e)
62 {
63 if (roiView.SelectedItems.Count == 0)
64 return;
65 anno.BoundingBox = new RectangleD(anno.BoundingBox.X, (double)yBox.Value, anno.BoundingBox.W, anno.BoundingBox.H);
66 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
67 anno.Validate();
69 }
70 private void wBox_ValueChanged(object sender, EventArgs e)
71 {
72 if (roiView.SelectedItems.Count == 0)
73 return;
74 if(anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
75 {
76 anno.BoundingBox = new RectangleD(anno.BoundingBox.X, anno.BoundingBox.Y,(double)wBox.Value, anno.BoundingBox.H);
77 anno.Validate();
78 }
80 }
81 private void hBox_ValueChanged(object sender, EventArgs e)
82 {
83 if (roiView.SelectedItems.Count == 0)
84 return;
85 anno.BoundingBox = new RectangleD(anno.BoundingBox.X, anno.BoundingBox.Y, anno.BoundingBox.W, (double)hBox.Value);
86 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
87 anno.Validate();
89 }
90 private void sBox_ValueChanged(object sender, EventArgs e)
91 {
92 if (roiView.SelectedItems.Count == 0)
93 return;
94 //anno.serie = (int)sBox.Value;
96 }
97
98 private void zBox_ValueChanged(object sender, EventArgs e)
99 {
100 if (roiView.SelectedItems.Count == 0)
101 return;
102 anno.coord.Z = (int)zBox.Value;
104 }
105 private void cBox_ValueChanged(object sender, EventArgs e)
106 {
107 if (roiView.SelectedItems.Count == 0)
108 return;
109 anno.coord.C = (int)cBox.Value;
111 }
112 private void tBox_ValueChanged(object sender, EventArgs e)
113 {
114 if (roiView.SelectedItems.Count == 0)
115 return;
116 anno.coord.T = (int)cBox.Value;
118 }
119 private void rBox_ValueChanged(object sender, EventArgs e)
120 {
121 if (roiView.SelectedItems.Count == 0)
122 return;
123 anno.strokeColor = Color.FromArgb((byte)rBox.Value, anno.strokeColor.G, anno.strokeColor.B);
125 }
126 private void gBox_ValueChanged(object sender, EventArgs e)
127 {
128 if (roiView.SelectedItems.Count == 0)
129 return;
130 anno.strokeColor = Color.FromArgb(anno.strokeColor.R, (byte)gBox.Value, anno.strokeColor.B);
132 }
133 private void bBox_ValueChanged(object sender, EventArgs e)
134 {
135 if (roiView.SelectedItems.Count == 0)
136 return;
137 anno.strokeColor = Color.FromArgb(anno.strokeColor.R, anno.strokeColor.G, (byte)bBox.Value);
139 }
140 private void typeBox_SelectedIndexChanged(object sender, EventArgs e)
141 {
142 if (roiView.SelectedItems.Count == 0)
143 return;
144 anno.type = (ROI.Type)typeBox.SelectedItem;
146 }
147 private void textBox_TextChanged(object sender, EventArgs e)
148 {
149 if (roiView.SelectedItems.Count == 0)
150 return;
151 anno.Text = textBox.Text;
153 }
154 private void idBox_TextChanged(object sender, EventArgs e)
155 {
156 if (roiView.SelectedItems.Count == 0)
157 return;
158 anno.id = idBox.Text;
160 }
161 private void ROIManager_Activated(object sender, EventArgs e)
162 {
163 if (ImageView.SelectedImage == null)
164 return;
165 string n = System.IO.Path.GetFileName(ImageView.SelectedImage.ID);
166 if (imageNameLabel.Text != n)
167 imageNameLabel.Text = n;
169 }
170
171 private void roiView_SelectedIndexChanged(object sender, EventArgs e)
172 {
173 if (roiView.SelectedItems.Count == 0)
174 return;
175 ListViewItem it = roiView.SelectedItems[0];
176 anno = (ROI)it.Tag;
177 if(App.viewer!=null)
178 App.viewer.SetCoordinate(anno.coord.Z, anno.coord.C, anno.coord.T);
179 if(anno.type == ROI.Type.Line || anno.type == ROI.Type.Polygon ||
180 anno.type == ROI.Type.Polyline)
181 {
182 xBox.Enabled = false;
183 yBox.Enabled = false;
184 wBox.Enabled = false;
185 hBox.Enabled = false;
186 }
187 else
188 {
189 xBox.Enabled = true;
190 yBox.Enabled = true;
191 wBox.Enabled = true;
192 hBox.Enabled = true;
193 }
194 if(anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
195 {
196 pointIndexBox.Enabled = false;
197 pointXBox.Enabled = false;
198 pointYBox.Enabled = false;
199 }
200 else
201 {
202 pointIndexBox.Enabled = true;
203 pointXBox.Enabled = true;
204 pointYBox.Enabled = true;
205 }
206 xBox.Value = (decimal)anno.X;
207 yBox.Value = (decimal)anno.Y;
208 wBox.Value = (decimal)anno.W;
209 hBox.Value = (decimal)anno.H;
210 zBox.Value = anno.coord.Z;
211 cBox.Value = anno.coord.C;
212 tBox.Value = anno.coord.T;
213 rBox.Value = anno.strokeColor.R;
214 gBox.Value = anno.strokeColor.G;
215 bBox.Value = anno.strokeColor.B;
216 strokeWBox.Value = (decimal)anno.strokeWidth;
217 idBox.Text = anno.id;
218 textBox.Text = anno.Text;
219 typeBox.SelectedIndex = (int)anno.type;
221 }
222 private void updateBut_Click(object sender, EventArgs e)
223 {
224 if (roiView.SelectedItems.Count == 0)
225 return;
226 if (ImageView.SelectedImage == null)
227 return;
228 ImageView.SelectedImage.Annotations[roiView.SelectedIndices[0]] = anno;
230 }
231 private void addButton_Click(object sender, EventArgs e)
232 {
233 ImageView.SelectedImage.Annotations.Add(anno);
235 }
236 private void showBoundsBox_CheckedChanged(object sender, EventArgs e)
237 {
238 ImageView.showBounds = showBoundsBox.Checked;
240 }
241 private void showTextBox_CheckedChanged(object sender, EventArgs e)
242 {
243 ImageView.showText = showTextBox.Checked;
245 }
246 private void pointXBox_ValueChanged(object sender, EventArgs e)
247 {
248 if (anno == null)
249 return;
250 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
251 return;
252 anno.UpdatePoint(new PointD((double)pointXBox.Value, (double)pointYBox.Value),(int)pointIndexBox.Value);
253 anno.UpdateBoundingBox();
255 }
256 private void pointYBox_ValueChanged(object sender, EventArgs e)
257 {
258 if (anno == null)
259 return;
260 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
261 return;
262 anno.UpdatePoint(new PointD((double)pointXBox.Value, (double)pointYBox.Value), (int)pointIndexBox.Value);
263 anno.UpdateBoundingBox();
265 }
266 public bool autoUpdate = true;
267 public void UpdatePointBox()
268 {
269 if (anno == null)
270 return;
271 PointD d = anno.GetPoint((int)pointIndexBox.Value);
272 pointXBox.Value = (int)d.X;
273 pointYBox.Value = (int)d.Y;
274 }
275 private void pointIndexBox_ValueChanged(object sender, EventArgs e)
276 {
278 }
279 private void fontBut_Click(object sender, EventArgs e)
280 {
281 if (anno == null)
282 return;
283 if (fontDialog.ShowDialog() != DialogResult.OK)
284 return;
285 anno.family = fontDialog.Font.FontFamily.ToString();
286 anno.fontSize = fontDialog.Font.Size;
287 }
288 private void strokeWBox_ValueChanged(object sender, EventArgs e)
289 {
290 if (anno == null)
291 return;
292 anno.strokeWidth = (int)strokeWBox.Value;
294 }
295 private void selectBoxSize_ValueChanged(object sender, EventArgs e)
296 {
297 App.viewer.UpdateSelectBoxSize((float)selectBoxSize.Value);
299 }
300 private void rChBox_CheckedChanged(object sender, EventArgs e)
301 {
302 if (App.viewer == null)
303 return;
304 App.viewer.showRROIs = rChBox.Checked;
306 }
307 private void gChBox_CheckedChanged(object sender, EventArgs e)
308 {
309 if (App.viewer == null)
310 return;
311 App.viewer.showGROIs = gChBox.Checked;
313 }
314 private void bChBox_CheckedChanged(object sender, EventArgs e)
315 {
316 if (App.viewer == null)
317 return;
318 App.viewer.showBROIs = bChBox.Checked;
320 }
321 private void ROIManager_FormClosing(object sender, FormClosingEventArgs e)
322 {
323 e.Cancel = true;
324 this.WindowState = FormWindowState.Minimized;
325 }
326
327 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
328 {
329 for (int i = 0; i < roiView.SelectedItems.Count; i++)
330 {
331 ImageView.SelectedImage.Annotations.Remove((ROI)roiView.SelectedItems[i].Tag);
332 }
335 }
336
337 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
338 {
339 List<ROI> annotations = new List<ROI>();
340 ROI an = (ROI)roiView.SelectedItems[0].Tag;
341 Clipboard.SetText(BioImage.ROIToString(an));
342 }
343
344 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
345 {
346
347 }
348
349 private void topMostBox_CheckedChanged(object sender, EventArgs e)
350 {
351 TopMost = topMostBox.Checked;
352 }
353 }
354}
AForge.RectangleD RectangleD
AForge.Color Color
AForge.PointD PointD
BioLib.BioImage BioImage
Definition TabsView.cs:15
static ImageView viewer
Definition App.cs:23
ImageView control for image stacks, pyramidal and whole-slide-images.
static BioImage SelectedImage
Definition ImageView.cs:270
void updateROI(int index, ROI an)
Definition ROIManager.cs:44
void UpdateAnnotationList()
Definition ROIManager.cs:26