Skip to content

Commit f031382

Browse files
committed
Migrate Transform Op Tests
1 parent ccb114c commit f031382

32 files changed

Lines changed: 3379 additions & 17 deletions

File tree

src/main/java/net/imagej/ops/transform/Transforms.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* {@link OpCollection} containing all of the transform {@link Op}s.
4545
*
4646
* TODO move these type variables into each Op?
47-
*
47+
*
4848
* @author Gabe Selzer
4949
*
5050
*
@@ -95,7 +95,6 @@ public class Transforms<T, R extends RealType<R>, N extends NumericType<N>, Y ex
9595

9696
@OpField(names = "transform.collapseRealView")
9797
@Parameter(key = "input")
98-
@Parameter(key = "numChannels")
9998
@Parameter(key = "result", type = ItemIO.OUTPUT)
10099
public final Function<RandomAccessibleInterval<R>, CompositeIntervalView<R, ? extends RealComposite<R>>> collapseRealViewRAI = Views::collapseReal;
101100

@@ -107,7 +106,6 @@ public class Transforms<T, R extends RealType<R>, N extends NumericType<N>, Y ex
107106

108107
@OpField(names = "transform.collapseNumericView")
109108
@Parameter(key = "input")
110-
@Parameter(key = "numChannels")
111109
@Parameter(key = "result", type = ItemIO.OUTPUT)
112110
public final Function<RandomAccessibleInterval<N>, CompositeIntervalView<N, ? extends NumericComposite<N>>> collapseNumericViewRAI = Views::collapseNumeric;
113111

@@ -137,7 +135,7 @@ public class Transforms<T, R extends RealType<R>, N extends NumericType<N>, Y ex
137135
@Parameter(key = "result", type = ItemIO.OUTPUT)
138136
public final TriFunction<Integer, StackAccessMode, List<RandomAccessibleInterval<T>>, RandomAccessibleInterval<T>> concatenateStackList = Views::concatenate;
139137

140-
@OpField(names = "transform.dropSingletonDimensions")
138+
@OpField(names = "transform.dropSingletonDimensionsView")
141139
@Parameter(key = "input")
142140
@Parameter(key = "result", type = ItemIO.OUTPUT)
143141
public final Function<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>> dropSingletonDimensions = Views::dropSingletonDimensions;
@@ -217,14 +215,14 @@ public class Transforms<T, R extends RealType<R>, N extends NumericType<N>, Y ex
217215
@Parameter(key = "result", type = ItemIO.OUTPUT)
218216
public final BiFunction<E, InterpolatorFactory<T, E>, RealRandomAccessible<T>> interpolateView = Views::interpolate;
219217

220-
@OpField(names = "transform.interpolateView")
218+
@OpField(names = "transform.intervalView")
221219
@Parameter(key = "input")
222220
@Parameter(key = "min")
223221
@Parameter(key = "max")
224222
@Parameter(key = "result", type = ItemIO.OUTPUT)
225223
public final TriFunction<RandomAccessible<T>, long[], long[], IntervalView<T>> intervalMinMax = Views::interval;
226224

227-
@OpField(names = "transform.interpolateView")
225+
@OpField(names = "transform.intervalView")
228226
@Parameter(key = "input")
229227
@Parameter(key = "interval")
230228
@Parameter(key = "result", type = ItemIO.OUTPUT)
@@ -254,6 +252,19 @@ public class Transforms<T, R extends RealType<R>, N extends NumericType<N>, Y ex
254252
@Parameter(key = "result", type = ItemIO.OUTPUT)
255253
public final BiFunction<RandomAccessibleInterval<T>, long[], IntervalView<T>> offsetRAI = Views::offset;
256254

255+
@OpField(names = "transform.offsetView")
256+
@Parameter(key = "input")
257+
@Parameter(key = "intervalMin")
258+
@Parameter(key = "intervalMax")
259+
@Parameter(key = "result", type = ItemIO.OUTPUT)
260+
public final TriFunction<RandomAccessible<T>, long[], long[], IntervalView<T>> offsetIntervalMinMax = Views::offsetInterval;
261+
262+
@OpField(names = "transform.offsetView")
263+
@Parameter(key = "input")
264+
@Parameter(key = "interval")
265+
@Parameter(key = "result", type = ItemIO.OUTPUT)
266+
public final BiFunction<RandomAccessible<T>, Interval, IntervalView<T>> offsetInterval = Views::offsetInterval;
267+
257268
@OpField(names = "transform.permuteView", priority = Priority.LOW)
258269
@Parameter(key = "input")
259270
@Parameter(key = "fromAxis")
@@ -296,7 +307,7 @@ public class Transforms<T, R extends RealType<R>, N extends NumericType<N>, Y ex
296307

297308
@OpField(names = "transform.rasterView")
298309
@Parameter(key = "input")
299-
@Parameter(key = "result")
310+
@Parameter(key = "result", type = ItemIO.OUTPUT)
300311
public final Function<RealRandomAccessible<T>, RandomAccessibleOnRealRandomAccessible<T>> rasterize = Views::raster;
301312

302313
@OpField(names = "transform.rotateView", priority = Priority.LOW)
@@ -328,23 +339,23 @@ public class Transforms<T, R extends RealType<R>, N extends NumericType<N>, Y ex
328339
@Parameter(key = "result", type = ItemIO.OUTPUT)
329340
public final QuadFunction<RandomAccessible<T>, Interval, Integer, Integer, IntervalView<T>> shearInterval = Views::shear;
330341

331-
@OpField(names = "transform.shearView")
342+
@OpField(names = "transform.stackView")
332343
@Parameter(key = "inputs")
333344
@Parameter(key = "result", type = ItemIO.OUTPUT)
334345
public final Function<List<? extends RandomAccessibleInterval<T>>, RandomAccessibleInterval<T>> stackList = Views::stack;
335346

336-
@OpField(names = "transform.shearView")
347+
@OpField(names = "transform.stackView")
337348
@Parameter(key = "inputs")
338349
@Parameter(key = "result", type = ItemIO.OUTPUT)
339350
public final Function<RandomAccessibleInterval<T>[], RandomAccessibleInterval<T>> stackArray = Views::stack;
340351

341-
@OpField(names = "transform.shearView")
352+
@OpField(names = "transform.stackView")
342353
@Parameter(key = "stackAccessMode")
343354
@Parameter(key = "inputs")
344355
@Parameter(key = "result", type = ItemIO.OUTPUT)
345356
public final BiFunction<StackAccessMode, List<? extends RandomAccessibleInterval<T>>, RandomAccessibleInterval<T>> stackAccessList = Views::stack;
346357

347-
@OpField(names = "transform.shearView")
358+
@OpField(names = "transform.stackView")
348359
@Parameter(key = "stackAccessMode")
349360
@Parameter(key = "inputs")
350361
@Parameter(key = "result", type = ItemIO.OUTPUT)
@@ -401,7 +412,7 @@ public class Transforms<T, R extends RealType<R>, N extends NumericType<N>, Y ex
401412
@Parameter(key = "result", type = ItemIO.OUTPUT)
402413
public final QuadFunction<RandomAccessible<T>, Interval, Integer, Integer, IntervalView<T>> unshearRAI = Views::unshear;
403414

404-
@OpField(names = "transform.zeroMin")
415+
@OpField(names = "transform.zeroMinView")
405416
@Parameter(key = "input")
406417
@Parameter(key = "result", type = ItemIO.OUTPUT)
407418
public final Function<RandomAccessibleInterval<T>, IntervalView<T>> zeroMinView = Views::zeroMin;

src/main/java/org/scijava/ops/util/Functions.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import org.scijava.ops.OpService;
88
import org.scijava.ops.core.Op;
9+
import org.scijava.ops.core.QuadFunction;
10+
import org.scijava.ops.core.TriFunction;
911
import org.scijava.types.Nil;
1012
import org.scijava.util.Types;
1113

@@ -18,8 +20,8 @@ private Functions() {
1820
// NB: Prevent instantiation of utility class.
1921
}
2022

21-
public static <I, O> Function<I, O> unary(final OpService ops, final String opName,
22-
final Nil<I> inputType, final Nil<O> outputType, final Object... secondaryArgs) {
23+
public static <I, O> Function<I, O> unary(final OpService ops, final String opName, final Nil<I> inputType,
24+
final Nil<O> outputType, final Object... secondaryArgs) {
2325

2426
Nil<Function<I, O>> functionNil = new Nil<Function<I, O>>() {
2527
@Override
@@ -56,4 +58,43 @@ public Type getType() {
5658
secondaryArgs);
5759
}
5860

61+
public static <I1, I2, I3, O> TriFunction<I1, I2, I3, O> ternary(final OpService ops, final String opName,
62+
final Nil<I1> input1Type, final Nil<I2> input2Type, final Nil<I3> input3Type, final Nil<O> outputType,
63+
final Object... secondaryArgs) {
64+
65+
Nil<TriFunction<I1, I2, I3, O>> functionNil = new Nil<TriFunction<I1, I2, I3, O>>() {
66+
@Override
67+
public Type getType() {
68+
return Types.parameterize(TriFunction.class, new Type[] { input1Type.getType(), input2Type.getType(),
69+
input3Type.getType(), outputType.getType() });
70+
}
71+
};
72+
73+
return ops.findOp( //
74+
opName, //
75+
functionNil, //
76+
new Nil[] { input1Type, input2Type, input3Type }, //
77+
new Nil[] { outputType }, //
78+
secondaryArgs);
79+
}
80+
81+
public static <I1, I2, I3, I4, O> QuadFunction<I1, I2, I3, I4, O> quaternary(final OpService ops,
82+
final String opName, final Nil<I1> input1Type, final Nil<I2> input2Type, final Nil<I3> input3Type,
83+
final Nil<I4> input4Type, final Nil<O> outputType, final Object... secondaryArgs) {
84+
85+
Nil<QuadFunction<I1, I2, I3, I4, O>> functionNil = new Nil<QuadFunction<I1, I2, I3, I4, O>>() {
86+
@Override
87+
public Type getType() {
88+
return Types.parameterize(QuadFunction.class, new Type[] { input1Type.getType(), input2Type.getType(),
89+
input3Type.getType(), input4Type.getType(), outputType.getType() });
90+
}
91+
};
92+
93+
return ops.findOp( //
94+
opName, //
95+
functionNil, //
96+
new Nil[] { input1Type, input2Type, input3Type, input4Type }, //
97+
new Nil[] { outputType }, //
98+
secondaryArgs);
99+
}
59100
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.transform.addDimensionView;
30+
31+
import static org.junit.Assert.assertEquals;
32+
33+
import java.util.function.Function;
34+
35+
import net.imglib2.RandomAccessible;
36+
import net.imglib2.RandomAccessibleInterval;
37+
import net.imglib2.img.Img;
38+
import net.imglib2.img.array.ArrayImgFactory;
39+
import net.imglib2.type.numeric.real.DoubleType;
40+
import net.imglib2.view.IntervalView;
41+
import net.imglib2.view.MixedTransformView;
42+
import net.imglib2.view.Views;
43+
44+
import org.junit.Test;
45+
import org.scijava.ops.AbstractTestEnvironment;
46+
import org.scijava.ops.core.TriFunction;
47+
import org.scijava.types.Nil;
48+
49+
/**
50+
* Tests {@link net.imagej.ops.Ops.Transform.AddDimensionView} ops.
51+
* <p>
52+
* This test only checks if the op call works with all parameters and that the
53+
* result is equal to that of the {@link Views} method call. It is not a
54+
* correctness test of {@link Views} itself.
55+
* </p>
56+
*
57+
* @author Tim-Oliver Buchholz (University of Konstanz)
58+
*/
59+
public class AddDimensionViewTest extends AbstractTestEnvironment {
60+
61+
@Test
62+
public void addDimensionTest() {
63+
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
64+
65+
MixedTransformView<DoubleType> il2 = Views.addDimension((RandomAccessible<DoubleType>) img);
66+
67+
Function<RandomAccessible<DoubleType>, MixedTransformView<DoubleType>> addDimFunc = ops().findOp(
68+
"transform.addDimensionView",
69+
new Nil<Function<RandomAccessible<DoubleType>, MixedTransformView<DoubleType>>>() {
70+
}, new Nil[] { new Nil<RandomAccessible<DoubleType>>() {
71+
} }, new Nil<MixedTransformView<DoubleType>>() {
72+
});
73+
MixedTransformView<DoubleType> opr = addDimFunc.apply(img);
74+
75+
assertEquals(il2.numDimensions(), opr.numDimensions());
76+
boolean[] il2Transform = new boolean[3];
77+
boolean[] oprTransform = new boolean[3];
78+
il2.getTransformToSource().getComponentZero(il2Transform);
79+
opr.getTransformToSource().getComponentZero(oprTransform);
80+
for (int i = 0; i < il2Transform.length; i++) {
81+
assertEquals(il2Transform[i], oprTransform[i]);
82+
}
83+
}
84+
85+
@Test
86+
public void addDimensionMinMaxTest() {
87+
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
88+
long max = 20;
89+
long min = 0;
90+
91+
IntervalView<DoubleType> il2 = Views.addDimension(img, min, max);
92+
93+
TriFunction<RandomAccessibleInterval<DoubleType>, Long, Long, IntervalView<DoubleType>> addDimFunc = ops()
94+
.findOp(
95+
"transform.addDimensionView",
96+
new Nil<TriFunction<RandomAccessibleInterval<DoubleType>, Long, Long, IntervalView<DoubleType>>>() {
97+
}, new Nil[] { new Nil<RandomAccessibleInterval<DoubleType>>() {
98+
}, new Nil<Long>() {
99+
}, new Nil<Long>() {
100+
} }, new Nil<IntervalView<DoubleType>>() {
101+
});
102+
IntervalView<DoubleType> opr = addDimFunc.apply(img, min, max);
103+
104+
assertEquals(il2.numDimensions(), opr.numDimensions(), 0.0);
105+
for (int i = 0; i < il2.numDimensions(); i++) {
106+
assertEquals(il2.dimension(i), opr.dimension(i), 0.0);
107+
}
108+
}
109+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.transform.collapseNumericView;
30+
31+
import static org.junit.Assert.assertEquals;
32+
33+
import java.util.function.BiFunction;
34+
import java.util.function.Function;
35+
36+
import net.imglib2.RandomAccessible;
37+
import net.imglib2.RandomAccessibleInterval;
38+
import net.imglib2.img.Img;
39+
import net.imglib2.img.array.ArrayImgFactory;
40+
import net.imglib2.type.numeric.NativeARGBDoubleType;
41+
import net.imglib2.view.Views;
42+
import net.imglib2.view.composite.CompositeIntervalView;
43+
import net.imglib2.view.composite.CompositeView;
44+
import net.imglib2.view.composite.NumericComposite;
45+
46+
import org.junit.Test;
47+
import org.scijava.ops.AbstractTestEnvironment;
48+
import org.scijava.ops.util.Functions;
49+
import org.scijava.types.Nil;
50+
51+
/**
52+
* Tests {@link net.imagej.ops.Ops.Transform.CollapseNumericView} ops.
53+
* <p>
54+
* This test only checks if the op call works with all parameters and that the
55+
* result is equal to that of the {@link Views} method call. It is not a
56+
* correctness test of {@link Views} itself.
57+
* </p>
58+
*
59+
* @author Tim-Oliver Buchholz (University of Konstanz)
60+
*/
61+
public class CollapseNumericViewTest extends AbstractTestEnvironment {
62+
63+
@Test
64+
public void defaultCollapseNumericTest() {
65+
66+
Function<RandomAccessibleInterval<NativeARGBDoubleType>, CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>>> collapseFunc = Functions
67+
.unary(ops(), "transform.collapseNumericView",
68+
new Nil<RandomAccessibleInterval<NativeARGBDoubleType>>() {
69+
},
70+
new Nil<CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>>>() {
71+
});
72+
73+
Img<NativeARGBDoubleType> img = new ArrayImgFactory<NativeARGBDoubleType>().create(new int[] { 10, 10 },
74+
new NativeARGBDoubleType());
75+
76+
CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2 = Views
77+
.collapseNumeric((RandomAccessibleInterval<NativeARGBDoubleType>) img);
78+
CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr = collapseFunc
79+
.apply(img);
80+
81+
assertEquals(il2.numDimensions(), opr.numDimensions());
82+
83+
BiFunction<RandomAccessible<NativeARGBDoubleType>, Integer, CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>>> collapseFuncRA = Functions
84+
.binary(ops(), "transform.collapseNumericView",
85+
new Nil<RandomAccessible<NativeARGBDoubleType>>() {
86+
}, new Nil<Integer>() {
87+
},
88+
new Nil<CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>>>() {
89+
});
90+
91+
CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2_2 = Views
92+
.collapseNumeric((RandomAccessible<NativeARGBDoubleType>) img, 1);
93+
CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr_2 = collapseFuncRA.apply(img,
94+
1);
95+
96+
assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
97+
}
98+
99+
}

0 commit comments

Comments
 (0)