Skip to content

Commit 6dec1f2

Browse files
committed
Minor cleaning
1 parent 5d0e2e3 commit 6dec1f2

7 files changed

+97
-103
lines changed

src/main/java/net/imglib2/imagej/imageplus/ImagePlusImgFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public ImagePlusImgFactory( final T type )
116116
@Override
117117
public < S > ImgFactory< S > imgFactory( final S type ) throws IncompatibleTypeException
118118
{
119-
if ( NativeType.class.isInstance( type ) )
119+
if (type instanceof NativeType)
120120
return new ImagePlusImgFactory( ( NativeType ) type );
121121
throw new IncompatibleTypeException( this, type.getClass().getCanonicalName() + " does not implement NativeType." );
122122
}

src/main/java/net/imglib2/imagej/img/AbstractVirtualStack.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ private BiConsumer<?, FloatType> voxelAccessAction( Integer channel, boolean isS
460460
if ( bitDepth == 24 )
461461
return arbgVoxelAccessAction( channel, isSetVoxels );
462462
return isSetVoxels ?
463-
(BiConsumer< RealType, FloatType >) ( a, b ) -> a.setReal( b.getRealFloat() ) :
464-
(BiConsumer< RealType, FloatType >) ( a, b ) -> b.setReal( a.getRealFloat() );
463+
(BiConsumer< RealType<?>, FloatType >) ( a, b ) -> a.setReal( b.getRealFloat() ) :
464+
(BiConsumer< RealType<?>, FloatType >) ( a, b ) -> b.setReal( a.getRealFloat() );
465465
}
466466

467467
private static BiConsumer<ARGBType, FloatType> arbgVoxelAccessAction( Integer channel, boolean isSetVoxel )

src/main/java/net/imglib2/imagej/img/ImageJVirtualStack.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
import net.imglib2.img.array.ArrayImgFactory;
5050
import net.imglib2.img.basictypeaccess.array.ArrayDataAccess;
5151
import net.imglib2.type.NativeType;
52+
import net.imglib2.type.Type;
5253
import net.imglib2.type.numeric.ARGBType;
5354
import net.imglib2.type.numeric.integer.UnsignedByteType;
5455
import net.imglib2.type.numeric.integer.UnsignedShortType;
5556
import net.imglib2.type.numeric.real.FloatType;
5657
import net.imglib2.util.IntervalIndexer;
57-
import net.imglib2.util.Util;
5858
import net.imglib2.view.Views;
5959

6060
import java.util.concurrent.ExecutorService;
@@ -113,7 +113,7 @@ protected ImageJVirtualStack( final RandomAccessibleInterval< T > source, final
113113
// if we were given an ExecutorService, use a multithreaded projector
114114
assert source.numDimensions() > 1;
115115
this.source = zeroMin( source );
116-
this.type = Util.getTypeFromInterval( source );
116+
this.type = source.getType();
117117
this.higherSourceDimensions = initHigherDimensions( source );
118118
}
119119

@@ -204,7 +204,7 @@ protected void setPixelsZeroBasedIndex( final int index, final Object pixels )
204204
Img< T > img = ( Img< T > ) ImageProcessorUtils.createImg( pixels, getWidth(), getHeight() );
205205
// NB: The use of Converter and Projector2D is a bit surprising.
206206
// As the converter intentionally uses the first parameter a output.
207-
project( index, img, (o, i) -> o.set( i ) );
207+
project( index, img, Type::set);
208208
}
209209

210210
@Override

src/main/java/net/imglib2/imagej/img/ImageJVirtualStackFloat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public class ImageJVirtualStackFloat extends ImageJVirtualStack< FloatType >
6767

6868
private static < T extends RealType< ? > > RandomAccessibleInterval<FloatType> toFloat( RandomAccessibleInterval<T> source )
6969
{
70-
if( Util.getTypeFromInterval(source) instanceof FloatType )
70+
if( source.getType() instanceof FloatType )
7171
return ( RandomAccessibleInterval< FloatType > ) source;
72-
return Converters.convert( source, new ToFloatSamplerConverter( Util.getTypeFromInterval( source )));
72+
return Converters.convert( source, new ToFloatSamplerConverter( source.getType()));
7373
}
7474

7575
public < S > ImageJVirtualStackFloat( final RandomAccessibleInterval< S > source,

src/main/java/net/imglib2/imagej/img/ImageJVirtualStackUnsignedByte.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public class ImageJVirtualStackUnsignedByte extends ImageJVirtualStack< Unsigned
6161

6262
private static < T extends RealType< ? > > RandomAccessibleInterval< UnsignedByteType > toUnsignedByteType( RandomAccessibleInterval< T > source )
6363
{
64-
if( Util.getTypeFromInterval( source ) instanceof UnsignedByteType )
64+
if( source.getType() instanceof UnsignedByteType )
6565
return ( RandomAccessibleInterval< UnsignedByteType > ) source;
66-
return Converters.convert(source, new ToUnsignedByteSamplerConverter( Util.getTypeFromInterval( source ) ) );
66+
return Converters.convert(source, new ToUnsignedByteSamplerConverter( source.getType() ) );
6767
}
6868

6969
public static ImageJVirtualStackUnsignedByte wrapAndScaleBitType( final RandomAccessibleInterval< BitType > source )

src/main/java/net/imglib2/imagej/img/ImageJVirtualStackUnsignedShort.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public class ImageJVirtualStackUnsignedShort extends ImageJVirtualStack< Unsigne
5757
public static < T extends RealType< ? > > ImageJVirtualStackUnsignedShort wrap( final RandomAccessibleInterval< T > source )
5858
{
5959
final ImageJVirtualStackUnsignedShort result = new ImageJVirtualStackUnsignedShort( toUnsignedShort( source ) );
60-
result.initMinMax( Util.getTypeFromInterval( source ) );
60+
result.initMinMax( source.getType() );
6161
return result;
6262
}
6363

6464
private static < T extends RealType< ? > > RandomAccessibleInterval< UnsignedShortType > toUnsignedShort( RandomAccessibleInterval< T > source )
6565
{
66-
if( Util.getTypeFromInterval( source ) instanceof UnsignedShortType )
66+
if( source.getType() instanceof UnsignedShortType )
6767
return ( RandomAccessibleInterval< UnsignedShortType > ) source;
68-
return Converters.convert( source, new ShortConverter( Util.getTypeFromInterval( source ) ) );
68+
return Converters.convert( source, new ShortConverter( source.getType() ) );
6969
}
7070

7171
public < S > ImageJVirtualStackUnsignedShort( final RandomAccessibleInterval< S > source, final Converter< ? super S, UnsignedShortType > converter )
@@ -76,7 +76,7 @@ public < S > ImageJVirtualStackUnsignedShort( final RandomAccessibleInterval< S
7676
public < S > ImageJVirtualStackUnsignedShort( final RandomAccessibleInterval< S > source, final Converter< ? super S, UnsignedShortType > converter, final ExecutorService service )
7777
{
7878
super( source, converter, new UnsignedShortType(), 16, service );
79-
initMinMax( Util.getTypeFromInterval( source ) );
79+
initMinMax( source.getType() );
8080
}
8181

8282
private ImageJVirtualStackUnsignedShort( final RandomAccessibleInterval< UnsignedShortType > source )
@@ -88,9 +88,9 @@ private void initMinMax( Object s )
8888
{
8989
int maxDisplay = ( 1 << 16 ) - 1;
9090

91-
if ( BitType.class.isInstance( s ) )
91+
if (s instanceof BitType)
9292
maxDisplay = 1;
93-
else if ( Unsigned12BitType.class.isInstance( s ) )
93+
else if (s instanceof Unsigned12BitType)
9494
maxDisplay = 4095;
9595

9696
setMinAndMax( 0, maxDisplay );

src/main/java/net/imglib2/imagej/img/MultithreadedIterableIntervalProjector2D.java

Lines changed: 81 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void map()
110110
max[dimX] = target.max( 0 );
111111
max[dimY] = target.max( 1 );
112112

113-
final IterableInterval< A > ii = Views.iterable( Views.interval( source, new FinalInterval( min, max ) ) );
113+
final IterableInterval< A > ii = Views.interval( source, new FinalInterval( min, max ) );
114114

115115
final long portionSize = target.size() / nTasks;
116116

@@ -119,92 +119,86 @@ public void map()
119119

120120
for ( int t = 0; t < nTasks; ++t )
121121
{
122-
tasks.add( new Callable< Void >()
123-
{
124-
125-
@Override
126-
public Void call() throws Exception
127-
{
128-
int i = ai.getAndIncrement();
129-
130-
final Cursor< B > targetCursor = target.localizingCursor();
131-
132-
// we might need either a cursor or a RandomAccess
133-
final RandomAccess< A > sourceRandomAccess = source.randomAccess();
134-
sourceRandomAccess.setPosition( position );
135-
136-
final Cursor< A > sourceCursor = ii.cursor();
137-
138-
// jump to correct starting point
139-
targetCursor.jumpFwd( i * portionSize );
140-
sourceCursor.jumpFwd( i * portionSize );
141-
long stepsTaken = 0;
142-
143-
if ( target.iterationOrder().equals( ii.iterationOrder() )
144-
&& !( sourceCursor instanceof RandomAccessibleIntervalCursor ) )
145-
{
146-
// either map a portion or (for the last portion) go
147-
// until the end
148-
while ( ( i != nTasks - 1 && stepsTaken < portionSize )
149-
|| ( i == nTasks - 1 && targetCursor.hasNext() ) )
150-
{
151-
stepsTaken++;
152-
converter.convert( sourceCursor.next(), targetCursor.next() );
153-
}
154-
}
155-
156-
else if ( target.iterationOrder() instanceof FlatIterationOrder )
157-
{
158-
159-
final long cr = -target.dimension( 0 );
160-
final long width = target.dimension( 0 );
161-
final long height = target.dimension( 1 );
162-
163-
final long initX = ( i * portionSize ) % width;
164-
final long initY = ( i * portionSize ) / width;
165-
// either map a portion or (for the last portion) go
166-
// until the end
167-
final long endX = ( i == nTasks - 1 ) ? width : ( initX + ( i + 1 ) * portionSize ) % width;
168-
final long endY = ( i == nTasks - 1 ) ? height - 1
169-
: ( initX + ( i + 1 ) * portionSize ) / width;
170-
171-
sourceRandomAccess.setPosition( initX, dimX );
172-
sourceRandomAccess.setPosition( initY, dimY );
173-
174-
for ( long y = initY; y <= endY; ++y )
175-
{
176-
for ( long x = ( y == initY ? initX : 0 ); x < ( y == endY ? endX : width ); ++x )
177-
{
178-
targetCursor.fwd();
179-
converter.convert( sourceRandomAccess.get(), targetCursor.get() );
180-
sourceRandomAccess.fwd( dimX );
181-
182-
}
183-
sourceRandomAccess.move( cr, dimX );
184-
sourceRandomAccess.fwd( dimY );
185-
}
186-
}
187-
188-
else
189-
{
190-
// either map a portion or (for the last portion) go
191-
// until the end
192-
while ( ( i != nTasks - 1 && stepsTaken < portionSize )
193-
|| ( i == nTasks - 1 && targetCursor.hasNext() ) )
194-
{
195-
stepsTaken++;
196-
197-
final B b = targetCursor.next();
198-
sourceRandomAccess.setPosition( targetCursor.getLongPosition( 0 ), dimX );
199-
sourceRandomAccess.setPosition( targetCursor.getLongPosition( 1 ), dimY );
200-
201-
converter.convert( sourceRandomAccess.get(), b );
202-
}
203-
}
204-
205-
return null;
206-
}
207-
} );
122+
tasks.add(() -> {
123+
int i = ai.getAndIncrement();
124+
125+
final Cursor< B > targetCursor = target.localizingCursor();
126+
127+
// we might need either a cursor or a RandomAccess
128+
final RandomAccess< A > sourceRandomAccess = source.randomAccess();
129+
sourceRandomAccess.setPosition( position );
130+
131+
final Cursor< A > sourceCursor = ii.cursor();
132+
133+
// jump to correct starting point
134+
targetCursor.jumpFwd( i * portionSize );
135+
sourceCursor.jumpFwd( i * portionSize );
136+
long stepsTaken = 0;
137+
138+
if ( target.iterationOrder().equals( ii.iterationOrder() )
139+
&& !( sourceCursor instanceof RandomAccessibleIntervalCursor ) )
140+
{
141+
// either map a portion or (for the last portion) go
142+
// until the end
143+
while ( ( i != nTasks - 1 && stepsTaken < portionSize )
144+
|| ( i == nTasks - 1 && targetCursor.hasNext() ) )
145+
{
146+
stepsTaken++;
147+
converter.convert( sourceCursor.next(), targetCursor.next() );
148+
}
149+
}
150+
151+
else if ( target.iterationOrder() instanceof FlatIterationOrder )
152+
{
153+
154+
final long cr = -target.dimension( 0 );
155+
final long width = target.dimension( 0 );
156+
final long height = target.dimension( 1 );
157+
158+
final long initX = ( i * portionSize ) % width;
159+
final long initY = ( i * portionSize ) / width;
160+
// either map a portion or (for the last portion) go
161+
// until the end
162+
final long endX = ( i == nTasks - 1 ) ? width : ( initX + ( i + 1 ) * portionSize ) % width;
163+
final long endY = ( i == nTasks - 1 ) ? height - 1
164+
: ( initX + ( i + 1 ) * portionSize ) / width;
165+
166+
sourceRandomAccess.setPosition( initX, dimX );
167+
sourceRandomAccess.setPosition( initY, dimY );
168+
169+
for ( long y = initY; y <= endY; ++y )
170+
{
171+
for ( long x = ( y == initY ? initX : 0 ); x < ( y == endY ? endX : width ); ++x )
172+
{
173+
targetCursor.fwd();
174+
converter.convert( sourceRandomAccess.get(), targetCursor.get() );
175+
sourceRandomAccess.fwd( dimX );
176+
177+
}
178+
sourceRandomAccess.move( cr, dimX );
179+
sourceRandomAccess.fwd( dimY );
180+
}
181+
}
182+
183+
else
184+
{
185+
// either map a portion or (for the last portion) go
186+
// until the end
187+
while ( ( i != nTasks - 1 && stepsTaken < portionSize )
188+
|| ( i == nTasks - 1 && targetCursor.hasNext() ) )
189+
{
190+
stepsTaken++;
191+
192+
final B b = targetCursor.next();
193+
sourceRandomAccess.setPosition( targetCursor.getLongPosition( 0 ), dimX );
194+
sourceRandomAccess.setPosition( targetCursor.getLongPosition( 1 ), dimY );
195+
196+
converter.convert( sourceRandomAccess.get(), b );
197+
}
198+
}
199+
200+
return null;
201+
});
208202
}
209203

210204
try

0 commit comments

Comments
 (0)