|
11 | 11 | * %%
|
12 | 12 | * Redistribution and use in source and binary forms, with or without
|
13 | 13 | * modification, are permitted provided that the following conditions are met:
|
14 |
| - * |
| 14 | + * |
15 | 15 | * 1. Redistributions of source code must retain the above copyright notice,
|
16 | 16 | * this list of conditions and the following disclaimer.
|
17 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
18 | 18 | * this list of conditions and the following disclaimer in the documentation
|
19 | 19 | * and/or other materials provided with the distribution.
|
20 |
| - * |
| 20 | + * |
21 | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
22 | 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23 | 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
33 | 33 | */
|
34 | 34 | package net.imglib2.algorithm.blocks;
|
35 | 35 |
|
36 |
| -import net.imglib2.blocks.PrimitiveBlocks; |
| 36 | +import net.imglib2.Interval; |
37 | 37 | import net.imglib2.cache.img.CachedCellImg;
|
38 | 38 | import net.imglib2.cache.img.CellLoader;
|
39 | 39 | import net.imglib2.cache.img.ReadOnlyCachedCellImgFactory;
|
40 | 40 | import net.imglib2.cache.img.ReadOnlyCachedCellImgOptions;
|
| 41 | +import net.imglib2.img.array.ArrayImg; |
| 42 | +import net.imglib2.img.array.ArrayImgFactory; |
| 43 | +import net.imglib2.img.basictypeaccess.array.ArrayDataAccess; |
41 | 44 | import net.imglib2.type.NativeType;
|
42 | 45 |
|
43 | 46 | /**
|
@@ -83,4 +86,27 @@ CellLoader< T > cellLoader( final BlockSupplier< T > blocks )
|
83 | 86 | cellLoader( blocks ),
|
84 | 87 | ReadOnlyCachedCellImgOptions.options().cellDimensions( cellDimensions ) );
|
85 | 88 | }
|
| 89 | + |
| 90 | + /** |
| 91 | + * Create a {@code ArrayImg} from the specified {@code interval} in {@code blocks}. |
| 92 | + * |
| 93 | + * @param blocks |
| 94 | + * provides data to be copied |
| 95 | + * @param interval |
| 96 | + * the interval to be copied |
| 97 | + * @param <T> |
| 98 | + * target type (type of the returned ArrayImg) |
| 99 | + * |
| 100 | + * @return a {@code ArrayImg} copied from {@code interval} in {@code blocks}. |
| 101 | + */ |
| 102 | + public static < T extends NativeType< T > > |
| 103 | + ArrayImg< T, ? > arrayImg( |
| 104 | + final BlockSupplier< T > blocks, |
| 105 | + final Interval interval ) |
| 106 | + { |
| 107 | + final ArrayImg< T, ? > img = new ArrayImgFactory<>( blocks.getType() ).create( interval ); |
| 108 | + final Object dest = ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray(); |
| 109 | + blocks.copy( interval, dest ); |
| 110 | + return img; |
| 111 | + } |
86 | 112 | }
|
0 commit comments