Skip to content
Snippets Groups Projects
Unverified Commit 61094aeb authored by Christian Tischer's avatar Christian Tischer Committed by GitHub
Browse files

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: default avatarChristian Tischer <christian.tischer@embl.de>
parent fec7a0d2
Branches
No related tags found
No related merge requests found
......@@ -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());
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment