}
public static boolean testImg( final long[] size, final ImgFactory< FloatType > factory1, final ImgFactory< FloatType > factory2 )
{
// create the image
final Img< FloatType > img1 = factory1.create( size, new FloatType() );
final Img< FloatType > img2 = factory2.create( size, new FloatType() );
final int numDimensions = img1.numDimensions();
// get a reference to compare to
final float[] reference = createReference( img1 );
// copy into a second image using simple cursors
final Cursor< FloatType > cursor1 = img1.cursor();
final Cursor< FloatType > cursor2 = img2.cursor();
while ( cursor1.hasNext() )
{
cursor1.fwd();
cursor2.fwd();
cursor2.get().set( cursor1.get() );
}
cursor1.reset();
cursor2.reset();
// and copy right back
while ( cursor2.hasNext() )
{
cursor1.fwd();
cursor2.fwd();
cursor1.get().set( cursor2.get() );
}
// copy back into a second image using localizable and positionable
// cursors
final Cursor< FloatType > localizableCursor1 = img1.localizingCursor();
final RandomAccess< FloatType > positionable2 = img2.randomAccess();
int i = 0;
while ( localizableCursor1.hasNext() )
{
localizableCursor1.fwd();
++i;
if ( i % 2 == 0 )
positionable2.setPosition( localizableCursor1 );
else
positionable2.setPosition( localizableCursor1 );
final FloatType t2 = positionable2.get();
final FloatType t1 = localizableCursor1.get();
// float f1 = t1.getRealFloat();
// float f2 = t2.getRealFloat();
t2.set( t1 );
// positionable2.get().set( localizableCursor1.get() );
}
// copy again to the first image using a LocalizableByDimOutsideCursor
// and a LocalizableByDimCursor
final ExtendedRandomAccessibleInterval< FloatType, Img< FloatType > > extendedImg2 = new ExtendedRandomAccessibleInterval< FloatType, Img< FloatType > >( img2, new OutOfBoundsPeriodicFactory< FloatType, Img< FloatType > >() );
final RandomAccess< FloatType > outsideCursor2 = extendedImg2.randomAccess();
localizableCursor1.reset();
final int[] pos = new int[ numDimensions ];
i = 0;
int direction = 1;
try
{
while ( localizableCursor1.hasNext() )
{
localizableCursor1.fwd();
localizableCursor1.localize( pos );
++i;
// how many times far away from the original image do we grab
// the pixel
final int distance = i % 5;
direction *= -1;
pos[ i % numDimensions ] += img1.dimension( i % numDimensions ) * distance * direction;
if ( i % 7 == 0 )
outsideCursor2.setPosition( pos );
else
outsideCursor2.setPosition( pos );
final FloatType t1 = localizableCursor1.get();
final FloatType t2 = outsideCursor2.get();
// final float f1 = t1.getRealFloat();
// final float f2 = t2.getRealFloat();
t1.set( t2 );