@SuppressWarnings( "unchecked" ) @Override public Cursor< T > cursor( final Interval interval ) { if ( this.sourceInterval instanceof SubIntervalIterable ) return ( ( SubIntervalIterable< T > ) this.sourceInterval ).cursor( interval ); else return Views.interval( this.sourceInterval, interval ).cursor(); }
@SuppressWarnings( "unchecked" ) @Override public Cursor< LabelingType< L > > cursor( final Interval interval ) { if ( this.sourceInterval instanceof SubIntervalIterable ) return ( ( SubIntervalIterable< LabelingType< L > > ) this.sourceInterval ).cursor( interval ); else return Views.interval( this.sourceInterval, interval ).cursor(); }
@SuppressWarnings( "unchecked" ) @Override public Cursor< T > cursor( final Interval interval ) { if ( this.sourceInterval instanceof SubIntervalIterable ) return ( ( SubIntervalIterable< T > ) this.sourceInterval ).cursor( interval ); else return Views.interval( this.sourceInterval, interval ).cursor(); }
@SuppressWarnings( "unchecked" ) @Override public Cursor< LabelingType< T > > cursor( final Interval interval ) { Cursor< I > c = null; if ( this.img instanceof SubIntervalIterable ) c = ( ( SubIntervalIterable< I > ) this.img ).cursor( interval ); else c = Views.interval( this.img, interval ).cursor(); return new LabelingConvertedCursor< I, T >( c, generation, mapping ); }
@SuppressWarnings( "unchecked" ) @Override public Cursor< LabelingType< T > > cursor( final Interval interval ) { final Cursor< I > c; if ( subIterable ) c = ( ( SubIntervalIterable< I > ) indexIterable ).cursor( interval ); else c = Views.interval( indexAccessible, interval ).cursor(); return new LabelingConvertedCursor( c ); }
/** Checks if any element in the neighbourhood is background */ private boolean isAnyBackground(final IntervalView<B> neighbourhood) { final Cursor<B> cursor = neighbourhood.cursor(); while (cursor.hasNext()) { cursor.fwd(); if (!cursor.get().get()) { return true; } } return false; }
@Test public void testJumpFwdShifted() { Cursor< IntType > cursor = Views.interval( img, intervalShifted ).cursor(); testCursorJumpFwd( cursor, intervalShifted ); }
@Test public void testIterationFast() { Cursor< IntType > cursor = Views.interval( img, intervalFast ).cursor(); testCursorIteration( cursor, intervalFast ); }
@Test public void testIterationShifted() { Cursor< IntType > cursor = Views.interval( img, intervalShifted ).cursor(); testCursorIteration( cursor, intervalShifted ); }
@Test public void testIterationIntervalLine() { Cursor< IntType > cursor = Views.interval( img, intervalLine ).cursor(); testCursorIteration( cursor, intervalLine ); }
@Test public void testIterationSinglePlaneShifted() { Cursor< IntType > cursor = Views.interval( img, intervalSinglePlaneShifted ).cursor(); testCursorIteration( cursor, intervalSinglePlaneShifted ); }
@Test public void testJumpFwdFast() { Cursor< IntType > cursor = Views.interval( img, intervalFast ).cursor(); testCursorJumpFwd( cursor, intervalFast ); }
@Test public void testIterationSinglePlane() { Cursor< IntType > cursor = Views.interval( img, intervalSinglePlaneFull ).cursor(); testCursorIteration( cursor, intervalSinglePlaneFull ); }
/** * Walk through an Interval on an Img using a Cursor * * @param img * @param interval */ protected static void walkThrough( final Img< IntType > img, final Interval interval ) { final Cursor< IntType > c = Views.interval( img, interval ).cursor(); int i = 0; while ( c.hasNext() ) { c.fwd(); i += c.get().get(); } j = i; }
@Test public void testOptimizable() { // Testing Cursor assertTrue( ( Views.interval( img, intervalFast ).cursor() instanceof ArraySubIntervalCursor ) ); // Testing Localizing Cursor assertTrue( ( Views.interval( img, intervalFast ).localizingCursor() instanceof AbstractArrayLocalizingCursor ) ); // Testing Cursor assertFalse( ( Views.interval( img, intervalFastPart ).cursor() instanceof ArraySubIntervalCursor ) ); // Testing Localizing Cursor assertFalse( ( Views.interval( img, intervalFastPart ).localizingCursor() instanceof AbstractArrayLocalizingCursor ) ); // Testing Cursor assertTrue( ( Views.interval( img, intervalShifted ).cursor() instanceof ArraySubIntervalCursor ) ); // Testing Localizing Cursor assertTrue( ( Views.interval( img, intervalShifted ).localizingCursor() instanceof AbstractArrayLocalizingCursor ) ); }
private static < T extends Type< T > > void testValueExtended( final RandomAccessible<T> accessible, final Interval inside, final Interval total, final T insideValue, final T outsideValue ) { final Cursor< T > cursor = Views.interval( accessible, total ).cursor(); while ( cursor.hasNext() ) { final T value = cursor.next(); assertTrue( value.valueEquals( Intervals.contains( inside, cursor ) ? insideValue : outsideValue ) ); } } }
@Test public void defaultPermuteCoordinatesTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType()); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[]{0, 1}).cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }
@Test public void permuteCoordinatesInverseOfDimensionTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType()); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } IntervalView<DoubleType> out = Views.permuteCoordinatesInverse(img, new int[]{0, 1}, 1); Cursor<DoubleType> il2 = out.cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}, 1).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }
@Test public void defaultPermuteCoordinatesInverseTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType()); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } Cursor<DoubleType> il2 = Views.permuteCoordinatesInverse(img, new int[]{0, 1}).cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }
@Test public void permuteCoordinatesOfDimensionTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType()); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[]{0, 1}, 1).cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}, 1).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }