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

Test changes

parent 2744819e
Branches
No related tags found
No related merge requests found
package azgracompress.compression; package azgracompress.compression;
import azgracompress.cache.QuantizationCacheManager; import azgracompress.cache.QuantizationCacheManager;
import azgracompress.data.Chunk3D;
import azgracompress.fileformat.QuantizationType; import azgracompress.fileformat.QuantizationType;
import azgracompress.io.InputData; import azgracompress.io.InputData;
import azgracompress.compression.exception.ImageCompressionException; import azgracompress.compression.exception.ImageCompressionException;
...@@ -236,11 +237,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -236,11 +237,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
planeIndex), e); planeIndex), e);
} }
System.arraycopy(planeVectors, System.arraycopy(planeVectors, 0, trainData, (planeCounter * chunkCountPerPlane), chunkCountPerPlane);
0,
trainData,
(planeCounter * chunkCountPerPlane),
chunkCountPerPlane);
++planeCounter; ++planeCounter;
} }
} }
...@@ -273,7 +270,18 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -273,7 +270,18 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
reportStatusToListeners("Operation completed."); reportStatusToListeners("Operation completed.");
} }
public long[] compressVoxels(DataOutputStream compressStream) throws ImageCompressionException { public long[] compressVoxels(DataOutputStream compressStream) throws ImageCompressionException {
int[][] voxels;
try {
IPlaneLoader loader = PlaneLoaderFactory.getPlaneLoaderForInputFile(options.getInputDataInfo());
final int[] data = loader.loadAllPlanesU16Data();
Chunk3D bigVoxel = new Chunk3D(options.getInputDataInfo().getDimensions(), data);
voxels = bigVoxel.divideInto3DVectors(options.getQuantizationVector());
} catch (Exception e) {
throw new ImageCompressionException("Unable to create data loader or load image data.", e);
}
return null;
} }
......
...@@ -47,8 +47,8 @@ public class Chunk2D { ...@@ -47,8 +47,8 @@ public class Chunk2D {
* @return Index inside chunk dimension data array. * @return Index inside chunk dimension data array.
*/ */
private int index(final int x, final int y, final V2i chunkDims) { private int index(final int x, final int y, final V2i chunkDims) {
assert (x >= 0 && x < dims.getX()) : "Index X out of bounds."; assert (x >= 0 && x < chunkDims.getX()) : "Index X out of bounds.";
assert (y >= 0 && y < dims.getY()) : "Index Y out of bounds."; assert (y >= 0 && y < chunkDims.getY()) : "Index Y out of bounds.";
return (y * chunkDims.getX()) + x; return (y * chunkDims.getX()) + x;
} }
......
package azgracompress.data; package azgracompress.data;
import java.util.Arrays;
public class Chunk3D { public class Chunk3D {
private final int FILL_VALUE = 0; private final int FILL_VALUE = 0;
private final int[] data; private final int[] data;
...@@ -40,9 +38,9 @@ public class Chunk3D { ...@@ -40,9 +38,9 @@ public class Chunk3D {
* @return Index inside chunk dimension data array. * @return Index inside chunk dimension data array.
*/ */
private int index(final int x, final int y, final int z, final V3i chunkDims) { private int index(final int x, final int y, final int z, final V3i chunkDims) {
assert (x >= 0 && x < dims.getX()) : "Index X out of bounds."; assert (x >= 0 && x < chunkDims.getX()) : "Index X out of bounds.";
assert (y >= 0 && y < dims.getY()) : "Index Y out of bounds."; assert (y >= 0 && y < chunkDims.getY()) : "Index Y out of bounds.";
assert (z >= 0 && z < dims.getZ()) : "Index Z out of bounds."; assert (z >= 0 && z < chunkDims.getZ()) : "Index Z out of bounds.";
// NOTE(Moravec): Description of the following calculation // NOTE(Moravec): Description of the following calculation
// plane index * plane pixel count // plane index * plane pixel count
...@@ -60,7 +58,7 @@ public class Chunk3D { ...@@ -60,7 +58,7 @@ public class Chunk3D {
// V // V
// colOffset = x; // colOffset = x;
return (chunkDims.getZ() * (chunkDims.getX() * chunkDims.getY())) + (y * chunkDims.getX()) + x; return (z * (chunkDims.getX() * chunkDims.getY())) + (y * chunkDims.getX()) + x;
} }
...@@ -163,8 +161,4 @@ public class Chunk3D { ...@@ -163,8 +161,4 @@ public class Chunk3D {
public int[] getData() { public int[] getData() {
return data; return data;
} }
public void zeroData() {
Arrays.fill(data, 0);
}
} }
package azgracompress.io.loader; package azgracompress.io.loader;
import azgracompress.data.ImageU16; import azgracompress.data.ImageU16;
import azgracompress.data.V3i;
import java.io.IOException; import java.io.IOException;
...@@ -10,4 +11,8 @@ public interface IPlaneLoader { ...@@ -10,4 +11,8 @@ public interface IPlaneLoader {
int[] loadPlanesU16Data(int[] planes) throws IOException; int[] loadPlanesU16Data(int[] planes) throws IOException;
int[] loadAllPlanesU16Data() throws IOException; int[] loadAllPlanesU16Data() throws IOException;
default int[][] loadVoxels(final V3i voxelDim) throws IOException {
throw new IOException("NOT IMPLEMENTED");
}
} }
package azgracompress.io.loader; package azgracompress.io.loader;
import azgracompress.data.Chunk3D;
import azgracompress.data.ImageU16; import azgracompress.data.ImageU16;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import azgracompress.io.BufferInputData; import azgracompress.io.BufferInputData;
...@@ -106,4 +107,133 @@ public class ImageJBufferLoader implements IPlaneLoader { ...@@ -106,4 +107,133 @@ public class ImageJBufferLoader implements IPlaneLoader {
throw new IOException("Unable to load unsupported pixel type."); throw new IOException("Unable to load unsupported pixel type.");
} }
} }
@Override
public int[][] loadVoxels(V3i voxelDim) throws IOException {
switch (bufferInputData.getPixelType()) {
case Gray16: {
final V3i dims = bufferInputData.getDimensions();
final int voxelSize = (int) voxelDim.multiplyTogether();
final int voxelCount = Chunk3D.calculateRequiredChunkCount(bufferInputData.getDimensions(), voxelDim);
int[][] voxels = new int[voxelCount][voxelSize];
int voxelIndex = 0;
for (int chunkZOffset = 0; chunkZOffset < dims.getZ(); chunkZOffset += voxelDim.getZ()) {
for (int chunkYOffset = 0; chunkYOffset < dims.getY(); chunkYOffset += voxelDim.getY()) {
for (int chunkXOffset = 0; chunkXOffset < dims.getX(); chunkXOffset += voxelDim.getX()) {
copyDataToVector(voxels[voxelIndex++], voxelDim, chunkXOffset, chunkYOffset, chunkZOffset);
}
}
}
return voxels;
}
default:
throw new IOException("Unable to load unsupported pixel type.");
}
}
private int readDataAt(final int x, final int y, final int z) {
final short[] srcBuffer = (short[]) bufferInputData.getPixelBuffer(z);
return srcBuffer[(y * bufferInputData.getDimensions().getX()) + x];
}
/**
* Copy this chunk data to chunk vector.
*
* @param vector Chunk vector.
* @param qVectorDims Dimensions of the vector.
* @param chunkXOffset Chunk X offset
* @param chunkYOffset Chunk Y offset.
* @param chunkZOffset Chunk Z offset.
*/
private void copyDataToVector(int[] vector,
final V3i qVectorDims,
final int chunkXOffset,
final int chunkYOffset,
final int chunkZOffset) {
int srcZ;
for (int z = 0; z < qVectorDims.getZ(); z++) {
srcZ = chunkZOffset + z;
fillVoxelFromPlane(vector, qVectorDims, srcZ, z, chunkXOffset, chunkYOffset);
}
} }
private void fillVoxelFromPlane(int[] vector,
final V3i qVectorDims,
final int srcZ,
final int z,
final int chunkXOffset,
final int chunkYOffset) {
if (srcZ >= bufferInputData.getDimensions().getZ())
return;
final short[] srcBuffer = (short[]) bufferInputData.getPixelBuffer(srcZ);
final int width = bufferInputData.getDimensions().getX();
int srcX, srcY;
for (int y = 0; y < qVectorDims.getY(); y++) {
srcY = chunkYOffset + y;
for (int x = 0; x < qVectorDims.getX(); x++) {
srcX = chunkXOffset + x;
final int dstIndex = index(x, y, z, qVectorDims);
vector[dstIndex] = isInside(srcX, srcY, srcZ) ? srcBuffer[(srcY * width) + srcX] : 0;
}
}
}
private boolean isInside(final int x, final int y, final int z) {
return (((x >= 0) && (x < bufferInputData.getDimensions().getX())) && (y >= 0) &&
(y < bufferInputData.getDimensions().getY()) && (z >= 0) &&
(z < bufferInputData.getDimensions().getZ()));
}
/**
* Calculate the index inside data array.
*
* @param x Zero based x coordinate.
* @param y Zero based y coordinate.
* @param z Zero based z coordinate.
* @return Index inside data array.
*/
private int index(final int x, final int y, final int z) {
return index(x, y, z, bufferInputData.getDimensions());
}
/**
* Calculate the index inside array of dimensions specified by chunkDims.
*
* @param x Zero based x coordinate.
* @param y Zero based y coordinate.
* @param z Zero based z coordinate.
* @param chunkDims Chunk dimensions.
* @return Index inside chunk dimension data array.
*/
private int index(final int x, final int y, final int z, final V3i chunkDims) {
assert (x >= 0 && x < chunkDims.getX()) : "Index X out of bounds.";
assert (y >= 0 && y < chunkDims.getY()) : "Index Y out of bounds.";
assert (z >= 0 && z < chunkDims.getZ()) : "Index Z out of bounds.";
// NOTE(Moravec): Description of the following calculation
// plane index * plane pixel count
// | |
// V V
// planeOffset = chunkDims.getZ() * (chunkDims.getX() * chunkDims.getY())
// row * pixels in row
// | |
// V V
// rowOffset = y * chunkDims.getX();
// column
// |
// V
// colOffset = x;
return (z * (chunkDims.getX() * chunkDims.getY())) + (y * chunkDims.getX()) + x;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment