Skip to content

Commit f84f1b3

Browse files
gselzerctrueden
authored andcommitted
WIP: port math Ops
TODO: Port code-generated Ops
1 parent f623fd7 commit f84f1b3

5 files changed

Lines changed: 1516 additions & 0 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
30+
package net.imagej.ops.math;
31+
32+
import net.imglib2.type.numeric.RealType;
33+
34+
import org.scijava.ops.OpField;
35+
import org.scijava.ops.core.OpCollection;
36+
import org.scijava.ops.core.computer.BiComputer;
37+
import org.scijava.ops.core.computer.Computer3;
38+
import org.scijava.param.Parameter;
39+
import org.scijava.plugin.Plugin;
40+
import org.scijava.struct.ItemIO;
41+
42+
/**
43+
* Binary Ops of the {@code math} namespace which operate on {@link RealType}s.
44+
*
45+
* TODO: Can these be static?
46+
*
47+
* @author Leon Yang
48+
*/
49+
@Plugin(type = OpCollection.class)
50+
public class BinaryRealTypeMath <I1 extends RealType<I1>, I2 extends RealType<I2>, O extends RealType<O>>{
51+
52+
/**
53+
* Sets the real component of an output real number to the addition of the
54+
* real components of two input real numbers.
55+
*/
56+
@OpField(names = "math.add")
57+
@Parameter(key = "input1")
58+
@Parameter(key = "input2")
59+
@Parameter(key = "sum", type = ItemIO.BOTH)
60+
public final BiComputer<I1, I2, O> adder = (input1, input2, output) ->
61+
output.setReal(input1.getRealDouble() + input2.getRealDouble());
62+
63+
/**
64+
* Sets the real component of an output real number to the logical AND of the
65+
* real component of two input real numbers.
66+
*/
67+
@OpField(names = "math.and")
68+
@Parameter(key = "input1")
69+
@Parameter(key = "input2")
70+
@Parameter(key = "result", type = ItemIO.BOTH)
71+
public final BiComputer<I1, I2, O> ander = (input1, input2, output) ->
72+
output.setReal((long) input1.getRealDouble() & (long) input2
73+
.getRealDouble());
74+
75+
/**
76+
* Sets the real component of an output real number to the division of the
77+
* real component of two input real numbers.
78+
*/
79+
@OpField(names = "math.divide")
80+
@Parameter(key = "input1")
81+
@Parameter(key = "input2")
82+
@Parameter(key = "divideByZeroValue")
83+
@Parameter(key = "result", type = ItemIO.BOTH)
84+
public final Computer3<I1, I2, Double, O> divider = (input1, input2, dbzVal, output) -> {
85+
if (input2.getRealDouble() == 0) {
86+
output.setReal(dbzVal);
87+
}
88+
else {
89+
output.setReal(input1.getRealDouble() / input2.getRealDouble());
90+
}
91+
};
92+
93+
/**
94+
* Sets the real component of an output real number to the multiplication of
95+
* the real component of two input real numbers.
96+
*/
97+
@OpField(names = "math.multiply")
98+
@Parameter(key = "input1")
99+
@Parameter(key = "input2")
100+
@Parameter(key = "result", type = ItemIO.BOTH)
101+
public final BiComputer<I1, I2, O> multiplier = (input1, input2, output) ->
102+
output.setReal(input1.getRealDouble() * input2.getRealDouble());
103+
104+
/**
105+
* Sets the real component of an output real number to the logical OR of the
106+
* real component of two input real numbers.
107+
*/
108+
@OpField(names = "math.or")
109+
@Parameter(key = "input1")
110+
@Parameter(key = "input2")
111+
@Parameter(key = "result", type = ItemIO.BOTH)
112+
public final BiComputer<I1, I2, O> orer = (input1, input2, output) ->
113+
output.setReal((long) input1.getRealDouble() | (long) input2
114+
.getRealDouble());
115+
116+
/**
117+
* Sets the real component of an output real number to the subtraction between
118+
* the real component of two input real numbers.
119+
*/
120+
@OpField(names = "math.subtract")
121+
@Parameter(key = "input1")
122+
@Parameter(key = "input2")
123+
@Parameter(key = "result", type = ItemIO.BOTH)
124+
public final BiComputer<I1, I2, O> subtracter = (input1, input2, output) ->
125+
output.setReal(input1.getRealDouble() - input2.getRealDouble());
126+
127+
/**
128+
* Sets the real component of an output real number to the logical XOR of the
129+
* real component of two input real numbers.
130+
*/
131+
@OpField(names = "math.xor")
132+
@Parameter(key = "input1")
133+
@Parameter(key = "input2")
134+
@Parameter(key = "result", type = ItemIO.BOTH)
135+
public final BiComputer<I1, I2, O> xorer = (input1, input2, output) ->
136+
output.setReal((long) input1.getRealDouble() ^ (long) input2
137+
.getRealDouble());
138+
139+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
30+
package net.imagej.ops.math;
31+
32+
import net.imglib2.type.Type;
33+
import net.imglib2.type.numeric.NumericType;
34+
35+
import org.scijava.ops.OpField;
36+
import org.scijava.ops.core.OpCollection;
37+
import org.scijava.ops.core.computer.Computer;
38+
import org.scijava.ops.core.computer.NullaryComputer;
39+
import org.scijava.param.Parameter;
40+
import org.scijava.plugin.Plugin;
41+
import org.scijava.struct.ItemIO;
42+
43+
/**
44+
* Nullary Ops of the {@code math} namespace which operate on
45+
* {@link NumericType}s.
46+
*
47+
* @author Leon Yang
48+
*/
49+
@Plugin(type = OpCollection.class)
50+
public class NullaryNumericTypeMath <T extends Type<T>, N extends NumericType<N>>{
51+
52+
/**
53+
* Sets the output to a constant.
54+
*/
55+
@OpField(names = "math.assign")
56+
@Parameter(key = "constant")
57+
@Parameter(key = "output", type = ItemIO.BOTH)
58+
public final Computer<T, T> assigner = (constant, output) -> output.set(constant);
59+
60+
/**
61+
* Sets the output to zero.
62+
*/
63+
@OpField(names = "math.zero")
64+
@Parameter(key = "output", type = ItemIO.BOTH)
65+
public final NullaryComputer<N> zeroer = (output) -> output.setZero();
66+
67+
}

0 commit comments

Comments
 (0)