diff --git a/src/main/java/fiji/plugin/mamut/ImportTGMMAnnotationPlugin_.java b/src/main/java/fiji/plugin/mamut/ImportTGMMAnnotationPlugin_.java index b649330..5fbaf53 100644 --- a/src/main/java/fiji/plugin/mamut/ImportTGMMAnnotationPlugin_.java +++ b/src/main/java/fiji/plugin/mamut/ImportTGMMAnnotationPlugin_.java @@ -424,12 +424,13 @@ protected Model createModel( final File tgmmFolder, final SpimDataMinimal spimDa final SequenceDescriptionMinimal seq = spimData.getSequenceDescription(); final ViewRegistrations regs = spimData.getViewRegistrations(); final List< AffineTransform3D > transforms = new ArrayList<>( seq.getTimePoints().size() ); - for ( final TimePoint t : seq.getTimePoints().getTimePointsOrdered() ) + final List< TimePoint > timepoints = seq.getTimePoints().getTimePointsOrdered(); + for ( final TimePoint t : timepoints ) { transforms.add( regs.getViewRegistration( t.getId(), setupID ).getModel() ); } - final TGMMImporter2 importer = new TGMMImporter2( tgmmFolder, transforms, TGMMImporter2.DEFAULT_PATTERN, logger, interval, tFrom, tTo ); + final TGMMImporter2 importer = new TGMMImporter2( tgmmFolder, transforms, timepoints, TGMMImporter2.DEFAULT_PATTERN, logger, interval, tFrom, tTo ); if ( !importer.checkInput() || !importer.process() ) { logger.error( importer.getErrorMessage() ); diff --git a/src/main/java/fiji/plugin/mamut/io/TGMMImporter2.java b/src/main/java/fiji/plugin/mamut/io/TGMMImporter2.java index cf69e36..9ea0078 100644 --- a/src/main/java/fiji/plugin/mamut/io/TGMMImporter2.java +++ b/src/main/java/fiji/plugin/mamut/io/TGMMImporter2.java @@ -25,6 +25,7 @@ import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -45,6 +46,7 @@ import fiji.plugin.trackmate.Model; import fiji.plugin.trackmate.Spot; import fiji.plugin.trackmate.SpotCollection; +import mpicbg.spim.data.sequence.TimePoint; import net.imglib2.RealInterval; import net.imglib2.RealLocalizable; import net.imglib2.RealPoint; @@ -97,6 +99,8 @@ public boolean accept( final File folder, final String name ) private final List< AffineTransform3D > transforms; + private final List< TimePoint > timepoints; + private final Logger logger; private long processingTime; @@ -111,11 +115,12 @@ public boolean accept( final File folder, final String name ) * CONSTRUCTORS */ - public TGMMImporter2( final File file, final List< AffineTransform3D > transforms, final Pattern framePattern, final Logger logger, final RealInterval interval, final int tFrom, final int tTo ) + public TGMMImporter2( final File file, final List< AffineTransform3D > transforms, final List< TimePoint > timepoints, final Pattern framePattern, final Logger logger, final RealInterval interval, final int tFrom, final int tTo ) { this.file = file; this.framePattern = framePattern; this.transforms = transforms; + this.timepoints = timepoints; this.logger = logger; this.interval = interval; this.tFrom = tFrom; @@ -170,7 +175,8 @@ public boolean process() */ final File[] xmlFiles = file.listFiles( xmlFilter ); - + Arrays.sort(xmlFiles); + /* * Extract frame information from filename. It is not stored elsewhere * so we have to rely on a specific pattern to get it. Note that it is @@ -194,7 +200,7 @@ public boolean process() try { final int frame = Integer.parseInt( strFrame ); - frames[ frame ] = i; + frames[ i ] = frame; } catch ( final NumberFormatException nfe ) { @@ -221,6 +227,8 @@ public boolean process() Map< Integer, Spot > previousSpotID = null; Map< Integer, Spot > currentSpotID; + AffineTransform3D transform = transforms.get( 0 ); + boolean transformNotFound; for ( int t = 0; t < frames.length; t++ ) { @@ -229,10 +237,26 @@ public boolean process() continue; } - logger.log( "Processing frame " + t + ". " ); - final AffineTransform3D transform = transforms.get( frames[ t ] ); + logger.log( "Processing frame " + frames[ t ] + ". " ); + transformNotFound = true; + + for ( int ii = 0; ii < timepoints.size(); ii++ ) + { + if ( timepoints.get( ii ).getId() == frames[ t ] ) + { + transform = transforms.get( ii ); + transformNotFound = false; + break; + } + } + + if ( transformNotFound ) + { + logger.log( "Unable to find AffineTransform3D for frame " + frames[ t ] + "; using most recently recalled transformation model!" ); + } + - xmlFile = xmlFiles[ frames[ t ] ]; + xmlFile = xmlFiles[ t ]; final Document doc = saxBuilder.build( xmlFile ); final Element root = doc.getRootElement(); final List< Element > detectionEls = root.getChildren( XML_DETECTION_NAME ); @@ -430,7 +454,7 @@ public boolean process() * Finished inspecting a frame. Store it in the spot collection. */ - sc.put( t, spots ); + sc.put( frames[ t ], spots ); previousSpotID = currentSpotID; logger.log( "Found " + spots.size() + " spots.\n" ); logger.setProgress( ( double ) t / frames.length );