From 2992ff8087f7205ced9b7f95ae552a6d044e7cfc Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Tue, 5 Nov 2024 11:19:04 -0500 Subject: [PATCH] support more fetcher threads for SplitViewerImgLoader.java fix generics --- .../splitting/SplitViewerImgLoader.java | 34 ++++++++++--------- .../splitting/SplitViewerSetupImgLoader.java | 1 - 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/splitting/SplitViewerImgLoader.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/splitting/SplitViewerImgLoader.java index 364e4360..fe07cfe1 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/splitting/SplitViewerImgLoader.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/splitting/SplitViewerImgLoader.java @@ -35,6 +35,7 @@ import mpicbg.spim.data.sequence.SequenceDescription; import net.imglib2.Interval; import net.imglib2.cache.queue.BlockingFetchQueues; +import net.imglib2.util.Cast; public class SplitViewerImgLoader implements ViewerImgLoader, MultiResolutionImgLoader { @@ -58,13 +59,15 @@ public class SplitViewerImgLoader implements ViewerImgLoader, MultiResolutionImg /** * Remembers instances of SplitSetupImgLoader */ - private final HashMap< Integer, SplitViewerSetupImgLoader > splitSetupImgLoaders; + private final HashMap< Integer, SplitViewerSetupImgLoader > splitSetupImgLoaders; /** * Its own cell cache */ protected VolatileGlobalCellCache cache; + private int requestedNumFetcherThreads = -1; + public SplitViewerImgLoader( final ViewerImgLoader underlyingImgLoader, final HashMap< Integer, Integer > new2oldSetupId, @@ -81,34 +84,33 @@ public SplitViewerImgLoader( private boolean isOpen = false; @Override - public SplitViewerSetupImgLoader getSetupImgLoader( final int setupId ) + public SplitViewerSetupImgLoader getSetupImgLoader( final int setupId ) { return getSplitViewerSetupImgLoader( underlyingImgLoader, new2oldSetupId.get( setupId ), setupId, newSetupId2Interval.get( setupId ) ); } - private final synchronized SplitViewerSetupImgLoader getSplitViewerSetupImgLoader( final ViewerImgLoader underlyingImgLoader, final int oldSetupId, final int newSetupId, final Interval interval ) + private final synchronized SplitViewerSetupImgLoader getSplitViewerSetupImgLoader( final ViewerImgLoader underlyingImgLoader, final int oldSetupId, final int newSetupId, final Interval interval ) { - SplitViewerSetupImgLoader sil = splitSetupImgLoaders.get( newSetupId ); + SplitViewerSetupImgLoader sil = splitSetupImgLoaders.get( newSetupId ); if ( sil == null ) { - final ViewerSetupImgLoader setupLoader = underlyingImgLoader.getSetupImgLoader( oldSetupId ); - //final Object imgType = setupLoader.getImageType(); - //final Object volTyoe = setupLoader.getVolatileImageType(); - - //if ( !imgType.getClass().isInstance( new UnsignedShortType() ) || !volTyoe.getClass().isInstance( new VolatileUnsignedShortType() ) ) - // throw new RuntimeException( "The underlying ViewerSetupImgLoader is not typed for , cannot split up for BDV." ); - - sil = createNewSetupImgLoader( (ViewerSetupImgLoader)underlyingImgLoader.getSetupImgLoader( oldSetupId ), interval ); + sil = createNewSetupImgLoader( (ViewerSetupImgLoader)underlyingImgLoader.getSetupImgLoader( oldSetupId ), interval ); splitSetupImgLoaders.put( newSetupId, sil ); } return sil; } - private final synchronized SplitViewerSetupImgLoader createNewSetupImgLoader( - final ViewerSetupImgLoader setupImgLoader, + private final synchronized SplitViewerSetupImgLoader createNewSetupImgLoader( + final ViewerSetupImgLoader setupImgLoader, final Interval interval ) { - return new SplitViewerSetupImgLoader( setupImgLoader, interval ); + return new SplitViewerSetupImgLoader<>( Cast.unchecked( setupImgLoader ), interval ); + } + + @Override + public synchronized void setNumFetcherThreads( final int n ) + { + requestedNumFetcherThreads = n; } private void open() @@ -132,7 +134,7 @@ private void open() maxNumLevels = resolutions.length; } - final int numFetcherThreads = 1; + final int numFetcherThreads = ( requestedNumFetcherThreads > 0 ) ? requestedNumFetcherThreads : Runtime.getRuntime().availableProcessors(); final BlockingFetchQueues< Callable< ? > > queue = new BlockingFetchQueues<>( maxNumLevels, numFetcherThreads ); cache = new VolatileGlobalCellCache( queue ); } diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/splitting/SplitViewerSetupImgLoader.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/splitting/SplitViewerSetupImgLoader.java index 962604b7..d6964eb9 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/splitting/SplitViewerSetupImgLoader.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/splitting/SplitViewerSetupImgLoader.java @@ -35,7 +35,6 @@ import net.imglib2.realtransform.AffineTransform3D; import net.imglib2.type.NativeType; import net.imglib2.view.Views; -import net.preibisch.legacy.io.IOFunctions; public class SplitViewerSetupImgLoader< T extends NativeType< T >, V extends Volatile< T > & NativeType< V > > implements ViewerSetupImgLoader< T, V >, MultiResolutionSetupImgLoader< T > {