Skip to content

Commit 5acc2c4

Browse files
committed
Test for RandomAccessiblePair of Neighborhood
1 parent 4bf3a8a commit 5acc2c4

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.imglib2.algorithm.neighborhood;
2+
3+
import net.imglib2.Cursor;
4+
import net.imglib2.FinalDimensions;
5+
import net.imglib2.RandomAccess;
6+
import net.imglib2.RandomAccessible;
7+
import net.imglib2.RandomAccessibleInterval;
8+
import net.imglib2.img.Img;
9+
import net.imglib2.img.array.ArrayImgFactory;
10+
import net.imglib2.outofbounds.OutOfBoundsBorderFactory;
11+
import net.imglib2.outofbounds.OutOfBoundsFactory;
12+
import net.imglib2.type.numeric.integer.ByteType;
13+
import net.imglib2.util.Pair;
14+
import net.imglib2.view.Views;
15+
16+
import org.junit.Test;
17+
18+
public class RandomAccessiblePairWithNeighborhoodTest {
19+
20+
@Test
21+
public void test() {
22+
// Extend input with Views.extend()
23+
Img<ByteType> in = new ArrayImgFactory< ByteType >().create( new FinalDimensions(3, 3), new ByteType() );
24+
OutOfBoundsFactory<ByteType, RandomAccessibleInterval<ByteType>> outOfBoundsFactory =
25+
new OutOfBoundsBorderFactory<>();
26+
RandomAccessibleInterval<ByteType> extendedIn = Views.interval(Views.extend(in, outOfBoundsFactory), in); // FAILS
27+
// RandomAccessible<ByteType> extendedIn = Views.extend(in, outOfBoundsFactory); // WORKS
28+
29+
// Create RandomAccessiblePair
30+
final RandomAccessible<Neighborhood<ByteType>> safe = new RectangleShape(1,
31+
false).neighborhoodsRandomAccessibleSafe(extendedIn);
32+
RandomAccessible<Pair<Neighborhood<ByteType>, ByteType>> pair = Views.pair(safe, extendedIn);
33+
34+
// Set position out of bounds
35+
RandomAccess<Pair<Neighborhood<ByteType>, ByteType>> randomAccess = pair
36+
.randomAccess();
37+
randomAccess.setPosition(new int[] { 0, 0 });
38+
39+
// Get value from Neighborhood via RandomAccessiblePair
40+
Pair<Neighborhood<ByteType>, ByteType> pair2 = randomAccess.get();
41+
Neighborhood<ByteType> neighborhood = pair2.getA();
42+
Cursor<ByteType> cursor = neighborhood.cursor();
43+
44+
// Tries to access (-1, -1) of the source
45+
cursor.next().getRealDouble();
46+
}
47+
48+
}

0 commit comments

Comments
 (0)