Skip to content

Commit 7d70b7d

Browse files
authored
Merge pull request #69 from scijava/scijava/scijava-ops-engine/non-readable-op-methods
Handle OpMethods that the SciJava Ops Engine module cannot read
2 parents c3a5c8a + 8788ba9 commit 7d70b7d

3 files changed

Lines changed: 195 additions & 111 deletions

File tree

‎imagej/imagej-ops2/src/main/java/net/imagej/ops2/convert/Converters.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public class Converters<I, O extends Type<O>> {
4444
* @output outputII
4545
* @implNote op names='convert'
4646
*/
47-
public final Functions.Arity3<RandomAccessible<I>, Converter<? super I, ? super O>, O, RandomAccessible<O>> generalConverterRA = (
48-
inputRA, converter, type) -> net.imglib2.converter.Converters.convert(inputRA, converter, type);
47+
public final Functions.Arity3<RandomAccessible<I>, Converter<? super I, ? super O>, O, RandomAccessible<O>> generalConverterRA =
48+
net.imglib2.converter.Converters::convert;
4949

5050
/**
5151
* @input inputII
@@ -54,7 +54,7 @@ public class Converters<I, O extends Type<O>> {
5454
* @output outputII
5555
* @implNote op names='convert'
5656
*/
57-
public final Functions.Arity3<IterableInterval<I>, Converter<? super I, ? super O>, O, IterableInterval<O>> generalConverterII = (
58-
inputII, converter, type) -> net.imglib2.converter.Converters.convert(inputII, converter, type);
57+
public final Functions.Arity3<IterableInterval<I>, Converter<? super I, ? super O>, O, IterableInterval<O>> generalConverterII =
58+
net.imglib2.converter.Converters::convert;
5959

6060
}

‎imagej/imagej-ops2/src/main/java/net/imagej/ops2/filter/gauss/Gaussians.java‎

Lines changed: 105 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.Arrays;
3333
import java.util.concurrent.ExecutorService;
3434

35+
import org.scijava.ops.spi.OpCollection;
36+
3537
import net.imglib2.RandomAccessible;
3638
import net.imglib2.RandomAccessibleInterval;
3739
import net.imglib2.algorithm.gauss3.Gauss3;
@@ -45,74 +47,78 @@
4547
import net.imglib2.type.numeric.real.FloatType;
4648
import net.imglib2.view.Views;
4749

48-
import org.scijava.function.Computers;
49-
import org.scijava.ops.spi.OpCollection;
50-
5150
/**
5251
* {@link OpCollection} containing various wrappings of Gaussian operations.
5352
*
5453
* @author Gabriel Selzer
55-
*
56-
* @param <T>
57-
* the input type
5854
*/
59-
public class Gaussians<T extends NumericType<T> & NativeType<T>> {
55+
public class Gaussians {
6056

6157
/**
62-
* Gaussian filter, wrapping {@link Gauss3} of imglib2-algorithms. Note that we
63-
* put this at a lower priority so then if the input is a
58+
* Gaussian filter, wrapping {@link Gauss3} of imglib2-algorithms. Note that
59+
* we put this at a lower priority so then if the input is a
6460
* {@link RandomAccessibleInterval} we match to
6561
* {@link Gaussians#defaultGaussRAISimple} instead.
6662
*
6763
* @author Stephan Saalfeld
6864
* @author Christian Dietz (University of Konstanz)
69-
* @param <T>
70-
* type of input and output
71-
* @input input
72-
* @input executorService
73-
* @input sigmas
74-
* @container output
75-
* @implNote op names='filter.gauss', priority='-100.'
65+
* @param <T> type of input and output
66+
* @param input the input image
67+
* @param es the {@link ExecutorService}
68+
* @param sigmas the sigmas for the Gaussian
69+
* @param output the pre-allocated output image
70+
* @implNote op names='filter.gauss', priority='-100.',
71+
* type='org.scijava.function.Computers$Arity3'
7672
*/
77-
public final Computers.Arity3<RandomAccessible<T>, ExecutorService, double[], RandomAccessibleInterval<T>> defaultGaussRA = (input,
78-
es, sigmas, output) -> {
73+
public static <T extends NumericType<T> & NativeType<T>> void defaultGaussRA(
74+
final RandomAccessible<T> input, //
75+
final ExecutorService es, //
76+
final double[] sigmas, //
77+
final RandomAccessibleInterval<T> output //
78+
) {
7979
try {
80-
SeparableSymmetricConvolution.convolve(Gauss3.halfkernels(sigmas), input, output,
81-
es);
82-
} catch (final IncompatibleTypeException e) {
80+
SeparableSymmetricConvolution.convolve(Gauss3.halfkernels(sigmas), input,
81+
output, es);
82+
}
83+
catch (final IncompatibleTypeException e) {
8384
throw new RuntimeException(e);
8485
}
85-
};
86+
}
8687

8788
/**
8889
* Gaussian filter, wrapping {@link Gauss3} of imglib2-algorithms.
8990
*
9091
* @author Christian Dietz (University of Konstanz)
9192
* @author Stephan Saalfeld
92-
* @param <T>
93-
* type of input and output
94-
* @input input
95-
* @input executorService
96-
* @input sigmas
97-
* @input outOfBoundsFactory
98-
* @container output
99-
* @implNote op names='filter.gauss'
93+
* @param <T> type of input and output
94+
* @param input the input image
95+
* @param es the {@link ExecutorService}
96+
* @param sigmas the sigmas for the gaussian
97+
* @param outOfBounds the {@link OutOfBoundsFactory} that defines how the
98+
* calculation is affected outside the input bounds.
99+
* @param output the output image
100+
* @implNote op names='filter.gauss',
101+
* type='org.scijava.function.Computers$Arity4'
100102
*/
101103
@SuppressWarnings({ "unchecked", "rawtypes" })
102-
public final Computers.Arity4<RandomAccessibleInterval<T>, ExecutorService, double[], //
103-
OutOfBoundsFactory<T, RandomAccessibleInterval<T>>, RandomAccessibleInterval<T>> defaultGaussRAI = (input,
104-
es, sigmas, outOfBounds, output) -> {
105-
106-
final RandomAccessible<FloatType> eIn = //
107-
(RandomAccessible) Views.extend(input, outOfBounds);
104+
public static <T extends NumericType<T> & NativeType<T>> void defaultGaussRAI(
105+
final RandomAccessibleInterval<T> input, //
106+
final ExecutorService es, //
107+
final double[] sigmas, //
108+
final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBounds, //
109+
final RandomAccessibleInterval<T> output //
110+
) {
111+
final RandomAccessible<FloatType> eIn = //
112+
(RandomAccessible) Views.extend(input, outOfBounds);
108113

109-
try {
110-
SeparableSymmetricConvolution.convolve(Gauss3.halfkernels(sigmas), eIn, output,
111-
es);
112-
} catch (final IncompatibleTypeException e) {
113-
throw new RuntimeException(e);
114-
}
115-
};
114+
try {
115+
SeparableSymmetricConvolution.convolve(Gauss3.halfkernels(sigmas), eIn,
116+
output, es);
117+
}
118+
catch (final IncompatibleTypeException e) {
119+
throw new RuntimeException(e);
120+
}
121+
}
116122

117123
// -- Convenience Ops -- //
118124

@@ -121,58 +127,76 @@ public class Gaussians<T extends NumericType<T> & NativeType<T>> {
121127
* {@link OutOfBoundsFactory}, in the case that the user does not provide one.
122128
*
123129
* @author Gabriel Selzer
124-
*
125-
* @param <T>
126-
* type of input
127-
* @input input
128-
* @input executorService
129-
* @input sigmas
130-
* @container output
131-
* @implNote op names='filter.gauss'
130+
* @param <T> type of input
131+
* @param input the input image
132+
* @param es the {@link ExecutorService}
133+
* @param sigmas the sigmas for the gaussian
134+
* @param output the output image
135+
* @implNote op names='filter.gauss',
136+
* type='org.scijava.function.Computers$Arity3'
132137
*/
133-
@SuppressWarnings({ "unchecked", "rawtypes" })
134-
public final Computers.Arity3<RandomAccessibleInterval<T>, ExecutorService, double[], RandomAccessibleInterval<T>> defaultGaussRAISimple = (
135-
input, es, sigmas, output) -> defaultGaussRAI.compute(input, es, sigmas,
136-
new OutOfBoundsMirrorFactory<>(Boundary.SINGLE), output);
138+
public static <T extends NumericType<T> & NativeType<T>> void
139+
defaultGaussRAISimple( //
140+
final RandomAccessibleInterval<T> input, //
141+
final ExecutorService es, //
142+
final double[] sigmas, //
143+
final RandomAccessibleInterval<T> output //
144+
) {
145+
defaultGaussRAI(input, es, sigmas, new OutOfBoundsMirrorFactory<>(
146+
Boundary.SINGLE), output);
147+
}
137148

138149
/**
139-
* Gaussian filter which can be called with single sigma, i.e. the sigma is the
140-
* same in each dimension.
150+
* Gaussian filter which can be called with single sigma, i.e. the sigma is
151+
* the same in each dimension.
141152
*
142153
* @author Christian Dietz (University of Konstanz)
143154
* @author Stephan Saalfeld
144-
* @param <T>
145-
* type of input
146-
* @input input
147-
* @input executorService
148-
* @input sigma
149-
* @input outOfBoundsFactory
150-
* @container output
151-
* @implNote op names='filter.gauss'
155+
* @param <T> type of input
156+
* @param input the input image
157+
* @param es the {@link ExecutorService}
158+
* @param sigma the sigmas for the Gaussian
159+
* @param outOfBounds the {@link OutOfBoundsFactory} that defines how the
160+
* calculation is affected outside the input bounds.
161+
* @param output the preallocated output image
162+
* @implNote op names='filter.gauss',
163+
* type='org.scijava.function.Computers$Arity4'
152164
*/
153-
public final Computers.Arity4<RandomAccessibleInterval<T>, ExecutorService, Double, //
154-
OutOfBoundsFactory<T, RandomAccessibleInterval<T>>, RandomAccessibleInterval<T>> //
155-
gaussRAISingleSigma = (input, es, sigma, outOfBounds, output) -> { //
165+
public static <T extends NumericType<T> & NativeType<T>> void
166+
gaussRAISingleSigma( //
167+
final RandomAccessibleInterval<T> input, //
168+
final ExecutorService es, //
169+
final Double sigma, //
170+
final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBounds, //
171+
final RandomAccessibleInterval<T> output //
172+
) {
156173
final double[] sigmas = new double[input.numDimensions()];
157174
Arrays.fill(sigmas, sigma);
158-
defaultGaussRAI.compute(input, es, sigmas, outOfBounds, output);
175+
defaultGaussRAI(input, es, sigmas, outOfBounds, output);
159176
};
160177

161178
/**
162-
* Gaussian filter which can be called with single sigma, i.e. the sigma is the
163-
* same in each dimension. Used when the user does not provide an
179+
* Gaussian filter which can be called with single sigma, i.e. the sigma is
180+
* the same in each dimension. Used when the user does not provide an
164181
* {@link OutOfBoundsFactory}
165182
*
166183
* @author Gabriel Selzer
167-
* @param <T>
168-
* type of input
169-
* @input input
170-
* @input executorService
171-
* @input sigma
172-
* @container output
173-
* @implNote op names='filter.gauss'
184+
* @param <T> type of input
185+
* @param input the input image
186+
* @param es the {@link ExecutorService}
187+
* @param sigma the sigmas for the gaussian
188+
* @param output the output image
189+
* @implNote op names='filter.gauss',
190+
* type='org.scijava.function.Computers$Arity3'
174191
*/
175-
public final Computers.Arity3<RandomAccessibleInterval<T>, ExecutorService, Double, RandomAccessibleInterval<T>> gaussRAISingleSigmaSimple = (
176-
input, es, sigma, output) -> gaussRAISingleSigma.compute(input, es, sigma,
177-
new OutOfBoundsMirrorFactory<>(Boundary.SINGLE), output);
192+
public static <T extends NumericType<T> & NativeType<T>> void
193+
gaussRAISingleSigmaSimple( //
194+
final RandomAccessibleInterval<T> input, //
195+
final ExecutorService es, //
196+
final Double sigma, //
197+
final RandomAccessibleInterval<T> output //
198+
) {
199+
gaussRAISingleSigma(input, es, sigma, new OutOfBoundsMirrorFactory<>(
200+
Boundary.SINGLE), output);
201+
}
178202
}

0 commit comments

Comments
 (0)