Skip to content

Commit

Permalink
Add getType implementations for most of RA/RAI classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanslovsky committed Mar 2, 2022
1 parent 1f67b63 commit dc0b039
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ public C getDestinationType()
{
return converterSupplier.get();
}

@Override
public C getType() {
return converted.createVariable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,9 @@ public C getDestinationType()
{
return converterSupplier.get();
}

@Override
public C getType() {
return converted.createVariable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ public B getDestinationType()
{
return converterSupplier.get();
}

@Override
public B getType() {
return converted.createVariable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import net.imglib2.Interval;
import net.imglib2.RandomAccessible;
import net.imglib2.Sampler;
import net.imglib2.converter.AbstractConvertedRandomAccessible;

/**
Expand Down Expand Up @@ -74,4 +75,31 @@ public WriteConvertedRandomAccess< A, B > randomAccess( final Interval interval
{
return new WriteConvertedRandomAccess< A, B >( source.randomAccess( interval ), converterSupplier );
}

@Override
public B getType() {
return converterSupplier.get().convert( ( Sampler< ? extends A > ) new ConstantSampler( getSource().getType() ) );
}

private static class ConstantSampler< T > implements Sampler< T >
{

private final T t;

public ConstantSampler( T t ) {
this.t = t;
}

@Override
public T get()
{
return t;
}

@Override
public Sampler< T > copy()
{
return new ConstantSampler<>( t );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.imglib2.AbstractWrappedInterval;
import net.imglib2.Interval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.Sampler;

/**
* TODO
Expand Down Expand Up @@ -74,4 +75,31 @@ public WriteConvertedRandomAccess< A, B > randomAccess( final Interval interval
{
return new WriteConvertedRandomAccess< A, B >( sourceInterval.randomAccess( interval ), converterSupplier );
}

@Override
public B getType() {
return converterSupplier.get().convert( ( Sampler< ? extends A > ) new ConstantSampler( getSource().getType() ) );
}

private static class ConstantSampler< T > implements Sampler< T >
{

private final T t;

public ConstantSampler( T t ) {
this.t = t;
}

@Override
public T get()
{
return t;
}

@Override
public Sampler< T > copy()
{
return new ConstantSampler<>( t );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,9 @@ public DiscreteFrequencyDistribution copy()
return new DiscreteFrequencyDistribution( counts.copy() );
}

@Override
public LongType getType() {
return new LongType();
}

}
4 changes: 4 additions & 0 deletions src/main/java/net/imglib2/histogram/Histogram1d.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ public Histogram1d< T > copy()
return new Histogram1d< T >( this );
}

public LongType getType() {
return new LongType();
}

// -- helpers --

private void reset()
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/imglib2/histogram/HistogramNd.java
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,11 @@ public HistogramNd< T > copy()
return new HistogramNd< T >( this );
}

@Override
public LongType getType() {
return new LongType();
}

// -- helpers --

private void reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ public FunctionRandomAccess randomAccess( final Interval interval )
{
return randomAccess();
}

@Override
public T getType() {
return super.typeSupplier.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ public RandomAccess< LongType > randomAccess( final Interval interval )
{
return randomAccess();
}

@Override
public LongType getType() {
return new LongType();
}
}
5 changes: 5 additions & 0 deletions src/main/java/net/imglib2/util/ConstantUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public RandomAccess< T > randomAccess( final Interval interval )
{
return randomAccess();
}

@Override
public T getType() {
return constant;
}
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/imglib2/util/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ public Iterator< Interval > iterator()
{
return cursor();
}

@Override
public Interval getType() { return firstElement(); }
}

private final CellIntervals cellIntervals;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/imglib2/view/StackView.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public RandomAccess< T > randomAccess( final Interval interval )
new DefaultRA< T >( slices, interval );
}

@Override
public T getType() {
return slices.length > 0 ? slices[0].getType() : null;
}

/**
* Get the source slices that are stacked in this {@link StackView}. These
* are {@code (numDimensions() - 1)} dimensional
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/imglib2/view/TransformBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ public RandomAccess< T > randomAccess( final Interval interval )
{
return new TransformRandomAccess< T >( s.randomAccess(), t );
}

@Override
public T getType() {
return s.getType();
}
};
}

Expand Down Expand Up @@ -417,6 +422,11 @@ public RandomAccess< T > randomAccess( final Interval interval )
return new FullSourceMapMixedRandomAccess< T >( s.randomAccess(), t );
return new MixedRandomAccess< T >( s.randomAccess(), t );
}

@Override
public T getType() {
return s.getType();
}
};
}

Expand All @@ -441,6 +451,11 @@ public TranslationRandomAccess< T > randomAccess( final Interval interval )
{
return new TranslationRandomAccess< T >( s.randomAccess(), t );
}

@Override
public T getType() {
return s.getType();
}
};
}

Expand Down Expand Up @@ -470,6 +485,11 @@ public RandomAccess< T > randomAccess( final Interval interval )
return new FullSourceMapSlicingRandomAccess< T >( s.randomAccess(), t );
return new SlicingRandomAccess< T >( s.randomAccess(), t );
}

@Override
public T getType() {
return s.getType();
}
};
}
}

0 comments on commit dc0b039

Please sign in to comment.