Skip to content
Snippets Groups Projects
Commit 0e1775af authored by Tobias Pietzsch's avatar Tobias Pietzsch
Browse files

Merge remote-tracking branch 'github/master'

parents 5e50d333 0e375af1
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,9 @@ import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.generic.sequence.BasicViewSetup;
......@@ -370,13 +373,55 @@ public class Hdf5ImageLoader extends AbstractViewerImgLoader< UnsignedShortType,
// copy unsigned short img to float img
final FloatType f = new FloatType();
final Img< FloatType > floatImg = net.imglib2.util.Util.getArrayOrCellImgFactory( ushortImg, f ).create( ushortImg, f );
final Cursor< UnsignedShortType > in = Views.iterable( ushortImg ).localizingCursor();
final RandomAccess< FloatType > out = floatImg.randomAccess();
while( in.hasNext() )
// set up executor service
final int numProcessors = Runtime.getRuntime().availableProcessors();
final ExecutorService taskExecutor = Executors.newFixedThreadPool( numProcessors );
final ArrayList< Callable< Boolean > > tasks = new ArrayList< Callable< Boolean > >();
// set up all threads
final int numPortions = numProcessors * 2;
final long threadChunkSize = floatImg.size() / numPortions;
final long threadChunkMod = floatImg.size() % numPortions;
for ( int portionID = 0; portionID < numPortions; ++portionID )
{
// move to the starting position of the current thread
final long startPosition = portionID * threadChunkSize;
// the last thread may has to run longer if the number of pixels cannot be divided by the number of threads
final long loopSize = ( portionID == numPortions - 1 ) ? threadChunkSize + threadChunkMod : threadChunkSize;
tasks.add( new Callable< Boolean >()
{
@Override
public Boolean call() throws Exception
{
final Cursor< UnsignedShortType > in = Views.iterable( ushortImg ).localizingCursor();
final RandomAccess< FloatType > out = floatImg.randomAccess();
in.jumpFwd( startPosition );
for ( long j = 0; j < loopSize; ++j )
{
final UnsignedShortType vin = in.next();
out.setPosition( in );
out.get().set( vin.getRealFloat() );
}
return true;
}
});
}
try
{
// invokeAll() returns when all tasks are complete
taskExecutor.invokeAll( tasks );
}
catch ( final InterruptedException e )
{
in.next();
out.setPosition( in );
out.get().set( in.get().getRealFloat() );
return null;
}
if ( normalize )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment