From 61094aebb570232632f8584ac8fd470819c5b37b Mon Sep 17 00:00:00 2001 From: Christian Tischer <tischitischer@gmail.com> Date: Thu, 6 Aug 2020 19:58:27 +0200 Subject: [PATCH] Handle missing n5 blocks (#104) handle missing n5 blocks by creating empty arrays TODO consider handling this in the CachedCellImg or possibly re-using arrays to reduce RAM consumption/ better utilize cache Co-authored-by: Christian Tischer <christian.tischer@embl.de> --- src/main/java/bdv/img/n5/N5ImageLoader.java | 40 +++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/bdv/img/n5/N5ImageLoader.java b/src/main/java/bdv/img/n5/N5ImageLoader.java index 00eb8c60..e3d6db5a 100644 --- a/src/main/java/bdv/img/n5/N5ImageLoader.java +++ b/src/main/java/bdv/img/n5/N5ImageLoader.java @@ -89,11 +89,7 @@ import net.imglib2.type.volatiles.VolatileUnsignedLongType; import net.imglib2.type.volatiles.VolatileUnsignedShortType; import net.imglib2.util.Cast; import net.imglib2.view.Views; -import org.janelia.saalfeldlab.n5.DataBlock; -import org.janelia.saalfeldlab.n5.DataType; -import org.janelia.saalfeldlab.n5.DatasetAttributes; -import org.janelia.saalfeldlab.n5.N5FSReader; -import org.janelia.saalfeldlab.n5.N5Reader; +import org.janelia.saalfeldlab.n5.*; import static bdv.img.n5.BdvN5Format.DATA_TYPE_KEY; import static bdv.img.n5.BdvN5Format.DOWNSAMPLING_FACTORS_KEY; @@ -352,7 +348,39 @@ public class N5ImageLoader implements ViewerImgLoader, MultiResolutionImgLoader @Override public A loadArray( final long[] gridPosition ) throws IOException { - return createArray.apply( n5.readBlock( pathName, attributes, gridPosition ) ); + final DataBlock< ? > dataBlock = n5.readBlock( pathName, attributes, gridPosition ); + + if ( dataBlock == null ) + return createEmptyArray( gridPosition ); + else + return createArray.apply( dataBlock ); + } + + private A createEmptyArray( long[] gridPosition ) + { + final int[] blockSize = attributes.getBlockSize(); + final int n = blockSize[ 0 ] * blockSize[ 1 ] * blockSize[ 2 ]; + switch ( attributes.getDataType() ) + { + case UINT8: + case INT8: + return createArray.apply( new ByteArrayDataBlock( blockSize, gridPosition, new byte[ n ] ) ); + case UINT16: + case INT16: + return createArray.apply( new ShortArrayDataBlock( blockSize, gridPosition, new short[ n ] ) ); + case UINT32: + case INT32: + return createArray.apply( new IntArrayDataBlock( blockSize, gridPosition, new int[ n ] ) ); + case UINT64: + case INT64: + return createArray.apply( new LongArrayDataBlock( blockSize, gridPosition, new long[ n ] ) ); + case FLOAT32: + return createArray.apply( new FloatArrayDataBlock( blockSize, gridPosition, new float[ n ] ) ); + case FLOAT64: + return createArray.apply( new DoubleArrayDataBlock( blockSize, gridPosition, new double[ n ] ) ); + default: + throw new UnsupportedOperationException("Data type not supported: " + attributes.getDataType()); + } } } -- GitLab