From 5a3d0ea2a8e424187074b214917aa02d54f4219d Mon Sep 17 00:00:00 2001 From: Kyle Harrington Date: Mon, 19 Jun 2023 08:03:31 -0400 Subject: [PATCH] [wip] trying Converters stuck on bug java.util.concurrent.ExecutionException: java.lang.ClassCastException: class net.imglib2.img.basictypeaccess.array.ShortArray cannot be cast to class net.imglib2.img.basictypeaccess.volatiles.VolatileShortAccess (net.imglib2.img.basictypeaccess.array.ShortArray and net.imglib2.img.basictypeaccess.volatiles.VolatileShortAccess are in unnamed module of loader 'app') It looks like this is happening in GenericShortType.updateContainer --- build.gradle.kts | 2 ++ .../demo/advanced/OpenOrganelleDemo.java | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3fb13a2a..313f0bc7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -29,9 +29,11 @@ repositories { logger.warn("Using local Maven repository as source") mavenLocal() } + mavenCentral() maven("https://oss.sonatype.org/content/repositories/graphicsscenery-1222") maven("https://maven.scijava.org/content/groups/public") + mavenLocal() } dependencies { diff --git a/src/main/java/sc/iview/commands/demo/advanced/OpenOrganelleDemo.java b/src/main/java/sc/iview/commands/demo/advanced/OpenOrganelleDemo.java index 112532eb..298b08e3 100644 --- a/src/main/java/sc/iview/commands/demo/advanced/OpenOrganelleDemo.java +++ b/src/main/java/sc/iview/commands/demo/advanced/OpenOrganelleDemo.java @@ -51,6 +51,7 @@ import net.imglib2.cache.CacheLoader; import net.imglib2.cache.LoaderCache; import net.imglib2.cache.img.CachedCellImg; +import net.imglib2.cache.img.LoadedCellCacheLoader; import net.imglib2.cache.img.RandomAccessibleCacheLoader; import net.imglib2.cache.ref.SoftRefLoaderCache; import net.imglib2.cache.volatiles.CacheHints; @@ -75,6 +76,7 @@ import net.imglib2.type.numeric.integer.UnsignedByteType; import net.imglib2.type.numeric.integer.UnsignedShortType; import net.imglib2.type.volatiles.VolatileARGBType; +import net.imglib2.type.volatiles.VolatileUnsignedShortType; import net.imglib2.util.Util; import net.imglib2.view.Views; import org.janelia.saalfeldlab.n5.DataType; @@ -108,6 +110,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Function; +import java.util.function.Supplier; import static bdv.BigDataViewer.createConverterToARGB; import static bdv.BigDataViewer.wrapWithTransformedSource; @@ -118,9 +121,11 @@ /** * OpenOrganelle demo * + * This borrows heavily from n5-viewer and BVV code. + * * @author Kyle Harrington */ -@Plugin(type = Command.class, label = "Show segmentation", menuRoot = "SciView", // +@Plugin(type = Command.class, label = "Open Organelle", menuRoot = "SciView", // menu = { @Menu(label = "Demo", weight = DEMO), // @Menu(label = "Advanced", weight = DEMO_ADVANCED), // @Menu(label = "Open Organelle (Java)", weight = DEMO_ADVANCED_SEGMENTATION) }) @@ -240,18 +245,30 @@ else if( metadata instanceof N5DatasetMetadata ) { { final CachedCellImg vimg = N5Utils.openVolatile( n5, datasetsToOpen[s] ); + + RandomAccessibleInterval shortRAI = Converters.convert( + (RandomAccessibleInterval) vimg, + (a, b) -> b.set(a.get()), + new VolatileUnsignedShortType()); + + + // shortRAI = Converters.convert(vimg, (i, o) -> o.set(i.get().get())); + // BVV can only handle UnsignedShortTypes now, we need to convert Set accessFlags = AccessFlags.setOf(AccessFlags.VOLATILE); UnsignedShortType type = new UnsignedShortType(); //ArrayDataAccessFactory.get(type, accessFlags); - // TODO need to finish making the cache final Function loaderCacheFactory = dataType -> new SoftRefLoaderCache<>(); - final DatasetAttributes attributes = n5.getDatasetAttributes(datasetsToOpen[s]); + // final DatasetAttributes attributes = n5.getDatasetAttributes(datasetsToOpen[s]); // TODO hardcoded n5 datatype final LoaderCache loaderCache = loaderCacheFactory.apply(DataType.UINT16); - CacheLoader> loader = RandomAccessibleCacheLoader.get(vimg.getCellGrid(), vimg, accessFlags); + // TODO problem is here: class net.imglib2.img.basictypeaccess.volatiles.array.VolatileByteArray cannot be cast to class net.imglib2.img.basictypeaccess.ShortAccess (net.imglib2.img.basictypeaccess.volatiles.array.VolatileByteArray and net.imglib2.img.basictypeaccess.ShortAccess are in unnamed module of loader 'app') + CacheLoader> loader = RandomAccessibleCacheLoader.get(vimg.getCellGrid(), shortRAI, accessFlags); + // CacheLoader> loader = RandomAccessibleCacheLoader.get(vimg.getCellGrid(), vimg, accessFlags); + // Could we use a LoadedCellCacheLoader here? How? + Cache cache = loaderCache.withLoader(loader); CachedCellImg unsignedShortVimg = new CachedCellImg(vimg.getCellGrid(), type, cache, ArrayDataAccessFactory.get(type, accessFlags)); @@ -263,7 +280,7 @@ else if( metadata instanceof N5DatasetMetadata ) { } else { - images[ s ] = vimg; + images[ s ] = unsignedShortVimg; } } @@ -460,8 +477,13 @@ else if ( meta instanceof CanonicalMultichannelMetadata) * * Only UnsignedShortType is supported * + * https://javadoc.scijava.org/ImgLib2/net/imglib2/cache/img/LoadedCellCacheLoader.html + * */ + + + // use scenery's Volume.fromSpimData to open Volume v = sciView.addVolume( sourcesAndConverters, converterSetups,