From 60e7c2d4cad0ecc98494ebd6b7f5ae166661f971 Mon Sep 17 00:00:00 2001 From: Christopher Lee Date: Tue, 21 Sep 2021 12:37:25 -0500 Subject: [PATCH] Add decompressor helper functions (#42) * add decompressor helper functions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add num_extra_bytes to las header * add tests Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- include/copc-lib/laz/decompressor.hpp | 25 ++++++++++++++++++------- python/bindings.cpp | 5 +++++ test/reader_test.cpp | 2 ++ test/reader_test.py | 2 ++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/copc-lib/laz/decompressor.hpp b/include/copc-lib/laz/decompressor.hpp index e93d3827..be4b0c66 100644 --- a/include/copc-lib/laz/decompressor.hpp +++ b/include/copc-lib/laz/decompressor.hpp @@ -19,16 +19,15 @@ class Decompressor { public: // Decompresses bytes from the instream and returns them - static std::vector DecompressBytes(std::istream &in_stream, const las::LasHeader &header, - const int &point_count) + static std::vector DecompressBytes(std::istream &in_stream, const int8_t &point_format_id, + const uint16_t &num_extra_bytes, const int &point_count) { std::vector out; InFileStream stre(in_stream); - las_decompressor::ptr decompressor = - build_las_decompressor(stre.cb(), header.point_format_id, header.NumExtraBytes()); + las_decompressor::ptr decompressor = build_las_decompressor(stre.cb(), point_format_id, num_extra_bytes); - int point_size = header.point_record_length; + int point_size = copc::las::ComputePointBytes(point_format_id, num_extra_bytes); char buff[255]; for (int i = 0; i < point_count; i++) { @@ -40,11 +39,23 @@ class Decompressor return out; } - static std::vector DecompressBytes(const std::vector &compressed_data, const las::LasHeader &header, + static std::vector DecompressBytes(std::istream &in_stream, const las::LasHeader &header, const int &point_count) + { + return DecompressBytes(in_stream, header.point_format_id, header.NumExtraBytes(), point_count); + } + + static std::vector DecompressBytes(const std::vector &compressed_data, const int8_t &point_format_id, + const uint16_t &num_extra_bytes, const int &point_count) { std::istringstream in_stream(std::string(compressed_data.begin(), compressed_data.end())); - return DecompressBytes(in_stream, header, point_count); + return DecompressBytes(in_stream, point_format_id, num_extra_bytes, point_count); + } + + static std::vector DecompressBytes(const std::vector &compressed_data, const las::LasHeader &header, + const int &point_count) + { + return DecompressBytes(compressed_data, header.point_format_id, header.NumExtraBytes(), point_count); } }; } // namespace copc::laz diff --git a/python/bindings.cpp b/python/bindings.cpp index 7e089341..65783a1d 100644 --- a/python/bindings.cpp +++ b/python/bindings.cpp @@ -244,8 +244,13 @@ PYBIND11_MODULE(copclib, m) py::overload_cast &, const las::LasHeader &, const int &>( &laz::Decompressor::DecompressBytes), py::arg("compressed_data"), py::arg("header"), py::arg("point_count")); + m.def("DecompressBytes", + py::overload_cast &, const int8_t &, const uint16_t &, const int &>( + &laz::Decompressor::DecompressBytes), + py::arg("compressed_data"), py::arg("point_format_id"), py::arg("num_extra_bytes"), py::arg("point_count")); py::class_(m, "LasHeader") + .def_property_readonly("num_extra_bytes", &las::LasHeader::NumExtraBytes) .def_readwrite("file_source_id", &las::LasHeader::file_source_id) .def_readwrite("global_encoding", &las::LasHeader::global_encoding) .def_property("guid", py::overload_cast<>(&las::LasHeader::GUID, py::const_), diff --git a/test/reader_test.cpp b/test/reader_test.cpp index d4359aff..708ea191 100644 --- a/test/reader_test.cpp +++ b/test/reader_test.cpp @@ -33,6 +33,8 @@ TEST_CASE("Reader tests", "[Reader]") REQUIRE(header.header_size == 375); REQUIRE(header.point_format_id == 3); REQUIRE(header.point_count == 10653336); + REQUIRE(header.point_record_length == 36); + REQUIRE(header.NumExtraBytes() == 2); } SECTION("WKT") diff --git a/test/reader_test.py b/test/reader_test.py index a7e08ea8..59c22553 100644 --- a/test/reader_test.py +++ b/test/reader_test.py @@ -23,6 +23,8 @@ def test_reader(): assert header.header_size == 375 assert header.point_format_id == 3 assert header.point_count == 10653336 + assert header.point_record_length == 36 + assert header.num_extra_bytes == 2 # WKT Test wkt = reader.GetWkt()