From 0684d101ab20c9f7ac4387816c23d8f980c55606 Mon Sep 17 00:00:00 2001 From: mhdominguez <69379072+mhdominguez@users.noreply.github.com> Date: Wed, 5 May 2021 12:25:03 -0700 Subject: [PATCH] TGMMImporter2::process() does not allow series that begin on frames other than 0 -- even if user sets `tFrom` / `tTo` correctly. Following these changes, importer works correctly. Additional changes were made to ImportTGMMAnnotationPlugin_.java to pass list of timepoints for which affine registration models are available, so those can be properly matched with the incoming TGMM data. modified: src/main/java/fiji/plugin/mamut/ImportTGMMAnnotationPlugin_.java modified: src/main/java/fiji/plugin/mamut/io/TGMMImporter2.java --- .../mamut/ImportTGMMAnnotationPlugin_.java | 5 ++- .../fiji/plugin/mamut/io/TGMMImporter2.java | 39 +++++++++++++++---- 2 files changed, 35 insertions(+), 9 deletions(-) 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..8997b66 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 ); + int timepointIndex; for ( int t = 0; t < frames.length; t++ ) { @@ -229,10 +237,27 @@ public boolean process() continue; } - logger.log( "Processing frame " + t + ". " ); - final AffineTransform3D transform = transforms.get( frames[ t ] ); + logger.log( "Processing frame " + frames[ t ] + ". " ); + timepointIndex = -1; + + for ( int ii = 0; ii < timepoints.size(); ii++ ) + { + if ( timepoints.get( ii ).getId() == frames[ t ] ) + { + transform = transforms.get( ii ); + timepointIndex = ii; + break; + } + } + + if ( timepointIndex < 0 ) + { + errorMessage = BASE_ERROR_MSG + "Unable to find frame " + frames[ t ] + " in " + xmlFile + ".\n"; + return false; + } + - 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 +455,7 @@ public boolean process() * Finished inspecting a frame. Store it in the spot collection. */ - sc.put( t, spots ); + sc.put( timepointIndex, spots ); previousSpotID = currentSpotID; logger.log( "Found " + spots.size() + " spots.\n" ); logger.setProgress( ( double ) t / frames.length );