Skip to content

Commit 066eb2e

Browse files
committed
ImgMath: OffsetSource, allowing a ViewableFunction (most ops) to be read with an offset.
1 parent 3eb870f commit 066eb2e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ static public final < T extends RealType< T > > RandomAccessibleSource< T > offs
371371
return new RandomAccessibleSource< T >( src, offset );
372372
}
373373

374+
static public final < T extends RealType< T > > OffsetSource< T > offset( final IFunction f, final long[] offset )
375+
{
376+
return new OffsetSource< T >( f, offset );
377+
}
378+
374379
static public final < T extends RealType< T > > IFunction source( final RandomAccessible< T > src )
375380
{
376381
if ( src instanceof RandomAccessibleInterval< ? > )
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package net.imglib2.algorithm.math;
2+
3+
import java.util.Map;
4+
5+
import net.imglib2.RandomAccessible;
6+
import net.imglib2.algorithm.math.abstractions.IFunction;
7+
import net.imglib2.algorithm.math.abstractions.OFunction;
8+
import net.imglib2.algorithm.math.abstractions.RandomAccessOnly;
9+
import net.imglib2.algorithm.math.abstractions.ViewableFunction;
10+
import net.imglib2.algorithm.math.execution.IterableRandomAccessibleFunction;
11+
import net.imglib2.algorithm.math.execution.LetBinding;
12+
import net.imglib2.algorithm.math.execution.RandomAccessibleOffsetSourceDirect;
13+
import net.imglib2.algorithm.math.execution.Variable;
14+
import net.imglib2.converter.Converter;
15+
import net.imglib2.type.numeric.RealType;
16+
17+
public class OffsetSource< I extends RealType< I > > extends ViewableFunction implements RandomAccessOnly< I >
18+
{
19+
private final IFunction f;
20+
private final long[] offset;
21+
22+
public OffsetSource( final IFunction f, final long[] offset )
23+
{
24+
this.f = f;
25+
this.offset = offset;
26+
}
27+
28+
@Override
29+
public < O extends RealType< O > > OFunction< O > reInit(
30+
final O tmp,
31+
final Map< String, LetBinding< O > > bindings,
32+
final Converter< RealType< ? >, O > converter,
33+
final Map< Variable< O >, OFunction< O > > imgSources )
34+
{
35+
return new RandomAccessibleOffsetSourceDirect< O >(
36+
tmp.copy(),
37+
new IterableRandomAccessibleFunction< O, O >( this.f, converter, tmp.createVariable(), tmp.createVariable(), null ),
38+
this.offset );
39+
}
40+
41+
@Override
42+
public RandomAccessible< I > getRandomAccessible()
43+
{
44+
return this.view();
45+
}
46+
}

0 commit comments

Comments
 (0)