1313import org .mastodon .graph .object .ObjectEdge ;
1414import org .mastodon .graph .object .ObjectGraph ;
1515import org .mastodon .graph .object .ObjectVertex ;
16+ import org .mastodon .revised .mamut .MastodonLogger ;
1617import org .mastodon .revised .model .AbstractModel ;
17- import org .mastodon .revised .ui .ProgressListener ;
1818import org .scijava .InstantiableException ;
19- import org .scijava .app .StatusService ;
20- import org .scijava .log .LogService ;
19+ import org .scijava .log .LogSource ;
2120import org .scijava .plugin .Parameter ;
2221import org .scijava .plugin .PluginInfo ;
2322import org .scijava .plugin .PluginService ;
@@ -30,28 +29,34 @@ public abstract class AbstractFeatureComputerService< AM extends AbstractModel<
3029 private PluginService pluginService ;
3130
3231 @ Parameter
33- private LogService logService ;
34-
35- @ Parameter
36- private StatusService status ;
32+ private MastodonLogger logger ;
3733
3834 /**
3935 * Feature computers of any type, mapped by their key, for dependency
4036 * management.
4137 */
4238 private final Map < String , FeatureComputer < AM > > featureComputers = new HashMap <>();
4339
40+ private LogSource logSource ;
41+
42+ @ Override
43+ public void initialize ()
44+ {
45+ super .initialize ();
46+ logSource = logger .getLogSourceRoot ().subSource ( "Feature computer" );
47+ }
48+
4449 @ Override
45- public boolean compute ( final AM model , final FeatureModel featureModel , final Set < FeatureComputer < AM > > computers , final ProgressListener progressListener )
50+ public boolean compute ( final AM model , final FeatureModel featureModel , final Set < FeatureComputer < AM > > computers )
4651 {
4752 final ObjectGraph < FeatureComputer < AM > > dependencyGraph = getDependencyGraph ( computers );
4853 final TopologicalSort < ObjectVertex < FeatureComputer < AM > >, ObjectEdge < FeatureComputer < AM > > > sorter = new TopologicalSort <>( dependencyGraph );
4954
5055 if ( sorter .hasFailed () )
5156 {
52- logService .error ( "Could not compute features using " + computers +
53- " as they have a circular dependency." );
54- progressListener . showStatus ( "Circular dependency!" );
57+ logger .error ( "Could not compute features using " + computers +
58+ " as they have a circular dependency." , logSource );
59+ logger . setStatus ( "Circular dependency!" , logSource );
5560 return false ;
5661 }
5762
@@ -62,16 +67,16 @@ public boolean compute( final AM model, final FeatureModel featureModel, final S
6267 for ( final ObjectVertex < FeatureComputer < AM > > v : sorter .get () )
6368 {
6469 final FeatureComputer < AM > computer = v .getContent ();
65- progressListener . showStatus ( computer .getKey () );
70+ logger . setStatus ( computer .getKey (), logSource );
6671 final Feature < ?, ? > feature = computer .compute ( model );
6772 featureModel .declareFeature ( feature );
6873
69- progressListener . showProgress ( progress ++, computers .size () );
74+ logger . setProgress ( progress ++ / ( double ) computers .size (), logSource );
7075 }
7176
7277 final long end = System .currentTimeMillis ();
73- progressListener . clearStatus ( );
74- progressListener . showStatus ( String .format ( "Done in %.1f s." , ( end - start ) / 1000. ) );
78+ logger . setProgress ( 1. , logSource );
79+ logger . info ( String .format ( "Done in %.1f s." , ( end - start ) / 1000. ), logSource );
7580
7681 return true ;
7782 }
@@ -148,14 +153,14 @@ private final ObjectVertex< FeatureComputer< AM > > addDepVertex(
148153 final FeatureComputer < AM > computerDep = featureComputers .get ( dep );
149154 if ( null == computerDep )
150155 {
151- logService .error ( "Cannot add feature computer named " + dep + " as it is not registered." );
156+ logger .error ( "Cannot add feature computer named " + dep + " as it is not registered." , logSource );
152157 return null ;
153158 }
154159
155160 final ObjectVertex < FeatureComputer < AM > > target = addDepVertex ( computerDep , computerGraph , vref2 );
156161 if ( null == target )
157162 {
158- logService .error ( "Removing feature computer named " + computer + " as some of its dependencies could not be resolved." );
163+ logger .error ( "Removing feature computer named " + computer + " as some of its dependencies could not be resolved." , logSource );
159164 computerGraph .remove ( source );
160165 break ;
161166 }
@@ -180,8 +185,8 @@ protected < K extends FeatureComputer< AM > > void initializeFeatureComputers( f
180185 final String name = info .getName ();
181186 if ( featureComputers .keySet ().contains ( name ) )
182187 {
183- logService .error ( "Cannot register feature computer with name " + name + " of class " + cl +
184- ". There is already a feature computer registered with this name." );
188+ logger .error ( "Cannot register feature computer with name " + name + " of class " + cl +
189+ ". There is already a feature computer registered with this name." , logSource );
185190 continue ;
186191 }
187192
@@ -192,8 +197,8 @@ protected < K extends FeatureComputer< AM > > void initializeFeatureComputers( f
192197 }
193198 catch ( final InstantiableException e )
194199 {
195- logService .error ( "Could not instantiate computer with name " + name + " of class " + cl +
196- ":\n " + e .getMessage () );
200+ logger .error ( "Could not instantiate computer with name " + name + " of class " + cl +
201+ ":\n " + e .getMessage (), logSource );
197202 e .printStackTrace ();
198203 }
199204 }
0 commit comments