/** * Provide an (<em>n + m</em>)-dimensional {@link RandomAccessible} of T as * an <em>m</em>-dimensional {@link RandomAccessible} of * <em>n</em>-dimensional {@link RandomAccessible RandomAccessibles} of T. * * @param source * @param axes * the axes to become the inner axes (embedded into the * co-domain) * * @return */ public static < T > RandomAccessible< ? extends RandomAccessible< T > > hyperSlices( final RandomAccessible< T > source, final int... axes ) { return new HyperSlicesView<>( source, axes ); }
@Override public HyperSlicesViewRandomAccess randomAccess( final Interval interval ) { /* intervals only matter inside hyperslice space as the slice itself is only * one pixel thick (constant) in all outer dimensions */ return randomAccess(); }
@Test public void test() { final long n = LongStream.of( sizes ).reduce( 1, ( x, y ) -> x * y ); final long[] data = new long[ ( int )n ]; for ( int d = 0; d < n ; ++d ) data[ d ] = d; final RandomAccessibleInterval< LongType > source = ArrayImgs.longs( data, sizes ); RandomAccessibleInterval< LongType > slice = source; while ( slice.numDimensions() > 2 ) slice = Views.hyperSlice( slice, slice.numDimensions() - 1, 0 ); final HyperSlicesView< LongType > hyperSlices = new HyperSlicesView< LongType >( source, 2, 3 ); final RandomAccess< HyperSlice< LongType > > hyperSlicesAccess = hyperSlices.randomAccess(); final long[][] expecteds = new long[][]{ {0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114}, {1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, 103, 109, 115}, {2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98, 104, 110, 116}, {3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99, 105, 111, 117} }; for ( int d = 0; hyperSlicesAccess.getLongPosition( 0 ) < sizes[ 2 ]; hyperSlicesAccess.fwd( 0 ), ++d ) { Assert.assertArrayEquals( expecteds[ d ], hyperSlice2Array(hyperSlicesAccess, 2, 3 ) ); } }
@Override public HyperSlicesViewRandomAccess randomAccess( final Interval interval ) { /* intervals only matter inside hyperslice space as the slice itself is only * one pixel thick (constant) in all outer dimensions */ return randomAccess(); }
/** * Provide an (<em>n + m</em>)-dimensional {@link RandomAccessible} of T as * an <em>m</em>-dimensional {@link RandomAccessible} of * <em>n</em>-dimensional {@link RandomAccessible RandomAccessibles} of T. * * @param source * @param axes * the axes to become the inner axes (embedded into the * co-domain) * * @return */ public static < T > RandomAccessible< ? extends RandomAccessible< T > > hyperSlices( final RandomAccessible< T > source, final int... axes ) { return new HyperSlicesView<>( source, axes ); }