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
StageTool.cs
Go to the documentation of this file.
1using FlaUI.Core.AutomationElements;
2using System;
3using System.Collections.Generic;
4using System.ComponentModel;
5using System.Data;
6using System.Drawing;
7using System.Linq;
8using System.Text;
9using System.Threading.Tasks;
10using System.Windows.Forms;
11using AForge;
12using Point = AForge.Point;
13using AForge.Imaging;
14using BioLib;
15namespace BioImager
16{
17 public partial class StageTool : Form
18 {
20 public StageTool()
21 {
22 InitializeComponent();
24 //panel.Controls.Add(App.stageView);
25 this.Show();
27 objBox.Items.AddRange(Microscope.Objectives.List.ToArray());
28 folderBox.Text = Properties.Settings.Default.ImagingPath;
29 dockBox.Checked = Properties.Settings.Default.DockMicro;
30 moveXBox.Value = (decimal)Microscope.GetObjectiveViewRectangle().W;
31 moveYBox.Value = (decimal)Microscope.GetObjectiveViewRectangle().H;
32 Microscope.viewSize = new PointD((double)moveXBox.Value, (double)moveYBox.Value);
33
34 timer.Start();
35 }
36 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
37 public string ImagingFolder
38 {
39 get
40 {
41 return folderBox.Text;
42 }
43 set
44 {
45 Properties.Settings.Default.ImagingPath = folderBox.Text;
46 Properties.Settings.Default.Save();
47 }
48 }
49 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
50 public string ImageName
51 {
52 get
53 {
54 return nameBox.Text;
55 }
56 set
57 {
58 nameBox.Text = value;
59 Properties.Settings.Default.ImageName = nameBox.Text;
60 Properties.Settings.Default.Save();
61 }
62 }
63 private void hideToolStripMenuItem_Click(object sender, EventArgs e)
64 {
65 panel2.Hide();
66 //panel.Width = Width;
67 }
68
69 private void toolStripMenuItem1_Click(object sender, EventArgs e)
70 {
71 panel2.Show();
72 //panel.Width -= panel2.Width;
73 }
74 private void hideToolStripMenuItem1_Click(object sender, EventArgs e)
75 {
76 panel2.Hide();
77 //panel.Width = Width;
78 }
79
80 private void showToolStripMenuItem_Click(object sender, EventArgs e)
81 {
82 panel2.Show();
83 //panel.Width -= panel2.Width;
84 }
85 private void upBut_Click(object sender, EventArgs e)
86 {
87 Microscope.MoveUp((double)moveYBox.Value);
88 App.viewer.UpdateOverlay();
89 }
90
91 private void rightBut_Click(object sender, EventArgs e)
92 {
93 Microscope.MoveRight((double)moveXBox.Value);
94 App.viewer.UpdateOverlay();
95 }
96
97 private void downBut_Click(object sender, EventArgs e)
98 {
99 Microscope.MoveDown((double)moveYBox.Value);
100 App.viewer.UpdateOverlay();
101 }
102
103 private void leftBut_Click(object sender, EventArgs e)
104 {
105 Microscope.MoveLeft((double)moveXBox.Value);
106 App.viewer.UpdateOverlay();
107 }
108
109 private void objToolStripMenuItem_Click(object sender, EventArgs e)
110 {
111 App.setup.Show();
112 }
113
114 private void imagerToolStripMenuItem_Click(object sender, EventArgs e)
115 {
116 App.imager.Show();
117 }
118
119 private void objBox_SelectedIndexChanged(object sender, EventArgs e)
120 {
121 moveXBox.Value = (decimal)Microscope.Objectives.List[objBox.SelectedIndex].ViewWidth;
122 moveYBox.Value = (decimal)Microscope.Objectives.List[objBox.SelectedIndex].ViewHeight;
123 }
124 private void setObjBut_Click(object sender, EventArgs e)
125 {
126 if (objBox.SelectedItem == null)
127 return;
128 Objectives.Objective o = (Objectives.Objective)objBox.SelectedItem;
129 Microscope.Objectives.SetPosition(o.Index);
130 }
131
132 private void topMostBox_CheckedChanged(object sender, EventArgs e)
133 {
134 TopMost = topMostBox.Checked;
135 }
136
137 private void takeImageBut_Click(object sender, EventArgs e)
138 {
139 Microscope.TakeImage();
140 }
141
142 private void stackBut_Click(object sender, EventArgs e)
143 {
144 Microscope.UpperLimit = (double)upperLimBox.Value;
145 Microscope.LowerLimit = (double)lowerLimBox.Value;
146 Microscope.fInterVal = (double)fIntervalBox.Value;
147 Microscope.SetFolder(folderBox.Text);
148 BioImage bm = Microscope.TakeImageStack();
149 App.viewer.AddImage(bm);
150 }
156 private void timer_Tick(object sender, EventArgs e)
157 {
158 if (dockBox.Checked)
159 {
160 if (!Properties.Settings.Default.PycroManager && !Properties.Settings.Default.PMicroscope)
161 {
162 //We set window location based on imaging app location.
163 Win32.Rect r = new Win32.Rect();
164 Win32.GetWindowRect(Imager.apph, ref r);
165 Point pp = new Point(r.Right - Width, r.Bottom - Height - App.imager.Height - 30);
166 this.Location = new System.Drawing.Point((int)pp.X, (int)pp.Y);
167 }
168 string s = Win32.GetActiveWindowTitle();
169 if (s != null)
170 if (s.Contains(Properties.Settings.Default.AppName))
171 {
172 if (dockBox.Checked)
173 Show();
174 else
175 {
176 if (!s.Contains("Imager"))
177 {
178 if (dockBox.Checked)
179 Hide();
180 }
181 }
182 }
183 }
184
185 }
186
191 private void dockBox_CheckedChanged(object sender, EventArgs e)
192 {
193 Properties.Settings.Default.DockMicro = dockBox.Checked;
194#if DEBUG
195 this.Location = new System.Drawing.Point(0, 0);
196#endif
197 }
198
203 private void setUpperBut_Click(object sender, EventArgs e)
204 {
205 upperLimBox.Value = (decimal)Microscope.Focus.GetFocus(true);
206 }
207
212 private void setLowerBut_Click(object sender, EventArgs e)
213 {
214 lowerLimBox.Value = (decimal)Microscope.Focus.GetFocus(true);
215 }
216
222 private void fIntervalBox_ValueChanged(object sender, EventArgs e)
223 {
224 Microscope.fInterVal = (double)fIntervalBox.Value;
225 UpdateSlices();
226 }
229 private void UpdateSlices()
230 {
231 double d = (double)upperLimBox.Value - (double)lowerLimBox.Value;
232 sliceBox.Value = (decimal)(d / (double)fIntervalBox.Value);
233 }
238 private void sliceBox_ValueChanged(object sender, EventArgs e)
239 {
240 double d = (double)upperLimBox.Value - (double)lowerLimBox.Value;
241 double interval = d / (double)sliceBox.Value;
242 double dd = interval / (double)fIntervalBox.Value;
243 fIntervalBox.Value = (decimal)interval;
244 }
245
251 private void upperLimBox_ValueChanged(object sender, EventArgs e)
252 {
253 Microscope.UpperLimit = (double)upperLimBox.Value;
254 }
255
261 private void lowerLimBox_ValueChanged(object sender, EventArgs e)
262 {
263 Microscope.LowerLimit = (double)lowerLimBox.Value;
264 }
265
270 private void nameBox_TextChanged(object sender, EventArgs e)
271 {
272 Properties.Settings.Default.ImageName = nameBox.Text;
273 Properties.Settings.Default.Save();
274 }
275
284 private void tilesBut_Click(object sender, EventArgs e)
285 {
286 ImageTiles im = new ImageTiles();
287 if (im.ShowDialog() != DialogResult.OK)
288 return;
289 Microscope.TakeTiles(im.SizeX, im.SizeY);
290 }
291
298 private void setFolderBut_Click(object sender, EventArgs e)
299 {
300 FolderBrowserDialog fs = new FolderBrowserDialog();
301 fs.Description = "Select Imaging Folder";
302 if (fs.ShowDialog() != DialogResult.OK)
303 {
304 fs.Dispose();
305 }
306 else
307 {
308 fs.Dispose();
309 folderBox.Text = fs.SelectedPath;
310 Microscope.SetFolder(fs.SelectedPath);
311 Properties.Settings.Default.ImagingPath = fs.SelectedPath;
312 }
313 }
314
320 private void moveXBox_ValueChanged(object sender, EventArgs e)
321 {
322 Microscope.viewSize = new PointD((double)moveXBox.Value, (double)moveYBox.Value);
323 if (App.viewer != null)
324 App.viewer.UpdateView();
325 }
326
332 private void moveYBox_ValueChanged(object sender, EventArgs e)
333 {
334 Microscope.viewSize = new PointD((double)moveXBox.Value, (double)moveYBox.Value);
335 if (App.viewer != null)
336 App.viewer.UpdateView();
337 }
338
339 private void goUpperBut_Click(object sender, EventArgs e)
340 {
341 Microscope.SetFocus((double)upperLimBox.Value);
342 }
343
344 private void goLowerBut_Click(object sender, EventArgs e)
345 {
346 Microscope.SetFocus((double)lowerLimBox.Value);
347 }
348
349 private void viewBut_Click(object sender, EventArgs e)
350 {
351 if (!Automation.Properties.ContainsKey("LiveView"))
352 {
353 MessageBox.Show("'LiveView' GUI Property not set. Go to automation tab and create a property corresponding to the live view GUI element.");
354 return;
355 }
356 System.Drawing.Rectangle re = Automation.Properties["LiveView"].GetBounds();
357 Microscope.SetFocus((double)upperLimBox.Value);
358 long max = long.MinValue;
359 double ud = (double)upperLimBox.Value;
360 for (double i = 0; i < (double)upperLimBox.Value; i += (double)focusInterval.Value)
361 {
362 Microscope.SetFocus((double)i);
363 System.Drawing.Graphics g;
364 System.Drawing.Bitmap b = new System.Drawing.Bitmap((int)re.Width, (int)re.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
365 g = System.Drawing.Graphics.FromImage(b);
366 g.CopyFromScreen(new System.Drawing.Point((int)re.X, (int)re.Y), new System.Drawing.Point(0, 0), new System.Drawing.Size(re.Width, re.Height));
367 Clipboard.SetImage(b);
368 System.Drawing.Imaging.BitmapData d = b.LockBits(new System.Drawing.Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
369 AForge.Bitmap bf = new AForge.Bitmap("", new UnmanagedImage(d.Scan0, b.Width, b.Height, b.Width * 4, PixelFormat.Format32bppArgb), new ZCT(), 0);
370 long dd = BioImage.CalculateFocusQuality(bf);
371 if (max < dd)
372 {
373 max = dd;
374 ud = (double)i;
375 }
376 b.UnlockBits(d);
377 g.Dispose();
378 b.Dispose();
379 }
380 Microscope.SetFocus(ud);
381 }
382 }
383}
AForge.Point Point
AForge.PointD PointD
AForge.PixelFormat PixelFormat
BioLib.BioImage BioImage
Definition TabsView.cs:15
AForge.ZCT ZCT
Definition TabsView.cs:17
static MicroscopeSetup setup
Definition App.cs:28
static Objectives Objectives
static RectangleD GetObjectiveViewRectangle()
static void Initialize()
List< Objective > List
MicroscopeSetup objectiveSetup
Definition StageTool.cs:19