Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TGMMImporter2.java #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 32 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 );
int timepointIndex;

for ( int t = 0; t < frames.length; t++ )
{
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down