Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions apps/console_tools/laz_to_pcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -58,18 +58,18 @@ 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;
}
uint8_t* pointDataPtr = pointsBinary.data() + point_read_count * PointSizeBytes;
uint8_t* pointerTimstamp = pointDataPtr + sizeof(float) * 4;
uint8_t* pointDataEndPtr = pointDataPtr + PointSizeBytes;

std::span<float> xyzi(reinterpret_cast<float*>(pointDataPtr), 3);
std::span<float> xyzi(reinterpret_cast<float*>(pointDataPtr), 4);
xyzi[0] = static_cast<float>(header->x_offset + header->x_scale_factor * static_cast<double>(point->X));
xyzi[1] = static_cast<float>(header->y_offset + header->x_scale_factor * static_cast<double>(point->Y));
xyzi[2] = static_cast<float>(header->z_offset + header->x_scale_factor * static_cast<double>(point->Z));
xyzi[1] = static_cast<float>(header->y_offset + header->y_scale_factor * static_cast<double>(point->Y));
xyzi[2] = static_cast<float>(header->z_offset + header->z_scale_factor * static_cast<double>(point->Z));
xyzi[3] = static_cast<float>(point->intensity);
const double ts = point->gps_time;
memcpy(pointerTimstamp, &ts, sizeof(double));
Expand All @@ -78,6 +78,12 @@ bool convert_and_save(const char* from, const char* to)
}
progress.finish(static_cast<uint64_t>(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";
Expand All @@ -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
{
Expand Down
26 changes: 22 additions & 4 deletions apps/console_tools/laz_to_txt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <limits>
#include <vector>

#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -47,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;
}
Expand All @@ -60,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;
}
Expand All @@ -76,18 +78,34 @@ bool convert_and_save(const char* from, const char* to)
}
progress.finish(static_cast<uint64_t>(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.
const auto coordinate_precision = to_file.precision();
const auto timestamp_precision = std::numeric_limits<double>::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);

to_file.write((const char*)points.data(), points.size() * sizeof(Point));
to_file.close();
if (!to_file)
{
spdlog::error("Failed writing TXT output {}", to);
return false;
}
}
else
{
Expand Down
Loading