Skip to content

Commit bdb8df8

Browse files
authored
Merge pull request #64 from scijava/scijava/scijava-ops-engine/skip-map-history
Scijava/scijava ops engine/skip map history
2 parents 9abb96c + 94ae742 commit bdb8df8

5 files changed

Lines changed: 54 additions & 7 deletions

File tree

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

Lines changed: 22 additions & 3 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
@@ -88,7 +91,7 @@ public void compute(final RandomAccessibleInterval<I> in1, final Shape in2,
8891
* We also assume that the input and output have identical dimensions.
8992
*
9093
* @author Gabriel Selzer
91-
*@implNote op names='map.neighborhood', priority='100.'
94+
* @implNote op names='map.neighborhood', priority='100.'
9295
*/
9396
class MapNeighborhoodAllRAI<I, O> implements
9497
Computers.Arity3<RandomAccessibleInterval<I>, Shape, Computers.Arity1<Iterable<I>, O>, RandomAccessibleInterval<O>>
@@ -104,17 +107,33 @@ class MapNeighborhoodAllRAI<I, O> implements
104107
*/
105108
@Override
106109
public void compute(final RandomAccessibleInterval<I> in1, final Shape in2,
107-
final Computers.Arity1<Iterable<I>, O> centerAwareOp,
110+
final Computers.Arity1<Iterable<I>, O> op,
108111
final RandomAccessibleInterval<O> out)
109112
{
110113
// generate a neighborhood image with the bounds of the input
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) -> {
116-
centerAwareOp.compute(neighborhood, outPixel);
129+
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: 19 additions & 1 deletion
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
@@ -95,7 +98,7 @@ public void compute(final RandomAccessibleInterval<I> in1, final Shape in2,
9598
* We also assume that the input and output have identical dimensions.
9699
*
97100
* @author Gabriel Selzer
98-
*@implNote op names='map.neighborhood', priority='100.'
101+
* @implNote op names='map.neighborhood', priority='100.'
99102
*/
100103
class MapNeighborhoodWithCenterAllRAI<I, O> implements
101104
Computers.Arity3<RandomAccessibleInterval<I>, Shape, Computers.Arity2<Iterable<I>, I, O>, RandomAccessibleInterval<O>>
@@ -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
}

‎scijava/scijava-ops-api/src/main/java/org/scijava/ops/api/OpMetadata.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class OpMetadata {
1616
/* The hierarchy of OpInfos used to make the Op */
1717
private final InfoChain info;
1818
/* The set of Hints used to in the initial Op call */
19-
private final Hints hints;
19+
private Hints hints;
2020
/* The OpHistory used by the Op */
2121
private final OpHistory history;
2222

@@ -63,4 +63,12 @@ public OpHistory history() {
6363
return history;
6464
}
6565

66+
/**
67+
* Sets the {@link Hints} for this Op
68+
*
69+
* @param hints New {@link Hints} to use for this Op
70+
*/
71+
public void setHints(Hints hints) {
72+
this.hints = hints;
73+
}
6674
}

‎scijava/scijava-ops-engine/src/main/java/org/scijava/ops/engine/DefaultOpEnvironment.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ private List<RichOp<?>> resolveOpDependencies(OpInfo info,
551551
try {
552552
// TODO: Consider a new Hint implementation
553553
Hints hintsCopy = hints.plus(DependencyMatching.IN_PROGRESS,
554-
History.SKIP_RECORDING, Simplification.FORBIDDEN);
554+
Simplification.FORBIDDEN);
555555
if (!dependency.isAdaptable()) {
556556
hintsCopy = hintsCopy.plus(Adaptation.FORBIDDEN);
557557
}

‎scijava/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/impl/AbstractRichOp.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public void preprocess(Object... inputs) {
5151
@Override
5252
public void postprocess(Object output) {
5353
// Log a new execution
54-
metadata.history().logOutput(this, output);
54+
if (!metadata.hints().contains(History.SKIP_RECORDING)) {
55+
metadata.history().logOutput(this, output);
56+
}
5557
Progress.complete();
5658
}
5759

0 commit comments

Comments
 (0)