@SuppressWarnings( "unchecked" ) @Override public Cursor< T > localizingCursor( final Interval interval ) { if ( this.sourceInterval instanceof SubIntervalIterable ) return ( ( SubIntervalIterable< T > ) this.sourceInterval ).localizingCursor( interval ); else return Views.interval( this.sourceInterval, interval ) .localizingCursor(); }
@SuppressWarnings( "unchecked" ) @Override public Cursor< LabelingType< L > > localizingCursor( final Interval interval ) { if ( this.sourceInterval instanceof SubIntervalIterable ) return ( ( SubIntervalIterable< LabelingType< L > > ) this.sourceInterval ).localizingCursor( interval ); else return Views.interval( this.sourceInterval, interval ).localizingCursor(); } }
@SuppressWarnings( "unchecked" ) @Override public Cursor< T > localizingCursor( final Interval interval ) { if ( this.sourceInterval instanceof SubIntervalIterable ) return ( ( SubIntervalIterable< T > ) this.sourceInterval ).localizingCursor( interval ); else return Views.interval( this.sourceInterval, interval ) .localizingCursor(); }
@SuppressWarnings( "unchecked" ) @Override public Cursor< LabelingType< T > > localizingCursor( final Interval interval ) { final Cursor< I > c; if ( subIterable ) c = ( ( SubIntervalIterable< I > ) indexIterable ).localizingCursor( interval ); else c = Views.interval( indexAccessible, interval ).localizingCursor(); return new LabelingConvertedCursor( c ); }
@SuppressWarnings( "unchecked" ) @Override public Cursor< LabelingType< T > > localizingCursor( final Interval interval ) { Cursor< I > c = null; if ( this.img instanceof SubIntervalIterable ) c = ( ( SubIntervalIterable< I > ) this.img ).localizingCursor( interval ); else c = Views.interval( this.img, interval ).localizingCursor(); return new LabelingConvertedCursor< I, T >( c, generation, mapping ); } }
@Test public void testLocalizingIterationFast() { Cursor< IntType > cursor = Views.interval( img, intervalFast ).localizingCursor(); testCursorIteration( cursor, intervalFast ); }
@Test public void testLocalizingIterationShifted() { Cursor< IntType > cursor = Views.interval( img, intervalShifted ).localizingCursor(); testCursorIteration( cursor, intervalShifted ); }
@Test public void testLocalizingJumpFwdSinglePlane() { Cursor< IntType > cursor = Views.interval( img, intervalSinglePlaneFull ).localizingCursor(); testCursorJumpFwd( cursor, intervalSinglePlaneFull ); }
@Test public void testLocalizingJumpFwdShifted() { Cursor< IntType > cursor = Views.interval( img, intervalShifted ).localizingCursor(); testCursorJumpFwd( cursor, intervalShifted ); }
@Test public void testLocalizingIterationSinglePlane() { Cursor< IntType > cursor = Views.interval( img, intervalSinglePlaneFull ).localizingCursor(); testCursorIteration( cursor, intervalSinglePlaneFull ); } }
@Test public void testLocalizingJumpFwdFast() { Cursor< IntType > cursor = Views.interval( img, intervalFast ).localizingCursor(); testCursorJumpFwd( cursor, intervalFast ); }
@Test public void testJumpFwdSinglePlane() { Cursor< IntType > cursor = Views.interval( img, intervalSinglePlaneFull ).localizingCursor(); testCursorJumpFwd( cursor, intervalSinglePlaneFull ); }
@Test public void testLocalizingtIterationSinglePlaneShifted() { Cursor< IntType > cursor = Views.interval( img, intervalSinglePlaneShifted ).localizingCursor(); testCursorIteration( cursor, intervalSinglePlaneShifted ); }
@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 ) ); }
/** * Walk through an Interval on an Img using a LocalizingCursor, localizing * on every step. * * @param img * @param interval */ protected static void localizingWalkThrough( final Img< IntType > img, final Interval interval ) { final Cursor< IntType > c = Views.interval( img, interval ).localizingCursor(); final long[] pos = new long[ interval.numDimensions() ]; int i = 0; while ( c.hasNext() ) { c.fwd(); i += c.get().get(); c.localize( pos ); } j = ( int ) pos[ 0 ] + i; }
@Test public void defaultIntervalTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType()); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } Cursor<DoubleType> il2 = Views.interval(img, img).localizingCursor(); RandomAccess<DoubleType> opr = ops.transform().intervalView(img, img).randomAccess(); while (il2.hasNext()) { DoubleType e = il2.next(); opr.setPosition(il2); assertEquals(e.get(), opr.get().get(), 1e-10); } }
@Test public void intervalMinMaxTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType()); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } Cursor<DoubleType> il2 = Views.interval(img, new long[]{1, 1}, new long[]{8,9}).localizingCursor(); RandomAccess<DoubleType> opr = ops.transform().intervalView(img, new long[]{1, 1}, new long[]{8,9}).randomAccess(); while (il2.hasNext()) { DoubleType e = il2.next(); opr.setPosition(il2); assertEquals(e.get(), opr.get().get(), 1e-10); } } }
@Test public void defaultSubsampleTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2); SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2); Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 4 }).localizingCursor(); RandomAccess<DoubleType> oprRA = opr.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } }
@Test public void defaultSubsampleStepsTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2, 1); SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2, 1); Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor(); RandomAccess<DoubleType> oprRA = opr.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } }
@Test public void testIntervalSubsampleSteps() { Img<DoubleType> img = ArrayImgs.doubles(10,10); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } SubsampleIntervalView<DoubleType> expected = Views.subsample((RandomAccessibleInterval<DoubleType>) img, 2, 1); SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2, 1); Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor(); RandomAccess<DoubleType> oprRA = actual.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } assertTrue(Intervals.equals(expected, actual)); } }