From 7bf29d5a2c7a310a8f90cc99d4340b65a3250e13 Mon Sep 17 00:00:00 2001 From: Thibault Payet <monwarez@gmail.com> Date: Thu, 30 Apr 2020 22:13:58 +0200 Subject: [PATCH] add txt2pcd code --- main.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++- meson.build | 4 +++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index c05c0c4..6b69233 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,59 @@ -int main(int argc, char **argv) +#include <filesystem> +#include <fstream> +#include <iostream> +#include <pcl/io/pcd_io.h> + +void txt2pcd( std::filesystem::path input, std::filesystem::path output ) { + std::ifstream inputFile{input.c_str()}; + + if ( inputFile ) + { + pcl::PointCloud<pcl::PointXYZRGB> cloud; + + while ( !inputFile.eof() ) + { + pcl::PointXYZRGB point; + + inputFile >> point.x; + inputFile >> point.y; + inputFile >> point.z; + + inputFile >> point.r; + inputFile >> point.g; + inputFile >> point.b; + + cloud.push_back( point ); + } + + pcl::PCDWriter pcdWriter{}; + + pcdWriter.writeBinaryCompressed( output.string(), cloud ); + } +} + +void printHelp() +{ + std::cout << "Usage: txt2pcd inputCloud.txt outputCloud.pcd\n"; +} + +int main( int argc, char** argv ) +{ + if ( argc == 3 ) + { + try + { + txt2pcd( argv[ 1 ], argv[ 2 ] ); + } + catch ( std::exception const& e ) + { + std::cerr << e.what() << "\n"; + } + } + else + { + printHelp(); + } + return 0; } diff --git a/meson.build b/meson.build index 33e23a3..7327966 100644 --- a/meson.build +++ b/meson.build @@ -5,6 +5,8 @@ pcl_version = get_option('pcl_version') pcl_io_dep = dependency('pcl_io-@0@'.format(pcl_version), required: true) +boost_dep = dependency('boost') + executable('txt2pcd', sources: files(['main.cpp']), - dependencies: [pcl_io_dep]) + dependencies: [pcl_io_dep, boost_dep]) -- GitLab