From 990215665c85f7205909f123d88efe611805e63f Mon Sep 17 00:00:00 2001 From: Stephane Dallongeville <stephane.dallongeville@pasteur.fr> Date: Wed, 1 Dec 2021 14:27:11 +0100 Subject: [PATCH] Updated for Icy kernel 2.4.0 (interruptible process) --- pom.xml | 2 +- .../blocks/tools/ij/ImagePlusToSequence.java | 28 +++++++++++--- .../blocks/tools/ij/SequenceToImagePlus.java | 18 ++++++++- .../adufour/blocks/tools/roi/DilateROI.java | 37 ++++++++++++------- .../adufour/blocks/tools/roi/ErodeROI.java | 37 ++++++++++++------- .../adufour/blocks/tools/roi/MergeROI.java | 34 ++++++++++------- .../adufour/blocks/tools/roi/SubtractROI.java | 13 ++++++- .../tools/sequence/SequenceScreenshot.java | 20 +++++++--- 8 files changed, 134 insertions(+), 55 deletions(-) diff --git a/pom.xml b/pom.xml index 9063ed7..a98a9c9 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ </parent> <artifactId>protocols</artifactId> - <version>3.2.1</version> + <version>3.2.2</version> <packaging>jar</packaging> diff --git a/src/main/java/plugins/adufour/blocks/tools/ij/ImagePlusToSequence.java b/src/main/java/plugins/adufour/blocks/tools/ij/ImagePlusToSequence.java index ef66688..22b26a5 100644 --- a/src/main/java/plugins/adufour/blocks/tools/ij/ImagePlusToSequence.java +++ b/src/main/java/plugins/adufour/blocks/tools/ij/ImagePlusToSequence.java @@ -5,28 +5,44 @@ import icy.plugin.abstract_.Plugin; import plugins.adufour.blocks.util.VarList; import plugins.adufour.vars.lang.VarImagePlus; import plugins.adufour.vars.lang.VarSequence; +import plugins.adufour.vars.util.VarException; public class ImagePlusToSequence extends Plugin implements IJBlock { VarImagePlus vip = new VarImagePlus("IJ ImagePlus", null); - VarSequence vs = new VarSequence("Icy Sequence", null); - + VarSequence vs = new VarSequence("Icy Sequence", null); + @Override public void run() { - vs.setValue(ImageJUtil.convertToIcySequence(vip.getValue(true), null)); + try + { + vs.setValue(ImageJUtil.convertToIcySequence(vip.getValue(true), null)); + } + catch (IllegalAccessError e) + { + throw new VarException(vip, e.getMessage()); + } + catch (VarException e) + { + throw e; + } + catch (InterruptedException e) + { + Thread.currentThread().interrupt(); + } } - + @Override public void declareInput(VarList inputMap) { inputMap.add("IJ ImagePlus", vip); } - + @Override public void declareOutput(VarList outputMap) { outputMap.add("Icy Sequence", vs); } - + } diff --git a/src/main/java/plugins/adufour/blocks/tools/ij/SequenceToImagePlus.java b/src/main/java/plugins/adufour/blocks/tools/ij/SequenceToImagePlus.java index 57e5ff0..4298171 100644 --- a/src/main/java/plugins/adufour/blocks/tools/ij/SequenceToImagePlus.java +++ b/src/main/java/plugins/adufour/blocks/tools/ij/SequenceToImagePlus.java @@ -5,6 +5,7 @@ import icy.plugin.abstract_.Plugin; import plugins.adufour.blocks.util.VarList; import plugins.adufour.vars.lang.VarImagePlus; import plugins.adufour.vars.lang.VarSequence; +import plugins.adufour.vars.util.VarException; public class SequenceToImagePlus extends Plugin implements IJBlock { @@ -14,7 +15,22 @@ public class SequenceToImagePlus extends Plugin implements IJBlock @Override public void run() { - vip.setValue(ImageJUtil.convertToImageJImage(vs.getValue(true), null)); + try + { + vip.setValue(ImageJUtil.convertToImageJImage(vs.getValue(true), null)); + } + catch (IllegalAccessError e) + { + throw new VarException(vs, e.getMessage()); + } + catch (VarException e) + { + throw e; + } + catch (InterruptedException e) + { + Thread.currentThread().interrupt(); + } } @Override diff --git a/src/main/java/plugins/adufour/blocks/tools/roi/DilateROI.java b/src/main/java/plugins/adufour/blocks/tools/roi/DilateROI.java index 1a984cd..e0b8bda 100644 --- a/src/main/java/plugins/adufour/blocks/tools/roi/DilateROI.java +++ b/src/main/java/plugins/adufour/blocks/tools/roi/DilateROI.java @@ -24,16 +24,23 @@ public class DilateROI extends MorphROI @Override public void run() { - switch (unit.getValue()) + try { - case PIXELS: - roiOUT.setValue(dilateROI(roiIN.getValue(), x.getValue(), y.getValue(), z.getValue())); - break; - case PERCENTAGE: - roiOUT.setValue(dilateROIByPercentage(roiIN.getValue(), x.getValue(), y.getValue(), z.getValue())); - break; - default: - throw new VarException(unit, "Unsupported unit"); + switch (unit.getValue()) + { + case PIXELS: + roiOUT.setValue(dilateROI(roiIN.getValue(), x.getValue(), y.getValue(), z.getValue())); + break; + case PERCENTAGE: + roiOUT.setValue(dilateROIByPercentage(roiIN.getValue(), x.getValue(), y.getValue(), z.getValue())); + break; + default: + throw new VarException(unit, "Unsupported unit"); + } + } + catch (InterruptedException e) + { + Thread.currentThread().interrupt(); } } @@ -50,8 +57,9 @@ public class DilateROI extends MorphROI * @param zRadius * the radius (in pixels) along Z (not used if <code>roi</code> is 2D) * @return a new set of dilated ROI of type "area" + * @throws InterruptedException */ - public static ROI[] dilateROI(ROI[] inputRoi, int xRadius, int yRadius, int zRadius) + public static ROI[] dilateROI(ROI[] inputRoi, int xRadius, int yRadius, int zRadius) throws InterruptedException { ArrayList<ROI> out = new ArrayList<ROI>(inputRoi.length); @@ -81,8 +89,9 @@ public class DilateROI extends MorphROI * @param zPct * the percentage (from 0 to 100) to dilate along Z (not used in 2D) * @return a new set of dilated ROI of type "area" + * @throws InterruptedException */ - public static ROI[] dilateROIByPercentage(ROI[] inputRoi, int xPct, int yPct, int zPct) + public static ROI[] dilateROIByPercentage(ROI[] inputRoi, int xPct, int yPct, int zPct) throws InterruptedException { ArrayList<ROI> out = new ArrayList<ROI>(inputRoi.length); @@ -113,8 +122,9 @@ public class DilateROI extends MorphROI * @param zPct * the percentage (from 0 to 100) to dilate along Z (not used in 2D) * @return a new, dilated ROI of type "area" + * @throws InterruptedException */ - public static ROI dilateROIByPercentage(ROI roi, int xPct, int yPct, int zPct) + public static ROI dilateROIByPercentage(ROI roi, int xPct, int yPct, int zPct) throws InterruptedException { int xRadius = percentageToRadiusX(roi, xPct); int yRadius = percentageToRadiusY(roi, yPct); @@ -135,8 +145,9 @@ public class DilateROI extends MorphROI * @param zRadius * the radius in pixels along Z (not used if <code>roi</code> is 2D) * @return a new, dilated ROI of type "area" + * @throws InterruptedException */ - public static ROI dilateROI(ROI roi, int xRadius, int yRadius, int zRadius) + public static ROI dilateROI(ROI roi, int xRadius, int yRadius, int zRadius) throws InterruptedException { int rx = xRadius, rrx = rx * rx; int ry = yRadius, rry = ry * ry; diff --git a/src/main/java/plugins/adufour/blocks/tools/roi/ErodeROI.java b/src/main/java/plugins/adufour/blocks/tools/roi/ErodeROI.java index aa0fc7d..df4ed59 100644 --- a/src/main/java/plugins/adufour/blocks/tools/roi/ErodeROI.java +++ b/src/main/java/plugins/adufour/blocks/tools/roi/ErodeROI.java @@ -24,16 +24,23 @@ public class ErodeROI extends MorphROI @Override public void run() { - switch (unit.getValue()) + try { - case PIXELS: - roiOUT.setValue(erodeROI(roiIN.getValue(), x.getValue(), y.getValue(), z.getValue())); - break; - case PERCENTAGE: - roiOUT.setValue(erodeROIByPercentage(roiIN.getValue(), x.getValue(), y.getValue(), z.getValue())); - break; - default: - throw new VarException(unit, "Unsupported unit"); + switch (unit.getValue()) + { + case PIXELS: + roiOUT.setValue(erodeROI(roiIN.getValue(), x.getValue(), y.getValue(), z.getValue())); + break; + case PERCENTAGE: + roiOUT.setValue(erodeROIByPercentage(roiIN.getValue(), x.getValue(), y.getValue(), z.getValue())); + break; + default: + throw new VarException(unit, "Unsupported unit"); + } + } + catch (InterruptedException e) + { + Thread.currentThread().interrupt(); } } @@ -50,8 +57,9 @@ public class ErodeROI extends MorphROI * @param zRadius * the radius (in pixels) along Z (not used if <code>roi</code> is 2D) * @return a new set of eroded ROI of type "area" + * @throws InterruptedException */ - public static ROI[] erodeROI(ROI[] inputRoi, int xRadius, int yRadius, int zRadius) + public static ROI[] erodeROI(ROI[] inputRoi, int xRadius, int yRadius, int zRadius) throws InterruptedException { ArrayList<ROI> out = new ArrayList<ROI>(inputRoi.length); @@ -81,8 +89,9 @@ public class ErodeROI extends MorphROI * @param zPct * the percentage (from 0 to 100) to erode along Z (not used in 2D) * @return a new set of eroded ROI of type "area" + * @throws InterruptedException */ - public static ROI[] erodeROIByPercentage(ROI[] inputRoi, int xPct, int yPct, int zPct) + public static ROI[] erodeROIByPercentage(ROI[] inputRoi, int xPct, int yPct, int zPct) throws InterruptedException { ArrayList<ROI> out = new ArrayList<ROI>(inputRoi.length); @@ -113,8 +122,9 @@ public class ErodeROI extends MorphROI * @param zPct * the percentage (from 0 to 100) to dilate along Z (not used in 2D) * @return a new, dilated ROI of type "area" + * @throws InterruptedException */ - public static ROI erodeROIByPercentage(ROI roi, int xPct, int yPct, int zPct) + public static ROI erodeROIByPercentage(ROI roi, int xPct, int yPct, int zPct) throws InterruptedException { int xRadius = percentageToRadiusX(roi, xPct); int yRadius = percentageToRadiusY(roi, yPct); @@ -135,8 +145,9 @@ public class ErodeROI extends MorphROI * @param zRadius * the radius in pixels along Z (not used if <code>roi</code> is 2D) * @return a new, eroded ROI of type "area" + * @throws InterruptedException */ - public static ROI erodeROI(ROI roi, int xRadius, int yRadius, int zRadius) + public static ROI erodeROI(ROI roi, int xRadius, int yRadius, int zRadius) throws InterruptedException { // The basis of this erosion operator is to remove all pixels within a distance of "radius" // from the border. Since we have easy access to the contour points of the ROI, we will diff --git a/src/main/java/plugins/adufour/blocks/tools/roi/MergeROI.java b/src/main/java/plugins/adufour/blocks/tools/roi/MergeROI.java index 07c51d5..d5945ad 100644 --- a/src/main/java/plugins/adufour/blocks/tools/roi/MergeROI.java +++ b/src/main/java/plugins/adufour/blocks/tools/roi/MergeROI.java @@ -14,34 +14,40 @@ import plugins.adufour.vars.lang.VarROIArray; public class MergeROI extends Plugin implements ROIBlock { VarEnum<BooleanOperator> operation = new VarEnum<BooleanOperator>("Merge operation", BooleanOperator.AND); - - VarROIArray roiIn = new VarROIArray("List of ROI"); - - VarROIArray roiOut = new VarROIArray("Merged ROI"); - + + VarROIArray roiIn = new VarROIArray("List of ROI"); + + VarROIArray roiOut = new VarROIArray("Merged ROI"); + @Override public void run() { roiOut.setValue(new ROI[0]); - - List<ROI> rois = Arrays.asList(roiIn.getValue()); - - ROI merge = ROIUtil.merge(rois, operation.getValue()); - - if (merge != null) roiOut.add(merge); + + try + { + List<ROI> rois = Arrays.asList(roiIn.getValue()); + ROI merge = ROIUtil.merge(rois, operation.getValue()); + if (merge != null) + roiOut.add(merge); + } + catch (InterruptedException e) + { + Thread.currentThread().interrupt(); + } } - + @Override public void declareInput(VarList inputMap) { inputMap.add("List of ROI", roiIn); inputMap.add("Merge operation", operation); } - + @Override public void declareOutput(VarList outputMap) { outputMap.add("Merged ROI", roiOut); } - + } diff --git a/src/main/java/plugins/adufour/blocks/tools/roi/SubtractROI.java b/src/main/java/plugins/adufour/blocks/tools/roi/SubtractROI.java index 3529353..9c1d162 100644 --- a/src/main/java/plugins/adufour/blocks/tools/roi/SubtractROI.java +++ b/src/main/java/plugins/adufour/blocks/tools/roi/SubtractROI.java @@ -18,7 +18,14 @@ public class SubtractROI extends Plugin implements ROIBlock @Override public void run() { - roiOut.setValue(subtractROI(roiA.getValue(true), roiB.getValue(true))); + try + { + roiOut.setValue(subtractROI(roiA.getValue(true), roiB.getValue(true))); + } + catch (InterruptedException e) + { + Thread.currentThread().interrupt(); + } } @Override @@ -42,8 +49,10 @@ public class SubtractROI extends Plugin implements ROIBlock * @param roiB * ROIs subtracted from the first group of ROIs. * @return A - B. The group of ROIs resulting from the subtraction from the each element of the group A and each element of the group B. + * @throws InterruptedException + * @throws UnsupportedOperationException */ - public static ROI[] subtractROI(ROI[] roiA, ROI[] roiB) + public static ROI[] subtractROI(ROI[] roiA, ROI[] roiB) throws UnsupportedOperationException, InterruptedException { ArrayList<ROI> out = new ArrayList<ROI>(roiA.length); diff --git a/src/main/java/plugins/adufour/blocks/tools/sequence/SequenceScreenshot.java b/src/main/java/plugins/adufour/blocks/tools/sequence/SequenceScreenshot.java index f5ae733..4bbc133 100644 --- a/src/main/java/plugins/adufour/blocks/tools/sequence/SequenceScreenshot.java +++ b/src/main/java/plugins/adufour/blocks/tools/sequence/SequenceScreenshot.java @@ -44,11 +44,21 @@ public class SequenceScreenshot extends Plugin implements SequenceBlock final Canvas2D canvas2D = canvas2DP[0]; - for (int t = 0; t < time; t++) - for (int z = 0; z < depth; z++) - out.setImage(t, z, canvas2D.getRenderedImage(t, z, -1, false)); - - viewer.close(); + try + { + for (int t = 0; t < time; t++) + for (int z = 0; z < depth; z++) + out.setImage(t, z, canvas2D.getRenderedImage(t, z, -1, false)); + } + catch (InterruptedException e) + { + Thread.currentThread().interrupt(); + return; + } + finally + { + viewer.close(); + } seqOut.setValue(out); } -- GitLab