Skip to content

Commit 7355e0f

Browse files
committed
Add BlockAlgoUtils.arrayImg
1 parent c504cdd commit 7355e0f

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
* %%
1212
* Redistribution and use in source and binary forms, with or without
1313
* modification, are permitted provided that the following conditions are met:
14-
*
14+
*
1515
* 1. Redistributions of source code must retain the above copyright notice,
1616
* this list of conditions and the following disclaimer.
1717
* 2. Redistributions in binary form must reproduce the above copyright notice,
1818
* this list of conditions and the following disclaimer in the documentation
1919
* and/or other materials provided with the distribution.
20-
*
20+
*
2121
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2222
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2323
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -33,11 +33,14 @@
3333
*/
3434
package net.imglib2.algorithm.blocks;
3535

36-
import net.imglib2.blocks.PrimitiveBlocks;
36+
import net.imglib2.Interval;
3737
import net.imglib2.cache.img.CachedCellImg;
3838
import net.imglib2.cache.img.CellLoader;
3939
import net.imglib2.cache.img.ReadOnlyCachedCellImgFactory;
4040
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;
4144
import net.imglib2.type.NativeType;
4245

4346
/**
@@ -83,4 +86,27 @@ CellLoader< T > cellLoader( final BlockSupplier< T > blocks )
8386
cellLoader( blocks ),
8487
ReadOnlyCachedCellImgOptions.options().cellDimensions( cellDimensions ) );
8588
}
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+
}
86112
}

0 commit comments

Comments
 (0)