Skip to content

Commit

Permalink
fix: converter setup wiring for cached transform source
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Oct 17, 2024
1 parent de06a76 commit afa838f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/main/java/bigwarp/BigWarpData.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class BigWarpData< T >
public List< SourceAndConverter< T > > sources;

public final LinkedHashMap< Integer, SourceInfo > sourceInfos = new LinkedHashMap<>();

public final List< ConverterSetup > converterSetups;

public final CacheControl cache;
Expand Down Expand Up @@ -410,7 +411,7 @@ public void applyTransformations() {
sourceForExport = newSac;
final InvertibleRealTransform invTransform = transform instanceof InvertibleRealTransform ? (InvertibleRealTransform)transform
: new WrappedIterativeInvertibleRealTransform(transform);
newSac = BigWarpInit.cacheTransformedSource(sac, invTransform, getSharedQueue());
newSac = BigWarpInit.cacheTransformedSource( this, i, sac, invTransform, getSharedQueue());
}

// will need to reload transformation on export if the transform is cached
Expand All @@ -430,6 +431,8 @@ public void applyTransformation(final SourceInfo info, Source<T> unWrappedSource
return;

final SourceAndConverter sac = info.getSourceAndConverter();
final int index = sources.indexOf(sac);

SourceAndConverter<?> sourceForExport = null;
SourceAndConverter newSac = inheritConverter(
applyFixedTransform(sac.getSpimSource(), transform),
Expand All @@ -440,14 +443,14 @@ public void applyTransformation(final SourceInfo info, Source<T> unWrappedSource
sourceForExport = newSac;
final InvertibleRealTransform invTransform = transform instanceof InvertibleRealTransform ? (InvertibleRealTransform)transform
: new WrappedIterativeInvertibleRealTransform(transform);
newSac = BigWarpInit.cacheTransformedSource(sac, invTransform, getSharedQueue());
newSac = BigWarpInit.cacheTransformedSource(this, index, sac, invTransform, getSharedQueue());
}

// will need to reload transformation on export if the transform is
// cached
info.setSourceForExport(sourceForExport);
info.setSourceAndConverter(newSac);
sources.set(sources.indexOf(sac), newSac);
sources.set(index, newSac);
}

public static < T > SourceAndConverter< T > inheritConverter( final Source<T> src, final SourceAndConverter< T > sac )
Expand All @@ -457,10 +460,7 @@ public static < T > SourceAndConverter< T > inheritConverter( final Source<T> sr
}
else
{
System.err.println( "Inherit Converter can't handle volatile");
return null;
// inheritConverter( src, sac );
// return new SourceAndConverter< T >( src, sac.getConverter(), wrapSourceAsTransformed( src, name + "_vol", ndims ) );
}
}

Expand Down
44 changes: 36 additions & 8 deletions src/main/java/bigwarp/BigWarpInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
import net.imglib2.converter.Converters;
import net.imglib2.display.RealARGBColorConverter;
import net.imglib2.display.ScaledARGBConverter;
import net.imglib2.display.ScaledARGBConverter.ARGB;
import net.imglib2.display.ScaledARGBConverter.VolatileARGB;
import net.imglib2.img.cell.AbstractCellImg;
import net.imglib2.interpolation.randomaccess.ClampingNLinearInterpolatorFactory;
import net.imglib2.outofbounds.OutOfBoundsConstantValueFactory;
Expand All @@ -130,6 +132,7 @@
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.integer.UnsignedIntType;
import net.imglib2.type.volatiles.VolatileARGBType;
import net.imglib2.util.ValuePair;
import net.imglib2.view.ExtendedRandomAccessibleInterval;
import net.imglib2.view.IntervalView;
import net.imglib2.view.Views;
Expand Down Expand Up @@ -195,8 +198,9 @@ public static void initSourceARGB( final Source< ARGBType > src, final int setup
{
final SourceAndConverter< ARGBType > soc = new SourceAndConverter<>( src, null );

final ScaledARGBConverter.VolatileARGB vconverter = new ScaledARGBConverter.VolatileARGB( 0, 255 );
final ScaledARGBConverter.ARGB converter = new ScaledARGBConverter.ARGB( 0, 255 );
ValuePair<ARGB, VolatileARGB> converters = initColorConverterARGB();
final ScaledARGBConverter.ARGB converter = converters.getA();
final ScaledARGBConverter.VolatileARGB vconverter = converters.getB();

sources.add( soc );
converterSetups.add( new RealARGBColorConverterSetup( setupId, converter, vconverter ) );
Expand All @@ -205,17 +209,30 @@ public static void initSourceARGB( final Source< ARGBType > src, final int setup
public static < T extends RealType< T > > void initSourceReal( final Source< T > src, final int setupId, final List< ConverterSetup > converterSetups, final List< SourceAndConverter< ? > > sources )
{
final T type = src.getType();
final double typeMin = Math.max( 0, Math.min( type.getMinValue(), 65535 ) );
final double typeMax = Math.max( 0, Math.min( type.getMaxValue(), 65535 ) );
final RealARGBColorConverter< T > converter = RealARGBColorConverter.create( type, typeMin, typeMax );
converter.setColor( new ARGBType( 0xffffffff ) );
final RealARGBColorConverter< T > converter = initColorConverterReal( type );

final SourceAndConverter< T > soc = new SourceAndConverter<>( src, converter );

sources.add( soc );
converterSetups.add( new RealARGBColorConverterSetup( setupId, converter ) );
}

private static <T extends RealType<T>> RealARGBColorConverter<T> initColorConverterReal(T type) {

final double typeMin = Math.max(0, Math.min(type.getMinValue(), 65535));
final double typeMax = Math.max(0, Math.min(type.getMaxValue(), 65535));
final RealARGBColorConverter<T> converter = RealARGBColorConverter.create(type, typeMin, typeMax);
converter.setColor(new ARGBType(0xffffffff));
return converter;
}

private static ValuePair<ScaledARGBConverter.ARGB, ScaledARGBConverter.VolatileARGB> initColorConverterARGB() {

final ScaledARGBConverter.VolatileARGB vconverter = new ScaledARGBConverter.VolatileARGB(0, 255);
final ScaledARGBConverter.ARGB converter = new ScaledARGBConverter.ARGB(0, 255);;
return new ValuePair<>(converter, vconverter);
}

public static BigWarpData< ? > createBigWarpData( final AbstractSpimData< ? >[] spimDataPList, final AbstractSpimData< ? >[] spimDataQList )
{
return createBigWarpData( spimDataPList, spimDataQList, null );
Expand Down Expand Up @@ -1070,11 +1087,17 @@ private static <T> SourceAndConverter<T> wrapSourceAsRenamable(final SourceAndCo

@SuppressWarnings("unchecked")
public static <T extends NumericType<T> & NativeType<T>, V extends Volatile<T> & NumericType<V>> SourceAndConverter<T> cacheTransformedSource(
final BigWarpData data,
final int index,
final SourceAndConverter<T> sac,
final InvertibleRealTransform transform,
SharedQueue sharedQueue) {


final SourceInfo info = data.getSourceInfo(sac);
final Source<T> src = sac.getSpimSource();
final int setupId = info.getId();

final int nd = src.getSource(0, 0).numDimensions();
final int N = src.getNumMipmapLevels();

Expand Down Expand Up @@ -1143,19 +1166,24 @@ public void load(SingleCellArrayImg<T, ?> cell) throws Exception {
final CacheHints cacheHints = new CacheHints(LoadingStrategy.BUDGETED, priority, false);
vmipmaps[i] = VolatileViews.wrapAsVolatile(cachedTransformedMipmap, sharedQueue, cacheHints);
}

final RandomAccessibleIntervalMipmapSource<T> cachedTransformedSource =
new RandomAccessibleIntervalMipmapSource<T>(
mipmaps,
type,
sourceTransforms,
src.getVoxelDimensions(),
src.getName() + "cached tform",
src.getName() + " (cached transform)",
src.doBoundingBoxCulling());


final Source<V> vsrc = new VolatileSource<T, V>(cachedTransformedSource, vtype, sharedQueue);
final SourceAndConverter<V> vsac = new SourceAndConverter<V>(vsrc, BigDataViewer.createConverterToARGB(vtype));
return new SourceAndConverter<T>(cachedTransformedSource, BigDataViewer.createConverterToARGB(type), vsac);

final SourceAndConverter<T> tsac = new SourceAndConverter<T>(cachedTransformedSource, BigDataViewer.createConverterToARGB(type), vsac);
ConverterSetup converterSetup = BigDataViewer.createConverterSetup(tsac, setupId);
data.converterSetups.set(index, converterSetup);
return tsac;
}

@SuppressWarnings("rawtypes")
Expand Down

0 comments on commit afa838f

Please sign in to comment.