diff --git a/main.cpp b/main.cpp index c05c0c4bdf591a68fe5b426769f73581d0836909..6b69233cf309806254cf978f8a3dbfaa3bac09c2 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 33e23a3de07ad0f8104f40c0b3febee48121bb9b..7327966f1b199b8b30ff7f2839c71747ba6c8c09 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])