Skip to content

Commit b14b020

Browse files
committed
Formatting
1 parent ac0dbee commit b14b020

18 files changed

+339
-306
lines changed

src/main/java/net/imglib2/algorithm/convolution/AbstractMultiThreadedConvolution.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package net.imglib2.algorithm.convolution;
22

3-
import net.imglib2.RandomAccessible;
4-
import net.imglib2.RandomAccessibleInterval;
5-
63
import java.util.concurrent.ExecutorService;
74
import java.util.concurrent.Executors;
85
import java.util.concurrent.ThreadPoolExecutor;
96

7+
import net.imglib2.RandomAccessible;
8+
import net.imglib2.RandomAccessibleInterval;
9+
1010
/**
1111
* Abstract class to help implementing a Convolution, that is multi threaded
1212
* using an {@link ExecutorService}. This implements the method
1313
* {@link Convolution#setExecutor(ExecutorService)}.
1414
* <p>
15-
* Classes that derive from
16-
* {@link AbstractMultiThreadedConvolution} must override
15+
* Classes that derive from {@link AbstractMultiThreadedConvolution} must
16+
* override
1717
* {@link AbstractMultiThreadedConvolution#process(RandomAccessible, RandomAccessibleInterval, ExecutorService, int)}
18+
*
19+
* @author Matthias Arzt
1820
*/
1921
public abstract class AbstractMultiThreadedConvolution< T > implements Convolution< T >
2022
{
@@ -24,20 +26,21 @@ public abstract class AbstractMultiThreadedConvolution< T > implements Convoluti
2426
abstract protected void process( RandomAccessible< ? extends T > source,
2527
RandomAccessibleInterval< ? extends T > target,
2628
ExecutorService executorService,
27-
int numThreads);
29+
int numThreads );
2830

2931
@Override
30-
public void setExecutor( ExecutorService executor )
32+
public void setExecutor( final ExecutorService executor )
3133
{
3234
this.executor = executor;
3335
}
3436

3537
@Override
36-
final public void process( RandomAccessible< ? extends T > source, RandomAccessibleInterval< ? extends T > target )
38+
final public void process( final RandomAccessible< ? extends T > source, final RandomAccessibleInterval< ? extends T > target )
3739
{
38-
if(executor == null) {
39-
int numThreads = suggestNumThreads();
40-
ExecutorService executor = Executors.newFixedThreadPool( numThreads );
40+
if ( executor == null )
41+
{
42+
final int numThreads = suggestNumThreads();
43+
final ExecutorService executor = Executors.newFixedThreadPool( numThreads );
4144
try
4245
{
4346
process( source, target, executor, numThreads );
@@ -47,12 +50,13 @@ final public void process( RandomAccessible< ? extends T > source, RandomAccessi
4750
executor.shutdown();
4851
}
4952
}
50-
else {
53+
else
54+
{
5155
process( source, target, executor, getNumThreads( executor ) );
5256
}
5357
}
5458

55-
private int getNumThreads(ExecutorService executor)
59+
private int getNumThreads( final ExecutorService executor )
5660
{
5761
if ( executor instanceof ThreadPoolExecutor )
5862
return ( ( ThreadPoolExecutor ) executor ).getMaximumPoolSize();

src/main/java/net/imglib2/algorithm/convolution/Concatenation.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package net.imglib2.algorithm.convolution;
22

3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.List;
6+
import java.util.concurrent.ExecutorService;
7+
38
import net.imglib2.Interval;
49
import net.imglib2.RandomAccessible;
510
import net.imglib2.RandomAccessibleInterval;
@@ -11,11 +16,6 @@
1116
import net.imglib2.util.ValuePair;
1217
import net.imglib2.view.Views;
1318

14-
import java.util.ArrayList;
15-
import java.util.Collections;
16-
import java.util.List;
17-
import java.util.concurrent.ExecutorService;
18-
1919
/**
2020
* Helper to implement {@link Convolution#concat}.
2121
*
@@ -26,18 +26,19 @@ class Concatenation< T > implements Convolution< T >
2626

2727
private final List< Convolution< T > > steps;
2828

29-
Concatenation( List< ? extends Convolution< T > > steps )
29+
Concatenation( final List< ? extends Convolution< T > > steps )
3030
{
3131
this.steps = new ArrayList<>( steps );
3232
}
3333

34-
@Override public void setExecutor( ExecutorService executor )
34+
@Override
35+
public void setExecutor( final ExecutorService executor )
3536
{
3637
steps.forEach( step -> step.setExecutor( executor ) );
3738
}
3839

3940
@Override
40-
public Interval requiredSourceInterval( Interval targetInterval )
41+
public Interval requiredSourceInterval( final Interval targetInterval )
4142
{
4243
Interval result = targetInterval;
4344
for ( int i = steps.size() - 1; i >= 0; i-- )
@@ -54,17 +55,17 @@ public T preferredSourceType( T targetType )
5455
}
5556

5657
@Override
57-
public void process( RandomAccessible< ? extends T > source, RandomAccessibleInterval< ? extends T > target )
58+
public void process( final RandomAccessible< ? extends T > source, final RandomAccessibleInterval< ? extends T > target )
5859
{
59-
List< Pair< T, Interval > > srcIntervals = tmpIntervals( Util.getTypeFromInterval( target ), target );
60+
final List< Pair< T, Interval > > srcIntervals = tmpIntervals( Util.getTypeFromInterval( target ), target );
6061
RandomAccessibleInterval< ? extends T > currentSource = Views.interval( source, srcIntervals.get( 0 ).getB() );
6162
RandomAccessibleInterval< ? extends T > available = null;
6263

6364
for ( int i = 0; i < steps.size(); i++ )
6465
{
65-
Convolution< T > step = steps.get( i );
66-
T targetType = srcIntervals.get( i + 1 ).getA();
67-
Interval targetInterval = srcIntervals.get( i + 1 ).getB();
66+
final Convolution< T > step = steps.get( i );
67+
final T targetType = srcIntervals.get( i + 1 ).getA();
68+
final Interval targetInterval = srcIntervals.get( i + 1 ).getB();
6869
RandomAccessibleInterval< ? extends T > currentTarget =
6970
( i == steps.size() - 1 ) ? target : null;
7071

@@ -84,27 +85,28 @@ public void process( RandomAccessible< ? extends T > source, RandomAccessibleInt
8485
}
8586
}
8687

87-
private static < T extends NativeType< T > > RandomAccessibleInterval< T > createImage( T targetType, Interval targetInterval )
88+
private static < T extends NativeType< T > > RandomAccessibleInterval< T > createImage( final T targetType, final Interval targetInterval )
8889
{
89-
long[] dimensions = Intervals.dimensionsAsLongArray( targetInterval );
90-
Img< T > ts = Util.getArrayOrCellImgFactory( targetInterval, targetType ).create( dimensions );
90+
final long[] dimensions = Intervals.dimensionsAsLongArray( targetInterval );
91+
final Img< T > ts = Util.getArrayOrCellImgFactory( targetInterval, targetType ).create( dimensions );
9192
return Views.translate( ts, Intervals.minAsLongArray( targetInterval ) );
9293
}
9394

94-
private static < T > T uncheckedCast( Object in )
95+
private static < T > T uncheckedCast( final Object in )
9596
{
9697
@SuppressWarnings( "unchecked" )
98+
final
9799
T in1 = ( T ) in;
98100
return in1;
99101
}
100102

101103
private List< Pair< T, Interval > > tmpIntervals( T type, Interval interval )
102104
{
103-
List< Pair< T, Interval > > result = new ArrayList<>( Collections.nCopies( steps.size() + 1, null ) );
105+
final List< Pair< T, Interval > > result = new ArrayList<>( Collections.nCopies( steps.size() + 1, null ) );
104106
result.set( steps.size(), new ValuePair<>( type, interval ) );
105107
for ( int i = steps.size() - 1; i >= 0; i-- )
106108
{
107-
Convolution< T > step = steps.get( i );
109+
final Convolution< T > step = steps.get( i );
108110
interval = step.requiredSourceInterval( interval );
109111
type = step.preferredSourceType( type );
110112
result.set( i, new ValuePair<>( type, interval ) );

src/main/java/net/imglib2/algorithm/convolution/Convolution.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,64 @@
11
package net.imglib2.algorithm.convolution;
22

3-
import net.imglib2.Interval;
4-
import net.imglib2.RandomAccessible;
5-
import net.imglib2.RandomAccessibleInterval;
6-
73
import java.util.Arrays;
84
import java.util.List;
95
import java.util.concurrent.ExecutorService;
106

7+
import net.imglib2.Interval;
8+
import net.imglib2.RandomAccessible;
9+
import net.imglib2.RandomAccessibleInterval;
10+
1111
/**
12-
* This interface allows the client to perform a convolution.
13-
* But also to query for the required input image size and preferred input image type.
14-
* The ExectorService can be set, to allow multi or single threaded operation.
12+
* This interface allows the client to perform a convolution. But also to query
13+
* for the required input image size and preferred input image type. The
14+
* ExectorService can be set, to allow multi or single threaded operation.
1515
* <p>
1616
* Very importantly, multiple {@link Convolution}s can be easily concatenated.
1717
*
1818
* @author Matthias Arzt
1919
*/
2020
public interface Convolution< T >
2121
{
22-
2322
/**
24-
* Returns the required size for source image, to calculate the given target interval?
23+
* Returns the required size for source image, to calculate the given target
24+
* interval.
2525
*/
2626
Interval requiredSourceInterval( Interval targetInterval );
2727

2828
/**
29-
* What's the preferred type for the source image,
30-
* when target should have the specified type.
31-
**/
29+
* What's the preferred type for the source image, when target should have
30+
* the specified type?
31+
*/
3232
T preferredSourceType( T targetType );
3333

3434
/**
3535
* Set the {@link ExecutorService} to be used for convolution.
3636
*/
37-
default void setExecutor( ExecutorService executor )
38-
{
39-
}
37+
default void setExecutor( final ExecutorService executor )
38+
{}
4039

4140
/**
4241
* Fills the target image, with the convolution result.
4342
*
44-
* @param source Source image. It must allow pixel access in the interval returned
45-
* by {@code requiredSourceInterval(target)}
46-
* @param target Target image.
43+
* @param source
44+
* Source image. It must allow pixel access in the interval
45+
* returned by {@code requiredSourceInterval(target)}
46+
* @param target
47+
* Target image.
4748
*/
4849
void process( RandomAccessible< ? extends T > source, RandomAccessibleInterval< ? extends T > target );
4950

5051
/**
51-
* Concatenate multiple {@link Convolution}s to one convolution.
52-
* (e.g. Concatenation of a gauss convolution in X, and a gauss convolution in Y will be a 2d gauss convolution).
52+
* Concatenate multiple {@link Convolution}s to one convolution. (e.g.
53+
* Concatenation of a gauss convolution in X, and a gauss convolution in Y
54+
* will be a 2d gauss convolution).
5355
*/
54-
static < T > Convolution< T > concat( Convolution< T >... steps )
56+
static < T > Convolution< T > concat( final Convolution< T >... steps )
5557
{
5658
return concat( Arrays.asList( steps ) );
5759
}
5860

59-
static < T > Convolution< T > concat( List< ? extends Convolution< T > > steps )
61+
static < T > Convolution< T > concat( final List< ? extends Convolution< T > > steps )
6062
{
6163
if ( steps.isEmpty() )
6264
throw new IllegalArgumentException( "Concat requires at least one convolution operation." );
@@ -65,4 +67,3 @@ static < T > Convolution< T > concat( List< ? extends Convolution< T > > steps )
6567
return new Concatenation<>( steps );
6668
}
6769
}
68-

0 commit comments

Comments
 (0)