Skip to content
Snippets Groups Projects
Commit c6482399 authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Move most of the 2D block loading to loaders.

This change allows us to save memory on loading, by skipping one copy
step. Also loading is a bit faster. Next-up is 1D row vector loading.
parent bda49d9b
Branches
No related tags found
No related merge requests found
package azgracompress.io.loader; package azgracompress.io.loader;
import azgracompress.data.Range; import azgracompress.data.Range;
import azgracompress.data.V2i;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import java.io.IOException; import java.io.IOException;
...@@ -9,6 +10,13 @@ import java.io.IOException; ...@@ -9,6 +10,13 @@ import java.io.IOException;
* Interface for dataset loaders. * Interface for dataset loaders.
*/ */
public interface IPlaneLoader { public interface IPlaneLoader {
/**
* Get dimensions of the image, for which the loader was created.
*
* @return Image of the loader image.
*/
V3i getImageDimensions();
/** /**
* Load specified plane data. * Load specified plane data.
* *
...@@ -36,6 +44,27 @@ public interface IPlaneLoader { ...@@ -36,6 +44,27 @@ public interface IPlaneLoader {
*/ */
int[] loadAllPlanesU16Data() throws IOException; int[] loadAllPlanesU16Data() throws IOException;
/**
* Load blocks from the entire dataset.
*
* @param blockDim Dimensions of the 2D block. (Matrix)
* @return Block data from the entire dataset.
* @throws IOException When fails to load plane data.
*/
default int[][] loadBlocks(final V2i blockDim) throws IOException {
return loadBlocks(blockDim, new Range<>(0, getImageDimensions().getZ()));
}
/**
* Load blocks from specified plane range in the dataset.
*
* @param blockDim Dimensions of the 2D block. (Matrix)
* @param planeRange Source plane range.
* @return Block data from the specified plane range.
* @throws IOException When fails to load plane data.
*/
int[][] loadBlocks(final V2i blockDim, final Range<Integer> planeRange) throws IOException;
/** /**
* Load voxels from entire dataset. * Load voxels from entire dataset.
* *
...@@ -43,15 +72,17 @@ public interface IPlaneLoader { ...@@ -43,15 +72,17 @@ public interface IPlaneLoader {
* @return Voxel data from the entire dataset. * @return Voxel data from the entire dataset.
* @throws IOException when fails to load plane data. * @throws IOException when fails to load plane data.
*/ */
int[][] loadVoxels(final V3i voxelDim) throws IOException; default int[][] loadVoxels(final V3i voxelDim) throws IOException {
return loadVoxels(voxelDim, new Range<>(0, getImageDimensions().getZ()));
}
/** /**
* Load voxels from specified plane range in the datasIet. * Load voxels from specified plane range in the dataset.
* Plane range should be divisible by `voxelDim.getZ()` * Plane range should be divisible by `voxelDim.getZ()`
* *
* @param voxelDim Voxel dimensions. * @param voxelDim Voxel dimensions.
* @param planeRange Source voxel dimensions. * @param planeRange Source plane range.
* @return Voxel data from the entire dataset. * @return Voxel data from the specified plane range.
* @throws IOException when fails to load plane data. * @throws IOException when fails to load plane data.
*/ */
int[][] loadVoxels(final V3i voxelDim, final Range<Integer> planeRange) throws IOException; int[][] loadVoxels(final V3i voxelDim, final Range<Integer> planeRange) throws IOException;
......
package azgracompress.io.loader; package azgracompress.io.loader;
import azgracompress.data.Range; import azgracompress.data.Range;
import azgracompress.data.V2i;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import azgracompress.io.BufferInputData; import azgracompress.io.BufferInputData;
import azgracompress.io.InputData; import azgracompress.io.InputData;
...@@ -87,8 +88,8 @@ public final class ImageJBufferLoader extends BasicLoader implements IPlaneLoade ...@@ -87,8 +88,8 @@ public final class ImageJBufferLoader extends BasicLoader implements IPlaneLoade
} }
@Override @Override
public int[][] loadVoxels(final V3i voxelDim) throws IOException { public int[][] loadBlocks(V2i blockDim, Range<Integer> planeRange) throws IOException {
return loadVoxels(voxelDim, new Range<>(0, bufferInputData.getDimensions().getZ())); return loadBlocksImplByValueAt(blockDim, planeRange);
} }
@Override @Override
......
package azgracompress.io.loader; package azgracompress.io.loader;
import azgracompress.data.Range; import azgracompress.data.Range;
import azgracompress.data.V2i;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import azgracompress.io.FileInputData; import azgracompress.io.FileInputData;
import azgracompress.utilities.TypeConverter; import azgracompress.utilities.TypeConverter;
...@@ -117,8 +118,8 @@ public final class RawDataLoader extends BasicLoader implements IPlaneLoader { ...@@ -117,8 +118,8 @@ public final class RawDataLoader extends BasicLoader implements IPlaneLoader {
} }
@Override @Override
public int[][] loadVoxels(final V3i voxelDim) throws IOException { public int[][] loadBlocks(V2i blockDim, Range<Integer> planeRange) throws IOException {
return loadVoxels(voxelDim, new Range<>(0, inputDataInfo.getDimensions().getZ())); return loadBlocksImplLoadPlaneData(blockDim, planeRange);
} }
@Override @Override
......
...@@ -2,6 +2,7 @@ package azgracompress.io.loader; ...@@ -2,6 +2,7 @@ package azgracompress.io.loader;
import azgracompress.ScifioWrapper; import azgracompress.ScifioWrapper;
import azgracompress.data.Range; import azgracompress.data.Range;
import azgracompress.data.V2i;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import azgracompress.io.FileInputData; import azgracompress.io.FileInputData;
import azgracompress.utilities.TypeConverter; import azgracompress.utilities.TypeConverter;
...@@ -12,10 +13,13 @@ import java.io.IOException; ...@@ -12,10 +13,13 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
public final class SCIFIOLoader extends BasicLoader implements IPlaneLoader { public final class SCIFIOLoader extends BasicLoader implements IPlaneLoader {
private final FileInputData inputDataInfo; private final FileInputData inputDataInfo;
private final Reader reader; private final Reader reader;
// Current plane buffer
private int currentPlaneIndex = -1;
private int[] currentPlaneData;
/** /**
* Create SCIFIO reader from input file. * Create SCIFIO reader from input file.
* *
...@@ -29,6 +33,26 @@ public final class SCIFIOLoader extends BasicLoader implements IPlaneLoader { ...@@ -29,6 +33,26 @@ public final class SCIFIOLoader extends BasicLoader implements IPlaneLoader {
this.reader = ScifioWrapper.getReader(this.inputDataInfo.getFilePath()); this.reader = ScifioWrapper.getReader(this.inputDataInfo.getFilePath());
} }
// @Override
// protected int valueAt(int plane, int offset) {
// // TODO(Moravec): Measure if caching the current plane byte buffer make any sense.
// if (plane != currentPlaneIndex) {
// currentPlaneIndex = plane;
// try {
// currentPlaneData = TypeConverter.unsignedShortBytesToIntArray(reader.openPlane(0, currentPlaneIndex).getBytes());
// } catch (FormatException e) {
// System.err.println(e.toString());
// e.printStackTrace();
// assert (false) : "FormatException in SCIFIOLoader::valueAt()";
// } catch (IOException e) {
// System.err.println(e.toString());
// e.printStackTrace();
// assert (false) : "IOException in SCIFIOLoader::valueAt()";
// }
// }
// return currentPlaneData[offset];
// }
@Override @Override
public int[] loadPlaneData(final int plane) throws IOException { public int[] loadPlaneData(final int plane) throws IOException {
byte[] planeBytes; byte[] planeBytes;
...@@ -106,8 +130,8 @@ public final class SCIFIOLoader extends BasicLoader implements IPlaneLoader { ...@@ -106,8 +130,8 @@ public final class SCIFIOLoader extends BasicLoader implements IPlaneLoader {
} }
@Override @Override
public int[][] loadVoxels(final V3i voxelDim) throws IOException { public int[][] loadBlocks(V2i blockDim, Range<Integer> planeRange) throws IOException {
return loadVoxels(voxelDim, new Range<>(0, inputDataInfo.getDimensions().getZ())); return loadBlocksImplLoadPlaneData(blockDim, planeRange);
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment