Skip to content

Commit

Permalink
Adds a small hack to allow for lazy downscaling in WrapVolatileSource
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoKiaru committed May 9, 2024
1 parent c5a4d96 commit b125e84
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
34 changes: 24 additions & 10 deletions src/main/java/bdv/util/WrapVolatileSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class WrapVolatileSource<T extends NumericType<T>, V extends Volatile<T>

final Source<T> originSource;

Source<V> volatileSource = null;

protected final DefaultInterpolators<V> interpolators =
new DefaultInterpolators<>();

Expand All @@ -87,15 +89,27 @@ public WrapVolatileSource(final Source<T> source) {

public WrapVolatileSource(final Source<T> 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<V> volatileSource) {
this.volatileSource = volatileSource;
}

@Override
public boolean isPresent(int t) {
return originSource.isPresent(t);
}

public RandomAccessibleInterval<V> buildSource(int t, int level) {
if ((level==0)&&(volatileSource!=null)) {
return volatileSource.getSource(t,0);
}
return VolatileViews.wrapAsVolatile(originSource.getSource(t, level),
queue);
}
Expand Down Expand Up @@ -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
Expand All @@ -162,19 +176,19 @@ public int getNumMipmapLevels() {
* @param t a NumericType instance
* @return the volatile equivalent class of this NumericType instance
*/

static public Volatile<? extends NumericType> getVolatileOf(
NumericType<?> t)
static public<T extends NumericType<T>, V extends Volatile<T> > V getVolatileOf(
NumericType<T> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
* <a href="https://github.com/scijava/scijava-common/issues/379">bug</a>) 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
Expand Down

0 comments on commit b125e84

Please sign in to comment.