879 {
880 try
881 {
882 var gateway =
OMERO.gateway;
883 var roiService = gateway.getFacility(typeof(ROIFacility)) as ROIFacility;
884 var browse = gateway.getFacility(typeof(BrowseFacility)) as BrowseFacility;
886 ImageData image = browse.getImage(ctx, imageId);
887 int count = 0;
888 ROI[] rois = b.Annotations.ToArray();
889
890 foreach (
ROI an
in rois)
891 {
892 ROIData roi = new ROIData();
893 ShapeData shape = null;
894
895 switch (an.type)
896 {
898 {
899 var pt = new omero.gateway.model.PointData(
902 );
903 pt.setZ(an.coord.Z);
904 pt.setC(an.coord.C);
905 pt.setT(an.coord.T);
906 pt.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
907 shape = pt;
908 break;
909 }
910
911 case ROI.Type.Rectangle:
912 {
913 var r = new RectangleData(
918 );
919 r.setZ(an.coord.Z);
920 r.setC(an.coord.C);
921 r.setT(an.coord.T);
922 r.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
923 shape = r;
924 break;
925 }
926
927 case ROI.Type.Ellipse:
928 {
933
934 var e = new EllipseData(cx, cy, rx, ry);
935 e.setZ(an.coord.Z);
936 e.setC(an.coord.C);
937 e.setT(an.coord.T);
938 e.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
939 shape = e;
940 break;
941 }
942
944 {
945 var l = new LineData(
950 );
951 l.setZ(an.coord.Z);
952 l.setC(an.coord.C);
953 l.setT(an.coord.T);
954 l.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
955 shape = l;
956 break;
957 }
958
959 case ROI.Type.Polygon:
960 case ROI.Type.Freeform:
961 {
962 var pts = new List<PointD>();
963 foreach (var p in an.Points)
964 pts.Add(new PointD(
967 ));
968
969 var poly = new PolygonData(BioPointToOmeroPoint(an,b));
970 poly.setZ(an.coord.Z);
971 poly.setC(an.coord.C);
972 poly.setT(an.coord.T);
973 poly.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
974 shape = poly;
975 break;
976 }
977
978 case ROI.Type.Polyline:
979 {
980 var pts = new List<PointD>();
981 foreach (var p in an.Points)
982 pts.Add(new PointD(
985 ));
986
987 var pl = new PolylineData(BioPointToOmeroPoint(an, b));
988 pl.setZ(an.coord.Z);
989 pl.setC(an.coord.C);
990 pl.setT(an.coord.T);
991 pl.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
992 shape = pl;
993 break;
994 }
995
997 {
998 var t = new TextData(
999 string.IsNullOrEmpty(an.Text) ? "Label" : an.Text,
1002 );
1003
1004 t.setZ(an.coord.Z);
1005 t.setC(an.coord.C);
1006 t.setT(an.coord.T);
1007 shape = t;
1008 break;
1009 }
1010
1012 {
1013 if (an.roiMask == null)
1014 continue;
1015
1016 var m = new MaskData(
1017 an.roiMask.X,
1018 an.roiMask.Y,
1019 an.roiMask.Width,
1020 an.roiMask.Height,
1021 an.roiMask.GetBytes()
1022 );
1023
1024 m.setZ(an.coord.Z);
1025 m.setC(an.coord.C);
1026 m.setT(an.coord.T);
1027 m.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1028 shape = m;
1029 break;
1030 }
1031 }
1032
1033 if (shape == null)
1034 continue;
1035
1036 shape.getShapeSettings().setStroke(new java.awt.Color(
1037 an.strokeColor.A,
1038 an.strokeColor.R,
1039 an.strokeColor.G,
1040 an.strokeColor.B
1041 ));
1042
1043 shape.getShapeSettings().setFill(new java.awt.Color(
1044 an.fillColor.A,
1045 an.fillColor.R,
1046 an.fillColor.G,
1047 an.fillColor.B
1048 ));
1049
1050 shape.getShapeSettings().setStrokeWidth(
1051 new omero.model.LengthI(an.strokeWidth, omero.model.enums.UnitsLength.PIXEL)
1052 );
1053
1054 roi.addShapeData(shape);
1055
1056
1057 java.util.List roiList = new java.util.ArrayList();
1058 roiList.add(roi);
1059
1060 var saved = roiService.saveROIs(ctx, imageId, user, roiList);
1061 count++;
1062
1063 }
1064
1065 Console.WriteLine($"Added {count} ROIs to OMERO image {imageId}");
1066 return count;
1067 }
1068 catch (Exception ex)
1069 {
1070 Console.WriteLine("Error adding ROIs: " + ex);
1071 return 0;
1072 }
1073 }
double ToImageSpaceY(double y)
Definition Bio.cs:3315
double ToImageSizeX(double d)
Convert a physical size to an image size.
Definition Bio.cs:3285
double ToImageSizeY(double d)
Convert a physical size in Y direction to an image size in Y direction.
Definition Bio.cs:3295
double ToImageSpaceX(double x)
Definition Bio.cs:3304
PointD GetPoint(int i)
Definition ROI.cs:1282