Skip to content

Commit a956dab

Browse files
authored
Save multiple ROIs and fix fill color in ImageJ (#47)
* Add saveROIs method to ImageWrapper (speed) * Update pom.xml, README and .editorconfig * Make fill color null in ImageJ if transparent on OMERO
1 parent 404cff9 commit a956dab

15 files changed

Lines changed: 85 additions & 74 deletions

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ij_java_case_statement_on_separate_line = true
7171
ij_java_catch_on_new_line = false
7272
ij_java_class_annotation_wrap = split_into_lines
7373
ij_java_class_brace_style = end_of_line
74-
ij_java_class_count_to_use_import_on_demand = 10
74+
ij_java_class_count_to_use_import_on_demand = 20
7575
ij_java_class_names_in_javadoc = 1
7676
ij_java_do_not_indent_top_level_class_members = false
7777
ij_java_do_not_wrap_after_single_annotation = false

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Java CI with Maven](https://github.com/GReD-Clermont/simple-omero-client/actions/workflows/maven.yml/badge.svg)](https://github.com/GReD-Clermont/simple-omero-client/actions/workflows/maven.yml)
2+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=GReD-Clermont_simple-omero-client&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=GReD-Clermont_simple-omero-client)
23
[![codecov](https://codecov.io/gh/GReD-Clermont/simple-omero-client/branch/main/graph/badge.svg)](https://codecov.io/gh/GReD-Clermont/simple-omero-client)
34
[![DOI](https://img.shields.io/badge/DOI-10.12688%2Ff1000research.110385.2-GREEN)](https://doi.org/10.12688/f1000research.110385.2)
45

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<groupId>fr.igred</groupId>
1111
<artifactId>simple-omero-client</artifactId>
12-
<version>5.9.4</version>
12+
<version>5.10.0</version>
1313
<packaging>jar</packaging>
1414

1515
<name>Simple OMERO Client</name>

src/main/java/fr/igred/omero/repository/ImageWrapper.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,33 @@ public List<ImageWrapper> getFilesetImages(Client client)
364364
}
365365

366366

367+
/**
368+
* Links ROIs to the image in OMERO.
369+
* <p> DO NOT USE IT IF A SHAPE WAS DELETED !!!
370+
*
371+
* @param client The client handling the connection.
372+
* @param rois ROIs to be added.
373+
*
374+
* @return The updated list of ROIs.
375+
*
376+
* @throws ServiceException Cannot connect to OMERO.
377+
* @throws AccessException Cannot access data.
378+
* @throws ExecutionException A Facility can't be retrieved or instantiated.
379+
*/
380+
public List<ROIWrapper> saveROIs(Client client, Collection<? extends ROIWrapper> rois)
381+
throws ServiceException, AccessException, ExecutionException {
382+
rois.forEach(r -> r.setImage(this));
383+
List<ROIData> roisData = rois.stream().map(ROIWrapper::asROIData).collect(Collectors.toList());
384+
Collection<ROIData> results = new ArrayList<>(0);
385+
try {
386+
results = client.getRoiFacility().saveROIs(client.getCtx(), data.getId(), roisData);
387+
} catch (DSOutOfServiceException | DSAccessException e) {
388+
handleServiceOrAccess(e, "Cannot link ROI to " + this);
389+
}
390+
return wrap(results, ROIWrapper::new);
391+
}
392+
393+
367394
/**
368395
* Links a ROI to the image in OMERO
369396
* <p> DO NOT USE IT IF A SHAPE WAS DELETED !!!

src/main/java/fr/igred/omero/roi/EllipseWrapper.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public EllipseWrapper(ij.gui.Roi ijRoi) {
6363
ijRoi.getBounds().getWidth() / 2,
6464
ijRoi.getBounds().getHeight() / 2);
6565
data.setText(ijRoi.getName());
66-
super.copy(ijRoi);
66+
super.copyFromIJRoi(ijRoi);
6767
}
6868

6969

@@ -288,12 +288,7 @@ public Roi toImageJ() {
288288
double y2 = shape2.getY();
289289
roi = new EllipseRoi(x1, y1, x2, y2, ratio);
290290
}
291-
roi.setStrokeColor(getStroke());
292-
roi.setFillColor(getFill());
293-
int c = Math.max(0, getC() + 1);
294-
int z = Math.max(0, getZ() + 1);
295-
int t = Math.max(0, getT() + 1);
296-
roi.setPosition(c, z, t);
291+
copyToIJRoi(roi);
297292
return roi;
298293
}
299294

src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static ShapeList fromImageJ(ij.gui.Roi ijRoi) {
9595
points.add(new PointWrapper(x[i], y[i]));
9696
}
9797
points.forEach(p -> p.setText(ijRoi.getName()));
98-
points.forEach(p -> p.copy(ijRoi));
98+
points.forEach(p -> p.copyFromIJRoi(ijRoi));
9999
list.addAll(points);
100100
break;
101101
case Roi.COMPOSITE:
@@ -122,7 +122,7 @@ static ShapeList fromImageJ(ij.gui.Roi ijRoi) {
122122
*
123123
* @param ijRoi An ImageJ Roi.
124124
*/
125-
protected void copy(ij.gui.Roi ijRoi) {
125+
protected void copyFromIJRoi(ij.gui.Roi ijRoi) {
126126
data.setC(Math.max(-1, ijRoi.getCPosition() - 1));
127127
data.setZ(Math.max(-1, ijRoi.getZPosition() - 1));
128128
data.setT(Math.max(-1, ijRoi.getTPosition() - 1));
@@ -137,6 +137,23 @@ protected void copy(ij.gui.Roi ijRoi) {
137137
}
138138

139139

140+
/**
141+
* Copies details to an ImageJ ROI (name, position, stroke color, fill color, stroke width).
142+
*
143+
* @param ijRoi An ImageJ Roi.
144+
*/
145+
protected void copyToIJRoi(ij.gui.Roi ijRoi) {
146+
ijRoi.setName(getText());
147+
ijRoi.setStrokeColor(getStroke());
148+
Color fill = getFill();
149+
if(!TRANSPARENT.equals(fill)) ijRoi.setFillColor(getFill());
150+
int c = Math.max(0, getC() + 1);
151+
int z = Math.max(0, getZ() + 1);
152+
int t = Math.max(0, getT() + 1);
153+
ijRoi.setPosition(c, z, t);
154+
}
155+
156+
140157
/**
141158
* Gets the ShapeData object contained.
142159
*
@@ -420,13 +437,7 @@ public RectangleWrapper getBoundingBox() {
420437
*/
421438
public Roi toImageJ() {
422439
Roi roi = new ij.gui.ShapeRoi(createTransformedAWTShape()).trySimplify();
423-
roi.setName(getText());
424-
roi.setStrokeColor(getStroke());
425-
roi.setFillColor(getFill());
426-
int c = Math.max(0, getC() + 1);
427-
int z = Math.max(0, getZ() + 1);
428-
int t = Math.max(0, getT() + 1);
429-
roi.setPosition(c, z, t);
440+
copyToIJRoi(roi);
430441
return roi;
431442
}
432443

src/main/java/fr/igred/omero/roi/LineWrapper.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public LineWrapper(Line line) {
7070
data.getShapeSettings().setMarkerStart(ARROW);
7171
}
7272
}
73-
super.copy(line);
73+
super.copyFromIJRoi(line);
7474
}
7575

7676

@@ -295,12 +295,7 @@ public Roi toImageJ() {
295295
default:
296296
roi = new Line(x1, y1, x2, y2);
297297
}
298-
roi.setStrokeColor(getStroke());
299-
roi.setFillColor(getFill());
300-
int c = Math.max(0, getC() + 1);
301-
int z = Math.max(0, getZ() + 1);
302-
int t = Math.max(0, getT() + 1);
303-
roi.setPosition(c, z, t);
298+
copyToIJRoi(roi);
304299
return roi;
305300
}
306301

src/main/java/fr/igred/omero/roi/MaskWrapper.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,7 @@ public Roi toImageJ() {
305305

306306
roi = new ij.gui.RotatedRectRoi(x1, y1, x2, y2, getWidth());
307307
}
308-
roi.setStrokeColor(getStroke());
309-
roi.setFillColor(getFill());
310-
int c = Math.max(0, getC() + 1);
311-
int z = Math.max(0, getZ() + 1);
312-
int t = Math.max(0, getT() + 1);
313-
roi.setPosition(c, z, t);
308+
copyToIJRoi(roi);
314309
return roi;
315310
}
316311

src/main/java/fr/igred/omero/roi/PointWrapper.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,7 @@ public ij.gui.Roi toImageJ() {
190190
double y = awtShape.getBounds2D().getY();
191191

192192
PointRoi roi = new PointRoi(x, y);
193-
194-
roi.setStrokeColor(getStroke());
195-
roi.setFillColor(getFill());
196-
int c = Math.max(0, getC() + 1);
197-
int z = Math.max(0, getZ() + 1);
198-
int t = Math.max(0, getT() + 1);
199-
roi.setPosition(c, z, t);
193+
copyToIJRoi(roi);
200194

201195
return roi;
202196
}

src/main/java/fr/igred/omero/roi/PolygonWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public PolygonWrapper(Roi ijRoi) {
6969

7070
data.setPoints(points);
7171
data.setText(ijRoi.getName());
72-
super.copy(ijRoi);
72+
super.copyFromIJRoi(ijRoi);
7373
}
7474

7575

0 commit comments

Comments
 (0)