Skip to content

Commit

Permalink
Add PrimitiveBlocks.numDimensions()
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietzsch committed Sep 7, 2024
1 parent c100e5c commit 865e0c1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/main/java/net/imglib2/blocks/FallbackPrimitiveBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/imglib2/blocks/PrimitiveBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -101,10 +103,8 @@
* @param <T>
* 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).
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/imglib2/blocks/ViewAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 )
{
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/imglib2/blocks/ViewProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -110,6 +115,7 @@ public String toString()
{
return "ViewProperties{" +
"viewType=" + viewType.getClass().getSimpleName() +
", viewNumDimensions=" + viewNumDimensions +
", root=" + root +
", rootType=" + rootType.getClass().getSimpleName() +
", extension=" + extension +
Expand All @@ -125,6 +131,11 @@ public T getViewType()
return viewType;
}

public int getViewNumDimensions()
{
return viewNumDimensions;
}

public NativeImg< R, ? > getRoot()
{
return root;
Expand Down

0 comments on commit 865e0c1

Please sign in to comment.