From 4d44724a63d12e6f22fc08c0ff951cdc500dc154 Mon Sep 17 00:00:00 2001
From: Vojtech Moravec <vojtech.moravec.st@vsb.cz>
Date: Mon, 19 Oct 2020 08:49:28 +0200
Subject: [PATCH] RawDataLoader: Allow loading of image data to 2D array.

---
 .../cz/it4i/qcmp/io/loader/RawDataLoader.java | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/main/java/cz/it4i/qcmp/io/loader/RawDataLoader.java b/src/main/java/cz/it4i/qcmp/io/loader/RawDataLoader.java
index c226a72..e6f310c 100644
--- a/src/main/java/cz/it4i/qcmp/io/loader/RawDataLoader.java
+++ b/src/main/java/cz/it4i/qcmp/io/loader/RawDataLoader.java
@@ -130,6 +130,28 @@ public final class RawDataLoader extends BasicLoader implements IPlaneLoader {
         return values;
     }
 
+    public int[][] loadAllPlanesTo2DArray() throws IOException {
+        final V3i imageDims = inputDataInfo.getDimensions();
+        final int planePixelCount = imageDims.getX() * imageDims.getY();
+        final int planeDataSize = planePixelCount * 2;
+        final int[][] result = new int[imageDims.getZ()][];
+
+        final byte[] planeBuffer = new byte[planeDataSize];
+        try (final FileInputStream fileStream = new FileInputStream(inputDataInfo.getFilePath())) {
+
+            for (int plane = 0; plane < imageDims.getZ(); plane++) {
+                int toRead = planeDataSize;
+                while (toRead > 0) {
+                    final int read = fileStream.read(planeBuffer, planeDataSize - toRead, toRead);
+                    assert (read > 0);
+                    toRead -= read;
+                }
+                result[plane] = TypeConverter.unsignedShortBytesToIntArray(planeBuffer);
+            }
+        }
+        return result;
+    }
+
     @Override
     public int[][] loadRowVectors(final int vectorSize, final Range<Integer> planeRange) throws IOException {
         return loadRowVectorsImplByLoadPlaneData(vectorSize, planeRange);
@@ -144,4 +166,6 @@ public final class RawDataLoader extends BasicLoader implements IPlaneLoader {
     public int[][] loadVoxels(final V3i voxelDim, final Range<Integer> planeRange) throws IOException {
         return loadVoxelsImplByLoadPlaneData(voxelDim, planeRange);
     }
+
+
 }
-- 
GitLab