From aeb499d21b0fe55b7c6d2f4d8391ef3be083d819 Mon Sep 17 00:00:00 2001 From: Sagi Amangeldi Date: Sat, 7 Nov 2026 19:08:34 +0900 Subject: [PATCH 1/5] Stop laz_to_txt appending binary points --- apps/console_tools/laz_to_txt.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/console_tools/laz_to_txt.cpp b/apps/console_tools/laz_to_txt.cpp index 274892fc..bcdc868e 100644 --- a/apps/console_tools/laz_to_txt.cpp +++ b/apps/console_tools/laz_to_txt.cpp @@ -86,8 +86,6 @@ bool convert_and_save(const char* from, const char* to) write_progress.update(++points_written); } write_progress.finish(points_written); - - to_file.write((const char*)points.data(), points.size() * sizeof(Point)); } else { From c3c7509b9e2954ce6f1cb3d494382f6bf97a03a2 Mon Sep 17 00:00:00 2001 From: Sagi Amangeldi Date: Sat, 7 Nov 2026 19:08:48 +0900 Subject: [PATCH 2/5] Write full-precision timestamps in laz_to_txt --- apps/console_tools/laz_to_txt.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/console_tools/laz_to_txt.cpp b/apps/console_tools/laz_to_txt.cpp index bcdc868e..3156096c 100644 --- a/apps/console_tools/laz_to_txt.cpp +++ b/apps/console_tools/laz_to_txt.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include @@ -78,11 +80,16 @@ bool convert_and_save(const char* from, const char* to) if (std::ofstream to_file = std::ofstream(to, std::ios::out)) { + // The default 6 significant digits would print every timestamp as e.g. 1.731e+09. + const auto coordinate_precision = to_file.precision(); + const auto timestamp_precision = std::numeric_limits::max_digits10; + ConsoleProgress write_progress("Writing points", points.size()); uint64_t points_written = 0; for (const auto& point : points) { - to_file << point.x << ' ' << point.y << ' ' << point.z << ' ' << point.intensity << ' ' << point.timestamp << '\n'; + to_file << std::setprecision(coordinate_precision) << point.x << ' ' << point.y << ' ' << point.z << ' ' << point.intensity + << ' ' << std::setprecision(timestamp_precision) << point.timestamp << '\n'; write_progress.update(++points_written); } write_progress.finish(points_written); From 912b8c51b4c338b9d1ec99368e4ae1ee4a7f99be Mon Sep 17 00:00:00 2001 From: Sagi Amangeldi Date: Sat, 7 Nov 2026 19:08:54 +0900 Subject: [PATCH 3/5] Use y and z scale factors in laz_to_pcd --- apps/console_tools/laz_to_pcd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/console_tools/laz_to_pcd.cpp b/apps/console_tools/laz_to_pcd.cpp index ca537744..e6f17379 100644 --- a/apps/console_tools/laz_to_pcd.cpp +++ b/apps/console_tools/laz_to_pcd.cpp @@ -68,8 +68,8 @@ bool convert_and_save(const char* from, const char* to) std::span xyzi(reinterpret_cast(pointDataPtr), 3); xyzi[0] = static_cast(header->x_offset + header->x_scale_factor * static_cast(point->X)); - xyzi[1] = static_cast(header->y_offset + header->x_scale_factor * static_cast(point->Y)); - xyzi[2] = static_cast(header->z_offset + header->x_scale_factor * static_cast(point->Z)); + xyzi[1] = static_cast(header->y_offset + header->y_scale_factor * static_cast(point->Y)); + xyzi[2] = static_cast(header->z_offset + header->z_scale_factor * static_cast(point->Z)); xyzi[3] = static_cast(point->intensity); const double ts = point->gps_time; memcpy(pointerTimstamp, &ts, sizeof(double)); From b9d921a88f9f7fdfec03445849f5b1ed9e9e276c Mon Sep 17 00:00:00 2001 From: Sagi Amangeldi Date: Sat, 7 Nov 2026 19:08:57 +0900 Subject: [PATCH 4/5] Size the laz_to_pcd span for x, y, z and intensity --- apps/console_tools/laz_to_pcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/console_tools/laz_to_pcd.cpp b/apps/console_tools/laz_to_pcd.cpp index e6f17379..68d55627 100644 --- a/apps/console_tools/laz_to_pcd.cpp +++ b/apps/console_tools/laz_to_pcd.cpp @@ -66,7 +66,7 @@ bool convert_and_save(const char* from, const char* to) uint8_t* pointerTimstamp = pointDataPtr + sizeof(float) * 4; uint8_t* pointDataEndPtr = pointDataPtr + PointSizeBytes; - std::span xyzi(reinterpret_cast(pointDataPtr), 3); + std::span xyzi(reinterpret_cast(pointDataPtr), 4); xyzi[0] = static_cast(header->x_offset + header->x_scale_factor * static_cast(point->X)); xyzi[1] = static_cast(header->y_offset + header->y_scale_factor * static_cast(point->Y)); xyzi[2] = static_cast(header->z_offset + header->z_scale_factor * static_cast(point->Z)); From a960739db1d94d9301a0642840486aaf7d829b52 Mon Sep 17 00:00:00 2001 From: Sagi Amangeldi Date: Sat, 7 Nov 2026 19:09:18 +0900 Subject: [PATCH 5/5] Use and close the LASzip reader in laz_to_txt and laz_to_pcd --- apps/console_tools/laz_to_pcd.cpp | 16 ++++++++++++++-- apps/console_tools/laz_to_txt.cpp | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/apps/console_tools/laz_to_pcd.cpp b/apps/console_tools/laz_to_pcd.cpp index 68d55627..e6603033 100644 --- a/apps/console_tools/laz_to_pcd.cpp +++ b/apps/console_tools/laz_to_pcd.cpp @@ -42,7 +42,7 @@ bool convert_and_save(const char* from, const char* to) } laszip_point* point = nullptr; - if (laszip_get_point_pointer(header, &point)) + if (laszip_get_point_pointer(laszip_reader, &point)) { return false; } @@ -58,7 +58,7 @@ bool convert_and_save(const char* from, const char* to) while (point_read_count < point_count) { - if (laszip_read_point(header)) + if (laszip_read_point(laszip_reader)) { return false; } @@ -78,6 +78,12 @@ bool convert_and_save(const char* from, const char* to) } progress.finish(static_cast(point_read_count)); + if (laszip_close_reader(laszip_reader) || laszip_destroy(laszip_reader)) + { + spdlog::error("Failed closing LASzip reader"); + return false; + } + if (std::ofstream to_file = std::ofstream(to, std::ios::out | std::ios::binary)) { to_file << "# .PCD v0.7\n"; @@ -93,6 +99,12 @@ bool convert_and_save(const char* from, const char* to) to_file << "DATA binary\n"; to_file.write((const char*)pointsBinary.data(), pointsBinary.size()); + to_file.close(); + if (!to_file) + { + spdlog::error("Failed writing PCD output {}", to); + return false; + } } else { diff --git a/apps/console_tools/laz_to_txt.cpp b/apps/console_tools/laz_to_txt.cpp index 3156096c..d34185d1 100644 --- a/apps/console_tools/laz_to_txt.cpp +++ b/apps/console_tools/laz_to_txt.cpp @@ -49,7 +49,7 @@ bool convert_and_save(const char* from, const char* to) } laszip_point* point = nullptr; - if (laszip_get_point_pointer(header, &point)) + if (laszip_get_point_pointer(laszip_reader, &point)) { return false; } @@ -62,7 +62,7 @@ bool convert_and_save(const char* from, const char* to) laszip_I64 point_read_count = 0; while (point_read_count < point_count) { - if (laszip_read_point(header)) + if (laszip_read_point(laszip_reader)) { return false; } @@ -78,6 +78,12 @@ bool convert_and_save(const char* from, const char* to) } progress.finish(static_cast(point_read_count)); + if (laszip_close_reader(laszip_reader) || laszip_destroy(laszip_reader)) + { + spdlog::error("Failed closing LASzip reader"); + return false; + } + if (std::ofstream to_file = std::ofstream(to, std::ios::out)) { // The default 6 significant digits would print every timestamp as e.g. 1.731e+09. @@ -93,6 +99,13 @@ bool convert_and_save(const char* from, const char* to) write_progress.update(++points_written); } write_progress.finish(points_written); + + to_file.close(); + if (!to_file) + { + spdlog::error("Failed writing TXT output {}", to); + return false; + } } else {