Skip to content

Commit 94ae742

Browse files
committed
MapNeighborhood: disable per-pixel history
Per-pixel operations with imglib2 we can reasonably assume to be operating on Type wrappers that have some level of reuse. These are not thread-safe to use as output keys in our history, thus we cannot be recording per-pixel history.
1 parent bd504d7 commit 94ae742

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎imagej/imagej-ops2/src/main/java/net/imagej/ops2/map/neighborhood/DefaultMapNeighborhood.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
import net.imglib2.view.Views;
3939

4040
import org.scijava.function.Computers;
41+
import org.scijava.ops.api.OpMetadata;
42+
import org.scijava.ops.api.RichOp;
43+
import org.scijava.ops.api.features.BaseOpHints;
4144

4245
/**
4346
* Evaluates a {@link UnaryComputerOp} for each {@link Neighborhood} on the
@@ -111,10 +114,26 @@ public void compute(final RandomAccessibleInterval<I> in1, final Shape in2,
111114
RandomAccessibleInterval<Neighborhood<I>> neighborhoodInput = Views
112115
.interval(in2.neighborhoodsRandomAccessibleSafe(in1), in1);
113116

117+
boolean restoreRecording = true;
118+
if (op instanceof RichOp) {
119+
OpMetadata metadata = ((RichOp) op).metadata();
120+
if (metadata.hints().contains(BaseOpHints.History.SKIP_RECORDING)) {
121+
restoreRecording = false;
122+
} else {
123+
metadata.setHints(metadata.hints().plus(BaseOpHints.History.SKIP_RECORDING));
124+
}
125+
}
126+
114127
LoopBuilder.setImages(neighborhoodInput, out).multiThreaded()
115128
.forEachPixel((neighborhood, outPixel) -> {
116129
op.compute(neighborhood, outPixel);
117130
});
131+
132+
if (restoreRecording && op instanceof RichOp) {
133+
OpMetadata metadata = ((RichOp) op).metadata();
134+
135+
metadata.setHints(metadata.hints().minus( BaseOpHints.History.SKIP_RECORDING));
136+
}
118137
}
119138

120139
}

‎imagej/imagej-ops2/src/main/java/net/imagej/ops2/map/neighborhood/MapNeighborhoodWithCenter.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040

4141
import org.scijava.function.Computers;
4242
import org.scijava.ops.api.OpEnvironment;
43+
import org.scijava.ops.api.OpMetadata;
44+
import org.scijava.ops.api.RichOp;
45+
import org.scijava.ops.api.features.BaseOpHints;
4346

4447
/**
4548
* Evaluates a {@link CenterAwareComputerOp} for each {@link Neighborhood} on
@@ -118,10 +121,25 @@ public void compute(final RandomAccessibleInterval<I> in1, final Shape in2,
118121
RandomAccessibleInterval<Neighborhood<I>> neighborhoodInput = Views
119122
.interval(in2.neighborhoodsRandomAccessibleSafe(in1), in1);
120123

124+
boolean restoreRecording = true;
125+
if (centerAwareOp instanceof RichOp) {
126+
OpMetadata metadata = ((RichOp) centerAwareOp).metadata();
127+
if (metadata.hints().contains(BaseOpHints.History.SKIP_RECORDING)) {
128+
restoreRecording = false;
129+
} else {
130+
metadata.hints().plus(BaseOpHints.History.SKIP_RECORDING);
131+
}
132+
}
133+
121134
LoopBuilder.setImages(neighborhoodInput, in1, out).multiThreaded()
122135
.forEachPixel((neighborhood, inPixel, outPixel) -> {
123136
centerAwareOp.compute(neighborhood, inPixel, outPixel);
124137
});
138+
139+
if (restoreRecording && centerAwareOp instanceof RichOp) {
140+
((RichOp)centerAwareOp).metadata().hints().minus(
141+
BaseOpHints.History.SKIP_RECORDING);
142+
}
125143
}
126144

127145
}

0 commit comments

Comments
 (0)