From f136fe9bde11b9c798f0eef2d313357cf9840b67 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 22 Apr 2023 08:29:15 -0500 Subject: [PATCH] full data minor refactoring --- .../AbstractFullDataSourceLoader.java | 4 --- .../dataObjects/fullData/FullDataLoader.java | 1 - .../fullData/IIncompleteFullDataSource.java | 2 +- .../fullData/SingleChunkFullDataLoader.java | 1 - .../fullData/SparseFullDataLoader.java | 1 - .../fullData/accessor/FullArrayView.java | 25 ++++++++++------ .../fullData/accessor/IFullDataView.java | 3 +- .../accessor/SingleFullArrayView.java | 11 +++++++ .../sources/ChunkSizedFullDataSource.java | 4 +++ .../fullData/sources/FullDataSource.java | 7 +++-- .../sources/SparseFullDataSource.java | 29 ++++++++++--------- .../render/ColumnRenderLoader.java | 2 ++ .../render/ColumnRenderSource.java | 1 - 13 files changed, 56 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/AbstractFullDataSourceLoader.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/AbstractFullDataSourceLoader.java index c95434268..7b377d471 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/AbstractFullDataSourceLoader.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/AbstractFullDataSourceLoader.java @@ -1,15 +1,11 @@ package com.seibel.lod.core.dataObjects.fullData; import com.google.common.collect.HashMultimap; -import com.seibel.lod.core.dataObjects.fullData.sources.FullDataSource; -import com.seibel.lod.core.dataObjects.transformers.FullToColumnTransformer; -import com.seibel.lod.core.level.IDhClientLevel; import com.seibel.lod.core.level.IDhLevel; import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile; import java.io.BufferedInputStream; import java.io.IOException; -import java.io.InputStream; import java.util.*; public abstract class AbstractFullDataSourceLoader diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/FullDataLoader.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/FullDataLoader.java index b2f68b352..078569f9f 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/FullDataLoader.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/FullDataLoader.java @@ -6,7 +6,6 @@ import com.seibel.lod.core.level.IDhLevel; import java.io.BufferedInputStream; import java.io.IOException; -import java.io.InputStream; public class FullDataLoader extends AbstractFullDataSourceLoader { diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/IIncompleteFullDataSource.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/IIncompleteFullDataSource.java index 7c0c8625d..234dbc8a3 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/IIncompleteFullDataSource.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/IIncompleteFullDataSource.java @@ -2,7 +2,7 @@ package com.seibel.lod.core.dataObjects.fullData; public interface IIncompleteFullDataSource extends IFullDataSource { - void sampleFrom(IFullDataSource source); + void sampleFrom(IFullDataSource fullDataSource); IFullDataSource trySelfPromote(); diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/SingleChunkFullDataLoader.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/SingleChunkFullDataLoader.java index 3fdf55bab..680e1723d 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/SingleChunkFullDataLoader.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/SingleChunkFullDataLoader.java @@ -6,7 +6,6 @@ import com.seibel.lod.core.level.IDhLevel; import java.io.BufferedInputStream; import java.io.IOException; -import java.io.InputStream; public class SingleChunkFullDataLoader extends AbstractFullDataSourceLoader { diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/SparseFullDataLoader.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/SparseFullDataLoader.java index e535a91d2..ee0bb20a9 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/SparseFullDataLoader.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/SparseFullDataLoader.java @@ -6,7 +6,6 @@ import com.seibel.lod.core.level.IDhLevel; import java.io.BufferedInputStream; import java.io.IOException; -import java.io.InputStream; public class SparseFullDataLoader extends AbstractFullDataSourceLoader { diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/FullArrayView.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/FullArrayView.java index b984cacb1..664352fa4 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/FullArrayView.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/FullArrayView.java @@ -12,11 +12,15 @@ public class FullArrayView implements IFullDataView protected final int dataSize; protected final FullDataPointIdMap mapping; + + public FullArrayView(FullDataPointIdMap mapping, long[][] dataArrays, int size) { if (dataArrays.length != size * size) - throw new IllegalArgumentException( - "tried constructing dataArrayView with invalid input!"); + { + throw new IllegalArgumentException("tried constructing dataArrayView with invalid input!"); + } + this.dataArrays = dataArrays; this.size = size; this.dataSize = size; @@ -28,8 +32,7 @@ public class FullArrayView implements IFullDataView { if (source.size < size || source.size < size + offsetX || source.size < size + offsetZ) { - throw new IllegalArgumentException( - "tried constructing dataArrayView subview with invalid input!"); + throw new IllegalArgumentException("tried constructing dataArrayView subview with invalid input!"); } this.dataArrays = source.dataArrays; @@ -39,6 +42,8 @@ public class FullArrayView implements IFullDataView this.offset = source.offset + offsetX * this.dataSize + offsetZ; } + + @Override public FullDataPointIdMap getMapping() { return this.mapping; } @@ -52,7 +57,7 @@ public class FullArrayView implements IFullDataView public int width() { return this.size; } @Override - public FullArrayView subView(int size, int ox, int oz) { return new FullArrayView(this, size, ox, oz); } + public FullArrayView subView(int size, int xOffset, int zOffset) { return new FullArrayView(this, size, xOffset, zOffset); } /** WARNING: This will potentially share the underlying array object! */ public void shadowCopyTo(FullArrayView target) @@ -61,6 +66,7 @@ public class FullArrayView implements IFullDataView { throw new IllegalArgumentException("Target view must have same size as this view"); } + if (target.mapping.equals(this.mapping)) { for (int x = 0; x < this.size; x++) @@ -82,6 +88,7 @@ public class FullArrayView implements IFullDataView { newData[i] = FullDataPointUtil.remap(remappedIds, sourceData[i]); } + target.dataArrays[target.offset + x * target.dataSize + o] = newData; } } @@ -92,12 +99,12 @@ public class FullArrayView implements IFullDataView { LodUtil.assertTrue(source.size > this.size && source.size % this.size == 0); int dataPerUnit = source.size / this.size; - for (int ox = 0; ox < this.size; ox++) + for (int xOffset = 0; xOffset < this.size; xOffset++) { - for (int oz = 0; oz < this.size; oz++) + for (int zOffset = 0; zOffset < this.size; zOffset++) { - SingleFullArrayView column = this.get(ox, oz); - column.downsampleFrom(source.subView(dataPerUnit, ox * dataPerUnit, oz * dataPerUnit)); + SingleFullArrayView column = this.get(xOffset, zOffset); + column.downsampleFrom(source.subView(dataPerUnit, xOffset * dataPerUnit, zOffset * dataPerUnit)); } } } diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/IFullDataView.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/IFullDataView.java index 64811ff8a..ef2c57c6f 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/IFullDataView.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/IFullDataView.java @@ -10,7 +10,6 @@ public interface IFullDataView FullDataPointIdMap getMapping(); SingleFullArrayView get(int index); - SingleFullArrayView get(int x, int z); int width(); @@ -35,6 +34,6 @@ public interface IFullDataView }; } - IFullDataView subView(int size, int ox, int oz); + IFullDataView subView(int size, int xOffset, int zOffset); } diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/SingleFullArrayView.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/SingleFullArrayView.java index e2c3d41d0..0a7cb4096 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/SingleFullArrayView.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/accessor/SingleFullArrayView.java @@ -9,6 +9,8 @@ public class SingleFullArrayView implements IFullDataView private final int offset; private final FullDataPointIdMap mapping; + + public SingleFullArrayView(FullDataPointIdMap mapping, long[][] dataArrays, int offset) { this.dataArrays = dataArrays; @@ -16,6 +18,8 @@ public class SingleFullArrayView implements IFullDataView this.mapping = mapping; } + + public boolean doesItExist() { return this.dataArrays[this.offset].length != 0; } @Override @@ -25,7 +29,9 @@ public class SingleFullArrayView implements IFullDataView public SingleFullArrayView get(int index) { if (index != 0) + { throw new IllegalArgumentException("Only contains 1 column of full data!"); + } return this; } @@ -34,7 +40,9 @@ public class SingleFullArrayView implements IFullDataView public SingleFullArrayView get(int x, int z) { if (x != 0 || z != 0) + { throw new IllegalArgumentException("Only contains 1 column of full data!"); + } return this; } @@ -56,7 +64,10 @@ public class SingleFullArrayView implements IFullDataView public IFullDataView subView(int size, int ox, int oz) { if (size != 1 || ox != 1 || oz != 1) + { throw new IllegalArgumentException("Getting invalid range of subView from SingleFullArrayView!"); + } + return this; } diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/ChunkSizedFullDataSource.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/ChunkSizedFullDataSource.java index 7f3660122..b42e6fa90 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/ChunkSizedFullDataSource.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/ChunkSizedFullDataSource.java @@ -10,6 +10,8 @@ public class ChunkSizedFullDataSource extends FullArrayView public final int x; public final int z; + + public ChunkSizedFullDataSource(byte dataDetail, int x, int z) { super(new FullDataPointIdMap(), new long[16 * 16][0], 16); @@ -18,6 +20,8 @@ public class ChunkSizedFullDataSource extends FullArrayView this.z = z; } + + public void setSingleColumn(long[] data, int x, int z) { dataArrays[x * 16 + z] = data; diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/FullDataSource.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/FullDataSource.java index c443e0d59..a1e5e9180 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/FullDataSource.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/FullDataSource.java @@ -17,7 +17,7 @@ import org.apache.logging.log4j.Logger; import java.io.*; /** - * 1 chunk + * */ public class FullDataSource extends FullArrayView implements IFullDataSource { @@ -106,7 +106,10 @@ public class FullDataSource extends FullArrayView implements IFullDataSource //FIXME: TEMPORARY int chunkPerFull = 1 << (this.getDataDetail() - 4); if (data.x % chunkPerFull != 0 || data.z % chunkPerFull != 0) + { return; + } + DhLodPos baseOffset = this.sectionPos.getCorner(this.getDataDetail()); DhLodPos dataOffset = data.getBBoxLodPos().convertToDetailLevel(this.getDataDetail()); int offsetX = dataOffset.x - baseOffset.x; @@ -227,7 +230,6 @@ public class FullDataSource extends FullArrayView implements IFullDataSource { throw new IOException("invalid data length end guard"); } - for (int i = 0; i < data.length; i++) { if (data[i].length == 0) @@ -237,6 +239,7 @@ public class FullDataSource extends FullArrayView implements IFullDataSource data[i][j] = dataInputStream.readLong(); } } + // Id mapping end = dataInputStream.readInt(); if (end != 0xFFFFFFFF) diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/SparseFullDataSource.java b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/SparseFullDataSource.java index daf98a235..5d56ab74d 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/SparseFullDataSource.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/fullData/sources/SparseFullDataSource.java @@ -56,7 +56,6 @@ public class SparseFullDataSource implements IIncompleteFullDataSource //==============// public static SparseFullDataSource createEmpty(DhSectionPos pos) { return new SparseFullDataSource(pos); } - protected SparseFullDataSource(DhSectionPos sectionPos) { LodUtil.assertTrue(sectionPos.sectionDetailLevel > SPARSE_UNIT_DETAIL); @@ -68,6 +67,7 @@ public class SparseFullDataSource implements IIncompleteFullDataSource this.chunkPos = sectionPos.getCorner(SPARSE_UNIT_DETAIL); this.mapping = new FullDataPointIdMap(); } + protected SparseFullDataSource(DhSectionPos sectionPos, FullDataPointIdMap mapping, FullArrayView[] data) { LodUtil.assertTrue(sectionPos.sectionDetailLevel > SPARSE_UNIT_DETAIL); @@ -124,12 +124,12 @@ public class SparseFullDataSource implements IIncompleteFullDataSource int count = this.dataPerChunk; int dataPerCount = SPARSE_UNIT_SIZE / this.dataPerChunk; - for (int ox = 0; ox < count; ox++) + for (int xOffset = 0; xOffset < count; xOffset++) { - for (int oz = 0; oz < count; oz++) + for (int zOffset = 0; zOffset < count; zOffset++) { - SingleFullArrayView column = newArray.get(ox, oz); - column.downsampleFrom(data.subView(dataPerCount, ox * dataPerCount, oz * dataPerCount)); + SingleFullArrayView column = newArray.get(xOffset, zOffset); + column.downsampleFrom(data.subView(dataPerCount, xOffset * dataPerCount, zOffset * dataPerCount)); } } } @@ -148,7 +148,10 @@ public class SparseFullDataSource implements IIncompleteFullDataSource LodUtil.assertTrue(pos.sectionDetailLevel < this.sectionPos.sectionDetailLevel); LodUtil.assertTrue(pos.overlaps(this.sectionPos)); if (source.isEmpty()) + { return; + } + if (source instanceof SparseFullDataSource) { @@ -175,16 +178,16 @@ public class SparseFullDataSource implements IIncompleteFullDataSource int offsetZ = dataPos.z-basePos.z; LodUtil.assertTrue(offsetX >= 0 && offsetX < this.chunks && offsetZ >= 0 && offsetZ < this.chunks); - for (int ox = 0; ox < sparseSource.chunks; ox++) + for (int xOffset = 0; xOffset < sparseSource.chunks; xOffset++) { - for (int oz = 0; oz < sparseSource.chunks; oz++) + for (int zOffset = 0; zOffset < sparseSource.chunks; zOffset++) { - FullArrayView sourceChunk = sparseSource.sparseData[ox * sparseSource.chunks + oz]; + FullArrayView sourceChunk = sparseSource.sparseData[xOffset * sparseSource.chunks + zOffset]; if (sourceChunk != null) { FullArrayView buff = new FullArrayView(this.mapping, new long[this.dataPerChunk * this.dataPerChunk][], this.dataPerChunk); buff.downsampleFrom(sourceChunk); - this.sparseData[(ox + offsetX) * this.chunks + (oz + offsetZ)] = buff; + this.sparseData[(xOffset + offsetX) * this.chunks + (zOffset + offsetZ)] = buff; } } } @@ -203,14 +206,14 @@ public class SparseFullDataSource implements IIncompleteFullDataSource int offsetZ = dataPos.z-basePos.z; LodUtil.assertTrue(offsetX >=0 && offsetX < this.chunks && offsetZ >=0 && offsetZ < this.chunks); - for (int ox = 0; ox < coveredChunks; ox++) + for (int xOffset = 0; xOffset < coveredChunks; xOffset++) { - for (int oz = 0; oz < coveredChunks; oz++) + for (int zOffset = 0; zOffset < coveredChunks; zOffset++) { - FullArrayView sourceChunk = fullSource.subView(sourceDataPerChunk, ox * sourceDataPerChunk, oz * sourceDataPerChunk); + FullArrayView sourceChunk = fullSource.subView(sourceDataPerChunk, xOffset * sourceDataPerChunk, zOffset * sourceDataPerChunk); FullArrayView buff = new FullArrayView(this.mapping, new long[this.dataPerChunk * this.dataPerChunk][], this.dataPerChunk); buff.downsampleFrom(sourceChunk); - this.sparseData[(ox + offsetX) * this.chunks + (oz + offsetZ)] = buff; + this.sparseData[(xOffset + offsetX) * this.chunks + (zOffset + offsetZ)] = buff; } } } diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/render/ColumnRenderLoader.java b/core/src/main/java/com/seibel/lod/core/dataObjects/render/ColumnRenderLoader.java index fc5ff71ec..acaeba1eb 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/render/ColumnRenderLoader.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/render/ColumnRenderLoader.java @@ -118,11 +118,13 @@ public class ColumnRenderLoader throw new IOException("Invalid data: yOffset is incorrect. Expected: ["+expectedYOffset+"], found: ["+fileYOffset+"]."); } + // read the column data byte[] rawByteData = new byte[maxNumberOfDataPoints * Long.BYTES]; ByteBuffer columnDataByteBuffer = ByteBuffer.wrap(rawByteData).order(ByteOrder.LITTLE_ENDIAN); inputStream.readFully(rawByteData); + // parse the column data long[] dataPoints = new long[maxNumberOfDataPoints]; columnDataByteBuffer.asLongBuffer().get(dataPoints); diff --git a/core/src/main/java/com/seibel/lod/core/dataObjects/render/ColumnRenderSource.java b/core/src/main/java/com/seibel/lod/core/dataObjects/render/ColumnRenderSource.java index e0e14bef1..0c8a145c6 100644 --- a/core/src/main/java/com/seibel/lod/core/dataObjects/render/ColumnRenderSource.java +++ b/core/src/main/java/com/seibel/lod/core/dataObjects/render/ColumnRenderSource.java @@ -215,7 +215,6 @@ public class ColumnRenderSource { // data is present dataOutputStream.writeByte(DATA_GUARD_BYTE); - dataOutputStream.writeInt(this.yOffset); // write the data for each column