Skip to content

Commit

Permalink
TGMMImporter2::process() does not allow series that begin on frames o…
Browse files Browse the repository at this point in the history
…ther 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
  • Loading branch information
mhdominguez committed Jun 1, 2021
1 parent c74e0d3 commit 07324c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
38 changes: 31 additions & 7 deletions src/main/java/fiji/plugin/mamut/io/TGMMImporter2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -194,7 +200,7 @@ public boolean process()
try
{
final int frame = Integer.parseInt( strFrame );
frames[ frame ] = i;
frames[ i ] = frame;
}
catch ( final NumberFormatException nfe )
{
Expand All @@ -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++ )
{
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 07324c1

Please sign in to comment.