Skip to content

Commit

Permalink
Update parent to pom-indago 2.2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
maarzt committed Jan 19, 2019
1 parent 2dcd8bf commit 9d8dad5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>sc.fiji</groupId>
<artifactId>pom-indago</artifactId>
<version>2.2.11</version>
<version>2.2.12</version>
</parent>

<properties>
Expand Down Expand Up @@ -48,7 +48,6 @@
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-labkit</artifactId>
<version>0.1.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.miglayout</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<List<Double>> thresholds() {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/indago/tr2d/plugins/seg/PredictionLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runnable> listeners = new Notifier<>();
private Notifier<Runnable> makeVisible = new Notifier<>();
private Notifier listeners = new Notifier();
private Notifier makeVisible = new Notifier();
private RandomAccessibleInterval<? extends NumericType<?>> view;
private AffineTransform3D transformation;
private Set<MySegmentationItem> alreadyRegistered = Collections.newSetFromMap(
Expand All @@ -53,23 +53,23 @@ 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());
}

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();
}
}
Expand All @@ -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<VolatileARGBType> coloredVolatileView(
Expand Down Expand Up @@ -142,7 +142,7 @@ public BdvShowable image() {
}

@Override
public Notifier<Runnable> listeners() {
public Notifier listeners() {
return listeners;
}

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/indago/tr2d/plugins/seg/SegmentationModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,8 +42,9 @@ public class SegmentationModel implements
private final RandomAccessibleInterval<? extends NumericType<?>> compatibleImage;
private final CellGrid grid;
private final Holder<Boolean> segmentationVisibility = new DefaultHolder<>(true);
private final Notifier listeners = new Notifier();

private Context context;
private final Context context;

public SegmentationModel(
RandomAccessibleInterval< ? extends NumericType< ? > > image,
Expand All @@ -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
Expand Down Expand Up @@ -107,6 +109,7 @@ public MySegmentationItem addSegmenter() {
MySegmentationItem segmentationItem = new MySegmentationItem(this,
initClassifier());
this.segmenters.add(segmentationItem);
listeners.notifyListeners();
return segmentationItem;
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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 {
Expand All @@ -208,4 +213,9 @@ public void save(ProjectFolder folder) throws IOException {
public Holder<Boolean> segmentationVisibility() {
return segmentationVisibility;
}

@Override
public Notifier listChangeListeners() {
return listeners;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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",
Expand Down Expand Up @@ -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())));
}
}

0 comments on commit 9d8dad5

Please sign in to comment.