diff --git a/pom.xml b/pom.xml index 1be905bb3178056b842ca267fcaa88dc2747cf96..ffb9c4edbc7019d9d5e9ec70735433afd19981f3 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ </parent> <artifactId>spot-detection-utilities</artifactId> - <version>1.1.7</version> + <version>2.0.0</version> <packaging>jar</packaging> diff --git a/src/main/java/plugins/nchenouard/spot/Detection.java b/src/main/java/plugins/nchenouard/spot/Detection.java index dfbfbdca018220da2d715ee8629f680ec70d8dc6..79c94bd86dc865543a0df9af4f67298161fa3f1d 100644 --- a/src/main/java/plugins/nchenouard/spot/Detection.java +++ b/src/main/java/plugins/nchenouard/spot/Detection.java @@ -1,21 +1,21 @@ /* - * Copyright 2010-2023 Institut Pasteur. + * Copyright (c) 2010-2023. Institut Pasteur. * - * This file is part of ICY. - * - * ICY is free software: you can redistribute it and/or modify + * 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, + * 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/>. + * along with Icy. If not, see <https://www.gnu.org/licenses/>. */ + package plugins.nchenouard.spot; import icy.file.xml.XMLPersistent; @@ -23,13 +23,12 @@ import icy.painter.Overlay; import icy.system.IcyExceptionHandler; import icy.util.ClassUtil; import icy.util.XMLUtil; - -import java.awt.Color; -import java.lang.reflect.Constructor; - import org.w3c.dom.Element; import org.w3c.dom.Node; +import java.awt.*; +import java.lang.reflect.Constructor; + /** * Detection is the basic detection class. Extends Detection to create more complete Detection. * @@ -41,7 +40,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { @Override public Object clone() throws CloneNotSupportedException { - Detection clone = (Detection) super.clone(); + final Detection clone = (Detection) super.clone(); clone.x = x; clone.y = y; @@ -49,7 +48,6 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { clone.t = t; clone.detectionType = detectionType; clone.selected = selected; - clone.detectionEditor = detectionEditor; clone.enabled = enabled; clone.color = new Color(color.getRed(), color.getGreen(), color.getBlue()); clone.originalColor = new Color(originalColor.getRGB()); @@ -84,22 +82,23 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { protected boolean selected = false; /** * Detection enabled/disable is the internal mechanism to filter track with TrackProcessor. At - * the start of TrackProcessor process, the enable track are all set to true. any TSP can then + * the start of the TrackProcessor process, the enable tracks are all set to true. Any TSP can then * disable it. */ protected boolean enabled = true; /** - * This color is used each time the TrackProcessor start, as it call the detection.reset() function. + * This color is used each time the TrackProcessor start, as it calls the detection.reset() function. * This color is loaded when using an XML file. - * While saving, the current color of the track ( color property ) is used. So at load it will become the new originalColor. + * While saving, the current color of the track (color property) is used. + * So at loading, it will become the new originalColor. */ protected Color originalColor = Color.blue; public final static int DETECTIONTYPE_REAL_DETECTION = 1; public final static int DETECTIONTYPE_VIRTUAL_DETECTION = 2; - public Detection(double x, double y, double z, int t) { + public Detection(final double x, final double y, final double z, final int t) { super("Detection", OverlayPriority.SHAPE_NORMAL); this.x = x; this.y = y; @@ -117,7 +116,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { return t; } - public void setT(int t) { + public void setT(final int t) { this.t = t; } @@ -125,7 +124,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { return x; } - public void setX(double x) { + public void setX(final double x) { this.x = x; } @@ -133,7 +132,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { return y; } - public void setY(double y) { + public void setY(final double y) { this.y = y; } @@ -141,7 +140,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { return z; } - public void setZ(double z) { + public void setZ(final double z) { this.z = z; } @@ -156,7 +155,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { return detectionType; } - public void setDetectionType(int detectionType) { + public void setDetectionType(final int detectionType) { this.detectionType = detectionType; } @@ -164,7 +163,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { return selected; } - public void setSelected(boolean selected) { + public void setSelected(final boolean selected) { this.selected = selected; } @@ -172,7 +171,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { return color; } - public void setColor(Color color) { + public void setColor(final Color color) { this.color = color; } @@ -180,33 +179,15 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { return enabled; } - public void setEnabled(boolean enabled) { + public void setEnabled(final boolean enabled) { this.enabled = enabled; } - @Deprecated - private DetectionEditor detectionEditor = null; - - @Deprecated - public void setExternalDetectionTools(DetectionEditor detectionEditor) { - this.detectionEditor = detectionEditor; - } - public void reset() { this.color = originalColor; this.setEnabled(true); } - @Deprecated - public DetectionEditor getDetectionEditor() { - return detectionEditor; - } - - @Deprecated - public void setDeet(DetectionEditor detectionEditor) { - this.detectionEditor = detectionEditor; - } - // @Override // public void paint(Graphics2D g, Sequence sequence, IcyCanvas canvas) { // if (enabled) @@ -227,9 +208,9 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { * @return true if load is successful. */ @Override - public boolean loadFromXML(Node node) { + public boolean loadFromXML(final Node node) { - Element detectionElement = (Element) node; + final Element detectionElement = (Element) node; x = XMLUtil.getAttributeDoubleValue(detectionElement, "x", 0); y = XMLUtil.getAttributeDoubleValue(detectionElement, "y", 0); @@ -246,9 +227,9 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { * @return true if save is successful. */ @Override - public boolean saveToXML(Node node) { + public boolean saveToXML(final Node node) { - Element detectionElement = (Element) node; + final Element detectionElement = (Element) node; XMLUtil.setAttributeDoubleValue(detectionElement, "x", x); XMLUtil.setAttributeDoubleValue(detectionElement, "y", y); @@ -265,7 +246,7 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { } // Inspired from the ROI Persistance mechanism - public static Detection createDetection(String className) { + public static Detection createDetection(final String className) { Detection result = null; try { @@ -280,7 +261,8 @@ public class Detection extends Overlay implements Cloneable, XMLPersistent { result = constructor.newInstance(); } - } catch (Exception e) { + } + catch (final Exception e) { System.err.println("********* TrackManager.createDetection('" + className + "', ...) error :"); IcyExceptionHandler.showErrorMessage(e, false); System.err.println("The object is maybe not compatible (should have a default constructor with no arguments and extends Detection)"); diff --git a/src/main/java/plugins/nchenouard/spot/DetectionEditor.java b/src/main/java/plugins/nchenouard/spot/DetectionEditor.java deleted file mode 100644 index 2d3f82bd0f0b15887027704578a11c2f1e3a0935..0000000000000000000000000000000000000000 --- a/src/main/java/plugins/nchenouard/spot/DetectionEditor.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 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.nchenouard.spot; - -import javax.swing.JPanel; - -/** - * @author Fabrice de Chaumont - * @deprecated detection editor not ready yet - */ -@Deprecated -public abstract class DetectionEditor { - - private final JPanel panel; - //protected TrackPool trackPool = null; - protected Detection currentDetection = null; - - public DetectionEditor() { - panel = new JPanel(); - } - - public JPanel getPanel() { - return panel; - } - - public abstract Detection createDetection(double x, double y, double z, int t); - - /** - * called by the trackManager to set a new detection when the user select a detection - */ - public final void setDetection(Detection detection) { - currentDetection = detection; - currentDetectionAsChanged(); - } - - /** - * Send the detection to the inheriting class. Should display data about it. Then use - * trackPool.<br> - * Fire to update TrackEditor Interface. - */ - protected abstract void currentDetectionAsChanged(); - - /* The trackPool is set by the trackEditor constructor */ -// public final void setTrackPool(TrackPool trackPool) -// { -// this.trackPool = trackPool; -// } - -} diff --git a/src/main/java/plugins/nchenouard/spot/DetectionResult.java b/src/main/java/plugins/nchenouard/spot/DetectionResult.java index 75ebf84ee1b8ec8ab000ab8a0f1c416fb55ea0a7..c599990396de852a73c121c6d9ffd64ec16822e8 100644 --- a/src/main/java/plugins/nchenouard/spot/DetectionResult.java +++ b/src/main/java/plugins/nchenouard/spot/DetectionResult.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.nchenouard.spot; import icy.plugin.abstract_.Plugin; @@ -42,7 +60,7 @@ public class DetectionResult extends Plugin { private void computeNumberOfDetection() { detectionNumber = 0; - for (int index : results.keySet()) { + for (final int index : results.keySet()) { detectionNumber += results.get(index).size(); } numberOfDetectionShouldBeRecomputed = false; @@ -53,10 +71,11 @@ public class DetectionResult extends Plugin { return sourceSequence; } - public void setSequence(Sequence seq) { + public void setSequence(final Sequence seq) { this.sourceSequence = seq; } + @Override protected void finalize() throws Throwable { results.clear(); super.finalize(); @@ -67,38 +86,33 @@ public class DetectionResult extends Plugin { numberOfDetectionShouldBeRecomputed = true; } - public DetectionResult(TreeMap<Integer, Vector<Spot>> results) { + public DetectionResult(final TreeMap<Integer, Vector<Spot>> results) { this.results = results; numberOfDetectionShouldBeRecomputed = true; } - public void addDetection(int t, Spot s) { - Vector<Spot> spots; - if (results.containsKey(Integer.valueOf(t))) - spots = results.get(Integer.valueOf(t)); + public void addDetection(final int t, final Spot s) { + final Vector<Spot> spots; + if (results.containsKey(t)) + spots = results.get(t); else { spots = new Vector<>(1); - results.put(Integer.valueOf(t), spots); + results.put(t, spots); } spots.add(s); numberOfDetectionShouldBeRecomputed = true; } - public void setResult(int t, Vector<Spot> detections) { - results.put(Integer.valueOf(t), new Vector<>(detections)); + public void setResult(final int t, final Vector<Spot> detections) { + results.put(t, new Vector<>(detections)); numberOfDetectionShouldBeRecomputed = true; } /** * @return a COPY of the detection vector at time t */ - public Vector<Spot> getDetectionsAtT(int t) { - Vector<Spot> spots = results.get(t); - if (spots == null) { - spots = new Vector<>(); - results.put(Integer.valueOf(t), spots); - } - return spots; + public Vector<Spot> getDetectionsAtT(final int t) { + return results.computeIfAbsent(t, k -> new Vector<>()); } /** @@ -109,22 +123,22 @@ public class DetectionResult extends Plugin { } public DetectionResult copy() { - TreeMap<Integer, Vector<Spot>> copy = new TreeMap<>(); - for (int key : results.keySet()) { - @SuppressWarnings("unchecked") - Vector<Spot> spotVectorClone = (Vector<Spot>) results.get(key).clone(); + final TreeMap<Integer, Vector<Spot>> copy = new TreeMap<>(); + for (final int key : results.keySet()) { + @SuppressWarnings("unchecked") final Vector<Spot> spotVectorClone = (Vector<Spot>) results.get(key).clone(); copy.put(key, spotVectorClone); } - DetectionResult dr = new DetectionResult(copy); + final DetectionResult dr = new DetectionResult(copy); dr.setName(name); return dr; } + @Override public String getName() { return name; } - public void setName(String name) { + public void setName(final String name) { this.name = name; } diff --git a/src/main/java/plugins/nchenouard/spot/Point3D.java b/src/main/java/plugins/nchenouard/spot/Point3D.java index c34b27b9b9ec81ed945d56b263ff96e7ab4364eb..aeb4b1f654c4571c720446f763640446422a43c3 100644 --- a/src/main/java/plugins/nchenouard/spot/Point3D.java +++ b/src/main/java/plugins/nchenouard/spot/Point3D.java @@ -1,13 +1,29 @@ +/* + * 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.nchenouard.spot; import java.awt.geom.Point2D; - public class Point3D { @Override public String toString() { - return "Point3D[" + x + "," + y + "," + z + "]"; } @@ -16,19 +32,19 @@ public class Point3D { public Point3D() { } - public Point3D(double x, double y, double z) { + public Point3D(final double x, final double y, final double z) { this.x = x; this.y = y; this.z = z; } - public Point3D(double x, double y) { + public Point3D(final double x, final double y) { this.x = x; this.y = y; this.z = 0; } - public Point3D(double[] coord) { + public Point3D(final double[] coord) { this.x = coord[0]; this.y = coord[1]; if (coord.length > 2) diff --git a/src/main/java/plugins/nchenouard/spot/Spot.java b/src/main/java/plugins/nchenouard/spot/Spot.java index f807fdd179d1a76a43b10e251c03a50bd78a5235..3ba66ba75769c905851536afa8d2acf440ccb81a 100644 --- a/src/main/java/plugins/nchenouard/spot/Spot.java +++ b/src/main/java/plugins/nchenouard/spot/Spot.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.nchenouard.spot; import java.io.PrintStream; @@ -13,7 +31,7 @@ public class Spot { public double meanIntensity; /** - * List of point of the detection + * List of detection points */ public ArrayList<Point3D> point3DList = new ArrayList<>(); @@ -21,18 +39,18 @@ public class Spot { mass_center = new Point3D(); } - public Spot(double x, double y, double z) { + public Spot(final double x, final double y, final double z) { mass_center = new Point3D(x, y, z); } - public Spot(double x, double y, double z, double minIntensity, double maxIntensity, double meanIntensity) { + public Spot(final double x, final double y, final double z, final double minIntensity, final double maxIntensity, final double meanIntensity) { mass_center = new Point3D(x, y, z); this.minIntensity = minIntensity; this.maxIntensity = maxIntensity; this.meanIntensity = meanIntensity; } - public Spot(double x, double y, double z, double minIntensity, double maxIntensity, double meanIntensity, ArrayList<Point3D> point3DList) { + public Spot(final double x, final double y, final double z, final double minIntensity, final double maxIntensity, final double meanIntensity, final ArrayList<Point3D> point3DList) { mass_center = new Point3D(x, y, z); this.minIntensity = minIntensity; this.maxIntensity = maxIntensity; @@ -45,15 +63,16 @@ public class Spot { String[] tmpTab = line.split("\\["); tmpTab = tmpTab[1].split("]"); line = tmpTab[0]; - String[] coordinates = line.split(",", 3); + final String[] coordinates = line.split(",", 3); if (coordinates.length > 2) { - NumberFormat nf = NumberFormat.getInstance(); - Spot s = new Spot(); + final NumberFormat nf = NumberFormat.getInstance(); + final Spot s = new Spot(); try { s.mass_center.x = nf.parse(coordinates[0]).intValue(); s.mass_center.y = nf.parse(coordinates[1]).intValue(); s.mass_center.z = nf.parse(coordinates[2]).intValue(); - } catch (ParseException e) { + } + catch (final ParseException e) { e.printStackTrace(); return null; } @@ -63,7 +82,7 @@ public class Spot { return null; } - public void save(PrintStream printOut, int num) { + public void save(final PrintStream printOut, final int num) { printOut.print("detection{" + num + "} = ["); printOut.print(mass_center.x + ","); printOut.print(mass_center.y + ",");