Skip to content

Commit da706e7

Browse files
acardonactrueden
authored andcommitted
ImgMath: added documentation to parallel execution methods.
1 parent 5c82415 commit da706e7

File tree

1 file changed

+78
-5
lines changed

1 file changed

+78
-5
lines changed

src/main/java/net/imglib2/algorithm/math/Compute.java

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,20 @@ public final void convert( final C comp, final C out) {
253253

254254
return target;
255255
}
256-
257256

257+
/**
258+
* View the result of the computations as a {@code RandomAccessibleInterval}, i.e. there is no target image,
259+
* instead any pixel can be viewed as the result of the computation applied to it, dynamically.
260+
*
261+
* See also {@code ViewableFunction} and methods below related to {@code Compute#randomAccess()} and {@code Compute#cursor()}.
262+
* The key difference is that, here, the computation and the output type can be different.
263+
*
264+
* @param inConverter_ To convert input images into the {@code computingType}. Can be null, defaults to a {@code Util#genericRealTypeConverter()}.
265+
* @param computingType The {@code Type} that defines the math to use.
266+
* @param outputType The @{code Type} of the constructed and returned {@code RandomAccessibleInterval}.
267+
* @param outConverter_ To convert from the {@code computingType} to the {@code outputType}. Can be null, defaults to a {@code Util#genericRealTypeConverter()}.
268+
* @return
269+
*/
258270
@SuppressWarnings("unchecked")
259271
public < O extends RealType< O >, C extends RealType< C > > RandomAccessibleInterval< O > asRandomAccessibleInterval(
260272
final Converter< RealType< ? >, C > inConverter_,
@@ -343,20 +355,38 @@ public RandomAccess< O > randomAccess( final Interval interval )
343355
return new RandomAccessIntervalCompute();
344356
}
345357

358+
/**
359+
* Compute the result multithreaded into an {@code ArrayImg} of the same {@code Type} as the first image found,
360+
* with mathematical operations using that same {@code Type}.
361+
*/
346362
public < O extends RealType< O > & NativeType< O > > RandomAccessibleInterval< O >
347363
parallelIntoArrayImg()
348364
{
349365
@SuppressWarnings("unchecked")
350-
final O outputType = ( ( RandomAccessibleInterval< O > )Util.findImg( operation ).iterator().next() ).randomAccess().get().createVariable();
351-
return parallelIntoArrayImg( null, outputType.createVariable(), outputType, null );
366+
final RandomAccessibleInterval< O > first = ( RandomAccessibleInterval< O > )Util.findImg( operation ).iterator().next();
367+
final O outputType = first.randomAccess().get().createVariable();
368+
final ArrayImg< O, ? > target = new ArrayImgFactory< O >( outputType ).create( first );
369+
return parallelInto( null, outputType.createVariable(), outputType, null, target );
352370
}
353371

372+
/**
373+
* Compute the result multithreaded into an {@code ArrayImg} of the given {@code Type}.
374+
*
375+
* @param outputType The {@code Type} used for both computations and the output image.
376+
*/
354377
public < O extends RealType< O > & NativeType< O > > RandomAccessibleInterval< O >
355378
parallelIntoArrayImg( final O outputType )
356379
{
357380
return parallelIntoArrayImg( null, outputType.createVariable(), outputType, null );
358381
}
359382

383+
/**
384+
* Compute the result multithreaded into an {@code ArrayImg} of the given {@code Type}.
385+
* Uses generic {@code RealType} converters where appropriate as provided by {@code Util#genericRealTypeConverter()}.
386+
*
387+
* @param computeType The {@code Type} used for computations.
388+
* @param outputType The {@code Type} used for the output image.
389+
*/
360390
public < O extends RealType< O > & NativeType< O >, C extends RealType< C > > RandomAccessibleInterval< O >
361391
parallelIntoArrayImg(
362392
final C computeType,
@@ -366,6 +396,14 @@ public RandomAccess< O > randomAccess( final Interval interval )
366396
return parallelIntoArrayImg( null, computeType, outputType, null );
367397
}
368398

399+
/**
400+
* Compute the result multithreaded into an {@code ArrayImg} of the given {@code Type}.
401+
*
402+
* @param inConverter From input to {@code computeType}, or when null, uses {@code Util#genericRealTypeConverter()}.
403+
* @param computeType The {@code Type} used for computations.
404+
* @param outputType The {@code Type} used for the output image.
405+
* @param outConverter From {@code computeType} to {@code outputType}, or when null, uses {@code Util#genericRealTypeConverter()}.
406+
*/
369407
public < O extends RealType< O > & NativeType< O >, C extends RealType< C > > RandomAccessibleInterval< O >
370408
parallelIntoArrayImg(
371409
final Converter< RealType< ? >, C > inConverter,
@@ -374,8 +412,43 @@ public RandomAccess< O > randomAccess( final Interval interval )
374412
final Converter< C, O > outConverter
375413
)
376414
{
377-
final RandomAccessibleInterval< O > source = asRandomAccessibleInterval( inConverter, computeType, outputType, outConverter ),
378-
target = new ArrayImgFactory< O >( outputType ).create( source );
415+
final ArrayImg< O, ? > target = new ArrayImgFactory< O >( outputType ).create( Util.findImg( operation ).iterator().next() );
416+
return parallelInto( inConverter, computeType, outputType, outConverter, target );
417+
}
418+
419+
/**
420+
* Compute the result multithreaded into an {@code ArrayImg} of the given {@code Type}.
421+
* Uses generic {@code RealType} converters where appropriate as provided by {@code Util#genericRealTypeConverter()}.
422+
*
423+
* @param target To store the result of the computation, with its {@code Type} defining both the output {@code Type} and the {@code Type} used for computations.
424+
*/
425+
public < O extends RealType< O > > RandomAccessibleInterval< O >
426+
parallelInto(
427+
final RandomAccessibleInterval< O > target
428+
)
429+
{
430+
final O type = net.imglib2.util.Util.getTypeFromInterval( target );
431+
return parallelInto( null, type.createVariable(), type, null, target );
432+
}
433+
434+
/**
435+
* Compute the result multithreaded into an {@code ArrayImg} of the given {@code Type}.
436+
*
437+
* @param inConverter From input to {@code computeType}, or when null, uses {@code Util#genericRealTypeConverter()}.
438+
* @param computeType The {@code Type} used for computations.
439+
* @param outputType The {@code Type} used for the output image.
440+
* @param outConverter From {@code computeType} to {@code outputType}, or when null, uses {@code Util#genericRealTypeConverter()}.
441+
*/
442+
public < O extends RealType< O >, C extends RealType< C > > RandomAccessibleInterval< O >
443+
parallelInto(
444+
final Converter< RealType< ? >, C > inConverter,
445+
final C computeType,
446+
final O outputType,
447+
final Converter< C, O > outConverter,
448+
final RandomAccessibleInterval< O > target
449+
)
450+
{
451+
final RandomAccessibleInterval< O > source = asRandomAccessibleInterval( inConverter, computeType, outputType, outConverter );
379452
LoopBuilder.setImages( source, target).forEachPixel( O::set );
380453
return target;
381454
}

0 commit comments

Comments
 (0)