BioImager  4.9.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
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();
26 public void UpdateAnnotationList()
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)
42 App.viewer.UpdateOverlay();
43 }
44 public void updateROI(int index, ROI an)
45 {
46 if (ImageView.SelectedImage == null)
47 return;
48 ImageView.SelectedImage.Annotations[index] = an;
49 UpdateOverlay();
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
57 UpdateOverlay();
58 }
59 private void yBox_ValueChanged(object sender, EventArgs e)
60 {
61 if (roiView.SelectedItems.Count == 0)
62 return;
63 anno.BoundingBox = new RectangleD(anno.BoundingBox.X, (double)yBox.Value, anno.BoundingBox.W, anno.BoundingBox.H);
64 UpdateOverlay();
65 }
66 private void wBox_ValueChanged(object sender, EventArgs e)
67 {
68 if (roiView.SelectedItems.Count == 0)
69 return;
70 if(anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
71 anno.BoundingBox = new RectangleD(anno.BoundingBox.X, anno.BoundingBox.Y,(double)wBox.Value, anno.BoundingBox.H);
72 UpdateOverlay();
73 }
74 private void hBox_ValueChanged(object sender, EventArgs e)
75 {
76 if (roiView.SelectedItems.Count == 0)
77 return;
78 anno.BoundingBox = new RectangleD(anno.BoundingBox.X, anno.BoundingBox.Y, anno.BoundingBox.W, (double)hBox.Value);
79 UpdateOverlay();
80 }
81 private void sBox_ValueChanged(object sender, EventArgs e)
82 {
83 if (roiView.SelectedItems.Count == 0)
84 return;
85 //anno.serie = (int)sBox.Value;
86 UpdateOverlay();
87 }
88
89 private void zBox_ValueChanged(object sender, EventArgs e)
90 {
91 if (roiView.SelectedItems.Count == 0)
92 return;
93 anno.coord.Z = (int)zBox.Value;
94 UpdateOverlay();
95 }
96 private void cBox_ValueChanged(object sender, EventArgs e)
97 {
98 if (roiView.SelectedItems.Count == 0)
99 return;
100 anno.coord.C = (int)cBox.Value;
101 UpdateOverlay();
102 }
103 private void tBox_ValueChanged(object sender, EventArgs e)
104 {
105 if (roiView.SelectedItems.Count == 0)
106 return;
107 anno.coord.T = (int)cBox.Value;
108 UpdateOverlay();
109 }
110 private void rBox_ValueChanged(object sender, EventArgs e)
111 {
112 if (roiView.SelectedItems.Count == 0)
113 return;
114 anno.strokeColor = Color.FromArgb((byte)rBox.Value, anno.strokeColor.G, anno.strokeColor.B);
115 UpdateOverlay();
116 }
117 private void gBox_ValueChanged(object sender, EventArgs e)
118 {
119 if (roiView.SelectedItems.Count == 0)
120 return;
121 anno.strokeColor = Color.FromArgb(anno.strokeColor.R, (byte)gBox.Value, anno.strokeColor.B);
122 UpdateOverlay();
123 }
124 private void bBox_ValueChanged(object sender, EventArgs e)
125 {
126 if (roiView.SelectedItems.Count == 0)
127 return;
128 anno.strokeColor = Color.FromArgb(anno.strokeColor.R, anno.strokeColor.G, (byte)bBox.Value);
129 UpdateOverlay();
130 }
131 private void typeBox_SelectedIndexChanged(object sender, EventArgs e)
132 {
133 if (roiView.SelectedItems.Count == 0)
134 return;
135 anno.type = (ROI.Type)typeBox.SelectedItem;
136 UpdateOverlay();
137 }
138 private void textBox_TextChanged(object sender, EventArgs e)
139 {
140 if (roiView.SelectedItems.Count == 0)
141 return;
142 anno.Text = textBox.Text;
143 UpdateOverlay();
144 }
145 private void idBox_TextChanged(object sender, EventArgs e)
146 {
147 if (roiView.SelectedItems.Count == 0)
148 return;
149 anno.id = idBox.Text;
150 UpdateOverlay();
151 }
152 private void ROIManager_Activated(object sender, EventArgs e)
153 {
154 if (ImageView.SelectedImage == null)
155 return;
156 string n = System.IO.Path.GetFileName(ImageView.SelectedImage.ID);
157 if (imageNameLabel.Text != n)
158 imageNameLabel.Text = n;
159 UpdateAnnotationList();
160 }
161
162 private void roiView_SelectedIndexChanged(object sender, EventArgs e)
163 {
164 if (roiView.SelectedItems.Count == 0)
165 return;
166 ListViewItem it = roiView.SelectedItems[0];
167 anno = (ROI)it.Tag;
168 if(App.viewer!=null)
169 App.viewer.SetCoordinate(anno.coord.Z, anno.coord.C, anno.coord.T);
170 if(anno.type == ROI.Type.Line || anno.type == ROI.Type.Polygon ||
171 anno.type == ROI.Type.Polyline)
172 {
173 xBox.Enabled = false;
174 yBox.Enabled = false;
175 wBox.Enabled = false;
176 hBox.Enabled = false;
177 }
178 else
179 {
180 xBox.Enabled = true;
181 yBox.Enabled = true;
182 wBox.Enabled = true;
183 hBox.Enabled = true;
184 }
185 if(anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
186 {
187 pointIndexBox.Enabled = false;
188 pointXBox.Enabled = false;
189 pointYBox.Enabled = false;
190 }
191 else
192 {
193 pointIndexBox.Enabled = true;
194 pointXBox.Enabled = true;
195 pointYBox.Enabled = true;
196 }
197 xBox.Value = (decimal)anno.X;
198 yBox.Value = (decimal)anno.Y;
199 wBox.Value = (decimal)anno.W;
200 hBox.Value = (decimal)anno.H;
201 zBox.Value = anno.coord.Z;
202 cBox.Value = anno.coord.C;
203 tBox.Value = anno.coord.T;
204 rBox.Value = anno.strokeColor.R;
205 gBox.Value = anno.strokeColor.G;
206 bBox.Value = anno.strokeColor.B;
207 strokeWBox.Value = (decimal)anno.strokeWidth;
208 idBox.Text = anno.id;
209 textBox.Text = anno.Text;
210 typeBox.SelectedIndex = (int)anno.type;
211 UpdatePointBox();
212 }
213 private void updateBut_Click(object sender, EventArgs e)
214 {
215 if (roiView.SelectedItems.Count == 0)
216 return;
217 if (ImageView.SelectedImage == null)
218 return;
219 ImageView.SelectedImage.Annotations[roiView.SelectedIndices[0]] = anno;
220 UpdateOverlay();
221 }
222 private void addButton_Click(object sender, EventArgs e)
223 {
224 ImageView.SelectedImage.Annotations.Add(anno);
225 UpdateOverlay();
226 }
227 private void showBoundsBox_CheckedChanged(object sender, EventArgs e)
228 {
229 ImageView.showBounds = showBoundsBox.Checked;
230 UpdateOverlay();
231 }
232 private void showTextBox_CheckedChanged(object sender, EventArgs e)
233 {
234 ImageView.showText = showTextBox.Checked;
235 UpdateOverlay();
236 }
237 private void pointXBox_ValueChanged(object sender, EventArgs e)
238 {
239 if (anno == null)
240 return;
241 if (anno.type == ROI.Type.Rectangle || anno.type == ROI.Type.Ellipse)
242 return;
243 anno.UpdatePoint(new PointD((double)pointXBox.Value, (double)pointYBox.Value),(int)pointIndexBox.Value);
244 UpdateOverlay();
245 }
246 private void pointYBox_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 UpdateOverlay();
254 }
255 public bool autoUpdate = true;
256 public void UpdatePointBox()
257 {
258 if (anno == null)
259 return;
260 PointD d = anno.GetPoint((int)pointIndexBox.Value);
261 pointXBox.Value = (int)d.X;
262 pointYBox.Value = (int)d.Y;
263 }
264 private void pointIndexBox_ValueChanged(object sender, EventArgs e)
265 {
266 UpdatePointBox();
267 }
268 private void fontBut_Click(object sender, EventArgs e)
269 {
270 if (anno == null)
271 return;
272 if (fontDialog.ShowDialog() != DialogResult.OK)
273 return;
274 anno.family = fontDialog.Font.FontFamily.ToString();
275 anno.fontSize = fontDialog.Font.Size;
276 }
277 private void strokeWBox_ValueChanged(object sender, EventArgs e)
278 {
279 if (anno == null)
280 return;
281 anno.strokeWidth = (int)strokeWBox.Value;
282 UpdateOverlay();
283 }
284 private void selectBoxSize_ValueChanged(object sender, EventArgs e)
285 {
286 App.viewer.UpdateSelectBoxSize((float)selectBoxSize.Value);
287 UpdateOverlay();
288 }
289 private void rChBox_CheckedChanged(object sender, EventArgs e)
290 {
291 if (App.viewer == null)
292 return;
293 App.viewer.showRROIs = rChBox.Checked;
294 UpdateOverlay();
295 }
296 private void gChBox_CheckedChanged(object sender, EventArgs e)
297 {
298 if (App.viewer == null)
299 return;
300 App.viewer.showGROIs = gChBox.Checked;
301 UpdateOverlay();
302 }
303 private void bChBox_CheckedChanged(object sender, EventArgs e)
304 {
305 if (App.viewer == null)
306 return;
307 App.viewer.showBROIs = bChBox.Checked;
308 UpdateOverlay();
309 }
310 private void ROIManager_FormClosing(object sender, FormClosingEventArgs e)
311 {
312 e.Cancel = true;
313 this.WindowState = FormWindowState.Minimized;
314 }
315
316 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
317 {
318 for (int i = 0; i < roiView.SelectedItems.Count; i++)
319 {
320 ImageView.SelectedImage.Annotations.Remove((ROI)roiView.SelectedItems[i].Tag);
321 }
322 UpdateAnnotationList();
323 UpdateOverlay();
324 }
325
326 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
327 {
328 List<ROI> annotations = new List<ROI>();
329 ROI an = (ROI)roiView.SelectedItems[0].Tag;
330 Clipboard.SetText(BioImage.ROIToString(an));
331 }
332
333 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
334 {
335
336 }
337
338 private void topMostBox_CheckedChanged(object sender, EventArgs e)
339 {
340 TopMost = topMostBox.Checked;
341 }
342 }
343}