42#ifndef UFO_IO_XYZI_HPP
43#define UFO_IO_XYZI_HPP
46#include <ufo/cloud/point_cloud.hpp>
47#include <ufo/core/intensity.hpp>
48#include <ufo/io/cloud_properties.hpp>
49#include <ufo/io/file_handler.hpp>
50#include <ufo/numeric/vec.hpp>
59[[nodiscard]] CloudProperties cloudPropertiesXYZI(std::filesystem::path
const& file);
61template <std::size_t Dim,
class T,
class... Ts>
62bool readXYZI(std::filesystem::path
const& file, PointCloud<Dim, T, Ts...>& pc)
64 FileHandler fp(file.c_str(),
"rb");
67 std::println(stderr,
"[UFO | Read XYZI] Failed to open file: {}", file.string());
73 for (
char* line = fp.readline();
nullptr != line; line = fp.readline()) {
76 if (4 == std::sscanf(line,
"%lf %lf %lf %lf", &p.x, &p.y, &p.z, &i)) {
77 if constexpr ((is_intensity_v<Ts> || ...)) {
78 pc.push_back(
convert<Vec<Dim, T>>(p), Intensity(i));
80 pc.push_back(
convert<Vec<Dim, T>>(p));
88template <std::size_t Dim,
class T,
class... Ts>
89bool writeXYZI(std::filesystem::path
const& file, PointCloud<Dim, T, Ts...>
const& pc)
91 FileHandler fp(file.c_str(),
"wb");
94 std::println(stderr,
"[UFO | Write XYZI] Failed to create file: {}", file.string());
98 std::size_t
const size = pc.size();
99 auto points = view<Vec<Dim, T>>(pc);
100 auto intensities = view<Intensity>(pc);
101 for (std::size_t i{}; size > i; ++i) {
102 auto p = convert<Vec<3, T>>(points[i]);
103 auto intensity = intensities[i];
104 if constexpr (std::is_same_v<T, float>) {
105 std::print(fp.get(),
"{:.6} {:.6} {:.6}", p.x, p.y, p.z);
106 }
else if constexpr (std::is_floating_point_v<T>) {
107 std::print(fp.get(),
"{:.10} {:.10} {:.10}", p.x, p.y, p.z);
109 std::print(fp.get(),
"{} {} {}", p.x, p.y, p.z);
111 if constexpr ((is_intensity_v<Ts> || ...)) {
112 std::println(fp.get(),
" {:.6}", intensity.intensity);
114 std::println(fp.get(),
" 0");
All vision-related classes and functions.
constexpr To convert(Vec< Dim, U > const &v) noexcept
Converts a vector to a different Vec type, truncating or zero-padding dimensions.