Skip to content

Commit

Permalink
Add point count and chunk count to lazwriter (#135)
Browse files Browse the repository at this point in the history
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 Oct 18, 2022
1 parent e09d1fe commit 481305a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- **\[Python/C++\]** Added `PointCount` and `ChunkCount` to LazWriter
- **\[Python/C++\]** Added `FilePath` property to LazWriter and FileWriter

## [2.5.0] - 2022-10-17

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions cpp/include/copc-lib/io/copc_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class FileWriter : public Writer, laz::BaseFileWriter

void Close() override;
~FileWriter() { Close(); }

std::string FilePath() { return file_path_; }
};

} // namespace copc
Expand Down
1 change: 1 addition & 0 deletions cpp/include/copc-lib/io/laz_base_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class BaseFileWriter

protected:
std::fstream f_stream_;
std::string file_path_;
};

} // namespace copc::laz
Expand Down
5 changes: 5 additions & 0 deletions cpp/include/copc-lib/io/laz_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class LazWriter : public BaseWriter
{
return std::dynamic_pointer_cast<las::LazConfigWriter>(config_);
}

uint64_t PointCount() { return point_count_; }
uint64_t ChunkCount() { return chunks_.size(); }
};

class LazFileWriter : BaseFileWriter, public LazWriter
Expand All @@ -49,6 +52,8 @@ class LazFileWriter : BaseFileWriter, public LazWriter
BaseFileWriter::Close();
};
~LazFileWriter() { Close(); };

std::string FilePath() { return file_path_; }
};

} // namespace copc::laz
Expand Down
1 change: 1 addition & 0 deletions cpp/src/io/laz_base_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void BaseWriter::Close()

BaseFileWriter::BaseFileWriter(const std::string &file_path)
{
file_path_ = file_path;
f_stream_.open(file_path.c_str(), std::ios::out | std::ios::binary);
if (!f_stream_.good())
throw std::runtime_error("FileWriterBase: Error while opening file path.");
Expand Down
4 changes: 4 additions & 0 deletions python/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ PYBIND11_MODULE(_core, m)
py::arg("scale") = py::none(), py::arg("offset") = py::none(), py::arg("wkt") = py::none(),
py::arg("extra_bytes_vlr") = py::none(), py::arg("has_extended_stats") = py::none())
.def_property_readonly("copc_config", &Writer::CopcConfig)
.def_property_readonly("path", &FileWriter::FilePath)
.def("FindNode", &Writer::FindNode)
.def("Close", &FileWriter::Close)
.def("AddNode", py::overload_cast<const VoxelKey &, const las::Points &, const VoxelKey &>(&Writer::AddNode),
Expand All @@ -439,6 +440,9 @@ PYBIND11_MODULE(_core, m)
py::class_<laz::LazFileWriter>(m, "LazWriter")
.def(py::init<const std::string &, const las::LazConfigWriter &>(), py::arg("file_path"), py::arg("config"))
.def_property_readonly("laz_config", &laz::LazWriter::LazConfig)
.def_property_readonly("point_count", &laz::LazWriter::PointCount)
.def_property_readonly("chunk_count", &laz::LazWriter::ChunkCount)
.def_property_readonly("path", &laz::LazFileWriter::FilePath)
.def("Close", &laz::LazFileWriter::Close)
.def("WritePoints", py::overload_cast<const las::Points &>(&laz::LazWriter::WritePoints), py::arg("points"))
.def("WritePointsCompressed", &laz::LazWriter::WritePointsCompressed, py::arg("compressed_data"),
Expand Down
4 changes: 4 additions & 0 deletions test/laz_writer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ TEST_CASE("LAZ Write Points", "[LAZ Writer]")
points.AddPoint(point);

writer.WritePoints(points);
REQUIRE(writer.PointCount() == 2);
REQUIRE(writer.ChunkCount() == 1);
writer.WritePoints(points);
REQUIRE(writer.PointCount() == 4);
REQUIRE(writer.ChunkCount() == 2);
writer.Close();

// Validate
Expand Down
4 changes: 4 additions & 0 deletions test/laz_writer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ def test_write():
points.AddPoint(p)

writer.WritePoints(points)
assert writer.point_count == 2
assert writer.chunk_count == 1
writer.WritePoints(points)
assert writer.point_count == 4
assert writer.chunk_count == 2
writer.Close()

reader = copc.LazReader(file_path)
Expand Down

0 comments on commit 481305a

Please sign in to comment.