diff --git a/pom.xml b/pom.xml index 9063ed73dc927c31274b1f65c5efcef8cd1b25fa..a98a9c9d8ad97df780d2139dc22b5ca26936aa5b 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 ef666887f5d9772d037e8b5d345dbc60511a3ce0..22b26a5646601b41d3e3d40e29e96f36428f0109 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 57e5ff055c95f5a45809c64c338f36b0e1b479f5..4298171cbfa9dd616a31041e01be5ce73913c6e1 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 1a984cd18fcbbd55eb2fdb10625c416e6c8fa072..e0b8bda7e6b21307b66e82c734de93cb74f9d05d 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 aa0fc7d76665454ab9b2eaabab45fca4f66ae9eb..df4ed5910046857be500e2ebf87cc23af842b531 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 07c51d5c0c080ce621c5cf97cf13b2739cdbcdb3..d5945ad3ece8757999a2405c235be46278aa1742 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 3529353bbb19c60aedbe23f9dd6459745ebc79c2..9c1d162bbc1a12e78b1334648e95a99732fd3e81 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 f5ae733307ebc464303ca5bc795a3c3ec7f28dae..4bbc133c3606cde85703b3c63bb40758986e5045 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); }