4using System.Collections.Generic;
5using System.Diagnostics;
8using System.Threading.Tasks;
12using System.Runtime.InteropServices;
13using org.micromanager.@
internal;
20 public static mmcorej.CMMCore
core;
24 public static Dictionary<string, List<Conf>>
Config =
new Dictionary<string, List<Conf>>();
27 public string Class {
get;
set; }
28 public string Type {
get;
set; }
39 foreach (
string item
in Values)
48 List<Conf> configs =
new List<Conf>();
49 foreach (var conf
in Config[Class])
51 if(conf.Type == Type) configs.Add(conf);
53 return configs.ToArray();
61 Directory.SetCurrentDirectory(
"C:/Program Files/Micro-Manager-2.0/");
62 java.lang.System.setProperty(
"force.annotation.index",
"true");
64 java.lang.System.setProperty(
"org.micromanager.corej.path",
"C:/Program Files/Micro-Manager-2.0");
65 java.lang.System.setProperty(
"user.dir",
"C:/Program Files/Micro-Manager-2.0/");
66 MMStudio.main(
new string[] { });
67 studio = MMStudio.getInstance();
70 Directory.SetCurrentDirectory(Path.GetDirectoryName(Environment.ProcessPath));
76 Console.WriteLine(
"Error during Micro-Manager initialization: " + e.Message);
83 int width, height, depth, bits, channels = 0;
85 TakeImage(name,out width,out height,out depth,out bits,out channels, out bm);
87 foreach (AForge.Bitmap item in bm)
89 item.Stats = Statistics.FromBytes(item);
91 im.Buffers.AddRange(bm);
95 Resolution res =
new Resolution(width, height, im.Buffers[0].PixelFormat, rec.W / im.Buffers[0].SizeX, rec.H / im.Buffers[0].SizeY, 1, p.X, p.Y, p.Z);
96 im.Volume.Location = p;
97 im.Volume.Width = rec.W;
98 im.Volume.Height = rec.H;
99 im.UpdateCoords(1, 1, 1);
100 im.Resolutions.Add(res);
101 for (
int c = 0; c < bm.Length; c++)
103 im.Channels.Add(
new Channel(c, bm[c].BitsPerPixel, bm[c].RGBChannelsCount));
108 private static bool TakeImage(
string file, out
int width, out
int height, out
int depth, out
int bits, out
int channels, out AForge.Bitmap[] bm)
110 string fil = Path.GetFileNameWithoutExtension(file);
111 width = (int)
core.getImageWidth();
112 height = (int)
core.getImageHeight();
113 depth = (int)
core.getImageBitDepth();
114 bits = (int)
core.getBytesPerPixel();
115 channels = (int)
core.getNumberOfCameraChannels();
117 if (depth > 8 && bits == 2)
119 else if(depth > 8 && bits == 6)
121 else if (depth == 8 && bits == 3)
123 else if (depth == 8 && bits == 4)
125 bm =
new AForge.Bitmap[channels];
127 for (
int i = 0; i < channels; i++)
131 byte[] bytes = (
byte[])
core.getImage(i);
132 bm[i] =
new AForge.Bitmap(width, height, format, bytes ,
new ZCT(),
"");
136 ushort[] buf = (ushort[])
core.getImage(i);
137 byte[] bts =
new byte[buf.Length * 2];
138 for (
int b = 0; b < buf.Length; b++)
140 byte[] pl = BitConverter.GetBytes(buf[b]);
144 bm[i] =
new AForge.Bitmap(width, height, format, bts,
new ZCT(),
"");
155 core.setXYPosition(p.X, p.Y);
156 core.setPosition(p.Z);
160 core.setXYPosition(p.X, p.Y);
164 var pos =
core.getXYStagePosition();
165 var f =
core.getPosition();
166 p =
new Point3D(pos.x, pos.y, f);
170 var pos =
core.getXYStagePosition();
171 p =
new PointD(pos.x, pos.y);
182 return GetConfigs(
"ConfigGroup",
"Objective").Length;
188 public string Name {
get;
set; }
198 internal static void Initialize()
202 List.Add(
new Objective(obj.
Values[0],
int.Parse(obj.
Values[3]),
int.Parse(obj.
Values[0].Replace(
"X",
""))));
231 public string Name {
get;
set; }
240 if (
Config.ContainsKey(
"Device"))
245 if (item.
Values.Last().Contains(
"Shutter"))
254 if (
core.getShutterOpen())
262 core.setShutterOpen(shutterName,
true);
264 core.setShutterOpen(shutterName,
false);
AForge.RectangleD RectangleD
AForge.PixelFormat PixelFormat
Objective(string name, int index, int mag)
static List< Objective > List
static Conf GetObjective(int index)
static int InstalledCount
Number of Installed Objectives.
static void SetPosition(int i)
static int GetPosition(string shutterName)
static void SetPosition(string shutterName, int state)
static List< Shutter > List
static void SetExposure(float f)
static void SetPosition(PointD p)
static void SetPosition(Point3D p)
static bool Initialize(string config)
static void GetPosition(out PointD p, bool update)
static Dictionary< string, List< Conf > > Config
static Conf[] GetConfigs(string Class, string Type)
static mmcorej.CMMCore core
static void GetPosition3D(out Point3D p, bool update)
static BioImage TakeImage(string name)
static RectangleD GetViewRectangle(bool update)
static Point3D GetPosition()
override string ToString()
Conf(string Class, string Type, string[] Values)