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
ApplyFilter.cs
1
2using System;
3using BioGTK;
4using Gtk;
5using AForge;
6using System.IO;
7
8namespace BioGTK
9{
10 public partial class ApplyFilter : Gtk.Dialog
11 {
12 #region Properties
13
15 private Builder _builder;
16
17#pragma warning disable 649
18 [Builder.Object]
19 private ComboBox stackABox;
20 [Builder.Object]
21 private ComboBox stackBBox;
22 [Builder.Object]
23 private ComboBox roiBox;
24 [Builder.Object]
25 private SpinButton wBox;
26 [Builder.Object]
27 private SpinButton hBox;
28 [Builder.Object]
29 private SpinButton xBox;
30 [Builder.Object]
31 private SpinButton yBox;
32 [Builder.Object]
33 private SpinButton angleBox;
34 [Builder.Object]
35 private ColorButton fillColor;
36 [Builder.Object]
37 private Button cancelBut;
38 [Builder.Object]
39 private Button applyBut;
40 [Builder.Object]
41 private Button inPlaceBut;
42#pragma warning restore 649
43
44 #endregion
45
46 #region Constructors / Destructors
47 static Filt filt;
48
57 public static ApplyFilter Create(Filt filter,bool two)
58 {
59 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/ApplyFilter.glade", FileMode.Open));
60 filt = filter;
61 return new ApplyFilter(builder, builder.GetObject("applyFilter").Handle, two, filter);
62 }
63
64 /* This is the constructor for the ApplyFilter class. */
65 protected ApplyFilter(Builder builder, IntPtr handle, bool two,Filt filter) : base(handle)
66 {
67 _builder = builder;
68 App.applyFilter = this;
69 builder.Autoconnect(this);
70 InitStacks();
71 stackABox.Changed += StackABox_Changed;
72 stackBBox.Changed += StackBBox_Changed;
73 applyBut.ButtonPressEvent += ApplyBut_ButtonPressEvent;
74 inPlaceBut.ButtonPressEvent += InPlaceBut_ButtonPressEvent;
75 this.FocusActivated += ApplyFilter_FocusActivated;
76 this.Title = filter.name;
77 if (!two)
78 {
79 stackBBox.Sensitive = false;
80 if (stackBBox.Children.Length > 1)
81 stackBBox.Active = 1;
82 }
83 if (stackABox.Children.Length > 0)
84 stackABox.Active = 0;
85 App.ApplyStyles(this);
86 }
87
93 private void InPlaceBut_ButtonPressEvent(object o, ButtonPressEventArgs args)
94 {
95 Apply(true);
96 DefaultResponse = ResponseType.Ok;
97 Destroy();
98 }
99
105 private void ApplyBut_ButtonPressEvent(object o, ButtonPressEventArgs args)
106 {
107 Apply(false);
108 DefaultResponse = ResponseType.Ok;
109 Destroy();
110 }
111
116 private void ApplyFilter_FocusActivated(object? sender, EventArgs e)
117 {
118 UpdateStacks();
119 }
120
126 private void StackBBox_Changed(object? sender, EventArgs e)
127 {
128 if (stackABox.Active == stackBBox.Active)
129 {
130 //Same image selected for A & B
131 stackBBox.Active = -1;
132 }
133 }
134
142 private void StackABox_Changed(object? sender, EventArgs e)
143 {
144 if (stackABox.Active == -1)
145 return;
146 ListStore roi = new ListStore(typeof(string));
147 roiBox.Model = null;
148 foreach (ROI r in ImageA.Annotations)
149 {
150 roi.AppendValues(r);
151 }
152 roiBox.Model = roi;
153 if (stackABox.Active == stackBBox.Active)
154 {
155 //Same image selected for A & B
156 stackBBox.Active = -1;
157 }
158 var renderer = new CellRendererText();
159 roiBox.PackStart(renderer, false);
160 roiBox.AddAttribute(renderer, "text", 0);
161 }
162 #endregion
164 public void InitStacks()
165 {
166 ListStore store = new ListStore(typeof(string));
167 if (Images.images.Count != stackABox.Children.Length)
168 {
169 stackABox.Model = null;
170 stackBBox.Model = null;
171 foreach (BioImage b in Images.images)
172 {
173 store.AppendValues(System.IO.Path.GetFileName(b.Filename));
174 }
175 stackABox.Active = 0;
176 }
177 stackABox.Model = store;
178 stackBBox.Model = store;
179 // Set the text column to display
180 var renderer = new CellRendererText();
181 stackABox.PackStart(renderer, false);
182 stackABox.AddAttribute(renderer, "text", 0);
183 // Set the text column to display
184 var renderer2 = new CellRendererText();
185 stackBBox.PackStart(renderer2, false);
186 stackBBox.AddAttribute(renderer2, "text", 0);
187
188 ListStore rois = new ListStore(typeof(string));
189 foreach (ROI b in ImageA.Annotations)
190 {
191 rois.AppendValues(b.ToString());
192 }
193 roiBox.Active = 0;
194 roiBox.Model = rois;
195 // Set the text column to display
196 var renderer3 = new CellRendererText();
197 roiBox.PackStart(renderer3, false);
198 roiBox.AddAttribute(renderer3, "text", 0);
199
200 }
202 public void UpdateStacks()
203 {
204 ListStore store = new ListStore(typeof(string));
205 if (Images.images.Count != stackABox.Children.Length)
206 {
207 stackABox.Model = null;
208 stackBBox.Model = null;
209 foreach (BioImage b in Images.images)
210 {
211 store.AppendValues(System.IO.Path.GetFileName(b.Filename));
212 }
213 stackABox.Active = 0;
214 }
215 stackABox.Model = store;
216 stackBBox.Model = store;
217 ListStore rois = new ListStore(typeof(string));
218 foreach (ROI b in ImageA.Annotations)
219 {
220 rois.AppendValues(b.ToString());
221 }
222 roiBox.Model = rois;
223 }
224 /* Returning the image that is selected in the dropdown menu. */
225 public BioImage ImageA
226 {
227 get { return Images.images[stackABox.Active]; }
228 }
229 /* Returning the image that is selected in the dropdown menu. */
230 public BioImage ImageB
231 {
232 get { return Images.images[stackBBox.Active]; }
233 }
234 /* Returning the rectangle that is selected in the dropdown menu. */
235 public RectangleD Rectangle
236 {
237 get
238 {
239 if (roiBox.Active != -1)
240 return ImageA.Annotations[roiBox.Active].BoundingBox;
241 else
242 return new RectangleD((double)xBox.Value, (double)yBox.Value, (double)wBox.Value, (double)hBox.Value);
243 }
244 }
245 /* Returning the angle of the image. */
246 public int Angle
247 {
248 get
249 {
250 return (int)angleBox.Value;
251 }
252 }
253 /* Returning the color of the image. */
254 public Color Color
255 {
256 get
257 {
258 return Color.FromArgb(fillColor.Color.Red, fillColor.Color.Green, fillColor.Color.Blue);
259 }
260 }
261 /* Returning the value of the wBox. */
262 public int W
263 {
264 get
265 {
266 return (int)wBox.Value;
267 }
268 }
269 /* Returning the value of the hBox. */
270 public int H
271 {
272 get
273 {
274 return (int)hBox.Value;
275 }
276 }
281 private void cancelBut_Click(object sender, EventArgs e)
282 {
283 DefaultResponse = ResponseType.Cancel;
284 Destroy();
285 }
291 private void Apply(bool inPlace)
292 {
293 if (filt.type == Filt.Type.Base)
294 {
295 ImageView.SelectedImage = Filters.Base(ImageA.ID, filt.name, inPlace);
296 }
297 if (filt.type == Filt.Type.Base2)
298 {
299 ImageView.SelectedImage = Filters.Base2(ImageA.ID, ImageB.ID, filt.name, inPlace);
300 }
301 else
302 if (filt.type == Filt.Type.InPlace)
303 {
304 ImageView.SelectedImage = Filters.InPlace(ImageA.ID, filt.name, inPlace);
305 }
306 else
307 if (filt.type == Filt.Type.InPlace2)
308 {
309 ImageView.SelectedImage = Filters.InPlace2(ImageA.ID, ImageB.ID, filt.name, inPlace);
310 }
311 else
312 if (filt.type == Filt.Type.InPlacePartial)
313 {
314 ImageView.SelectedImage = Filters.InPlacePartial(ImageA.ID, filt.name, inPlace);
315 }
316 else
317 if (filt.type == Filt.Type.Resize)
318 {
319 ImageView.SelectedImage = Filters.Resize(ImageA.ID, filt.name, inPlace, W, H);
320 }
321 else
322 if (filt.type == Filt.Type.Rotate)
323 {
324 ImageView.SelectedImage = Filters.Rotate(ImageA.ID, filt.name, inPlace, Angle, Color.A, Color.R, Color.G, Color.B);
325 }
326 else
327 if (filt.type == Filt.Type.Transformation)
328 {
329 //We use the Crop function of Bio as AForge doesn't support croppping 16bit images.
330 if (filt.name == "Crop")
331 {
332 App.tabsView.AddTab(Filters.Crop(ImageA.ID, Rectangle));
333 }
334 else
335 {
336 ImageView.SelectedImage = Filters.Transformation(ImageA.ID, filt.name, inPlace, Angle);
337 }
338 }
339 else
340 if (filt.type == Filt.Type.Copy)
341 {
342 ImageView.SelectedImage = Filters.Copy(ImageA.ID, filt.name, inPlace);
343 }
344 App.viewer.UpdateView();
345 }
346 }
347}
static ApplyFilter Create(Filt filter, bool two)
void UpdateStacks()
It takes the list of images and updates the dropdown boxes with the filenames of the images.
void InitStacks()
It takes the list of images and updates the dropdown boxes with the filenames of the images.
Definition ML.cs:17