Skip to content

Commit d9ac2a9

Browse files
authored
Merge pull request #15 from trackmate-sc/rework-serialization
Rework serialization. of parameter sweep.
2 parents fc2b067 + c4032a9 commit d9ac2a9

29 files changed

Lines changed: 497 additions & 478 deletions

src/main/java/fiji/plugin/trackmate/helper/ctc/CTCMetricsRunner.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import java.nio.file.Paths;
2929
import java.nio.file.SimpleFileVisitor;
3030
import java.nio.file.attribute.BasicFileAttributes;
31-
import java.util.Optional;
32-
import java.util.regex.Pattern;
33-
import java.util.stream.Stream;
3431

3532
import org.scijava.Context;
3633

@@ -57,7 +54,7 @@ public class CTCMetricsRunner extends MetricsRunner
5754
/**
5855
* Path to ground truth folder.
5956
*/
60-
private String gtPath;
57+
private final String gtPath;
6158

6259
public CTCMetricsRunner( final String gtPath, final String saveFolder, final Context context )
6360
{
@@ -70,42 +67,6 @@ public CTCMetricsRunner( final String gtPath, final String saveFolder, final Con
7067
@Override
7168
public TrackingMetrics performMetricsMeasurements( final TrackMate trackmate ) throws MetricsComputationErrorException
7269
{
73-
// Do we have a folder for the ground-truth, or a TrackMate file?
74-
if ( gtPath.toLowerCase().endsWith( ".xml" ) )
75-
{
76-
// Assume it's a TrackMate file, export it to CTC file format.
77-
batchLogger.log( "Ground-truth is in the TrackMate file format.\n" );
78-
79-
final String regexPattern = "\\d{2}_GT";
80-
final Pattern pattern = Pattern.compile( regexPattern );
81-
try (Stream< Path > paths = Files.list( resultsRootPath ))
82-
{
83-
final Optional< Path > ctcGTfolder = paths
84-
.filter( Files::isDirectory )
85-
.filter( path -> pattern.matcher( path.getFileName().toString() ).matches() )
86-
.findFirst();
87-
88-
if ( ctcGTfolder.isPresent() )
89-
{
90-
batchLogger.log( "Found a GT folder in CTC format: " + ctcGTfolder.get() + "\n" );
91-
gtPath = ctcGTfolder.get().toString();
92-
}
93-
else
94-
{
95-
batchLogger.log( "Exporting GT file to CTC format.\n" );
96-
gtPath = CTCExporter.exportAll( resultsRootPath.toString(), trackmate, ExportType.GOLD_TRUTH, batchLogger );
97-
gtPath = Paths.get( gtPath ).getParent().toString();
98-
}
99-
}
100-
catch ( final IOException e )
101-
{
102-
batchLogger.error( "Error reading the GT parent directory. Stopping."
103-
+ "\n" + e.getMessage() );
104-
e.printStackTrace();
105-
throw new RuntimeException( e );
106-
}
107-
}
108-
10970
batchLogger.log( "Exporting test results to CTC format.\n" );
11071
final int id = CTCExporter.getAvailableDatasetID( resultsRootPath.toString() );
11172
final String resultsFolder = CTCExporter.getExportTrackingDataPath( resultsRootPath.toString(), id, ExportType.RESULTS, trackmate );

src/main/java/fiji/plugin/trackmate/helper/model/AbstractSweepModelBase.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
* it under the terms of the GNU General Public License as
99
* published by the Free Software Foundation, either version 3 of the
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Public License for more details.
16-
*
16+
*
1717
* You should have received a copy of the GNU General Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/gpl-3.0.html>.
@@ -38,7 +38,7 @@ public interface ModelListener
3838
public void modelChanged();
3939
}
4040

41-
private transient Listeners.List< ModelListener > modelListeners;
41+
private final transient Listeners.List< ModelListener > modelListeners = new Listeners.SynchronizedList<>();
4242

4343
protected final String name;
4444

@@ -68,16 +68,6 @@ public String getName()
6868

6969
public final Listeners.List< ModelListener > listeners()
7070
{
71-
if ( modelListeners == null )
72-
{
73-
/*
74-
* Work around the listeners field being null after deserialization.
75-
* We also need to register again the sub-models.
76-
*/
77-
this.modelListeners = new Listeners.SynchronizedList<>();
78-
for ( final AbstractParamSweepModel< ? > model : models.values() )
79-
model.listeners().add( () -> notifyListeners() );
80-
}
8171
return modelListeners;
8272
}
8373

src/main/java/fiji/plugin/trackmate/helper/model/ParameterSweepModel.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
* it under the terms of the GNU General Public License as
99
* published by the Free Software Foundation, either version 3 of the
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Public License for more details.
16-
*
16+
*
1717
* You should have received a copy of the GNU General Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/gpl-3.0.html>.
@@ -48,7 +48,7 @@
4848
public class ParameterSweepModel
4949
{
5050

51-
private final transient Listeners.List< ModelListener > modelListeners;
51+
private final transient Listeners.List< ModelListener > modelListeners = new Listeners.SynchronizedList<>();
5252

5353
private final Map< String, DetectorSweepModel > detectorModels;
5454

@@ -62,8 +62,6 @@ public class ParameterSweepModel
6262

6363
public ParameterSweepModel()
6464
{
65-
modelListeners = new Listeners.SynchronizedList<>();
66-
6765
// Auto-detect detectors & trackers.
6866
detectorModels = autoDetect( DetectorSweepModel.class );
6967
trackerModels = autoDetect( TrackerSweepModel.class );
@@ -78,18 +76,34 @@ public ParameterSweepModel()
7876
this.spotFilterModels = new ArrayList<>();
7977
this.trackFilterModels = new ArrayList<>();
8078

81-
registerListeners();
82-
}
83-
84-
public void registerListeners()
85-
{
86-
// Forward component changes to listeners.
79+
// Register models.
8780
detectorModels().forEach( model -> model.listeners().add( () -> notifyListeners() ) );
8881
trackerModels().forEach( model -> model.listeners().add( () -> notifyListeners() ) );
8982
spotFilterModels().forEach( model -> model.listeners().add( () -> notifyListeners() ) );
9083
trackFilterModels().forEach( model -> model.listeners().add( () -> notifyListeners() ) );
9184
}
9285

86+
/**
87+
* This is used <b>only</b> for deserizalisation, to re-register listeners
88+
* in the model components of the main models.
89+
*/
90+
void reRegisterListeners()
91+
{
92+
final ModelListener notifier = () -> notifyListeners();
93+
reRegisterListeners( detectorModels.values(), notifier );
94+
reRegisterListeners( trackerModels.values(), notifier );
95+
reRegisterListeners( spotFilterModels, notifier );
96+
reRegisterListeners( spotFilterModels, notifier );
97+
}
98+
99+
private void reRegisterListeners( final Collection< ? extends AbstractSweepModelBase > models, final ModelListener notifier )
100+
{
101+
models.forEach( m -> {
102+
m.listeners().add( notifier );
103+
m.models.values().forEach( sm -> sm.listeners().add( notifier ) );
104+
} );
105+
}
106+
93107
public Collection< DetectorSweepModel > detectorModels()
94108
{
95109
return detectorModels.values();
@@ -179,7 +193,7 @@ public List< TrackerSweepModel > getActiveTracker()
179193
/**
180194
* Returns the count of the different settings that will be generated from
181195
* this model.
182-
*
196+
*
183197
* @return the count of settings.
184198
*/
185199
public int count()
@@ -190,7 +204,7 @@ public int count()
190204
/**
191205
* Returns the count of the different tracker settings that will be
192206
* generated from this model.
193-
*
207+
*
194208
* @return the count of settings.
195209
*/
196210
public int countTrackerSettings()
@@ -213,7 +227,7 @@ public int countTrackerSettings()
213227
/**
214228
* Returns the count of the different detector settings that will be
215229
* generated from this model.
216-
*
230+
*
217231
* @return the count of settings.
218232
*/
219233
public int countDetectorSettings()
@@ -236,7 +250,7 @@ public int countDetectorSettings()
236250
/**
237251
* Returns the count of the different spot filter settings that will be
238252
* generated from this model.
239-
*
253+
*
240254
* @return the count of settings.
241255
*/
242256
public int countSpotFilterSettings()
@@ -260,7 +274,7 @@ public int countSpotFilterSettings()
260274
/**
261275
* Returns the count of the different track filter settings that will be
262276
* generated from this model.
263-
*
277+
*
264278
* @return the count of settings.
265279
*/
266280
public int countTrackFilterSettings()

0 commit comments

Comments
 (0)