Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax NumericType restriction on AbstractSource and RandomAccessibleSources #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/main/java/bdv/util/AbstractSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,27 @@
import bdv.viewer.Source;
import mpicbg.spim.data.sequence.VoxelDimensions;
import net.imglib2.RealRandomAccessible;
import net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory;
import net.imglib2.type.Type;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.view.Views;

public abstract class AbstractSource< T extends NumericType< T > > implements Source< T >
public abstract class AbstractSource< T extends Type< T > > implements Source< T >
{
protected final T type;
protected final T extension;

protected final String name;

protected final DefaultInterpolators< T > interpolators;
protected final InterpolationFunction<T> interpolators;

public AbstractSource( final T type, final String name )
public AbstractSource( final T extension, final String name )
{
this.type = type;
this.extension = extension;
this.name = name;
interpolators = new DefaultInterpolators<>();
if(extension instanceof NumericType)
interpolators = new DefaultInterpolators();
else
interpolators = (interpolation -> new NearestNeighborInterpolatorFactory<>());
}

public AbstractSource( final Supplier< T > typeSupplier, final String name )
Expand All @@ -66,13 +71,13 @@ public boolean isPresent( final int t )
@Override
public T getType()
{
return type;
return extension;
}

@Override
public RealRandomAccessible< T > getInterpolatedSource( final int t, final int level, final Interpolation method )
{
return Views.interpolate( Views.extendZero( getSource( t, level ) ), interpolators.get( method ) );
return Views.interpolate( Views.extendValue( getSource( t, level ), extension ), interpolators.apply( method ) );
}

@Override
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/bdv/util/DefaultInterpolators.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package bdv.util;

import java.util.function.Function;

import bdv.viewer.Interpolation;
import net.imglib2.RandomAccessible;
import net.imglib2.interpolation.InterpolatorFactory;
import net.imglib2.interpolation.randomaccess.ClampingNLinearInterpolatorFactory;
import net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory;
import net.imglib2.type.numeric.NumericType;

public class DefaultInterpolators< T extends NumericType< T > > implements Function< Interpolation, InterpolatorFactory< T, RandomAccessible< T > > >
public class DefaultInterpolators< T extends NumericType< T > > implements InterpolationFunction< T >
{
private final InterpolatorFactory< T, RandomAccessible< T > >[] factories;

Expand All @@ -21,6 +19,7 @@ public DefaultInterpolators()
factories[ Interpolation.NLINEAR.ordinal() ] = new ClampingNLinearInterpolatorFactory<>();
}

@Override
public InterpolatorFactory< T, RandomAccessible< T > > get( final Interpolation method )
{
return factories[ method.ordinal() ];
Expand All @@ -30,10 +29,4 @@ public int size()
{
return factories.length;
}

@Override
public InterpolatorFactory< T, RandomAccessible< T > > apply( final Interpolation t )
{
return get( t );
}
}
19 changes: 19 additions & 0 deletions src/main/java/bdv/util/InterpolationFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package bdv.util;

import java.util.function.Function;

import bdv.viewer.Interpolation;
import net.imglib2.RandomAccessible;
import net.imglib2.interpolation.InterpolatorFactory;
import net.imglib2.type.Type;

public interface InterpolationFunction< T extends Type< T > > extends Function< Interpolation, InterpolatorFactory< T, RandomAccessible< T > > >
{
public abstract InterpolatorFactory< T, RandomAccessible< T > > get( final Interpolation method );

@Override
public default InterpolatorFactory< T, RandomAccessible< T > > apply( final Interpolation t )
{
return get( t );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.Volatile;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.Type;
import net.imglib2.type.numeric.NumericType;

public class RandomAccessibleIntervalMipmapSource< T extends NumericType< T > > extends AbstractSource< T >
public class RandomAccessibleIntervalMipmapSource< T extends Type< T > > extends AbstractSource< T >
{
protected final RandomAccessibleInterval< T >[] mipmapSources;

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/bdv/util/RandomAccessibleIntervalSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealRandomAccessible;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.Type;
import net.imglib2.view.Views;

public class RandomAccessibleIntervalSource< T extends NumericType< T > > extends AbstractSource< T >
public class RandomAccessibleIntervalSource< T extends Type< T > > extends AbstractSource< T >
{
private final RandomAccessibleInterval< T > source;

Expand All @@ -61,10 +61,8 @@ public RandomAccessibleIntervalSource(
this.source = img;
this.sourceTransform = sourceTransform;
interpolatedSources = new RealRandomAccessible[ Interpolation.values().length ];
final T zero = getType().createVariable();
zero.setZero();
for ( final Interpolation method : Interpolation.values() )
interpolatedSources[ method.ordinal() ] = Views.interpolate( Views.extendValue( source, zero ), interpolators.get( method ) );
interpolatedSources[ method.ordinal() ] = Views.interpolate( Views.extendValue( source, extension.copy() ), interpolators.get( method ) );
}

@Override
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/bdv/util/RandomAccessibleIntervalSource4D.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealRandomAccessible;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.Type;
import net.imglib2.view.Views;

public class RandomAccessibleIntervalSource4D< T extends NumericType< T > > extends AbstractSource< T >
public class RandomAccessibleIntervalSource4D< T extends Type< T > > extends AbstractSource< T >
{
private final RandomAccessibleInterval< T > source;

Expand Down Expand Up @@ -75,11 +75,9 @@ private void loadTimepoint( final int timepointIndex )
currentTimePointIndex = timepointIndex;
if ( isPresent( timepointIndex ) )
{
final T zero = getType().createVariable();
zero.setZero();
currentSource = Views.hyperSlice( source, 3, timepointIndex );
for ( final Interpolation method : Interpolation.values() )
currentInterpolatedSources[ method.ordinal() ] = Views.interpolate( Views.extendValue( currentSource, zero ), interpolators.get( method ) );
currentInterpolatedSources[ method.ordinal() ] = Views.interpolate( Views.extendValue( currentSource, extension.copy() ), interpolators.get( method ) );
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/bdv/util/RandomAccessibleSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealRandomAccessible;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.Type;
import net.imglib2.view.Views;

public class RandomAccessibleSource< T extends NumericType< T > > extends AbstractSource< T >
public class RandomAccessibleSource< T extends Type< T > > extends AbstractSource< T >
{
private final RandomAccessible< T > source;

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/bdv/util/RandomAccessibleSource4D.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealRandomAccessible;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.Type;
import net.imglib2.util.Intervals;
import net.imglib2.view.Views;

public class RandomAccessibleSource4D< T extends NumericType< T > > extends AbstractSource< T >
public class RandomAccessibleSource4D< T extends Type< T > > extends AbstractSource< T >
{
private final RandomAccessible< T > source;

Expand Down Expand Up @@ -88,8 +88,6 @@ private void loadTimepoint( final int timepointIndex )
currentTimePointIndex = timepointIndex;
if ( isPresent( timepointIndex ) )
{
final T zero = getType().createVariable();
zero.setZero();
final RandomAccessible< T > slice = Views.hyperSlice( source, 3, timepointIndex );
currentSource = Views.interval( slice, timeSliceInterval );
for ( final Interpolation method : Interpolation.values() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.Volatile;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.Type;

public class VolatileRandomAccessibleIntervalMipmapSource< T extends NumericType< T >, V extends Volatile< T > & NumericType< V > > extends AbstractSource< V >
public class VolatileRandomAccessibleIntervalMipmapSource< T extends Type< T >, V extends Volatile< T > & Type< V > > extends AbstractSource< V >
{
private final RandomAccessibleIntervalMipmapSource< T > source;

Expand Down