-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bio.cs
8411 lines (8294 loc) · 364 KB
/
Bio.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using BitMiracle.LibTiff.Classic;
using loci.common.services;
using loci.formats;
using loci.formats.services;
using ome.xml.model.primitives;
using loci.formats.meta;
using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Runtime.Serialization;
using System.Text;
using Bitmap = AForge.Bitmap;
using Color = AForge.Color;
using loci.formats.@in;
using Gtk;
using System.Linq;
using NetVips;
using System.Threading.Tasks;
using OpenSlideGTK;
using Bio;
namespace BioLib
{
/* A class declaration. */
public static class Images
{
public static List<BioImage> images = new List<BioImage>();
///
/// @param ids The id of the image you want to get.
public static BioImage GetImage(string ids)
{
for (int i = 0; i < images.Count; i++)
{
if (images[i].ID == ids || images[i].file == ids)
return images[i];
}
return null;
}
/// It adds an image to the list of images
///
/// @param BioImage A class that contains the image data and other information.
public static void AddImage(BioImage im, bool newtab)
{
if (images.Contains(im)) return;
im.Filename = GetImageName(im.ID);
int c = GetImageCountByName(im.ID);
if(c > 1)
im.ID = im.Filename + "-" + c;
else
im.ID = im.Filename;
images.Add(im);
}
/// It takes a string as an argument, and returns the number of times that string appears in the
/// list of images
///
/// @param s The name of the image
///
/// @return The number of images that contain the name of the image.
public static int GetImageCountByName(string s)
{
string name = Path.GetFileName(s);
string ext = Path.GetExtension(s);
if(name.Split('-').Length > 2)
name = name.Remove(name.LastIndexOf('-'),name.Length - name.LastIndexOf('-'));
int i = 0;
for (int im = 0; im < images.Count; im++)
{
if (images[im].ID.Contains(name) && images[im].ID.EndsWith(ext))
i++;
}
return i;
}
/// It takes a string, and returns a string
///
/// @param s The path to the image.
///
/// @return The name of the image.
public static string GetImageName(string s)
{
//Here we create a unique ID for an image.
int i = Images.GetImageCountByName(s);
if (i == 0)
return Path.GetFileName(s);
string name = Path.GetFileNameWithoutExtension(s);
if (Path.GetFileNameWithoutExtension(name)!=name)
name = Path.GetFileNameWithoutExtension(name);
string ext = s.Substring(s.IndexOf('.'),s.Length-s.IndexOf('.'));
if(name.Split('-').Length > 2)
{
string sts = name.Remove(name.LastIndexOf('-'),name.Length-name.LastIndexOf('-'));
return sts + "-" + i + ext;
}
else
return name + "-" + i + ext;
}
/// This function removes an image from the table
///
/// @param BioImage This is the image that you want to remove.
public static void RemoveImage(BioImage im)
{
RemoveImage(im.ID);
}
/// It removes an image from the table
///
/// @param id The id of the image to remove.
///
/// @return The image is being returned.
public static void RemoveImage(string id)
{
BioImage im = GetImage(id);
if (im == null)
return;
images.Remove(im);
im.Dispose();
}
/// It updates an image from the table
///
/// @param id The id of the image to update.
/// @param im The BioImage to update with.
/// @return The image is being returned.
public static void UpdateImage(BioImage im)
{
for (int i = 0; i < images.Count; i++)
{
if (images[i].ID == im.ID)
{
images[i] = im;
return;
}
}
}
}
/* A struct that is used to store the resolution of an image. */
/* A struct that is used to store the resolution of an image. */
public struct Resolution
{
int x;
int y;
PixelFormat format;
double px, py, pz, sx, sy, sz;
public int SizeX
{
get { return x; }
set { x = value; }
}
public int SizeY
{
get { return y; }
set { y = value; }
}
public double PhysicalSizeX
{
get { return px; }
set { px = value; }
}
public double PhysicalSizeY
{
get { return py; }
set { py = value; }
}
public double PhysicalSizeZ
{
get { return pz; }
set { pz = value; }
}
public double StageSizeX
{
get { return sx; }
set { sx = value; }
}
public double StageSizeY
{
get { return sy; }
set { sy = value; }
}
public double StageSizeZ
{
get { return sz; }
set { sz = value; }
}
public double VolumeWidth
{
get
{
return PhysicalSizeX * SizeX;
}
}
public double VolumeHeight
{
get
{
return PhysicalSizeY * SizeY;
}
}
public PixelFormat PixelFormat
{
get { return format; }
set { format = value; }
}
public int RGBChannelsCount
{
get
{
if (PixelFormat == PixelFormat.Format8bppIndexed || PixelFormat == PixelFormat.Format16bppGrayScale)
return 1;
else if (PixelFormat == PixelFormat.Format24bppRgb || PixelFormat == PixelFormat.Format48bppRgb)
return 3;
else
return 4;
}
}
public long SizeInBytes
{
get
{
if (format == PixelFormat.Format8bppIndexed)
return (long)y * (long)x;
else if (format == PixelFormat.Format16bppGrayScale)
return (long)y * (long)x * 2;
else if (format == PixelFormat.Format24bppRgb)
return (long)y * (long)x * 3;
else if (format == PixelFormat.Format32bppRgb || format == PixelFormat.Format32bppArgb)
return (long)y * (long)x * 4;
else if (format == PixelFormat.Format48bppRgb || format == PixelFormat.Format48bppRgb)
return (long)y * (long)x * 6;
throw new NotSupportedException(format + " is not supported.");
}
}
public Resolution(int w, int h, int omePx, int bitsPerPixel, double physX, double physY, double physZ, double stageX, double stageY, double stageZ)
{
x = w;
y = h;
sx = stageX;
sy = stageY;
sz = stageZ;
format = BioImage.GetPixelFormat(omePx, bitsPerPixel);
px = physX;
py = physY;
pz = physZ;
}
public Resolution(int w, int h, PixelFormat f, double physX, double physY, double physZ, double stageX, double stageY, double stageZ)
{
x = w;
y = h;
format = f;
sx = stageX;
sy = stageY;
sz = stageZ;
px = physX;
py = physY;
pz = physZ;
}
public Resolution Copy()
{
return new Resolution(x, y, format, px, py, pz, sx, sy, sz);
}
public override string ToString()
{
return "(" + x + ", " + y + ") " + format.ToString() + " " + (SizeInBytes / 1000) + " KB";
}
}
/* Declaring a struct named RectangleD. */
public struct RectangleD
{
private double x;
private double y;
private double w;
private double h;
public double X { get { return x; } set { x = value; } }
public double Y { get { return y; } set { y = value; } }
public double W { get { return w; } set { w = value; } }
public double H { get { return h; } set { h = value; } }
public RectangleD(double X, double Y, double W, double H)
{
x = X;
y = Y;
w = W;
h = H;
}
public Rectangle ToRectangleInt()
{
return new Rectangle((int)X, (int)Y, (int)W, (int)H);
}
/// If any of the four corners of the rectangle are inside the polygon, then the rectangle
/// intersects with the polygon
///
/// @param RectangleD The rectangle that is being checked for intersection.
///
/// @return a boolean value.
public bool IntersectsWith(RectangleD rect1)
{
if (rect1.X + rect1.W < X || X + W < rect1.X ||
rect1.Y + rect1.H < Y || Y + H < rect1.Y)
{
return false;
}
return true;
}
/// > Returns true if the point is inside the rectangle
///
/// @param PointD
///
/// @return The return value is a boolean value.
public bool IntersectsWith(PointD p)
{
return IntersectsWith(p.X, p.Y);
}
/// If the point is within the rectangle, return true. Otherwise, return false
///
/// @param x The x coordinate of the point to check
/// @param y The y coordinate of the point to test.
///
/// @return A boolean value.
public bool IntersectsWith(double x, double y)
{
if (X <= x && (X + W) >= x && Y <= y && (Y + H) >= y)
return true;
else
return false;
}
/// It converts a RectangleD to a RectangleF
///
/// @return A RectangleF object.
public RectangleF ToRectangleF()
{
return new RectangleF((float)X, (float)Y, (float)W, (float)H);
}
/// This function returns a string that contains the values of the X, Y, W, and H properties of
/// the object
///
/// @return The X, Y, W, and H values of the rectangle.
public override string ToString()
{
double w = Math.Round(W, 2, MidpointRounding.ToZero);
double h = Math.Round(H, 2, MidpointRounding.ToZero);
double x = Math.Round(X, 2, MidpointRounding.ToZero);
double y = Math.Round(Y, 2, MidpointRounding.ToZero);
return x + ", " + y + ", " + w + ", " + h;
}
}
/* The ROI class is a class that contains a list of points, a bounding box, and a type */
public class ROI : IDisposable
{
/* Defining an enum. */
public enum Type
{
Rectangle,
Point,
Line,
Polygon,
Polyline,
Freeform,
Ellipse,
Label,
Mask
}
/* A property of a class. */
public PointD Point
{
get
{
return Points[0];
}
set
{
UpdatePoint(value, 0);
UpdateBoundingBox();
}
}
public RectangleD Rect
{
get
{
if (Points.Count == 0)
return new RectangleD(0, 0, 0, 0);
if (type == Type.Line || type == Type.Polyline || type == Type.Polygon || type == Type.Freeform || type == Type.Label)
return BoundingBox;
if (type == Type.Rectangle || type == Type.Ellipse)
return new RectangleD(Points[0].X, Points[0].Y, Points[1].X - Points[0].X, Points[2].Y - Points[0].Y);
else
return new RectangleD(Points[0].X, Points[0].Y, 1, 1);
}
set
{
if (type == Type.Line || type == Type.Polyline || type == Type.Polygon || type == Type.Freeform)
{
BoundingBox = value;
}
else
if (Points.Count < 4 && (type == Type.Rectangle || type == Type.Ellipse))
{
AddPoint(new PointD(value.X, value.Y));
AddPoint(new PointD(value.X + value.W, value.Y));
AddPoint(new PointD(value.X, value.Y + value.H));
AddPoint(new PointD(value.X + value.W, value.Y + value.H));
}
else
if (type == Type.Rectangle || type == Type.Ellipse)
{
Points[0] = new PointD(value.X, value.Y);
Points[1] = new PointD(value.X + value.W, value.Y);
Points[2] = new PointD(value.X, value.Y + value.H);
Points[3] = new PointD(value.X + value.W, value.Y + value.H);
}
UpdateBoundingBox();
}
}
public double X
{
get
{
return Point.X;
}
set
{
Rect = new RectangleD(value, Y, W, H);
}
}
public double Y
{
get
{
return Point.Y;
}
set
{
Rect = new RectangleD(X, value, W, H);
}
}
public double W
{
get
{
if (type == Type.Point)
return strokeWidth;
else
return BoundingBox.W;
}
set
{
Rect = new RectangleD(X, Y, value, H);
}
}
public double H
{
get
{
if (type == Type.Point)
return strokeWidth;
else
return BoundingBox.H;
}
set
{
Rect = new RectangleD(X, Y, W, value);
}
}
public int Resolution
{
get { return resolution; }
set { resolution = value; }
}
public enum CoordinateSystem
{
pixel,
micron
}
public Type type;
public static float selectBoxSize = 8f;
private List<PointD> Points = new List<PointD>();
public List<PointD> PointsD
{
get
{
return Points;
}
}
private List<RectangleD> selectBoxs = new List<RectangleD>();
public List<int> selectedPoints = new List<int>();
public RectangleD BoundingBox;
public float fontSize = 12;
public Cairo.FontSlant slant;
public Cairo.FontWeight weight;
public string family = "Times New Roman";
public ZCT coord;
public Color strokeColor;
public Color fillColor;
public bool isFilled = false;
public string id = "";
public string roiID = "";
public string roiName = "";
public string properties = "";
public int serie = 0;
private string text = "";
private int resolution = 0;
public double strokeWidth = 1;
public int shapeIndex = 0;
public bool closed = false;
bool selected = false;
public bool Selected
{
get { return selected; }
set
{
if (roiMask != null)
roiMask.Selected = value;
selected = value;
}
}
public bool subPixel = false;
public Mask roiMask { get; set; }
/// <summary>
/// Represents a Mask layer.
/// </summary>
public class Mask : IDisposable
{
public float min = 0;
float[] mask;
int width;
int height;
public int Width { get { return width; } set { width = value; } }
public int Height { get { return height; } set { height = value; } }
public double PhysicalSizeX { get; set; }
public double PhysicalSizeY { get; set; }
bool updatePixbuf = true;
bool updateColored = true;
Gdk.Pixbuf pixbuf;
Gdk.Pixbuf colored;
bool selected = false;
internal bool Selected
{
get { return selected; }
set
{
selected = value;
if (selected)
UpdateColored(Color.Blue);
else
updateColored = true;
}
}
public bool IsSelected(int x, int y)
{
int ind = y * width + x;
if (ind > mask.Length)
throw new ArgumentException("Point " + x + "," + y + " is outside the mask.");
if (mask[ind]>min)
{
return true;
}
return false;
}
public float GetValue(int x, int y)
{
int ind = y * width + x;
if (ind > mask.Length)
throw new ArgumentException("Point " + x + "," + y + " is outside the mask.");
return mask[ind];
}
public void SetValue(int x, int y, float val)
{
int ind = y * width + x;
if (ind > mask.Length)
throw new ArgumentException("Point " + x + "," + y + " is outside the mask.");
mask[ind] = val;
updatePixbuf = true;
updateColored = true;
}
public Mask(float[] fts, int width, int height, double physX, double physY)
{
this.width = width;
this.height = height;
PhysicalSizeX = physX;
PhysicalSizeY = physY;
mask = fts;
}
public Mask(byte[] bts, int width, int height, double physX, double physY)
{
this.width = width;
this.height = height;
PhysicalSizeX = physX;
PhysicalSizeY = physY;
mask = new float[bts.Length];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int ind = y * width + x;
mask[ind] = (float)BitConverter.ToSingle(bts, ind * 4);
}
}
}
public Gdk.Pixbuf Pixbuf
{
get
{
if (updatePixbuf)
{
if (pixbuf != null)
pixbuf.Dispose();
byte[] pixelData = new byte[width * height * 4];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int ind = y * width + x;
if (mask[ind] > 0)
{
pixelData[4 * ind] = (byte)(mask[ind] / 255);// Blue
pixelData[4 * ind + 1] = (byte)(mask[ind] / 255);// Green
pixelData[4 * ind + 2] = (byte)(mask[ind] / 255);// Red
pixelData[4 * ind + 3] = 125;// Alpha
}
else
pixelData[4 * ind + 3] = 0;
}
}
pixbuf = new Gdk.Pixbuf(pixelData, true, 8, width, height, width * 4);
updatePixbuf = false;
return pixbuf;
}
else
return pixbuf;
}
}
void UpdateColored(AForge.Color col)
{
byte[] pixelData = new byte[width * height * 4];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int ind = y * width + x;
if (mask[ind] > 0)
{
pixelData[4 * ind] = col.R;
pixelData[4 * ind + 1] = col.G;
pixelData[4 * ind + 2] = col.B;
pixelData[4 * ind + 3] = 125;
}
else
pixelData[4 * ind + 3] = 0;
}
}
colored = new Gdk.Pixbuf(pixelData, true, 8, width, height, width * 4);
updateColored = false;
}
public Gdk.Pixbuf GetColored(AForge.Color col, bool forceUpdate = false)
{
if (updateColored || forceUpdate)
{
UpdateColored(col);
return colored;
}
else
return colored;
}
public byte[] GetBytes()
{
byte[] pixelData = new byte[width * height * 4];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int ind = y * width + x;
byte[] bt = BitConverter.GetBytes(mask[ind]);
pixelData[4 * ind] = bt[0];
pixelData[4 * ind + 1] = bt[1];
pixelData[4 * ind + 2] = bt[2];
pixelData[4 * ind + 3] = bt[3];
}
}
return pixelData;
}
public void Dispose()
{
if(pixbuf!=null)
pixbuf.Dispose();
if(colored!=null)
colored.Dispose();
mask = null;
}
}
/*
public Size TextSize
{
get
{
return TextRenderer.MeasureText(text, font);
}
}
*/
public ROI Copy()
{
ROI copy = new ROI();
copy.id = id;
copy.roiID = roiID;
copy.roiName = roiName;
copy.text = text;
copy.strokeWidth = strokeWidth;
copy.strokeColor = strokeColor;
copy.fillColor = fillColor;
copy.Points = Points;
copy.Selected = Selected;
copy.shapeIndex = shapeIndex;
copy.closed = closed;
copy.family = family;
copy.fontSize = fontSize;
copy.slant = slant;
copy.selectBoxs = selectBoxs;
copy.BoundingBox = BoundingBox;
copy.isFilled = isFilled;
copy.coord = coord;
copy.selectedPoints = selectedPoints;
return copy;
}
public ROI Copy(ZCT cord)
{
ROI copy = new ROI();
copy.type = type;
copy.id = id;
copy.roiID = roiID;
copy.roiName = roiName;
copy.text = text;
copy.strokeWidth = strokeWidth;
copy.strokeColor = strokeColor;
copy.fillColor = fillColor;
copy.Points.AddRange(Points);
copy.Selected = Selected;
copy.shapeIndex = shapeIndex;
copy.closed = closed;
copy.family = family;
copy.fontSize = fontSize;
copy.slant = slant;
copy.selectBoxs.AddRange(selectBoxs);
copy.BoundingBox = BoundingBox;
copy.isFilled = isFilled;
copy.coord = cord;
copy.selectedPoints = selectedPoints;
return copy;
}
public string Text
{
get
{
return text;
}
set
{
text = value;
if (type == Type.Label)
{
UpdateBoundingBox();
}
}
}
/// > This function returns a rectangle that is the bounding box of the object, but with a
/// border of half the scale
///
/// @param scale the scale of the image
///
/// @return A rectangle with the following properties:
public RectangleD GetSelectBound(double scaleX,double scaleY)
{
if (type == Type.Mask)
return BoundingBox;
double fx = scaleX / 2;
double fy = scaleY / 2;
return new RectangleD(BoundingBox.X - fx, BoundingBox.Y - fy, BoundingBox.W + scaleX, BoundingBox.H + scaleY);
}
/* Creating a new ROI object. */
public ROI()
{
coord = new ZCT(0, 0, 0);
strokeColor = Color.Yellow;
BoundingBox = new RectangleD(0, 0, 1, 1);
}
/// <summary>
/// The function "ImagePoints" takes a Resolution object as input and returns an array of PointD
/// objects that have been converted to image space using the provided resolution values.
/// </summary>
/// <param name="Resolution">The "Resolution" parameter is an object that contains information
/// about the resolution of an image. It typically includes properties such as the stage size
/// (width and height), physical size (width and height), and possibly other properties related
/// to the image resolution.</param>
/// <returns>
/// The method is returning an array of PointD objects.
/// </returns>
public PointD[] ImagePoints(Resolution res)
{
return BioImage.ToImageSpace(PointsD, (int)res.StageSizeX, (int)res.StageSizeY, (int)res.PhysicalSizeX, (int)res.PhysicalSizeY);
}
/// It returns an array of RectangleF objects that are used to draw the selection boxes around
/// the points of the polygon
///
/// @param s the size of the select box
///
/// @return A list of RectangleF objects.
public RectangleD[] GetSelectBoxes(double s)
{
double f = s / 2;
selectBoxs.Clear();
for (int i = 0; i < Points.Count; i++)
{
selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)s, (float)s));
}
return selectBoxs.ToArray();
}
/// Create a new ROI object, add a point to it, and return it
///
/// @param ZCT a class that contains the Z, C, and T coordinates of the image.
/// @param x x coordinate of the point
/// @param y The y coordinate of the point
///
/// @return A new ROI object
public static ROI CreatePoint(ZCT coord, double x, double y)
{
ROI an = new ROI();
an.coord = coord;
an.AddPoint(new PointD(x, y));
an.type = Type.Point;
return an;
}
/// Create a new ROI object, set its type to Line, add two points to it, and return it
///
/// @param ZCT Z is the Z-axis, C is the color channel, and T is the time frame.
/// @param PointD X,Y
/// @param PointD X,Y
///
/// @return A new ROI object.
public static ROI CreateLine(ZCT coord, PointD x1, PointD x2)
{
ROI an = new ROI();
an.coord = coord;
an.type = Type.Line;
an.AddPoint(x1);
an.AddPoint(x2);
return an;
}
/// Create a new ROI object with a rectangle shape, and add a line to the recorder
///
/// @param ZCT The ZCT coordinates of the image you want to create the ROI on.
/// @param x x coordinate of the top left corner of the rectangle
/// @param y y-coordinate of the top-left corner of the rectangle
/// @param w width
/// @param h height
///
/// @return A new ROI object.
public static ROI CreateRectangle(ZCT coord, double x, double y, double w, double h)
{
ROI an = new ROI();
an.coord = coord;
an.type = Type.Rectangle;
an.Rect = new RectangleD(x, y, w, h);
return an;
}
/// Create an ellipse ROI at the specified ZCT coordinate with the specified width and height
///
/// @param ZCT The ZCT coordinates of the image you want to create the ROI on.
/// @param x x-coordinate of the top-left corner of the rectangle
/// @param y The y-coordinate of the upper-left corner of the rectangle to create.
/// @param w width
/// @param h height
///
/// @return A new ROI object.
public static ROI CreateEllipse(ZCT coord, double x, double y, double w, double h)
{
ROI an = new ROI();
an.coord = coord;
an.type = Type.Ellipse;
an.Rect = new RectangleD(x, y, w, h);
return an;
}
/// > Create a new ROI object of type Polygon, with the given coordinate system and points
///
/// @param ZCT The ZCT coordinate of the ROI.
/// @param pts an array of PointD objects, which are just a pair of doubles (x,y)
///
/// @return A ROI object
public static ROI CreatePolygon(ZCT coord, PointD[] pts)
{
ROI an = new ROI();
an.coord = coord;
an.type = Type.Polygon;
an.AddPoints(pts);
an.closed = true;
return an;
}
/// > Create a new ROI object of type Freeform, with the specified ZCT coordinate and points
///
/// @param ZCT A class that contains the Z, C, and T coordinates of the ROI.
/// @param pts an array of PointD objects, which are just a pair of doubles (x,y)
///
/// @return A new ROI object.
public static ROI CreateFreeform(ZCT coord, PointD[] pts)
{
ROI an = new ROI();
an.coord = coord;
an.type = Type.Freeform;
an.AddPoints(pts);
an.closed = true;
return an;
}
public static ROI CreateMask(ZCT coord, float[] mask,int width,int height,PointD loc, double physicalX, double physicalY)
{
ROI an = new ROI();
an.coord = coord;
an.type = Type.Mask;
an.roiMask = new Mask(mask, width, height,physicalX,physicalY);
an.AddPoint(loc);
return an;
}
public static ROI CreateMask(ZCT coord, byte[] mask,int width,int height,PointD loc,double physicalX,double physicalY)
{
ROI an = new ROI();
an.coord = coord;
an.type = Type.Mask;
an.roiMask = new Mask(mask, width, height, physicalX, physicalY);
an.AddPoint(loc);
return an;
}
/// This function updates the point at the specified index
///
/// @param PointD A class that contains an X and Y coordinate.
/// @param i The index of the point to update
public void UpdatePoint(PointD p, int i)
{
if (i < Points.Count)
{
Points[i] = p;
}
UpdateBoundingBox();
}
/// This function returns the point at the specified index
///
/// @param i The index of the point to get.
///
/// @return The point at index i in the Points array.
public PointD GetPoint(int i)
{
return Points[i];
}
/// It returns an array of PointD objects
///
/// @return An array of PointD objects.
public PointD[] GetPoints()
{
return Points.ToArray();
}
/// It converts a list of points to an array of points
///
/// @return A PointF array.
public PointF[] GetPointsF()
{
PointF[] pfs = new PointF[Points.Count];
for (int i = 0; i < Points.Count; i++)
{
pfs[i].X = (float)Points[i].X;
pfs[i].Y = (float)Points[i].Y;
}
return pfs;
}
/// > Adds a point to the list of points and updates the bounding box
///
/// @param PointD
public void AddPoint(PointD p)
{
Points.Add(p);
UpdateBoundingBox();
}
/// > Adds a range of points to the Points collection and updates the bounding box
///
/// @param p The points to add to the polygon
public void AddPoints(PointD[] p)
{
Points.AddRange(p);
UpdateBoundingBox();
}
/// > Adds a range of integer points to the Points collection and updates the bounding box
///
/// @param p The points to add to the polygon
public void AddPoints(int[] xp, int[] yp)
{
for (int i = 0; i < xp.Length; i++)
{