diff --git a/src/main/java/bdv/util/volatiles/CacheControlUnsafe.java b/src/main/java/bdv/util/volatiles/CacheControlUnsafe.java new file mode 100644 index 00000000..e4bc897f --- /dev/null +++ b/src/main/java/bdv/util/volatiles/CacheControlUnsafe.java @@ -0,0 +1,27 @@ +package bdv.util.volatiles; + +import net.imglib2.cache.AbstractCache; +import net.imglib2.cache.volatiles.AbstractVolatileCache; + +/** + * + * @author Philipp Hanslovsky + * + * This interface is used to expose controls of + * {@link AbstractVolatileCache volatile caches} and + * {@link AbstractCache caches}, e.g. in {@link VolatileViewData}. + * Methods in this interface may have implications and/or side-effects + * and should be used with caution/by callers who are aware of these. + * + */ +public interface CacheControlUnsafe +{ + + /** + * Invalidate all existing cache entries, e.g. + * {@link AbstractCache#invalidateAll() or + * {@link AbstractVolatileCache#invalidateAll()}}. + */ + public void invalidateAll(); + +} diff --git a/src/main/java/bdv/util/volatiles/VolatileViewData.java b/src/main/java/bdv/util/volatiles/VolatileViewData.java index 61b1fbe2..c56dea1d 100644 --- a/src/main/java/bdv/util/volatiles/VolatileViewData.java +++ b/src/main/java/bdv/util/volatiles/VolatileViewData.java @@ -4,6 +4,7 @@ import net.imglib2.RandomAccessible; import net.imglib2.RandomAccessibleInterval; import net.imglib2.Volatile; +import net.imglib2.cache.Cache; import net.imglib2.cache.img.CachedCellImg; /** @@ -22,6 +23,7 @@ * corresponding volatile pixel type * * @author Tobias Pietzsch + * @author Philipp Hanslovsky */ public class VolatileViewData< T, V extends Volatile< T > > { @@ -29,6 +31,8 @@ public class VolatileViewData< T, V extends Volatile< T > > private final CacheControl cacheControl; + private final CacheControlUnsafe cacheControlUsnafe; + private final T type; private final V volatileType; @@ -36,11 +40,13 @@ public class VolatileViewData< T, V extends Volatile< T > > public VolatileViewData( final RandomAccessible< V > img, final CacheControl cacheControl, + final CacheControlUnsafe cacheControlUsnafe, final T type, final V volatileType ) { this.img = img; this.cacheControl = cacheControl; + this.cacheControlUsnafe = cacheControlUsnafe; this.type = type; this.volatileType = volatileType; } @@ -67,6 +73,18 @@ public CacheControl getCacheControl() return cacheControl; } + /** + * Get the {@link CacheControlUnsafe} for the {@link CachedCellImg}(s) at the + * bottom of the view cascade. + * + * @return the {@link CacheControlUnsafe} for the {@link CachedCellImg}(s) at the + * bottom of the view cascade + */ + public CacheControlUnsafe getCacheControlUnsafe() + { + return this.cacheControlUsnafe; + } + /** * Get the pixel type of the original image. * diff --git a/src/main/java/bdv/util/volatiles/VolatileViews.java b/src/main/java/bdv/util/volatiles/VolatileViews.java index c2030965..decaf993 100644 --- a/src/main/java/bdv/util/volatiles/VolatileViews.java +++ b/src/main/java/bdv/util/volatiles/VolatileViews.java @@ -31,6 +31,7 @@ * BigDataViewer while loading asynchronously. * * @author Tobias Pietzsch + * @author Philipp Hanslovsky */ public class VolatileViews { @@ -107,6 +108,7 @@ else if ( rai instanceof IntervalView ) return new VolatileViewData<>( new IntervalView<>( sourceData.getImg(), view ), sourceData.getCacheControl(), + sourceData.getCacheControlUnsafe(), sourceData.getType(), sourceData.getVolatileType() ); } @@ -117,6 +119,7 @@ else if ( rai instanceof MixedTransformView ) return new VolatileViewData<>( new MixedTransformView<>( sourceData.getImg(), view.getTransformToSource() ), sourceData.getCacheControl(), + sourceData.getCacheControlUnsafe(), sourceData.getType(), sourceData.getVolatileType() ); } @@ -147,7 +150,7 @@ private static < T extends NativeType< T >, V extends Volatile< T > & NativeType @SuppressWarnings( "rawtypes" ) final VolatileCachedCellImg< V, ? > img = createVolatileCachedCellImg( grid, vtype, dirty, ( Cache ) cache, queue, hints ); - return new VolatileViewData<>( img, queue, type, vtype ); + return new VolatileViewData<>( img, queue, cache::invalidateAll, type, vtype ); } private static < T extends NativeType< T >, A extends VolatileArrayDataAccess< A > > VolatileCachedCellImg< T, A > createVolatileCachedCellImg(