Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@

## SciJava release tools
pom.xml.releaseBackup

# Agent file
AGENTS.md
30 changes: 28 additions & 2 deletions src/main/java/fiji/plugin/trackmate/util/DetectionPreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class DetectionPreview

private TrackMate trackmate;

/** Receives the final summary (spots found / error) in addition to panel.logger. */
private Logger extraLogger = Logger.VOID_LOGGER;

protected DetectionPreview(
final Model model,
final Settings settings,
Expand Down Expand Up @@ -109,7 +112,9 @@ protected void preview(

final Model sourceModel = out.getA();
final Double threshold = out.getB();
panel.logger.log( "Found " + sourceModel.getSpots().getNSpots( true ) + " spots." );
final String msg = "Found " + sourceModel.getSpots().getNSpots( true ) + " spots.";
panel.logger.log( msg );
extraLogger.log( "[Preview] " + msg + "\n" );

// Update target model.
updateModelAndHistogram( model, sourceModel, frame, threshold );
Expand All @@ -118,6 +123,7 @@ protected void preview(
catch ( final Exception e )
{
panel.logger.error( e.getMessage() );
extraLogger.error( "[Preview] " + e.getMessage() + "\n" );
e.printStackTrace();
}
finally
Expand Down Expand Up @@ -198,6 +204,7 @@ protected Pair< Model, Double > runPreviewDetection(
if ( !detectionOk )
{
panel.logger.error( trackmate.getErrorMessage() );
extraLogger.error( "[Preview] " + trackmate.getErrorMessage() + "\n" );
return null;
}

Expand Down Expand Up @@ -450,6 +457,23 @@ public Builder thresholdKey( final String thresholdKey )
return this;
}

private Logger extraLogger = Logger.VOID_LOGGER;

/**
* Sets a secondary logger that receives only the final preview summary
* (spots found count or error message). Useful to surface results in the
* main TrackMate log when the primary logger is an in-panel widget.
*
* @param extraLogger
* the secondary logger.
* @return this builder.
*/
public Builder extraLogger( final Logger extraLogger )
{
this.extraLogger = ( extraLogger != null ) ? extraLogger : Logger.VOID_LOGGER;
return this;
}

public DetectionPreview get()
{
if ( settings == null )
Expand All @@ -463,7 +487,7 @@ public DetectionPreview get()
if ( frameSupplier == null )
throw new IllegalArgumentException( "The detection frame supplier cannot be null." );

return new DetectionPreview(
final DetectionPreview dp = new DetectionPreview(
model,
settings,
detectorFactory,
Expand All @@ -472,6 +496,8 @@ public DetectionPreview get()
thresholdUpdater,
axisLabel,
thresholdKey );
dp.extraLogger = extraLogger;
return dp;
}
}
}
Loading