Skip to content

Commit 5c82415

Browse files
acardonactrueden
authored andcommitted
ImgMath: add pow as an operation, following the addition of the Pow interface
to NumericType.
1 parent f1c25c2 commit 5c82415

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

src/main/java/net/imglib2/algorithm/math/ImgMath.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ static public final Div div( final Object... obs )
149149
return new Div( obs );
150150
}
151151

152+
static public final Pow pow( final Object o1, final Object o2 )
153+
{
154+
return new Pow( o1, o2 );
155+
}
156+
157+
static public final Pow power( final Object... obs )
158+
{
159+
return new Pow( obs );
160+
}
161+
162+
static public final Pow power( final Object o1, final Object o2 )
163+
{
164+
return new Pow( o1, o2 );
165+
}
166+
167+
static public final Pow pow( final Object... obs )
168+
{
169+
return new Pow( obs );
170+
}
171+
152172
static public final Max max( final Object o1, final Object o2 )
153173
{
154174
return new Max( o1, o2 );
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package net.imglib2.algorithm.math;
2+
3+
import java.util.Map;
4+
5+
import net.imglib2.algorithm.math.abstractions.ABinaryFunction;
6+
import net.imglib2.algorithm.math.abstractions.OFunction;
7+
import net.imglib2.algorithm.math.execution.LetBinding;
8+
import net.imglib2.algorithm.math.execution.Power;
9+
import net.imglib2.algorithm.math.execution.Variable;
10+
import net.imglib2.converter.Converter;
11+
import net.imglib2.type.numeric.RealType;
12+
13+
public final class Pow extends ABinaryFunction
14+
{
15+
public Pow( final Object o1, final Object o2 )
16+
{
17+
super( o1, o2 );
18+
}
19+
20+
public Pow( final Object... obs )
21+
{
22+
super( obs );
23+
}
24+
25+
@Override
26+
public < O extends RealType< O > > Power< O > reInit(
27+
final O tmp,
28+
final Map< String, LetBinding< O > > bindings,
29+
final Converter< RealType< ? >, O > converter,
30+
final Map< Variable< O >, OFunction< O > > imgSources )
31+
{
32+
return new Power< O >( tmp.copy(),
33+
this.a.reInit( tmp, bindings, converter, imgSources ),
34+
this.b.reInit( tmp, bindings, converter, imgSources ) );
35+
}
36+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package net.imglib2.algorithm.math.execution;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import net.imglib2.Localizable;
7+
import net.imglib2.algorithm.math.abstractions.OFunction;
8+
import net.imglib2.type.numeric.RealType;
9+
10+
public class Power< O extends RealType< O > > implements OFunction< O >
11+
{
12+
private final OFunction< O > a, b;
13+
private final O scrap;
14+
15+
public Power( final O scrap, final OFunction< O > a, final OFunction< O > b )
16+
{
17+
this.scrap = scrap;
18+
this.a = a;
19+
this.b = b;
20+
}
21+
22+
@Override
23+
public final O eval()
24+
{
25+
this.scrap.set( this.a.eval() );
26+
this.scrap.pow( this.b.eval() );
27+
return this.scrap;
28+
}
29+
30+
@Override
31+
public final O eval( final Localizable loc )
32+
{
33+
this.scrap.set( this.a.eval( loc ) );
34+
this.scrap.pow( this.b.eval( loc ) );
35+
return this.scrap;
36+
}
37+
38+
@Override
39+
public List< OFunction< O > > children()
40+
{
41+
return Arrays.asList( this.a, this.b );
42+
}
43+
44+
@Override
45+
public final double evalDouble()
46+
{
47+
return Math.pow( this.a.evalDouble(), this.b.evalDouble() );
48+
}
49+
50+
@Override
51+
public final double evalDouble( final Localizable loc )
52+
{
53+
return Math.pow( this.a.evalDouble( loc ), this.b.evalDouble( loc ) );
54+
}
55+
}

0 commit comments

Comments
 (0)