diff --git a/src/main/java/com/github/mreutegg/laszip4j/laszip/LASreadItemCompressed_BYTE14_v3.java b/src/main/java/com/github/mreutegg/laszip4j/laszip/LASreadItemCompressed_BYTE14_v3.java index 1b34fc5..e050373 100644 --- a/src/main/java/com/github/mreutegg/laszip4j/laszip/LASreadItemCompressed_BYTE14_v3.java +++ b/src/main/java/com/github/mreutegg/laszip4j/laszip/LASreadItemCompressed_BYTE14_v3.java @@ -29,9 +29,6 @@ public class LASreadItemCompressed_BYTE14_v3 extends LASreadItemCompressed{ private boolean[] requested_Bytes; - private byte[] bytes; - private int num_bytes_allocated; - private int current_context; private LAScontextBYTE14[] contexts = new LAScontextBYTE14[4]; @@ -77,11 +74,6 @@ public LASreadItemCompressed_BYTE14_v3(IByteStreamInProvider instreamProvider, i } } - /* init the bytes buffer to zero */ - - bytes = null; - num_bytes_allocated = 0; - /* mark the four scanner channel contexts as uninitialized */ for (int c = 0; c < contexts.length; c++) @@ -134,17 +126,10 @@ public void init(PointDataRecord seedItem, MutableInteger context) { { if (requested_Bytes[i]) num_bytes += num_bytes_Bytes[i]; } - - /* make sure the buffer is sufficiently large */ - - if (num_bytes > num_bytes_allocated) - { - bytes = new byte[num_bytes]; - num_bytes_allocated = num_bytes; - } - - /* load the requested bytes and init the corresponding instreams an decoders */ - + + /* load the requested bytes and init the corresponding instreams and decoders */ + + byte[] bytes; num_bytes = 0; for (i = 0; i < number; i++) { @@ -152,6 +137,7 @@ public void init(PointDataRecord seedItem, MutableInteger context) { { if (num_bytes_Bytes[i] != 0) { + bytes = new byte[num_bytes_Bytes[i]]; instream.getBytes(bytes, num_bytes_Bytes[i]); instream_Bytes[i].init(bytes, num_bytes_Bytes[i]); dec_Bytes[i].init(instream_Bytes[i]); diff --git a/src/test/java/com/github/mreutegg/laszip4j/DataFiles.java b/src/test/java/com/github/mreutegg/laszip4j/DataFiles.java index f645b67..f577cfb 100644 --- a/src/test/java/com/github/mreutegg/laszip4j/DataFiles.java +++ b/src/test/java/com/github/mreutegg/laszip4j/DataFiles.java @@ -44,6 +44,9 @@ public class DataFiles extends ExternalResource { // test file contributed via https://github.com/mreutegg/laszip4j/pull/141 public static final String LAZ_14_V3_RGB_NAME = "500m_5460_59370_IM2023_subset.laz"; + public static final String LAZ_14_BYTES_V3_COMPRESSED_NAME = "2019_saipan_waveform.laz"; + public static final int LAZ_14_BYTES_V3_COMPRESSED_NUM_POINT_RECORDS = 5198; + // file created with txt2las as described here: https://groups.google.com/g/lasroom/c/DWQ2GXKE8f8 public static final String EXTRA_TYPES_NAME = "extra-bytes.las"; @@ -55,6 +58,7 @@ public class DataFiles extends ExternalResource { public final File laz14 = new File(target, LAZ_14_NAME); public final File extraBytes = new File(resources, EXTRA_TYPES_NAME); public final File laz14v3rgb = new File(resources, LAZ_14_V3_RGB_NAME); + public final File laz14v3bytesCompressed = new File(resources, LAZ_14_BYTES_V3_COMPRESSED_NAME); @Override protected void before() throws Throwable { @@ -63,32 +67,22 @@ protected void before() throws Throwable { public void download() throws Exception { if (!laz.exists()) { - URI url = new URI(LAZ_BASE_URL + "/" + LAZ_NAME); - try (CloseableHttpClient client = HttpClients.createDefault()) { - try (CloseableHttpResponse response = client.execute(new HttpGet(url))) { - try (OutputStream out = Files.newOutputStream(laz.toPath())) { - response.getEntity().writeTo(out); - } - } - } + download(LAZ_BASE_URL + "/" + LAZ_NAME, laz); } if (!las.exists()) { - URI url = new URI(LAS_BASE_URL + "/" + LAS_NAME); - try (CloseableHttpClient client = HttpClients.createDefault()) { - try (CloseableHttpResponse response = client.execute(new HttpGet(url))) { - try (OutputStream out = Files.newOutputStream(las.toPath())) { - response.getEntity().writeTo(out); - } - } - } + download(LAS_BASE_URL + "/" + LAS_NAME, las); } if (!laz14.exists()) { - URI url = new URI(LAZ_14_BASE_URL + "/" + LAZ_14_NAME); - try (CloseableHttpClient client = HttpClients.createDefault()) { - try (CloseableHttpResponse response = client.execute(new HttpGet(url))) { - try (OutputStream out = Files.newOutputStream(laz14.toPath())) { - response.getEntity().writeTo(out); - } + download(LAZ_14_BASE_URL + "/" + LAZ_14_NAME, laz14); + } + } + + private static void download(String uri, File file) throws Exception { + URI url = new URI(uri); + try (CloseableHttpClient client = HttpClients.createDefault()) { + try (CloseableHttpResponse response = client.execute(new HttpGet(url))) { + try (OutputStream out = Files.newOutputStream(file.toPath())) { + response.getEntity().writeTo(out); } } } diff --git a/src/test/java/com/github/mreutegg/laszip4j/LASReaderTest.java b/src/test/java/com/github/mreutegg/laszip4j/LASReaderTest.java index 111fa60..632b177 100644 --- a/src/test/java/com/github/mreutegg/laszip4j/LASReaderTest.java +++ b/src/test/java/com/github/mreutegg/laszip4j/LASReaderTest.java @@ -591,4 +591,28 @@ public void readLaz14v3RGB() { assertEquals(21877, minBlue); assertEquals(63435, maxBlue); } + + @Test + public void read() { + LASReader reader = new LASReader(files.laz14v3bytesCompressed); + + int minX = Integer.MAX_VALUE; + int maxX = Integer.MIN_VALUE; + int minY = Integer.MAX_VALUE; + int maxY = Integer.MIN_VALUE; + long numPoints = 0; + for (LASPoint p : reader.getPoints()) { + minX = Math.min(minX, p.getX()); + maxX = Math.max(maxX, p.getX()); + minY = Math.min(minY, p.getY()); + maxY = Math.max(maxY, p.getY()); + numPoints++; + } + + assertEquals(DataFiles.LAZ_14_BYTES_V3_COMPRESSED_NUM_POINT_RECORDS, numPoints); + assertEquals(7025714, minX); + assertEquals(7031235, maxX); + assertEquals(7520541, minY); + assertEquals(7525854, maxY); + } } diff --git a/src/test/resources/2019_saipan_waveform.laz b/src/test/resources/2019_saipan_waveform.laz new file mode 100644 index 0000000..d8b62c4 Binary files /dev/null and b/src/test/resources/2019_saipan_waveform.laz differ