full data minor refactoring
This commit is contained in:
-4
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
|
||||
-1
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
+16
-9
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
+11
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -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;
|
||||
|
||||
+5
-2
@@ -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)
|
||||
|
||||
+16
-13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user