5050import net .imglib2 .Interval ;
5151import net .imglib2 .RandomAccessible ;
5252import net .imglib2 .RandomAccessibleInterval ;
53+ import net .imglib2 .algorithm .blocks .BlockSupplier ;
5354import net .imglib2 .converter .Converter ;
5455import net .imglib2 .converter .RealUnsignedByteConverter ;
5556import net .imglib2 .converter .RealUnsignedShortConverter ;
@@ -467,13 +468,15 @@ else if ( dataType == DataType.UINT16 )
467468 if ( overlappingViews .size () == 0 )
468469 return ;
469470
470- final RandomAccessibleInterval img ;
471+ //final RandomAccessibleInterval img;
472+ final BlockSupplier blockSupplier ;
473+ final FinalInterval interval = new FinalInterval ( bbMin , bbMax );
471474
472475 if ( masks )
473476 {
474477 System .out .println ( "Creating masks for block: offset=" + Util .printCoordinates ( gridBlock [0 ] ) + ", dimension=" + Util .printCoordinates ( gridBlock [1 ] ) );
475478
476- img = Views .zeroMin (
479+ blockSupplier = BlockSupplier . of ( Views .zeroMin (
477480 new GenerateComputeBlockMasks (
478481 dataLocal ,
479482 registrations ,
@@ -482,7 +485,7 @@ else if ( dataType == DataType.UINT16 )
482485 bbMax ,
483486 uint8 ,
484487 uint16 ,
485- maskOff ).call ( gridBlock ) );
488+ maskOff ).call ( gridBlock ) ) ) ;
486489 }
487490 else
488491 {
@@ -514,7 +517,7 @@ else if ( firstTileWinsInverse )
514517 fusionType = FusionType .AVG_BLEND ;
515518
516519 // returns a zero-min interval
517- img = BlkAffineFusion .init (
520+ blockSupplier = BlkAffineFusion .init (
518521 conv ,
519522 dataLocal .getSequenceDescription ().getImgLoader (),
520523 viewIds ,
@@ -523,36 +526,47 @@ else if ( firstTileWinsInverse )
523526 fusionType ,//fusion.getFusionType(),
524527 1 , // linear interpolation
525528 null , // intensity correction
526- new BoundingBox ( new FinalInterval ( bbMin , bbMax ) ),
529+ new BoundingBox ( interval ),
527530 (RealType & NativeType )type ,
528531 blockSize );
529532 }
530533
531- final long [] blockOffset , blockSizeExport , gridOffset ;
534+ final long [] /* blockOffset, blockSizeExport, */ gridOffset ;
532535
533- final RandomAccessible image ;
536+ final long [] blockMin = gridBlock [0 ].clone ();
537+ final long [] blockMax = new long [ blockMin .length ];
538+
539+ for ( int d = 0 ; d < blockMin .length ; ++d )
540+ blockMax [ d ] = Math .min ( Intervals .zeroMin ( interval ).max ( d ), blockMin [ d ] + gridBlock [1 ][ d ] - 1 );
541+
542+ final RandomAccessibleInterval image ;
543+ final RandomAccessibleInterval img = BlkAffineFusion .arrayImg ( blockSupplier , new FinalInterval ( blockMin , blockMax ) );
534544
535545 // 5D OME-ZARR CONTAINER
536546 if ( storageType == StorageFormat .ZARR )
537547 {
538548 // gridBlock is 3d, make it 5d
539- blockOffset = new long [] { gridBlock [0 ][0 ], gridBlock [0 ][1 ], gridBlock [0 ][2 ], cIndex , tIndex };
540- blockSizeExport = new long [] { gridBlock [1 ][0 ], gridBlock [1 ][1 ], gridBlock [1 ][2 ], 1 , 1 };
549+ // blockOffset = new long[] { gridBlock[0][0], gridBlock[0][1], gridBlock[0][2], cIndex, tIndex };
550+ // blockSizeExport = new long[] { gridBlock[1][0], gridBlock[1][1], gridBlock[1][2], 1, 1 };
541551 gridOffset = new long [] { gridBlock [2 ][0 ], gridBlock [2 ][1 ], gridBlock [2 ][2 ], cIndex , tIndex }; // because blocksize in C & T is 1
542552
543553 // img is 3d, make it 5d
544554 // the same information is returned no matter which index is queried in C and T
545- image = Views .addDimension ( Views .addDimension ( img ) );
555+ //image = Views.addDimension( Views.addDimension( img ) );
556+ image = Views .interval (
557+ Views .addDimension ( Views .addDimension ( img ) ),
558+ new FinalInterval ( new long [] { gridBlock [1 ][0 ], gridBlock [1 ][1 ], gridBlock [1 ][2 ], cIndex +1 , tIndex +1 } ) );
546559 }
547560 else
548561 {
549- blockOffset = gridBlock [0 ];
550- blockSizeExport = gridBlock [1 ];
562+ // blockOffset = gridBlock[0];
563+ // blockSizeExport = gridBlock[1];
551564 gridOffset = gridBlock [2 ];
552565
553566 image = img ;
554567 }
555568
569+ /*
556570 final Interval block =
557571 Intervals.translate(
558572 new FinalInterval( blockSizeExport ),
@@ -564,11 +578,12 @@ else if ( firstTileWinsInverse )
564578 final RandomAccessibleInterval sourceGridBlock =
565579 Views.offsetInterval(source, blockOffset, blockSizeExport);
566580
581+ */
567582 final N5Writer driverVolumeWriterLocal = N5Util .createN5Writer ( outPathURI , storageType );
568583
569584 // TODO: is this multithreaded??
570585 // TODO: should we catch the N5 exception and throw a general one?
571- N5Utils .saveBlock (sourceGridBlock , driverVolumeWriterLocal , mrInfo [ 0 ].dataset , gridOffset );
586+ N5Utils .saveBlock (/* sourceGridBlock*/ image , driverVolumeWriterLocal , mrInfo [ 0 ].dataset , gridOffset );
572587
573588 if ( N5Util .sharedHDF5Writer == null )
574589 driverVolumeWriterLocal .close ();
0 commit comments