From 5ed29d22a9ef9c787041d597b28adf407b3fc7f5 Mon Sep 17 00:00:00 2001
From: Thibault Payet <monwarez@gmail.com>
Date: Mon, 25 Apr 2022 15:36:02 +0200
Subject: [PATCH] Add an option to just convert a txt with same output name

---
 main.cpp | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/main.cpp b/main.cpp
index a322c47..6fad763 100644
--- a/main.cpp
+++ b/main.cpp
@@ -10,7 +10,7 @@
 
 void txt2pcd( std::filesystem::path input, std::filesystem::path output )
 {
-    std::ifstream inputFile{input.c_str()};
+    std::ifstream inputFile{ input.c_str() };
 
     if ( inputFile )
     {
@@ -20,7 +20,7 @@ void txt2pcd( std::filesystem::path input, std::filesystem::path output )
         std::string line;
         auto len = inputFile.tellg();
 
-        char buf{'\0'};
+        char buf{ '\0' };
 
         do
         {
@@ -104,7 +104,7 @@ void txt2pcd( std::filesystem::path input, std::filesystem::path output )
 
 void printHelp()
 {
-    std::cout << "Usage: txt2pcd inputCloud.txt outputCloud.pcd\n";
+    std::cout << "Usage: txt2pcd inputCloud.txt [outputCloud.pcd]\n";
 }
 
 int main( int argc, char** argv )
@@ -120,6 +120,14 @@ int main( int argc, char** argv )
             std::cerr << e.what() << "\n";
         }
     }
+    else if ( argc == 2 )
+    {
+        auto basefilename = std::filesystem::path{ argv[ 1 ] };
+        auto outfilename  = basefilename;
+        outfilename.replace_extension( std::filesystem::path{ "pcd" } );
+
+        txt2pcd( basefilename, outfilename );
+    }
     else
     {
         printHelp();
-- 
GitLab