diff --git a/.gitignore b/.gitignore index 5abffee43749afc5d07d2735617b71e4130a8b93..b2f15ce895696fd311b35bd9ebb831c094d75ac0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ bin/ *.jar .classpath .project -export.jardesc \ No newline at end of file +export.jardesc +**/.DS_Store \ No newline at end of file diff --git a/pom.xml b/pom.xml index bc0cfd355a6a01328796c83529a6505ca5f661c7..3c8ae15a3d8fd31a78ccd09ee0ab247463756965 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.bioimageanalysis.icy</groupId> - <artifactId>parent-pom-plugin</artifactId> - <version>1.0.8</version> + <artifactId>pom-icy</artifactId> + <version>2.2.0</version> </parent> <artifactId>convexify</artifactId> - <version>2.0.7</version> + <version>3.0.0</version> <packaging>jar</packaging> @@ -28,12 +28,10 @@ <dependency> <groupId>org.bioimageanalysis.icy</groupId> <artifactId>quickhull</artifactId> - <version>${quickhull.version}</version> </dependency> <dependency> <groupId>org.bioimageanalysis.icy</groupId> <artifactId>3d-mesh-roi</artifactId> - <version>${three-d-mesh-roi.version}</version> </dependency> </dependencies> diff --git a/src/main/java/plugins/adufour/roi/Convexify.java b/src/main/java/plugins/adufour/roi/Convexify.java index cdecc0da65e02e330d32f7e764bb2634b8005b5c..ef15db7f09951d41c34c7c66e99a226d02d04bc9 100644 --- a/src/main/java/plugins/adufour/roi/Convexify.java +++ b/src/main/java/plugins/adufour/roi/Convexify.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Icy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Icy. If not, see <https://www.gnu.org/licenses/>. + */ + package plugins.adufour.roi; import icy.roi.ROI; @@ -6,13 +24,6 @@ import icy.roi.ROI3D; import icy.roi.ROIUtil; import icy.sequence.Sequence; import icy.type.point.Point3D; - -import java.awt.geom.Point2D; -import java.util.Arrays; -import java.util.List; - -import javax.vecmath.Point3d; - import plugins.adufour.blocks.tools.roi.ROIBlock; import plugins.adufour.blocks.util.VarList; import plugins.adufour.ezplug.EzPlug; @@ -27,52 +38,50 @@ import plugins.kernel.roi.roi2d.ROI2DPolygon; import plugins.kernel.roi.roi2d.ROI2DShape; import plugins.kernel.roi.roi3d.ROI3DArea; -public class Convexify extends EzPlug implements ROIBlock -{ - private EzVarSequence input = new EzVarSequence("Input sequence"); +import javax.vecmath.Point3d; +import java.awt.geom.Point2D; +import java.util.Arrays; +import java.util.List; + +public class Convexify extends EzPlug implements ROIBlock { + private final EzVarSequence input = new EzVarSequence("Input sequence"); - private EzVarBoolean replace = new EzVarBoolean("Replace existing ROI", false); + private final EzVarBoolean replace = new EzVarBoolean("Replace existing ROI", false); - private VarROIArray roiIN = new VarROIArray("List of ROI"); + private final VarROIArray roiIN = new VarROIArray("List of ROI"); - private VarROIArray roiOUT = new VarROIArray("List of ROI"); + private final VarROIArray roiOUT = new VarROIArray("List of ROI"); @Override - protected void initialize() - { + protected void initialize() { addEzComponent(input); addEzComponent(replace); } @Override - public void clean() - { + public void clean() { } @Override - public void execute() - { - if (!isHeadLess()) - { + public void execute() { + if (!isHeadLess()) { roiIN.setValue(new ROI[0]); - Sequence s = input.getValue(true); + final Sequence s = input.getValue(true); roiIN.add(s.getROIs().toArray(new ROI[0])); } roiOUT.setValue(new ROI[0]); - for (ROI roi : roiIN) + for (final ROI roi : roiIN) roiOUT.add(createConvexROI(roi)); - if (!isHeadLess()) - { - Sequence s = input.getValue(true); + if (!isHeadLess()) { + final Sequence s = input.getValue(true); if (replace.getValue()) s.removeAllROI(); - for (ROI roi : roiOUT) - { + for (final ROI roi : roiOUT) { s.addROI(roi); } } @@ -80,36 +89,28 @@ public class Convexify extends EzPlug implements ROIBlock /** * Creates a convex ROI from the specified ROI. - * - * @param roi - * the ROI to be converted into a convex version + * + * @param roi the ROI to be converted into a convex version * @return a convex version of the ROI. This ROI is currently of type {@link ROI2DPolygon} in - * 2D, and of type {@link ROI3DArea} in 3D, although the return types may change in the - * future. - * @throws IllegalArgumentException - * if the specified ROI is not supported + * 2D, and of type {@link ROI3DArea} in 3D, although the return types may change in the + * future. + * @throws IllegalArgumentException if the specified ROI is not supported */ - public static ROI createConvexROI(ROI roi) throws IllegalArgumentException - { + public static ROI createConvexROI(final ROI roi) throws IllegalArgumentException { ROI output = null; - try - { - if (roi instanceof ROI2D) - { + try { + if (roi instanceof ROI2D) { final List<Point2D> envelope; - if (roi instanceof ROI2DShape) - { + if (roi instanceof ROI2DShape) { envelope = QuickHull2D.computeConvexEnvelope(((ROI2DShape) roi).getPoints()); } - else if (roi instanceof ROI2DArea) - { - Point2D[] points = ((ROI2DArea) roi).getBooleanMask(true).getContourPoints(); + else if (roi instanceof ROI2DArea) { + final Point2D[] points = ((ROI2DArea) roi).getBooleanMask(true).getContourPoints(); envelope = QuickHull2D.computeConvexEnvelope(Arrays.asList(points)); } - else - { + else { throw new IllegalArgumentException("Cannot compute convex hull for ROI " + roi.getName() + " of type " + roi.getClassName() + "."); } @@ -122,19 +123,17 @@ public class Convexify extends EzPlug implements ROIBlock ((ROI2D) output).setZ(roi2d.getZ()); ((ROI2D) output).setC(roi2d.getC()); } - else if (roi instanceof ROI3D) - { - Point3D[] points = ((ROI3D) roi).getBooleanMask(true).getContourPoints(); + else if (roi instanceof ROI3D) { + final Point3D[] points = ((ROI3D) roi).getBooleanMask(true).getContourPoints(); // convert to vecmath's Point3d - Point3d[] pt3d = new Point3d[points.length]; - for (int i = 0; i < points.length; i++) - { - Point3D p = points[i]; + final Point3d[] pt3d = new Point3d[points.length]; + for (int i = 0; i < points.length; i++) { + final Point3D p = points[i]; pt3d[i] = new Point3d(p.getX(), p.getY(), p.getZ()); } - QuickHull3D qhull = new QuickHull3D(); + final QuickHull3D qhull = new QuickHull3D(); qhull.build(pt3d, pt3d.length); // Use a 3D mesh to prepare the final ROI @@ -142,12 +141,11 @@ public class Convexify extends EzPlug implements ROIBlock // copy position info final ROI3D roi3d = (ROI3D) roi; - ((ROI3D)output).setT(roi3d.getT()); - ((ROI3D)output).setC(roi3d.getC()); + ((ROI3D) output).setT(roi3d.getT()); + ((ROI3D) output).setC(roi3d.getC()); } } - catch (Throwable t) - { + catch (final Throwable t) { // can happen with QuickHull3D / ROI3DPolygonalMesh... throw new IllegalArgumentException( "Cannot compute convex hull for ROI " + roi.getName() + " of type " + roi.getClassName() + ".", t); @@ -164,14 +162,12 @@ public class Convexify extends EzPlug implements ROIBlock } @Override - public void declareInput(VarList inputMap) - { + public void declareInput(final VarList inputMap) { inputMap.add("Regions of interest", roiIN); } @Override - public void declareOutput(VarList outputMap) - { + public void declareOutput(final VarList outputMap) { outputMap.add("Regions of interest", roiOUT); } }