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

Formatting and fixes.

Some code formatting. Redirect compression of voxels to its separate
function
parent 20e16248
No related branches found
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.fileformat.QuantizationType;
import azgracompress.io.InputData; import azgracompress.io.InputData;
import azgracompress.compression.exception.ImageCompressionException; import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.data.Chunk2D; import azgracompress.data.Chunk2D;
...@@ -98,6 +99,11 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -98,6 +99,11 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* @throws ImageCompressionException When compress process fails. * @throws ImageCompressionException When compress process fails.
*/ */
public long[] compress(DataOutputStream compressStream) throws ImageCompressionException { public long[] compress(DataOutputStream compressStream) throws ImageCompressionException {
if (options.getQuantizationType() == QuantizationType.Vector3D) {
return compressVoxels(compressStream);
}
assert (options.getQuantizationVector().getZ() == 1);
final InputData inputDataInfo = options.getInputDataInfo(); final InputData inputDataInfo = options.getInputDataInfo();
Stopwatch stopwatch = new Stopwatch(); Stopwatch stopwatch = new Stopwatch();
final boolean hasGeneralQuantizer = options.getCodebookType() != CompressionOptions.CodebookType.Individual; final boolean hasGeneralQuantizer = options.getCodebookType() != CompressionOptions.CodebookType.Individual;
...@@ -130,7 +136,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -130,7 +136,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
} }
reportStatusToListeners(String.format("Training vector quantizer from middle plane %d.", middlePlaneIndex)); reportStatusToListeners(String.format("Training vector quantizer from middle plane %d.", middlePlaneIndex));
final int[][] refPlaneVectors = middlePlane.toQuantizationVectors(options.getQuantizationVector()); final int[][] refPlaneVectors = middlePlane.toQuantizationVectors(options.getQuantizationVector().toV2i());
quantizer = trainVectorQuantizerFromPlaneVectors(refPlaneVectors); quantizer = trainVectorQuantizerFromPlaneVectors(refPlaneVectors);
huffman = createHuffmanCoder(huffmanSymbols, quantizer.getFrequencies()); huffman = createHuffmanCoder(huffmanSymbols, quantizer.getFrequencies());
writeQuantizerToCompressStream(quantizer, compressStream); writeQuantizerToCompressStream(quantizer, compressStream);
...@@ -148,13 +154,12 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -148,13 +154,12 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
ImageU16 plane = null; ImageU16 plane = null;
try { try {
plane = planeLoader.loadPlaneU16(planeIndex); plane = planeLoader.loadPlaneU16(planeIndex);
} catch (IOException ex) { } catch (IOException ex) {
throw new ImageCompressionException("Unable to load plane data.", ex); throw new ImageCompressionException("Unable to load plane data.", ex);
} }
final int[][] planeVectors = plane.toQuantizationVectors(options.getQuantizationVector()); final int[][] planeVectors = plane.toQuantizationVectors(options.getQuantizationVector().toV2i());
if (!hasGeneralQuantizer) { if (!hasGeneralQuantizer) {
reportStatusToListeners(String.format("Training vector quantizer from plane %d.", planeIndex)); reportStatusToListeners(String.format("Training vector quantizer from plane %d.", planeIndex));
...@@ -188,7 +193,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -188,7 +193,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
private int[][] loadPlaneQuantizationVectors(final IPlaneLoader planeLoader, private int[][] loadPlaneQuantizationVectors(final IPlaneLoader planeLoader,
final int planeIndex) throws IOException { final int planeIndex) throws IOException {
ImageU16 refPlane = planeLoader.loadPlaneU16(planeIndex); ImageU16 refPlane = planeLoader.loadPlaneU16(planeIndex);
return refPlane.toQuantizationVectors(options.getQuantizationVector()); return refPlane.toQuantizationVectors(options.getQuantizationVector().toV2i());
} }
private int[][] loadConfiguredPlanesData() throws ImageCompressionException { private int[][] loadConfiguredPlanesData() throws ImageCompressionException {
...@@ -200,13 +205,12 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -200,13 +205,12 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
} catch (Exception e) { } catch (Exception e) {
throw new ImageCompressionException("Unable to create SCIFIO reader. " + e.getMessage()); throw new ImageCompressionException("Unable to create SCIFIO reader. " + e.getMessage());
} }
int[][] trainData = null; int[][] trainData;
Stopwatch s = new Stopwatch(); Stopwatch s = new Stopwatch();
s.start(); s.start();
if (inputDataInfo.isPlaneIndexSet()) { if (inputDataInfo.isPlaneIndexSet()) {
reportStatusToListeners("VQ: Loading single plane data."); reportStatusToListeners("VQ: Loading single plane data.");
try { try {
trainData = loadPlaneQuantizationVectors(planeLoader, inputDataInfo.getPlaneIndex()); trainData = loadPlaneQuantizationVectors(planeLoader, inputDataInfo.getPlaneIndex());
} catch (IOException e) { } catch (IOException e) {
throw new ImageCompressionException("Failed to load plane data.", e); throw new ImageCompressionException("Failed to load plane data.", e);
...@@ -215,9 +219,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -215,9 +219,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
reportStatusToListeners(inputDataInfo.isPlaneRangeSet() ? "VQ: Loading plane range data." : "VQ: Loading all planes data."); reportStatusToListeners(inputDataInfo.isPlaneRangeSet() ? "VQ: Loading plane range data." : "VQ: Loading all planes data.");
final int[] planeIndices = getPlaneIndicesForCompression(); final int[] planeIndices = getPlaneIndicesForCompression();
final int chunkCountPerPlane = Chunk2D.calculateRequiredChunkCount( final int chunkCountPerPlane = Chunk2D.calculateRequiredChunkCount(inputDataInfo.getDimensions().toV2i(),
inputDataInfo.getDimensions().toV2i(), options.getQuantizationVector().toV2i());
options.getQuantizationVector());
final int totalChunkCount = chunkCountPerPlane * planeIndices.length; final int totalChunkCount = chunkCountPerPlane * planeIndices.length;
trainData = new int[totalChunkCount][vectorSize]; trainData = new int[totalChunkCount][vectorSize];
...@@ -270,5 +273,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -270,5 +273,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
reportStatusToListeners("Operation completed."); reportStatusToListeners("Operation completed.");
} }
public long[] compressVoxels(DataOutputStream compressStream) throws ImageCompressionException {
}
} }
...@@ -3,10 +3,12 @@ package azgracompress.io.loader; ...@@ -3,10 +3,12 @@ package azgracompress.io.loader;
import azgracompress.data.ImageU16; import azgracompress.data.ImageU16;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import azgracompress.io.FileInputData; import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import azgracompress.utilities.TypeConverter; import azgracompress.utilities.TypeConverter;
import java.io.*; import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
public class RawDataLoader implements IPlaneLoader { public class RawDataLoader implements IPlaneLoader {
......
...@@ -3,13 +3,11 @@ package azgracompress.quantization.vector; ...@@ -3,13 +3,11 @@ package azgracompress.quantization.vector;
public class VectorQuantizer { public class VectorQuantizer {
private final VectorDistanceMetric metric = VectorDistanceMetric.Euclidean; private final VectorDistanceMetric metric = VectorDistanceMetric.Euclidean;
private final VQCodebook codebook;
private final CodebookEntry[] codebookVectors; private final CodebookEntry[] codebookVectors;
private final int vectorSize; private final int vectorSize;
private final long[] frequencies; private final long[] frequencies;
public VectorQuantizer(final VQCodebook codebook) { public VectorQuantizer(final VQCodebook codebook) {
this.codebook = codebook;
this.codebookVectors = codebook.getVectors(); this.codebookVectors = codebook.getVectors();
vectorSize = codebookVectors[0].getVector().length; vectorSize = codebookVectors[0].getVector().length;
this.frequencies = codebook.getVectorFrequencies(); this.frequencies = codebook.getVectorFrequencies();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment