Skip to content

Commit 7604b05

Browse files
committed
formatted flood fill test according to ImgLib2 code style
1 parent accb914 commit 7604b05

File tree

1 file changed

+90
-91
lines changed

1 file changed

+90
-91
lines changed

src/test/java/net/imglib2/algorithm/fill/FloodFillTest.java

Lines changed: 90 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
* %%
1212
* Redistribution and use in source and binary forms, with or without
1313
* modification, are permitted provided that the following conditions are met:
14-
*
14+
*
1515
* 1. Redistributions of source code must retain the above copyright notice,
1616
* this list of conditions and the following disclaimer.
1717
* 2. Redistributions in binary form must reproduce the above copyright notice,
1818
* this list of conditions and the following disclaimer in the documentation
1919
* and/or other materials provided with the distribution.
20-
*
20+
*
2121
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2222
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2323
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -34,6 +34,9 @@
3434

3535
package net.imglib2.algorithm.fill;
3636

37+
import org.junit.Assert;
38+
import org.junit.Test;
39+
3740
import net.imglib2.Cursor;
3841
import net.imglib2.Point;
3942
import net.imglib2.algorithm.neighborhood.DiamondShape;
@@ -45,99 +48,95 @@
4548
import net.imglib2.util.Pair;
4649
import net.imglib2.view.ExtendedRandomAccessibleInterval;
4750
import net.imglib2.view.Views;
48-
import org.junit.Assert;
49-
import org.junit.Test;
5051

5152
/**
5253
* @author Philipp Hanslovsky <hanslovskyp@janelia.hhmi.org>
5354
* @author Stephan Saalfeld <saalfelds@janelia.hhmi.org>
5455
*/
55-
public class FloodFillTest {
56-
57-
private static final long START_LABEL = 1;
58-
private static final long FILL_LABEL = 2;
59-
private static final int[] N_DIMS = { 1, 2, 3, 4 };
60-
private static final int SIZE_OF_EACH_DIM = 60;
61-
62-
63-
private static < T extends IntegerType < T > > void runTest(
64-
int nDim,
65-
int sizeOfEachDim,
66-
ImgFactory< T > imageFactory,
67-
T t )
68-
{
69-
long[] dim = new long[nDim];
70-
long[] c = new long[nDim];
71-
long r = sizeOfEachDim / 4;
72-
for ( int d = 0; d < nDim; ++d ) {
73-
dim[d] = sizeOfEachDim;
74-
c[d] = sizeOfEachDim / 3;
75-
}
76-
77-
long divisionLine = r / 3;
78-
79-
Img<T> img = imageFactory.create(dim, t.copy() );
80-
Img<T> refImg = imageFactory.create(dim, t.copy());
81-
82-
for (Cursor<T> i = img.cursor(), ref = refImg.cursor(); i.hasNext(); )
83-
{
84-
i.fwd();
85-
ref.fwd();
86-
long diffSum = 0;
87-
for ( int d = 0; d < nDim; ++d )
88-
{
89-
long diff = i.getLongPosition( d ) - c[d];
90-
diffSum += diff * diff;
91-
92-
}
93-
94-
if ( ( diffSum < r * r ) ) {
95-
if ((i.getLongPosition(0) - c[0] < divisionLine)) {
96-
i.get().setInteger(START_LABEL);
97-
ref.get().setInteger( FILL_LABEL );
98-
} else if (i.getLongPosition(0) - c[0] > divisionLine) {
99-
i.get().setInteger( START_LABEL );
100-
ref.get().setInteger( START_LABEL );
101-
}
102-
}
103-
104-
}
105-
106-
T fillLabel = t.createVariable();
107-
fillLabel.setInteger( FILL_LABEL );
108-
109-
ExtendedRandomAccessibleInterval<T, Img<T>> extendedImg = Views.extendValue(img, fillLabel);
110-
111-
Filter<Pair<T, T>, Pair<T, T>> filter = new Filter< Pair< T, T >, Pair< T, T > >() {
112-
@Override
113-
public boolean accept(Pair< T, T > p1, Pair< T, T > p2) {
114-
return ( p1.getB().getIntegerLong() != p2.getB().getIntegerLong() ) &&
115-
( p1.getA().getIntegerLong() == p2.getA().getIntegerLong() );
116-
}
117-
};
118-
119-
FloodFill.fill( extendedImg, extendedImg, new Point( c ), fillLabel, new DiamondShape( 1 ), filter );
120-
121-
for ( Cursor< T > imgCursor = img.cursor(), refCursor = refImg.cursor(); imgCursor.hasNext(); )
122-
{
123-
Assert.assertEquals( refCursor.next(), imgCursor.next() );
124-
}
125-
126-
127-
}
128-
129-
@Test
130-
public void runTests()
131-
{
132-
for ( int nDim : N_DIMS )
133-
{
134-
runTest(
135-
nDim,
136-
SIZE_OF_EACH_DIM,
137-
new ArrayImgFactory<LongType>(),
138-
new LongType()
139-
);
140-
}
141-
}
56+
public class FloodFillTest
57+
{
58+
private static final long START_LABEL = 1;
59+
60+
private static final long FILL_LABEL = 2;
61+
62+
private static final int[] N_DIMS = { 1, 2, 3, 4 };
63+
64+
private static final int SIZE_OF_EACH_DIM = 60;
65+
66+
private static < T extends IntegerType< T > > void runTest( final int nDim, final int sizeOfEachDim, final ImgFactory< T > imageFactory, final T t )
67+
{
68+
final long[] dim = new long[ nDim ];
69+
final long[] c = new long[ nDim ];
70+
final long r = sizeOfEachDim / 4;
71+
for ( int d = 0; d < nDim; ++d )
72+
{
73+
dim[ d ] = sizeOfEachDim;
74+
c[ d ] = sizeOfEachDim / 3;
75+
}
76+
77+
final long divisionLine = r / 3;
78+
79+
final Img< T > img = imageFactory.create( dim, t.copy() );
80+
final Img< T > refImg = imageFactory.create( dim, t.copy() );
81+
82+
for ( Cursor< T > i = img.cursor(), ref = refImg.cursor(); i.hasNext(); )
83+
{
84+
i.fwd();
85+
ref.fwd();
86+
long diffSum = 0;
87+
for ( int d = 0; d < nDim; ++d )
88+
{
89+
final long diff = i.getLongPosition( d ) - c[ d ];
90+
diffSum += diff * diff;
91+
92+
}
93+
94+
if ( ( diffSum < r * r ) )
95+
{
96+
if ( ( i.getLongPosition( 0 ) - c[ 0 ] < divisionLine ) )
97+
{
98+
i.get().setInteger( START_LABEL );
99+
ref.get().setInteger( FILL_LABEL );
100+
}
101+
else if ( i.getLongPosition( 0 ) - c[ 0 ] > divisionLine )
102+
{
103+
i.get().setInteger( START_LABEL );
104+
ref.get().setInteger( START_LABEL );
105+
}
106+
}
107+
108+
}
109+
110+
final T fillLabel = t.createVariable();
111+
fillLabel.setInteger( FILL_LABEL );
112+
113+
final ExtendedRandomAccessibleInterval< T, Img< T > > extendedImg = Views.extendValue( img, fillLabel );
114+
115+
final Filter< Pair< T, T >, Pair< T, T > > filter = new Filter< Pair< T, T >, Pair< T, T > >()
116+
{
117+
@Override
118+
public boolean accept( final Pair< T, T > p1, final Pair< T, T > p2 )
119+
{
120+
return ( p1.getB().getIntegerLong() != p2.getB().getIntegerLong() ) && ( p1.getA().getIntegerLong() == p2.getA().getIntegerLong() );
121+
}
122+
};
123+
124+
FloodFill.fill( extendedImg, extendedImg, new Point( c ), fillLabel, new DiamondShape( 1 ), filter );
125+
126+
for ( Cursor< T > imgCursor = img.cursor(), refCursor = refImg.cursor(); imgCursor.hasNext(); )
127+
{
128+
Assert.assertEquals( refCursor.next(), imgCursor.next() );
129+
}
130+
131+
}
132+
133+
@Test
134+
public void runTests()
135+
{
136+
for ( final int nDim : N_DIMS )
137+
{
138+
runTest( nDim, SIZE_OF_EACH_DIM, new ArrayImgFactory< LongType >(), new LongType() );
139+
}
140+
}
142141

143142
}

0 commit comments

Comments
 (0)