diff --git a/src/main/java/bdv/util/WrapVolatileSource.java b/src/main/java/bdv/util/WrapVolatileSource.java index e074627a..a664da36 100644 --- a/src/main/java/bdv/util/WrapVolatileSource.java +++ b/src/main/java/bdv/util/WrapVolatileSource.java @@ -72,6 +72,8 @@ public class WrapVolatileSource, V extends Volatile final Source originSource; + Source volatileSource = null; + protected final DefaultInterpolators interpolators = new DefaultInterpolators<>(); @@ -87,15 +89,27 @@ public WrapVolatileSource(final Source source) { public WrapVolatileSource(final Source originSource, final SharedQueue queue) { this.originSource = originSource; + this.volatileSource = null; this.queue = queue; } + /** For lazy downscaling, we want to keep the original highest resolution level + * a bit hacky... + * @param volatileSource a volatile source already computed + */ + public void setVolatileSourceForHighestResolution(final Source volatileSource) { + this.volatileSource = volatileSource; + } + @Override public boolean isPresent(int t) { return originSource.isPresent(t); } public RandomAccessibleInterval buildSource(int t, int level) { + if ((level==0)&&(volatileSource!=null)) { + return volatileSource.getSource(t,0); + } return VolatileViews.wrapAsVolatile(originSource.getSource(t, level), queue); } @@ -138,7 +152,7 @@ public void getSourceTransform(int t, int level, @Override public V getType() { - return (V) getVolatileOf(originSource.getType()); + return getVolatileOf(originSource.getType()); } @Override @@ -162,19 +176,19 @@ public int getNumMipmapLevels() { * @param t a NumericType instance * @return the volatile equivalent class of this NumericType instance */ - - static public Volatile getVolatileOf( - NumericType t) + static public, V extends Volatile > V getVolatileOf( + NumericType t) { - if (t instanceof UnsignedShortType) return new VolatileUnsignedShortType(); + if (t instanceof UnsignedShortType) return (V) new VolatileUnsignedShortType(); + + if (t instanceof UnsignedIntType) return (V) new VolatileUnsignedIntType(); - if (t instanceof UnsignedIntType) return new VolatileUnsignedIntType(); + if (t instanceof UnsignedByteType) return (V) new VolatileUnsignedByteType(); - if (t instanceof UnsignedByteType) return new VolatileUnsignedByteType(); + if (t instanceof FloatType) return (V) new VolatileFloatType(); - if (t instanceof FloatType) return new VolatileFloatType(); + if (t instanceof ARGBType) return (V) new VolatileARGBType(); - if (t instanceof ARGBType) return new VolatileARGBType(); - return null; + throw new RuntimeException("Unknown volatile type matching pixel type "+t.getClass().getName()); } } diff --git a/src/main/java/sc/fiji/bdvpg/scijava/command/viewer/ViewSynchronizerCommand.java b/src/main/java/sc/fiji/bdvpg/scijava/command/viewer/ViewSynchronizerCommand.java index 6404de3b..c39f327f 100644 --- a/src/main/java/sc/fiji/bdvpg/scijava/command/viewer/ViewSynchronizerCommand.java +++ b/src/main/java/sc/fiji/bdvpg/scijava/command/viewer/ViewSynchronizerCommand.java @@ -31,7 +31,6 @@ import bdv.util.BdvHandle; import bvv.vistools.BvvHandle; -import org.scijava.command.CommandModule; import org.scijava.command.CommandService; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; @@ -56,7 +55,7 @@ /** * I wanted to do this as an Interactive Command but there's no callback when an * interactive command is closed (bug - * https://github.com/scijava/scijava-common/issues/379) so we cannot stop the + * bug) so we cannot stop the * synchronization appropriately. Hence the dirty JFrame the user has to close * to stop synchronization ... TODO fix potential memory leaks which could be a * consequence of this extra JFrame author Nicolas Chiaruttini, BIOP, EPFL, 2020