42#ifndef UFO_CLOUD_IO_XYZRGB_HPP
43#define UFO_CLOUD_IO_XYZRGB_HPP
46#include <ufo/cloud/point_cloud.hpp>
47#include <ufo/io/cloud_properties.hpp>
48#include <ufo/io/file_handler.hpp>
49#include <ufo/numeric/vec.hpp>
50#include <ufo/vision/color.hpp>
59[[nodiscard]] CloudProperties cloudPropertiesXYZRGB(std::filesystem::path
const& file);
61template <std::size_t Dim,
class T,
class... Ts>
62bool readXYZRGB(std::filesystem::path
const& file, PointCloud<Dim, T, Ts...>& pc)
64 FileHandler fp(file.c_str(),
"rb");
67 std::println(stderr,
"[UFO | Read XYZRGB] Failed to open file: {}", file.string());
73 for (
char line[1024];
nullptr != std::fgets(line,
sizeof line, fp.get());) {
76 if (6 == std::sscanf(line,
"%lf %lf %lf %f %f %f", &p.x, &p.y, &p.z, &c.red, &c.green,
78 if constexpr (std::disjunction_v<is_color<Ts>...>) {
79 pc.push_back(
convert<Vec<Dim, T>>(p),
convert<first_color_t<Ts...>>(c));
81 pc.push_back(
convert<Vec<Dim, T>>(p));
89template <std::size_t Dim,
class T,
class... Ts>
90bool writeXYZRGB(std::filesystem::path
const& file, PointCloud<Dim, T, Ts...>
const& pc)
92 FileHandler fp(file.c_str(),
"wb");
95 std::println(stderr,
"[UFO | Write XYZRGB] Failed to create file: {}", file.string());
99 std::size_t
const size = pc.size();
100 auto points = view<Vec<Dim, T>>(pc);
101 auto colors = view<first_color_t<Ts...>>(pc);
102 for (std::size_t i{}; size > i; ++i) {
103 auto p = convert<Vec<3, T>>(points[i]);
104 auto c = convert<FineRGB>(colors[i]);
105 if constexpr (std::is_same_v<T, float>) {
106 std::print(fp.get(),
"{:.6} {:.6} {:.6}", p.x, p.y, p.z);
107 }
else if constexpr (std::is_floating_point_v<T>) {
108 std::print(fp.get(),
"{:.10} {:.10} {:.10}", p.x, p.y, p.z);
110 std::print(fp.get(),
"{} {} {}", p.x, p.y, p.z);
112 if constexpr ((is_color_v<Ts> || ...)) {
113 std::println(fp.get(),
" {:.6} {:.6} {:.6}", c.red, c.green, c.blue);
115 std::println(fp.get(),
" 0 0 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.