Skip to content

Commit fb01605

Browse files
author
Stefan Hahmann
committed
Add StatusService to provide progress updates in LinkPrediction, RegionPropsComputation, and TrackastraLinker.
1 parent 452d128 commit fb01605

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/main/java/org/mastodon/mamut/linking/trackastra/TrackastraLinker.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ public class TrackastraLinker< V extends Vertex< E > & HasTimepoint & RealLocali
4646
public void mutate1( final ReadOnlyGraph< V, E > graph, final SpatioTemporalIndex< V > index )
4747
{
4848
long start = System.currentTimeMillis();
49+
statusService.clearStatus();
50+
statusService.showStatus( "Trackastra linking." );
4951
try
5052
{
5153
List< SingleTimepointRegionProps > regionProps = computeRegionProps( index );
5254
if ( !isCanceled() )
5355
runLinkPrediction( index, regionProps );
5456
ok = true;
57+
statusService.clearStatus();
5558
}
5659
catch ( TrackastraLinkingException e )
5760
{
@@ -87,7 +90,7 @@ private List< SingleTimepointRegionProps > computeRegionProps( final SpatioTempo
8790
throw new IllegalArgumentException(
8891
String.format( "Window size (%d) exceeds time range (%d). Adjust window size or time range.", windowSize, timeRange ) );
8992

90-
try (RegionPropsComputation computation = new RegionPropsComputation( logger, model, this ))
93+
try (RegionPropsComputation computation = new RegionPropsComputation( logger, model, this, this.statusService ))
9194
{
9295
return computation.computeRegionPropsForSource( source, level, Cast.unchecked( index ), minTimepoint, maxTimepoint );
9396
}
@@ -103,7 +106,8 @@ private void runLinkPrediction( final SpatioTemporalIndex< V > index, final List
103106
log.info( "Performing Trackastra link prediction" );
104107
try (RegionProps props = new RegionProps( regionProps );
105108
LinkPrediction prediction =
106-
new LinkPrediction( settings, Cast.unchecked( index ), Cast.unchecked( edgeCreator ), props, logger, this ))
109+
new LinkPrediction( settings, Cast.unchecked( index ), Cast.unchecked( edgeCreator ), props, logger, this,
110+
statusService ))
107111
{
108112
prediction.predictAndCreateLinks();
109113
}

src/main/java/org/mastodon/mamut/linking/trackastra/appose/computation/LinkPrediction.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.mastodon.spatial.SpatioTemporalIndex;
3535
import org.mastodon.tracking.linking.EdgeCreator;
3636
import org.scijava.Cancelable;
37+
import org.scijava.app.StatusService;
3738
import org.slf4j.Logger;
3839
import org.slf4j.LoggerFactory;
3940

@@ -52,9 +53,11 @@ public class LinkPrediction extends ApposeProcess
5253

5354
private final Cancelable cancelable;
5455

56+
private final StatusService statusService;
57+
5558
public LinkPrediction( final Map< String, Object > settings, final SpatioTemporalIndex< Spot > index,
5659
final EdgeCreator< Spot > edgeCreator, final RegionProps regionProps, final org.scijava.log.Logger uiLogger,
57-
final Cancelable cancelable
60+
final Cancelable cancelable, final StatusService statusService
5861
) throws IOException
5962
{
6063
super();
@@ -64,6 +67,7 @@ public LinkPrediction( final Map< String, Object > settings, final SpatioTempora
6467
this.regionProps = regionProps;
6568
this.uiLogger = uiLogger;
6669
this.cancelable = cancelable;
70+
this.statusService = statusService;
6771
}
6872

6973
public void predictAndCreateLinks() throws IOException
@@ -90,7 +94,10 @@ public void predictAndCreateLinks() throws IOException
9094
uiLogger.info( "Link prediction canceled by user.\n" );
9195
return;
9296
}
97+
uiLogger.info( "Link prediction finished. Now writing edges.\n" );
98+
statusService.showProgress( 9, 10 ); // 90% after prediction
9399
writeEdges( result );
100+
statusService.showProgress( 1, 1 ); // 100% after writing edges
94101
}
95102
finally
96103
{

src/main/java/org/mastodon/mamut/linking/trackastra/appose/computation/RegionPropsComputation.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.mastodon.mamut.util.ResourceUtils;
3939
import org.mastodon.spatial.SpatioTemporalIndex;
4040
import org.scijava.Cancelable;
41+
import org.scijava.app.StatusService;
4142
import org.slf4j.Logger;
4243
import org.slf4j.LoggerFactory;
4344

@@ -53,13 +54,17 @@ public class RegionPropsComputation extends ApposeProcess
5354

5455
private final Cancelable cancelable;
5556

56-
public RegionPropsComputation( final org.scijava.log.Logger uiLogger, final String model, final Cancelable cancelable )
57+
private final StatusService statusService;
58+
59+
public RegionPropsComputation( final org.scijava.log.Logger uiLogger, final String model, final Cancelable cancelable,
60+
final StatusService statusService )
5761
throws IOException
5862
{
5963
super();
6064
this.uiLogger = uiLogger;
6165
this.model = model;
6266
this.cancelable = cancelable;
67+
this.statusService = statusService;
6368
}
6469

6570
public List< SingleTimepointRegionProps > computeRegionPropsForSource( final Source< ? > source, final int level,
@@ -146,6 +151,7 @@ private SingleTimepointRegionProps computeSingleTimepointProps( final Source< ?
146151
private void formatProgress( final int done, final int todo )
147152
{
148153
double progress = ( double ) done / todo;
154+
statusService.showProgress( ( int ) ( 0.75d * done ), todo ); // reserve 25% for link prediction
149155
NumberFormat percentFormatter = NumberFormat.getPercentInstance();
150156
percentFormatter.setMinimumFractionDigits( 0 );
151157
percentFormatter.setMaximumFractionDigits( 0 );

0 commit comments

Comments
 (0)