From 9d8dad563847d3a86a4149c1dfdacd00ac0fc470 Mon Sep 17 00:00:00 2001 From: Matthias Arzt Date: Sat, 19 Jan 2019 16:30:34 +0100 Subject: [PATCH] Update parent to pom-indago 2.2.12 --- pom.xml | 3 +-- .../tr2d/plugins/seg/MySegmentationItem.java | 5 ++--- .../indago/tr2d/plugins/seg/PredictionLayer.java | 16 ++++++++-------- .../tr2d/plugins/seg/SegmentationModel.java | 16 +++++++++++++--- .../indago/tr2d/plugins/seg/ThresholdButton.java | 9 ++++++--- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 5ae175c..4295f54 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ sc.fiji pom-indago - 2.2.11 + 2.2.12 @@ -48,7 +48,6 @@ net.imglib2 imglib2-labkit - 0.1.15-SNAPSHOT com.miglayout diff --git a/src/main/java/com/indago/tr2d/plugins/seg/MySegmentationItem.java b/src/main/java/com/indago/tr2d/plugins/seg/MySegmentationItem.java index a28985e..f4a881b 100644 --- a/src/main/java/com/indago/tr2d/plugins/seg/MySegmentationItem.java +++ b/src/main/java/com/indago/tr2d/plugins/seg/MySegmentationItem.java @@ -49,8 +49,7 @@ public MySegmentationItem(SegmentationModel model, Segmenter segmenter, Labeling this.model = model; this.labeling = labeling; this.probability = probability; - segmenter.trainingCompletedListeners().add(this::resetProbability); - thresholds.notifier().add(ignore -> resetSegmentation()); + thresholds.notifier().add(this::resetSegmentation); } public MySegmentationItem(SegmentationModel model, Segmenter segmenter) { @@ -123,7 +122,7 @@ public Labeling labeling() { } public void train() { - segmenter().train(Collections.singletonList(new ValuePair<>(model.image(), labeling))); + super.train(Collections.singletonList(new ValuePair<>(model.image(), labeling))); } public Holder> thresholds() { diff --git a/src/main/java/com/indago/tr2d/plugins/seg/PredictionLayer.java b/src/main/java/com/indago/tr2d/plugins/seg/PredictionLayer.java index 13c9f72..8817d57 100644 --- a/src/main/java/com/indago/tr2d/plugins/seg/PredictionLayer.java +++ b/src/main/java/com/indago/tr2d/plugins/seg/PredictionLayer.java @@ -36,8 +36,8 @@ public class PredictionLayer implements BdvLayer { private final SharedQueue queue = new SharedQueue(Runtime.getRuntime() .availableProcessors()); private final Holder< Boolean > visibility; - private Notifier listeners = new Notifier<>(); - private Notifier makeVisible = new Notifier<>(); + private Notifier listeners = new Notifier(); + private Notifier makeVisible = new Notifier(); private RandomAccessibleInterval> view; private AffineTransform3D transformation; private Set alreadyRegistered = Collections.newSetFromMap( @@ -53,7 +53,7 @@ public PredictionLayer(Holder< ? extends MySegmentationItem > model, this.view = Views.interval(segmentationContainer, selected.interval()); this.visibility = visibility; classifierChanged(); - model.notifier().add(ignore -> classifierChanged()); + model.notifier().add(this::classifierChanged); registerListener(model.get()); } @@ -61,15 +61,15 @@ private void registerListener(MySegmentationItem segmenter) { if (alreadyRegistered.contains(segmenter)) return; alreadyRegistered.add(segmenter); final Segmenter segmenter1 = segmenter.segmenter(); - segmenter1.trainingCompletedListeners().add(() -> onTrainingFinished( + segmenter.results().segmentationChangedListeners().add(() -> onTrainingFinished( segmenter1)); - segmenter.thresholds().notifier().add(ignore -> onTrainingFinished( + segmenter.thresholds().notifier().add(() -> onTrainingFinished( segmenter1)); } private void onTrainingFinished(Segmenter segmenter) { if (model.get().segmenter() == segmenter) { - makeVisible.forEach(Runnable::run); + makeVisible.notifyListeners(); classifierChanged(); } } @@ -89,7 +89,7 @@ private void classifierChanged() { .extendValue(coloredVolatileView(segmentationItem), new VolatileARGBType( 0)) : getEmptyPrediction(selected); segmentationContainer.setSource(source); - listeners.forEach(Runnable::run); + listeners.notifyListeners(); } private RandomAccessibleInterval coloredVolatileView( @@ -142,7 +142,7 @@ public BdvShowable image() { } @Override - public Notifier listeners() { + public Notifier listeners() { return listeners; } diff --git a/src/main/java/com/indago/tr2d/plugins/seg/SegmentationModel.java b/src/main/java/com/indago/tr2d/plugins/seg/SegmentationModel.java index f717d89..42f719d 100644 --- a/src/main/java/com/indago/tr2d/plugins/seg/SegmentationModel.java +++ b/src/main/java/com/indago/tr2d/plugins/seg/SegmentationModel.java @@ -15,6 +15,7 @@ import net.imglib2.labkit.segmentation.weka.TimeSeriesSegmenter; import net.imglib2.labkit.segmentation.weka.TrainableSegmentationSegmenter; import net.imglib2.labkit.utils.LabkitUtils; +import net.imglib2.labkit.utils.Notifier; import net.imglib2.realtransform.AffineTransform3D; import net.imglib2.type.numeric.NumericType; import net.imglib2.type.numeric.integer.IntType; @@ -41,8 +42,9 @@ public class SegmentationModel implements private final RandomAccessibleInterval> compatibleImage; private final CellGrid grid; private final Holder segmentationVisibility = new DefaultHolder<>(true); + private final Notifier listeners = new Notifier(); - private Context context; + private final Context context; public SegmentationModel( RandomAccessibleInterval< ? extends NumericType< ? > > image, @@ -68,8 +70,8 @@ private static DefaultInputImage initInputImage( return defaultInputImage; } - private void selectedSegmenterChanged(MySegmentationItem segmentationItem) { - imageLabelingModel.labeling().set(segmentationItem.labeling()); + private void selectedSegmenterChanged() { + imageLabelingModel.labeling().set(selectedSegmenter.get().labeling()); } @Override @@ -107,6 +109,7 @@ public MySegmentationItem addSegmenter() { MySegmentationItem segmentationItem = new MySegmentationItem(this, initClassifier()); this.segmenters.add(segmentationItem); + listeners.notifyListeners(); return segmentationItem; } @@ -122,6 +125,7 @@ public void remove(MySegmentationItem item) { segmenters.remove(item); if(!segmenters.contains(selectedSegmenter.get())) selectedSegmenter.set(segmenters.get(0)); + listeners.notifyListeners(); } private Segmenter initClassifier() { @@ -194,6 +198,7 @@ private void replaceSegmentationItems(List< MySegmentationItem > result) { if(segmenters.isEmpty()) addSegmenter(); selectedSegmenter().set(segmenters.get(0)); + listeners.notifyListeners(); } public void save(ProjectFolder folder) throws IOException { @@ -208,4 +213,9 @@ public void save(ProjectFolder folder) throws IOException { public Holder segmentationVisibility() { return segmentationVisibility; } + + @Override + public Notifier listChangeListeners() { + return listeners; + } } diff --git a/src/main/java/com/indago/tr2d/plugins/seg/ThresholdButton.java b/src/main/java/com/indago/tr2d/plugins/seg/ThresholdButton.java index 8ed4d2f..b4ddd68 100644 --- a/src/main/java/com/indago/tr2d/plugins/seg/ThresholdButton.java +++ b/src/main/java/com/indago/tr2d/plugins/seg/ThresholdButton.java @@ -3,6 +3,7 @@ import net.imglib2.img.array.ArrayImgs; import net.imglib2.labkit.inputimage.DefaultInputImage; +import net.imglib2.labkit.models.Holder; import net.imglib2.labkit.panel.SegmenterPanel; import org.scijava.Context; @@ -23,7 +24,7 @@ public class ThresholdButton { public ThresholdButton(SegmentationModel segmentationModel) { this.segmentationModel = segmentationModel; segmentationModel.selectedSegmenter().notifier().add( - ignore -> updateThresholds()); + this::updateThresholds); button = new JButton("Thresholds ..."); button.addActionListener(a -> { String text = JOptionPane.showInputDialog(null, "Enter thresholds", @@ -83,7 +84,9 @@ public static void main(String... args) { frame.setSize(500, 500); frame.setVisible(true); segmentationModel.selectedSegmenter().notifier().add(System.out::println); - segmentationModel.selectedSegmenter().get().thresholds().notifier().add( - x -> System.out.println(Arrays.toString(x.toArray()))); + final Holder< List< Double > > thresholds = + segmentationModel.selectedSegmenter().get().thresholds(); + thresholds.notifier().add( + () -> System.out.println(Arrays.toString(thresholds.get().toArray()))); } }