diff --git a/src/main/java/bigwarp/BigWarpData.java b/src/main/java/bigwarp/BigWarpData.java index a9aa196..2a4283f 100644 --- a/src/main/java/bigwarp/BigWarpData.java +++ b/src/main/java/bigwarp/BigWarpData.java @@ -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; @@ -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 @@ -430,6 +431,8 @@ public void applyTransformation(final SourceInfo info, Source unWrappedSource return; final SourceAndConverter sac = info.getSourceAndConverter(); + final int index = sources.indexOf(sac); + SourceAndConverter sourceForExport = null; SourceAndConverter newSac = inheritConverter( applyFixedTransform(sac.getSpimSource(), transform), @@ -440,14 +443,14 @@ public void applyTransformation(final SourceInfo info, Source 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 src, final SourceAndConverter< T > sac ) @@ -457,10 +460,7 @@ public static < T > SourceAndConverter< T > inheritConverter( final Source 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 ) ); } } diff --git a/src/main/java/bigwarp/BigWarpInit.java b/src/main/java/bigwarp/BigWarpInit.java index 92f61f7..a2bee10 100644 --- a/src/main/java/bigwarp/BigWarpInit.java +++ b/src/main/java/bigwarp/BigWarpInit.java @@ -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; @@ -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; @@ -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 converters = initColorConverterARGB(); + final ScaledARGBConverter.ARGB converter = converters.getA(); + final ScaledARGBConverter.VolatileARGB vconverter = converters.getB(); sources.add( soc ); converterSetups.add( new RealARGBColorConverterSetup( setupId, converter, vconverter ) ); @@ -205,10 +209,7 @@ 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 ); @@ -216,6 +217,22 @@ public static < T extends RealType< T > > void initSourceReal( final Source< T > converterSetups.add( new RealARGBColorConverterSetup( setupId, converter ) ); } + private static > RealARGBColorConverter 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 converter = RealARGBColorConverter.create(type, typeMin, typeMax); + converter.setColor(new ARGBType(0xffffffff)); + return converter; + } + + private static ValuePair 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 ); @@ -1070,11 +1087,17 @@ private static SourceAndConverter wrapSourceAsRenamable(final SourceAndCo @SuppressWarnings("unchecked") public static & NativeType, V extends Volatile & NumericType> SourceAndConverter cacheTransformedSource( + final BigWarpData data, + final int index, final SourceAndConverter sac, final InvertibleRealTransform transform, SharedQueue sharedQueue) { + + final SourceInfo info = data.getSourceInfo(sac); final Source src = sac.getSpimSource(); + final int setupId = info.getId(); + final int nd = src.getSource(0, 0).numDimensions(); final int N = src.getNumMipmapLevels(); @@ -1143,19 +1166,24 @@ public void load(SingleCellArrayImg cell) throws Exception { final CacheHints cacheHints = new CacheHints(LoadingStrategy.BUDGETED, priority, false); vmipmaps[i] = VolatileViews.wrapAsVolatile(cachedTransformedMipmap, sharedQueue, cacheHints); } + final RandomAccessibleIntervalMipmapSource cachedTransformedSource = new RandomAccessibleIntervalMipmapSource( mipmaps, type, sourceTransforms, src.getVoxelDimensions(), - src.getName() + "cached tform", + src.getName() + " (cached transform)", src.doBoundingBoxCulling()); final Source vsrc = new VolatileSource(cachedTransformedSource, vtype, sharedQueue); final SourceAndConverter vsac = new SourceAndConverter(vsrc, BigDataViewer.createConverterToARGB(vtype)); - return new SourceAndConverter(cachedTransformedSource, BigDataViewer.createConverterToARGB(type), vsac); + + final SourceAndConverter tsac = new SourceAndConverter(cachedTransformedSource, BigDataViewer.createConverterToARGB(type), vsac); + ConverterSetup converterSetup = BigDataViewer.createConverterSetup(tsac, setupId); + data.converterSetups.set(index, converterSetup); + return tsac; } @SuppressWarnings("rawtypes")