From 10b3671e5740b6b84fc74e2ceeaab7c7a91d1ea1 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Mon, 1 Jul 2024 03:32:11 +0200 Subject: [PATCH] Add PrimitiveBlocks.numDimensions() --- .../net/imglib2/blocks/FallbackPrimitiveBlocks.java | 6 ++++++ .../java/net/imglib2/blocks/PrimitiveBlocks.java | 6 +++--- src/main/java/net/imglib2/blocks/ViewAnalyzer.java | 3 ++- .../java/net/imglib2/blocks/ViewPrimitiveBlocks.java | 12 ++++++++++++ src/main/java/net/imglib2/blocks/ViewProperties.java | 11 +++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/imglib2/blocks/FallbackPrimitiveBlocks.java b/src/main/java/net/imglib2/blocks/FallbackPrimitiveBlocks.java index 7354dee96..c1f75e841 100644 --- a/src/main/java/net/imglib2/blocks/FallbackPrimitiveBlocks.java +++ b/src/main/java/net/imglib2/blocks/FallbackPrimitiveBlocks.java @@ -77,6 +77,12 @@ public T getType() return type; } + @Override + public int numDimensions() + { + return source.numDimensions(); + } + @Override public void copy( final long[] srcPos, final Object dest, final int[] size ) { diff --git a/src/main/java/net/imglib2/blocks/PrimitiveBlocks.java b/src/main/java/net/imglib2/blocks/PrimitiveBlocks.java index 9c1b96c48..927287d79 100644 --- a/src/main/java/net/imglib2/blocks/PrimitiveBlocks.java +++ b/src/main/java/net/imglib2/blocks/PrimitiveBlocks.java @@ -36,7 +36,9 @@ import static net.imglib2.blocks.PrimitiveBlocks.OnFallback.FAIL; import static net.imglib2.blocks.PrimitiveBlocks.OnFallback.WARN; +import net.imglib2.EuclideanSpace; import net.imglib2.RandomAccessible; +import net.imglib2.Typed; import net.imglib2.type.NativeType; import net.imglib2.util.Util; @@ -101,10 +103,8 @@ * @param * pixel type */ -public interface PrimitiveBlocks< T extends NativeType< T > > +public interface PrimitiveBlocks< T extends NativeType< T > > extends Typed< T >, EuclideanSpace { - T getType(); - /** * Copy a block from the ({@code T}-typed) source into primitive arrays (of * the appropriate type). diff --git a/src/main/java/net/imglib2/blocks/ViewAnalyzer.java b/src/main/java/net/imglib2/blocks/ViewAnalyzer.java index 9a992b89f..2d490fc7c 100644 --- a/src/main/java/net/imglib2/blocks/ViewAnalyzer.java +++ b/src/main/java/net/imglib2/blocks/ViewAnalyzer.java @@ -596,9 +596,10 @@ private boolean splitTransform() private < T extends NativeType< T >, R extends NativeType< R > > ViewProperties< T, R > getViewProperties() { final T viewType = Cast.unchecked( ra.getType() ); + final int viewNumDimensions = ra.numDimensions(); final NativeImg< R, ? > root = Cast.unchecked( nodes.get( nodes.size() - 1 ).view() ); final R rootType = root.createLinkedType(); - return new ViewProperties<>( viewType, root, rootType, oobExtension, transform, permuteInvertTransform, converterSupplier ); + return new ViewProperties<>( viewType, viewNumDimensions, root, rootType, oobExtension, transform, permuteInvertTransform, converterSupplier ); } private < T extends NativeType< T > > FallbackProperties< T > getFallbackProperties() diff --git a/src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java b/src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java index 699fed751..b41e41196 100644 --- a/src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java +++ b/src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java @@ -87,6 +87,12 @@ public T getType() return props.getViewType(); } + @Override + public int numDimensions() + { + return props.getViewNumDimensions(); + } + /** * @param srcPos * min coordinates of block to copy from src Img. @@ -172,6 +178,12 @@ public T getType() return props.getViewType(); } + @Override + public int numDimensions() + { + return props.getViewNumDimensions(); + } + @Override public void copy( final long[] srcPos, final Object dest, final int[] size ) { diff --git a/src/main/java/net/imglib2/blocks/ViewProperties.java b/src/main/java/net/imglib2/blocks/ViewProperties.java index d42e9d9a0..e77b80a0c 100644 --- a/src/main/java/net/imglib2/blocks/ViewProperties.java +++ b/src/main/java/net/imglib2/blocks/ViewProperties.java @@ -58,6 +58,8 @@ class ViewProperties< T extends NativeType< T >, R extends NativeType< R > > { private final T viewType; + private final int viewNumDimensions; + private final NativeImg< R, ? > root; private final R rootType; @@ -78,6 +80,7 @@ class ViewProperties< T extends NativeType< T >, R extends NativeType< R > > * Create {@code ViewProperties}. * * @param viewType pixel type of the View to copy from + * @param viewNumDimensions number of dimensions of the View to copy from * @param root the {@code NativeImg} at the root of the View chain * @param rootType pixel type of the root {@code NativeImg} * @param extension out-of-bounds extension to apply to the root @@ -87,6 +90,7 @@ class ViewProperties< T extends NativeType< T >, R extends NativeType< R > > */ ViewProperties( final T viewType, + final int viewNumDimensions, final NativeImg< R, ? > root, final R rootType, final Extension extension, @@ -95,6 +99,7 @@ class ViewProperties< T extends NativeType< T >, R extends NativeType< R > > final Supplier< ? extends Converter< ?, ? > > converterSupplier ) { this.viewType = viewType; + this.viewNumDimensions = viewNumDimensions; this.root = root; this.rootType = rootType; this.extension = extension; @@ -110,6 +115,7 @@ public String toString() { return "ViewProperties{" + "viewType=" + viewType.getClass().getSimpleName() + + ", viewNumDimensions=" + viewNumDimensions + ", root=" + root + ", rootType=" + rootType.getClass().getSimpleName() + ", extension=" + extension + @@ -125,6 +131,11 @@ public T getViewType() return viewType; } + public int getViewNumDimensions() + { + return viewNumDimensions; + } + public NativeImg< R, ? > getRoot() { return root;