2using System.Collections.Generic;
3using System.ComponentModel;
8using System.Threading.Tasks;
9using System.Windows.Forms;
12using Color = AForge.Color;
15 public partial class ROIManager : Form
19 InitializeComponent();
20 foreach (ROI.Type item in Enum.GetValues(typeof(ROI.Type)))
22 typeBox.Items.Add(item);
25 public ROI
anno =
new ROI();
30 roiView.Items.Clear();
33 ListViewItem it =
new ListViewItem();
35 it.Text = an.ToString();
36 roiView.Items.Add(it);
51 private void xBox_ValueChanged(
object sender, EventArgs e)
53 if (roiView.SelectedItems.Count == 0)
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)
61 private void yBox_ValueChanged(
object sender, EventArgs e)
63 if (roiView.SelectedItems.Count == 0)
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)
70 private void wBox_ValueChanged(
object sender, EventArgs e)
72 if (roiView.SelectedItems.Count == 0)
74 if(
anno.type == ROI.Type.Rectangle ||
anno.type == ROI.Type.Ellipse)
76 anno.BoundingBox =
new RectangleD(
anno.BoundingBox.X,
anno.BoundingBox.Y,(
double)wBox.Value,
anno.BoundingBox.H);
81 private void hBox_ValueChanged(
object sender, EventArgs e)
83 if (roiView.SelectedItems.Count == 0)
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)
90 private void sBox_ValueChanged(
object sender, EventArgs e)
92 if (roiView.SelectedItems.Count == 0)
98 private void zBox_ValueChanged(
object sender, EventArgs e)
100 if (roiView.SelectedItems.Count == 0)
102 anno.coord.Z = (int)zBox.Value;
105 private void cBox_ValueChanged(
object sender, EventArgs e)
107 if (roiView.SelectedItems.Count == 0)
109 anno.coord.C = (int)cBox.Value;
112 private void tBox_ValueChanged(
object sender, EventArgs e)
114 if (roiView.SelectedItems.Count == 0)
116 anno.coord.T = (int)cBox.Value;
119 private void rBox_ValueChanged(
object sender, EventArgs e)
121 if (roiView.SelectedItems.Count == 0)
123 anno.strokeColor =
Color.FromArgb((
byte)rBox.Value,
anno.strokeColor.G,
anno.strokeColor.B);
126 private void gBox_ValueChanged(
object sender, EventArgs e)
128 if (roiView.SelectedItems.Count == 0)
130 anno.strokeColor =
Color.FromArgb(
anno.strokeColor.R, (
byte)gBox.Value,
anno.strokeColor.B);
133 private void bBox_ValueChanged(
object sender, EventArgs e)
135 if (roiView.SelectedItems.Count == 0)
137 anno.strokeColor =
Color.FromArgb(
anno.strokeColor.R,
anno.strokeColor.G, (
byte)bBox.Value);
140 private void typeBox_SelectedIndexChanged(
object sender, EventArgs e)
142 if (roiView.SelectedItems.Count == 0)
144 anno.type = (ROI.Type)typeBox.SelectedItem;
147 private void textBox_TextChanged(
object sender, EventArgs e)
149 if (roiView.SelectedItems.Count == 0)
151 anno.Text = textBox.Text;
154 private void idBox_TextChanged(
object sender, EventArgs e)
156 if (roiView.SelectedItems.Count == 0)
158 anno.id = idBox.Text;
161 private void ROIManager_Activated(
object sender, EventArgs e)
163 if (ImageView.SelectedImage ==
null)
165 string n = System.IO.Path.GetFileName(ImageView.SelectedImage.ID);
166 if (imageNameLabel.Text != n)
167 imageNameLabel.Text = n;
171 private void roiView_SelectedIndexChanged(
object sender, EventArgs e)
173 if (roiView.SelectedItems.Count == 0)
175 ListViewItem it = roiView.SelectedItems[0];
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)
182 xBox.Enabled =
false;
183 yBox.Enabled =
false;
184 wBox.Enabled =
false;
185 hBox.Enabled =
false;
194 if(
anno.type == ROI.Type.Rectangle ||
anno.type == ROI.Type.Ellipse)
196 pointIndexBox.Enabled =
false;
197 pointXBox.Enabled =
false;
198 pointYBox.Enabled =
false;
202 pointIndexBox.Enabled =
true;
203 pointXBox.Enabled =
true;
204 pointYBox.Enabled =
true;
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;
222 private void updateBut_Click(
object sender, EventArgs e)
224 if (roiView.SelectedItems.Count == 0)
226 if (ImageView.SelectedImage ==
null)
228 ImageView.SelectedImage.Annotations[roiView.SelectedIndices[0]] =
anno;
231 private void addButton_Click(
object sender, EventArgs e)
233 ImageView.SelectedImage.Annotations.Add(
anno);
236 private void showBoundsBox_CheckedChanged(
object sender, EventArgs e)
238 ImageView.showBounds = showBoundsBox.Checked;
241 private void showTextBox_CheckedChanged(
object sender, EventArgs e)
243 ImageView.showText = showTextBox.Checked;
246 private void pointXBox_ValueChanged(
object sender, EventArgs e)
250 if (
anno.type == ROI.Type.Rectangle ||
anno.type == ROI.Type.Ellipse)
252 anno.UpdatePoint(
new PointD((
double)pointXBox.Value, (
double)pointYBox.Value),(
int)pointIndexBox.Value);
253 anno.UpdateBoundingBox();
256 private void pointYBox_ValueChanged(
object sender, EventArgs e)
260 if (
anno.type == ROI.Type.Rectangle ||
anno.type == ROI.Type.Ellipse)
262 anno.UpdatePoint(
new PointD((
double)pointXBox.Value, (
double)pointYBox.Value), (
int)pointIndexBox.Value);
263 anno.UpdateBoundingBox();
271 PointD d =
anno.GetPoint((
int)pointIndexBox.Value);
272 pointXBox.Value = (int)d.X;
273 pointYBox.Value = (int)d.Y;
275 private void pointIndexBox_ValueChanged(
object sender, EventArgs e)
279 private void fontBut_Click(
object sender, EventArgs e)
283 if (fontDialog.ShowDialog() != DialogResult.OK)
285 anno.family = fontDialog.Font.FontFamily.ToString();
286 anno.fontSize = fontDialog.Font.Size;
288 private void strokeWBox_ValueChanged(
object sender, EventArgs e)
292 anno.strokeWidth = (int)strokeWBox.Value;
295 private void selectBoxSize_ValueChanged(
object sender, EventArgs e)
297 App.viewer.UpdateSelectBoxSize((
float)selectBoxSize.Value);
300 private void rChBox_CheckedChanged(
object sender, EventArgs e)
302 if (App.viewer ==
null)
304 App.viewer.showRROIs = rChBox.Checked;
307 private void gChBox_CheckedChanged(
object sender, EventArgs e)
309 if (App.viewer ==
null)
311 App.viewer.showGROIs = gChBox.Checked;
314 private void bChBox_CheckedChanged(
object sender, EventArgs e)
316 if (App.viewer ==
null)
318 App.viewer.showBROIs = bChBox.Checked;
321 private void ROIManager_FormClosing(
object sender, FormClosingEventArgs e)
324 this.WindowState = FormWindowState.Minimized;
327 private void deleteToolStripMenuItem_Click(
object sender, EventArgs e)
329 for (
int i = 0; i < roiView.SelectedItems.Count; i++)
331 ImageView.SelectedImage.Annotations.Remove((ROI)roiView.SelectedItems[i].Tag);
337 private void copyToolStripMenuItem_Click(
object sender, EventArgs e)
339 List<ROI> annotations =
new List<ROI>();
340 ROI an = (ROI)roiView.SelectedItems[0].Tag;
341 Clipboard.SetText(
BioImage.ROIToString(an));
344 private void saveToolStripMenuItem_Click(
object sender, EventArgs e)
349 private void topMostBox_CheckedChanged(
object sender, EventArgs e)
351 TopMost = topMostBox.Checked;
AForge.RectangleD RectangleD
ImageView control for image stacks, pyramidal and whole-slide-images.
static BioImage SelectedImage
void updateROI(int index, ROI an)
void UpdateAnnotationList()