Skip to content

Commit

Permalink
Add decompressor helper functions (#42)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
CCInc and pre-commit-ci[bot] authored Sep 21, 2021
1 parent 4696e37 commit 60e7c2d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
25 changes: 18 additions & 7 deletions include/copc-lib/laz/decompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ class Decompressor
{
public:
// Decompresses bytes from the instream and returns them
static std::vector<char> DecompressBytes(std::istream &in_stream, const las::LasHeader &header,
const int &point_count)
static std::vector<char> DecompressBytes(std::istream &in_stream, const int8_t &point_format_id,
const uint16_t &num_extra_bytes, const int &point_count)
{
std::vector<char> 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++)
{
Expand All @@ -40,11 +39,23 @@ class Decompressor
return out;
}

static std::vector<char> DecompressBytes(const std::vector<char> &compressed_data, const las::LasHeader &header,
static std::vector<char> 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<char> DecompressBytes(const std::vector<char> &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<char> DecompressBytes(const std::vector<char> &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
Expand Down
5 changes: 5 additions & 0 deletions python/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,13 @@ PYBIND11_MODULE(copclib, m)
py::overload_cast<const std::vector<char> &, 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 std::vector<char> &, 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_<las::LasHeader>(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_),
Expand Down
2 changes: 2 additions & 0 deletions test/reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions test/reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 60e7c2d

Please sign in to comment.