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
Plot.cs
Go to the documentation of this file.
1using ScottPlot;
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;
11
12namespace BioImager
13{
14 public partial class Plot : Form
15 {
16 ScottPlot.Plot model;
17 string file;
18 string name;
19 Bitmap bitmap;
20 List<double[]> data = new List<double[]>();
21 static Dictionary<string, Plot> plots = new Dictionary<string, Plot>();
22 public Plot(double[] vals, string name, PlotType typ)
23 {
24 InitializeComponent();
25 model = new ScottPlot.Plot();
26 data.Add(vals);
27 if (typ == PlotType.Scatter)
28 InitScatter();
29 else
30 if (typ == PlotType.Bar)
31 InitBars();
32 }
33 public enum PlotType
34 {
35 Bar,
37 }
38 PlotType type;
39 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
41 {
42 get { return type; }
43 set { type = value; }
44 }
45 public static Dictionary<string, Plot> Plots
46 {
47 get { return plots; }
48 }
49 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
50 public List<double[]> Data
51 {
52 get { return data; }
53 set { data = value; UpdateImage(); }
54 }
55 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
57 {
58 get { return bitmap; }
59 set { bitmap = value; }
60 }
61 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
62 public ScottPlot.Plot Model
63 {
64 get { return model; }
65 set { model = value; UpdateImage(); }
66 }
69 public void UpdateImage()
70 {
71 model.SavePng(file, Width, Height);
72 this.Text = name;
73 bitmap = (Bitmap)Bitmap.FromFile(file);
74 }
76 private void InitScatter()
77 {
78 model.Clear();
79 List<Coordinates> cs = new List<Coordinates>();
80 for (int i = 0; i < data.Count; i++)
81 {
82 for (int x = 0; x < data[i].Length; x++)
83 {
84 cs.Add(new ScottPlot.Coordinates(x, data[i][x]));
85 }
86 }
87 model.Add.Scatter(cs);
88 }
91 private void InitBars()
92 {
93 model.Clear();
94 foreach (double[] items in data)
95 {
96 int i = 0;
97 List<Bar> bars = new List<Bar>();
98 foreach (double item in items)
99 {
100 Bar b = new Bar();
101 b.Value = item;
102 b.Position = i;
103 bars.Add(b);
104 i++;
105 }
106 model.Add.Bars(bars);
107 }
108 }
109
110 private void Plot_ResizeEnd(object sender, EventArgs e)
111 {
112 UpdateImage();
113 }
114
115 private void Plot_Paint(object sender, PaintEventArgs e)
116 {
117 e.Graphics.DrawImage(Image, 0, 0);
118 }
119
120 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
121 {
122 if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
123 Image.Save(saveFileDialog.FileName);
124 }
125
126 private void saveCSVToolStripMenuItem_Click(object sender, EventArgs e)
127 {
128 if (saveCSVFileDialog.ShowDialog() != DialogResult.OK) return;
129 string s = "";
130 foreach (double[] item in data)
131 {
132 for (int i = 0; i < data.Count; i++)
133 {
134 s += i + ",";
135 }
136 s += Environment.NewLine;
137 foreach (double d in item)
138 {
139 s += d + "," + Environment.NewLine;
140 }
141 }
142 File.WriteAllText(saveCSVFileDialog.FileName, s);
143 }
144 }
145}
AForge.Bitmap Bitmap
System.Drawing.Image Image
Definition ImageView.cs:16
void UpdateImage()
Definition Plot.cs:69
static Dictionary< string, Plot > Plots
Definition Plot.cs:46
ScottPlot.Plot Model
Definition Plot.cs:63
PlotType Type
Definition Plot.cs:41
Plot(double[] vals, string name, PlotType typ)
Definition Plot.cs:22