Skip to content

Commit 6156cb8

Browse files
committed
Add convenience default method BlockSupplier.toCellImg(...)
1 parent 3971611 commit 6156cb8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/main/java/net/imglib2/algorithm/blocks/BlockSupplier.java

+20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import net.imglib2.RandomAccessible;
4545
import net.imglib2.Typed;
4646
import net.imglib2.blocks.PrimitiveBlocks;
47+
import net.imglib2.cache.img.CachedCellImg;
4748
import net.imglib2.type.NativeType;
4849
import net.imglib2.util.Cast;
4950
import net.imglib2.util.Util;
@@ -156,6 +157,25 @@ default < U extends NativeType< U > > BlockSupplier< U > andThen( Function< Bloc
156157
return andThen( function.apply( this ) );
157158
}
158159

160+
/**
161+
* Return a {@code CachedCellImg} which copies cells from this {@code BlockSupplier}.
162+
*
163+
* @param dimensions
164+
* dimensions of the {@code CachedCellImg} to create
165+
* @param cellDimensions
166+
* block size of the {@code CachedCellImg} to create.
167+
* This is extended or truncated as necessary.
168+
* For example if {@code cellDimensions={64,32}} then for creating a 3D
169+
* image it will be augmented to {@code {64,32,32}}. For creating a 1D image
170+
* it will be truncated to {@code {64}}.
171+
*
172+
* @return a {@code CachedCellImg} which copies cells from this {@code BlockSupplier}.
173+
*/
174+
default CachedCellImg< T, ? > toCellImg( final long[] dimensions, final int... cellDimensions )
175+
{
176+
return BlockAlgoUtils.cellImg( this, dimensions, cellDimensions );
177+
}
178+
159179
/**
160180
* Create a {@code BlockSupplier} accessor for an arbitrary {@code
161181
* RandomAccessible} source. Many View constructions (that ultimately end in

0 commit comments

Comments
 (0)