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