From d218c0ffe223acf6afd5393f7ffae786ec60c874 Mon Sep 17 00:00:00 2001 From: kapoorlab Date: Sat, 13 Apr 2024 22:19:09 +0200 Subject: [PATCH] make type generic --- pom.xml | 2 +- .../action/oneat/OneatCorrector.java | 9 ++- .../action/oneat/TrackCorrectorRunner.java | 56 ++++++++++--------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 7423d59..4414ae9 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ sc.fiji TrackMate-Oneat - 3.2.4-SNAPSHOT + 3.2.5-SNAPSHOT TrackMate-Oneat diff --git a/src/main/java/fiji/plugin/trackmate/action/oneat/OneatCorrector.java b/src/main/java/fiji/plugin/trackmate/action/oneat/OneatCorrector.java index 423850b..0063932 100644 --- a/src/main/java/fiji/plugin/trackmate/action/oneat/OneatCorrector.java +++ b/src/main/java/fiji/plugin/trackmate/action/oneat/OneatCorrector.java @@ -42,11 +42,12 @@ import fiji.plugin.trackmate.visualization.hyperstack.TrackOverlay; import ij.ImagePlus; import net.imagej.ImgPlus; +import net.imglib2.type.NativeType; import net.imglib2.type.numeric.integer.UnsignedShortType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Pair; -public class OneatCorrector implements TrackCorrector { +public class OneatCorrector > implements TrackCorrector { private final File oneatdivision; @@ -70,7 +71,7 @@ public class OneatCorrector implements TrackCorrector { private HashMap> Apoptosisspots; - private final ImgPlus img; + private final ImgPlus img; private final Map settings; @@ -90,7 +91,7 @@ public class OneatCorrector implements TrackCorrector { private static final String BASE_ERROR_MESSAGE = "[OneatTrackCorrector] "; - public OneatCorrector(final File oneatdivision, final File oneatapoptosis, final ImgPlus intimg, + public OneatCorrector(final File oneatdivision, final File oneatapoptosis, final ImgPlus intimg, final Model model, final TrackMate trackmate, final Settings modelsettings, final DisplaySettings displaySettings, double[] calibration, Map settings, final Logger logger, final Boolean addDisplay) { @@ -118,6 +119,8 @@ public OneatCorrector(final File oneatdivision, final File oneatapoptosis, final setNumThreads(); } + + @Override public SimpleWeightedGraph getResult() { diff --git a/src/main/java/fiji/plugin/trackmate/action/oneat/TrackCorrectorRunner.java b/src/main/java/fiji/plugin/trackmate/action/oneat/TrackCorrectorRunner.java index 9553ecc..241fc0b 100644 --- a/src/main/java/fiji/plugin/trackmate/action/oneat/TrackCorrectorRunner.java +++ b/src/main/java/fiji/plugin/trackmate/action/oneat/TrackCorrectorRunner.java @@ -69,6 +69,7 @@ import net.imglib2.img.display.imagej.ImgPlusViews; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; +import net.imglib2.type.numeric.integer.UnsignedShortType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.LinAlgHelpers; import net.imglib2.util.Pair; @@ -231,11 +232,11 @@ private static Set connectedSetOf(SimpleWeightedGraph> LinkCreator(final Model model, final TrackMate trackmate, + public static > List> LinkCreator(final Model model, final TrackMate trackmate, HashMap, Pair> uniquelabelID, Pair, HashMap>> DividingStartspots, HashMap>> Mitosisspots, Map settings, final int ndim, - final Logger logger, final ImgPlus img, HashMap> framespots, + final Logger logger, final ImgPlus img, HashMap> framespots, int numThreads, double[] calibration, boolean addDisplay) { // Get the trackmodel and spots in the default tracking result and start to @@ -533,6 +534,7 @@ public Graphobject call() throws Exception { /** * + * @param * @param model The TrackMate model * @param trackmate The TrackMate object * @param uniquelabelID HashMap of (label, frame) with value being @@ -558,12 +560,12 @@ public Graphobject call() throws Exception { * @throws InterruptedException */ - public static SimpleWeightedGraph getCorrectedTracks(final Model model, + public static > SimpleWeightedGraph getCorrectedTracks(final Model model, final TrackMate trackmate, HashMap, Pair> uniquelabelID, Pair, HashMap>> DividingStartspots, HashMap>> Mitosisspots, HashMap> Apoptosisspots, Map settings, final int ndim, - final Logger logger, final ImgPlus img, HashMap> framespots, + final Logger logger, final ImgPlus img, HashMap> framespots, int numThreads, double[] calibration, boolean addDisplay) throws InterruptedException, ExecutionException { // Get the trackmodel and spots in the default tracking result and start to @@ -717,7 +719,7 @@ private static void addOverlay(final Roi overlay, final ImagePlus imp, final Spo } - private static SpotCollection regionspot(final ImgPlus img, final SpotCollection allspots, + private static > SpotCollection regionspot(final ImgPlus img, final SpotCollection allspots, final Spot motherspot, final Logger logger, final double[] calibration, final int frame, final double region, final double[] motherslope, final double mariangle, final boolean mariprinciple) { @@ -800,7 +802,7 @@ private static Pair getEigen(final Ellipsoid ellipsoid, int } - private static Ellipsoid getEllipsoid(Spot currentspot, ImgPlus img, double[] calibration) { + private static > Ellipsoid getEllipsoid(Spot currentspot, ImgPlus img, double[] calibration) { int ndim = img.numDimensions(); Ellipsoid currentellipsoid = null; @@ -809,25 +811,25 @@ private static Ellipsoid getEllipsoid(Spot currentspot, ImgPlus img, center[d] = Math.round(currentspot.getFeature(Spot.POSITION_FEATURES[d]).doubleValue() / calibration[d]); } - ImgPlus frameimg = ImgPlusViews.hyperSlice(img, ndim - 1, + ImgPlus frameimg = ImgPlusViews.hyperSlice(img, ndim - 1, (int) currentspot.getFeature(Spot.FRAME).intValue()); long[] location = new long[ndim - 1]; - RandomAccess ranac = frameimg.randomAccess(); + RandomAccess ranac = frameimg.randomAccess(); for (int d = 0; d < ndim - 1; ++d) { location[d] = (long) (currentspot.getDoublePosition(d) / calibration[d]); ranac.setPosition(location[d], d); } - int label = (int) ranac.get().get(); + int label = (int) ( (UnsignedShortType) ranac.get()).get(); - Cursor cur = frameimg.localizingCursor(); + Cursor cur = frameimg.localizingCursor(); ArrayList points = new ArrayList(); while (cur.hasNext()) { cur.fwd(); - if (cur.get().get() == label) { + if ((int) ( (UnsignedShortType) cur.get()).get() == label) { long[] point = new long[center.length]; for (int d = 0; d < center.length; d++) { @@ -934,12 +936,12 @@ private static double[] computeAxisAndRadiiFromCovariance(double[][] covariance, * Spot, A second HashMap of trackID + starting spot and trackID + * list of dividing spots for that track */ - public static Pair, Pair>, Pair, HashMap>>> getFirstTrackMateobject( - final Model model, final ImgPlus img, final Logger logger, double[] calibration) { + public static > Pair, Pair>, Pair, HashMap>>> getFirstTrackMateobject( + final Model model, final ImgPlus img, final Logger logger, double[] calibration) { Pair, HashMap>> DividingStartspots = getTMStartSplit(model); int ndim = img.numDimensions() - 1; - RandomAccess ranac = img.randomAccess(); + RandomAccess ranac = img.randomAccess(); Set AllTrackIds = model.getTrackModel().trackIDs(true); HashMap, Pair> uniquelabelID = new HashMap, Pair>(); @@ -964,7 +966,7 @@ public static Pair, Pair>, Pair(label, frame), new ValuePair(spot, trackID)); @@ -978,10 +980,10 @@ public static Pair, Pair>, Pair & NativeType> HashMap> getapoptosisTrackID( + public static > HashMap> getapoptosisTrackID( HashMap, Pair> uniquelabelID, Pair, HashMap>> DividingStartspots, final Model model, - final ImgPlus img, HashMap> framespots, + final ImgPlus img, HashMap> framespots, final Map mapsettings, final Logger logger, final int numThreads, double[] calibration) { // Starting point of the tree + apoptotic spot in the trackID @@ -989,7 +991,7 @@ public static & NativeType> HashMap ranac = img.randomAccess(); + RandomAccess ranac = img.randomAccess(); logger.log("Matching with oneat apoptosis spots.\n"); logger.setProgress(1.); @@ -1013,7 +1015,7 @@ public static & NativeType> HashMap Alllabels = new ArrayList(); - int labelID = (int) ranac.get().get(); + int labelID = (int) ( (UnsignedShortType) ranac.get()).get(); if (labelID != 0) Alllabels.add(labelID); @@ -1050,10 +1052,10 @@ public static & NativeType> HashMap & NativeType> HashMap>> getmitosisTrackID( + public static > HashMap>> getmitosisTrackID( HashMap, Pair> uniquelabelID, Pair, HashMap>> DividingStartspots, final Model model, - final ImgPlus img, HashMap> framespots, + final ImgPlus img, HashMap> framespots, final Map mapsettings, final Logger logger, final int numThreads, double[] calibration) { // Starting point of the tree + list of mitosis spots in the trackID @@ -1062,7 +1064,7 @@ public static & NativeType> HashMap ranac = img.randomAccess(); + RandomAccess ranac = img.randomAccess(); logger.log("Matching with oneat mitosis spots.\n"); logger.setProgress(1.); @@ -1087,7 +1089,7 @@ public static & NativeType> HashMap Alllabels = new ArrayList(); - int labelID = (int) ranac.get().get(); + int labelID = (int) ( (UnsignedShortType) ranac.get()).get(); if (labelID != 0) Alllabels.add(labelID); @@ -1149,10 +1151,10 @@ public static & NativeType> HashMap BreakLinksTrack(final Model model, + private static > SimpleWeightedGraph BreakLinksTrack(final Model model, HashMap, Pair> uniquelabelID, Pair, HashMap>> DividingStartspots, - HashMap> framespots, final ImgPlus img, final Logger logger, + HashMap> framespots, final ImgPlus img, final Logger logger, final SimpleWeightedGraph graph, double[] calibration, int N) { int count = 0; @@ -1163,7 +1165,7 @@ private static SimpleWeightedGraph BreakLinksTrack(fi Set AllTrackIds = model.getTrackModel().trackIDs(true); - RandomAccess ranac = img.randomAccess(); + RandomAccess ranac = img.randomAccess(); ArrayList DividingTrackids = new ArrayList(); for (Map.Entry> framemap : framespots.entrySet()) { @@ -1184,7 +1186,7 @@ private static SimpleWeightedGraph BreakLinksTrack(fi } ranac.setPosition(frame, ndim); // Get the label ID of the current interesting spot - int labelID = (int) ranac.get().get(); + int labelID = (int) ( (UnsignedShortType) ranac.get()).get(); if (uniquelabelID.containsKey(new ValuePair(labelID, frame))) { Pair spotandtrackID = uniquelabelID