BioGTK  6.7.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
Loading...
Searching...
No Matches
Microscope.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using System.Globalization;
7
8using System.Diagnostics;
9using System.Threading;
10using System.Reflection;
11using System.IO;
12using AForge;
13
14namespace BioGTK
15{
16 public class Stage
17 {
18 /* Defining the stage and axis types. */
19 public static Type stageType;
20 public static Type axisType;
21 public static object xAxis;
22 public static object yAxis;
23 public static double minX;
24 public static double maxX;
25 public static double minY;
26 public static double maxY;
27 /* The constructor of the class Stage. */
28 public Stage()
29 {
30 PointD d = GetPosition();
31 x = GetPositionX();
32 y = GetPositionY();
33 UpdateSWLimit();
34 }
35
36 private double x;
37 private double y;
38 public double X
39 {
40 get
41 {
42 return x;
43 }
44 }
45 public double Y
46 {
47 get
48 {
49 return y;
50 }
51 }
52 public int moveWait = 250;
54 private void MoveWait()
55 {
56 Thread.Sleep(moveWait);
57 }
62 public void SetPosition(double px, double py)
63 {
64 x = px;
65 y = py;
66 }
70 public void SetPositionX(double px)
71 {
72 x = px;
73 SetPosition(px, y);
74 }
75 public void SetPositionY(double py)
76 {
77 y = py;
78 SetPosition(x, py);
79 }
80 public double GetPositionX()
81 {
82 x = GetPosition().X;
83 return x;
84 }
85 public double GetPositionY()
86 {
87 y = GetPosition().Y;
88 return y;
89 }
90 public PointD GetPosition()
91 {
92 return new PointD(x, y);
93 }
94 public void MoveUp(double m)
95 {
96 double y = GetPositionY() - m;
97 SetPositionY(y);
98 }
99 public void MoveDown(double m)
100 {
101 double y = GetPositionY() + m;
102 SetPositionY(y);
103 }
104 public void MoveRight(double m)
105 {
106 double x = GetPositionX() + m;
107 SetPositionX(x);
108 }
109 public void MoveLeft(double m)
110 {
111 double x = GetPositionX() - m;
112 SetPositionX(x);
113 }
114 public void UpdateSWLimit()
115 {
116
117 }
118 public void SetSWLimit(double xmin, double xmax, double ymin, double ymax)
119 {
120 }
121 }
122 public class Focus
123 {
124 public static Type focusType;
125 public static Type axisType;
126 public static object focus;
127 public static double upperLimit;
128 public static double lowerLimit;
129 private static double z;
130 public Focus()
131 {
132 }
133 public void SetFocus(double f)
134 {
135 }
136 public double GetFocus()
137 {
138 return z;
139 }
140 public PointD GetSWLimit()
141 {
142 return new PointD(lowerLimit, upperLimit);
143 }
144 public void SetSWLimit(double xd, double yd)
145 {
146 upperLimit = xd;
147 lowerLimit = yd;
148 }
149 }
150
151 /* The class is a wrapper for a list of objectives. */
152 public class Objectives
153 {
154 public List<Objective> List = new List<Objective>();
155 public static Type changerType = null;
156 public static object changer;
157
158 public Objectives()
159 {
160
161 }
162 public class Objective
163 {
164 public Dictionary<string, object> config = new Dictionary<string, object>();
165 public string Name = "";
166 public string UniqueName = "";
167 public string ElementType = "";
168 public bool Oil = false;
169 public int Magnification = 0;
170 public float NumericAperture = 0;
171 public int Index;
172 public string Modes = "";
173 public string Features = "";
174 public double LocateExposure = 50;
175 public int WorkingDistance = 0;
176 public double AcquisitionExposure = 50;
177 public string Configuration = "";
178 public double MoveAmountL = 40;
179 public double MoveAmountR = 10;
180 public double FocusMoveAmount = 0.02;
181 public double ViewWidth;
182 public double ViewHeight;
183 public Objective(object o, int index)
184 {
185 Index = index;
186 }
187 public Objective()
188 {
189 }
190 public override string ToString()
191 {
192 return Name.ToString() + " " + Index;
193 }
194 }
195 private int index;
196 public int moveWait = 1000;
197 private void MoveWait()
198 {
199 Thread.Sleep(moveWait);
200 }
201 public int Index
202 {
203 get
204 {
205 return GetPosition();
206 }
207 set
208 {
209 SetPosition(value);
210 }
211 }
212 public void SetPosition(int index)
213 {
214 this.index = index;
215 }
216 public int GetPosition()
217 {
218 return index;
219 }
220 public Objective GetObjective()
221 {
222 return List[index];
223 }
224 }
225
226
227 /* The class is a wrapper for the TLShutter class in the
228
229 The class is used to control the shutter.
230
231 The class is used in the following way:
232
233 1. Create an instance of the class.
234 2. Call the GetPosition() method to get the current position of the shutter.
235 3. Call the SetPosition() method to set the position of the shutter.
236
237 The GetPosition() method returns a short.
238
239 The SetPosition() method takes an int as an argument.
240
241 The SetPosition() method sets the position of the shutter.
242
243 /* The class is a wrapper for the TLShutter class*/
244 public class TLShutter
245 {
246 public static Type tlType;
247 public static object tlShutter = null;
248 public static int position;
249 public TLShutter()
250 {
251
252 }
253 public short GetPosition()
254 {
255 return (short)position;
256 }
257 public void SetPosition(int p)
258 {
259 position = p;
260 }
261 }
262
263 /* It's a class that has a static variable that holds the position of the shutter. */
264 public class RLShutter
265 {
266 public static Type rlType;
267 public static object rlShutter = null;
268 public static int position;
269 public RLShutter()
270 {
271 }
272 public short GetPosition()
273 {
274 return (short)position;
275 }
276 public void SetPosition(int p)
277 {
278 position = p;
279 }
280 }
281
282 public static class Microscope
283 {
284 /* Defining an enum. */
285 public enum Actions
286 {
287 StageUp,
288 StageRight,
289 StageDown,
290 StageLeft,
291 StageFieldUp,
292 StageFieldRight,
293 StageFieldDown,
294 StageFieldLeft,
295 FocusUp,
296 FocusDown,
297 TL,
298 RL,
299 Acquisition,
300 Locate,
301 }
302 public static bool redraw = false;
303 public static Focus Focus = null;
304 public static Stage Stage = null;
305 public static Objectives Objectives = null;
306 public static TLShutter TLShutter = null;
307 public static RLShutter RLShutter = null;
308 public static double UpperLimit, LowerLimit, fInterVal;
309 public static object CmdSetMode = null;
310 public static bool initialized = false;
311 public static bool ArrowKeysEnabled = true;
312 public static Point3D defaultPos = new Point3D(30000, 30000, 23900);
313 public static Assembly dll = null;
314 public static Dictionary<string, Type> Types = new Dictionary<string, Type>();
315 public static object root = null;
320 public static void Initialize()
321 {
322 if (initialized)
323 return;
324 Point3D.SetLimits(Stage.minX, Stage.maxX, Stage.minY, Stage.maxY, Focus.lowerLimit, Focus.upperLimit);
325 PointD.SetLimits(Stage.minX, Stage.maxX, Stage.minY, Stage.maxY);
326 Focus = new Focus();
327 Stage = new Stage();
328 Objectives = new Objectives();
329 TLShutter = new TLShutter();
330 RLShutter = new RLShutter();
331 initialized = true;
332 }
337 public static Point3D GetPosition()
338 {
339 if (Stage == null)
340 return new Point3D(0,0,0);
341 PointD p = Stage.GetPosition();
342 double f = Focus.GetFocus();
343 return new Point3D(p.X, p.Y, f);
344 }
345
349 public static void SetPosition(Point3D p)
350 {
351 Stage.SetPosition(p.X,p.Y);
352 Focus.SetFocus(p.Z);
353 Microscope.redraw = true;
354 }
355
360 public static void SetPosition(PointD p)
361 {
362 Stage.SetPosition(p.X, p.Y);
363 Microscope.redraw = true;
364 }
366 public static void OpenRL()
367 {
368 //If shutter is closed we open it.
369 if (RLShutter.GetPosition() == 0)
370 RLShutter.SetPosition(1);
371 }
372
374 public static void OpenTL()
375 {
376 //If shutter is closed we open it.
377 if (TLShutter.GetPosition() == 0)
378 TLShutter.SetPosition(1);
379 }
380
382 public static void CloseRL()
383 {
384 //If shutter is open then we close it.
385 if (RLShutter.GetPosition() == 0)
386 RLShutter.SetPosition(1);
387 }
388
390 public static void CloseTL()
391 {
392 //If shutter is open then we close it.
393 if (TLShutter.GetPosition() == 0)
394 TLShutter.SetPosition(1);
395 }
396
400 public static void SetTL(uint tl)
401 {
402 TLShutter.SetPosition((short)tl);
403 }
404
409 public static void SetRL(uint tr)
410 {
411 RLShutter.SetPosition((short)tr);
412 }
413
417 public static int GetTL()
418 {
419 return TLShutter.GetPosition();
420 }
421
425 public static int GetRL()
426 {
427 return RLShutter.GetPosition();
428 }
429
433 public static void MoveUp(double d)
434 {
435 Stage.MoveUp(d);
436 }
437
441 public static void MoveRight(double d)
442 {
443 Stage.MoveRight(d);
444 }
445
449 public static void MoveDown(double d)
450 {
451 Stage.MoveDown(d);
452 }
453
457 public static void MoveLeft(double d)
458 {
459 Stage.MoveLeft(d);
460 }
462 public static void MoveFieldUp()
463 {
464 Stage.MoveUp(Objectives.GetObjective().ViewHeight);
465 }
466
468 public static void MoveFieldRight()
469 {
470 Stage.MoveRight(Objectives.GetObjective().ViewWidth);
471 }
472
474 public static void MoveFieldDown()
475 {
476 Stage.MoveDown(Objectives.GetObjective().ViewHeight);
477 }
478
480 public static void MoveFieldLeft()
481 {
482 Stage.MoveLeft(Objectives.GetObjective().ViewWidth);
483 }
484
488 public static void SetFocus(double d)
489 {
490 Focus.SetFocus(d);
491 }
492
496 public static double GetFocus()
497 {
498 return Focus.GetFocus();
499 }
500 }
501
502}
void SetPositionX(double px)
Definition Microscope.cs:70
void SetPosition(double px, double py)
Definition Microscope.cs:62
Definition ML.cs:17