Skip to content

Commit f5633d5

Browse files
committed
ImgMath: refactored classes and interfaces into their own files.
Also added an static ImgMath.compute method to further ease the use of the library.
1 parent b1c8457 commit f5633d5

26 files changed

+984
-861
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package net.imglib2.algorithm.math;
2+
3+
import net.imglib2.Localizable;
4+
import net.imglib2.algorithm.math.abstractions.ABinaryFunction;
5+
import net.imglib2.type.numeric.RealType;
6+
7+
public final class Add extends ABinaryFunction
8+
{
9+
public Add( final Object o1, final Object o2 )
10+
{
11+
super( o1, o2 );
12+
}
13+
14+
public Add( final Object... obs )
15+
{
16+
super( obs );
17+
}
18+
19+
@SuppressWarnings({ "rawtypes", "unchecked" })
20+
@Override
21+
public final void eval( final RealType output ) {
22+
this.a.eval( output );
23+
this.b.eval( this.scrap );
24+
output.add( this.scrap );
25+
}
26+
27+
@SuppressWarnings({ "rawtypes", "unchecked" })
28+
@Override
29+
public final void eval( final RealType output, final Localizable loc ) {
30+
this.a.eval( output, loc );
31+
this.b.eval( this.scrap, loc );
32+
output.add( this.scrap );
33+
}
34+
35+
@Override
36+
public Add copy() {
37+
final Add f = new Add( this.a.copy(), this.b.copy() );
38+
f.setScrap( this.scrap );
39+
return f;
40+
}
41+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package net.imglib2.algorithm.math;
2+
3+
import net.imglib2.Localizable;
4+
import net.imglib2.algorithm.math.abstractions.ABinaryFunction;
5+
import net.imglib2.algorithm.math.abstractions.IFunction;
6+
import net.imglib2.type.numeric.RealType;
7+
8+
public final class Div extends ABinaryFunction implements IFunction
9+
{
10+
11+
public Div( final Object o1, final Object o2 )
12+
{
13+
super( o1, o2 );
14+
}
15+
16+
public Div( final Object... obs )
17+
{
18+
super( obs );
19+
}
20+
21+
@SuppressWarnings({ "rawtypes", "unchecked" })
22+
@Override
23+
public final void eval( final RealType output ) {
24+
this.a.eval( output );
25+
this.b.eval( this.scrap );
26+
output.div( this.scrap );
27+
}
28+
29+
@SuppressWarnings({ "rawtypes", "unchecked" })
30+
@Override
31+
public final void eval( final RealType output, final Localizable loc) {
32+
this.a.eval( output, loc );
33+
this.b.eval( this.scrap, loc );
34+
output.div( this.scrap );
35+
}
36+
37+
@Override
38+
public Div copy() {
39+
final Div f = new Div( this.a.copy(), this.b.copy() );
40+
f.setScrap( this.scrap );
41+
return f;
42+
}
43+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.imglib2.algorithm.math;
2+
3+
import net.imglib2.algorithm.math.abstractions.Compare;
4+
import net.imglib2.type.numeric.RealType;
5+
6+
public final class Equal extends Compare
7+
{
8+
public Equal( final Object o1, final Object o2) {
9+
super( o1, o2 );
10+
}
11+
12+
@SuppressWarnings({ "rawtypes", "unchecked" })
13+
public final boolean compare( final RealType t1, final RealType t2 )
14+
{
15+
return 0 == t1.compareTo( t2 );
16+
}
17+
18+
@Override
19+
public Equal copy() {
20+
final Equal copy = new Equal( this.a.copy(), this.b.copy() );
21+
copy.setScrap( this.scrap );
22+
return copy;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.imglib2.algorithm.math;
2+
3+
import net.imglib2.algorithm.math.abstractions.Compare;
4+
import net.imglib2.type.numeric.RealType;
5+
6+
public final class GreaterThan extends Compare
7+
{
8+
public GreaterThan( final Object o1, final Object o2) {
9+
super(o1, o2);
10+
}
11+
12+
@SuppressWarnings({ "rawtypes", "unchecked" })
13+
public final boolean compare( final RealType t1, final RealType t2 )
14+
{
15+
return 1 == t1.compareTo( t2 );
16+
}
17+
18+
@Override
19+
public GreaterThan copy() {
20+
final GreaterThan copy = new GreaterThan( this.a.copy(), this.b.copy() );
21+
copy.setScrap( this.scrap );
22+
return copy;
23+
}
24+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.imglib2.algorithm.math;
2+
3+
import net.imglib2.Localizable;
4+
import net.imglib2.algorithm.math.abstractions.ATrinaryFunction;
5+
import net.imglib2.type.numeric.RealType;
6+
7+
public final class If extends ATrinaryFunction
8+
{
9+
public If( final Object o1, final Object o2, final Object o3 )
10+
{
11+
super( o1, o2, o3 );
12+
}
13+
14+
@Override
15+
public final void eval( final RealType<?> output ) {
16+
this.a.eval( this.scrap );
17+
if ( 0.0f != this.scrap.getRealFloat() )
18+
{
19+
// Then
20+
this.b.eval( output );
21+
} else
22+
{
23+
// Else
24+
this.c.eval( output );
25+
}
26+
}
27+
28+
@Override
29+
public final void eval( final RealType<?> output, final Localizable loc ) {
30+
this.a.eval( this.scrap, loc );
31+
if ( 0.0f != this.scrap.getRealFloat() )
32+
{
33+
// Then
34+
this.b.eval( output, loc );
35+
} else
36+
{
37+
// Else
38+
this.c.eval( output, loc );
39+
}
40+
}
41+
42+
@Override
43+
public If copy() {
44+
final If copy = new If( this.a.copy(), this.b.copy(), this.c.copy() );
45+
copy.setScrap( this.scrap );
46+
return copy;
47+
}
48+
}

0 commit comments

Comments
 (0)