Skip to content
Snippets Groups Projects
Verified Commit bfadafe0 authored by Thibault Payet's avatar Thibault Payet
Browse files

add support to convert: x y z and x y z color

parent 6bc4686e
No related branches found
No related tags found
1 merge request!1add support to convert: x y z and x y z color
#include <filesystem>
#include <fstream>
#include <ios>
#include <iostream>
#include <string>
#include <pcl/io/ascii_io.h>
#include <pcl/io/pcd_io.h>
void txt2pcd( std::filesystem::path input, std::filesystem::path output )
......@@ -11,28 +15,71 @@ void txt2pcd( std::filesystem::path input, std::filesystem::path output )
{
pcl::PointCloud<pcl::PointXYZRGB> cloud;
while ( !inputFile.eof() )
// Read header
std::string line;
auto len = inputFile.tellg();
char buf{'\0'};
do
{
inputFile.get( buf );
if ( buf != '\0' && buf != '\n' )
{
line.push_back( buf );
}
} while ( buf != '\0' && buf != '\n' );
auto numberOfSpace = std::count( std::begin( line ), std::end( line ), ' ' );
if ( line.back() == ' ' )
{
if ( numberOfSpace > 0 )
{
--numberOfSpace;
}
}
auto const numArgument = numberOfSpace + 1;
inputFile.seekg( len, std::ios_base::beg );
pcl::PCDWriter pcdWriter{};
if ( numArgument == 6 )
{
pcl::PointXYZRGB point;
while ( !inputFile.eof() )
{
pcl::PointXYZRGB point;
inputFile >> point.x;
inputFile >> point.y;
inputFile >> point.z;
inputFile >> point.x;
inputFile >> point.y;
inputFile >> point.z;
int r, g, b;
int r, g, b;
inputFile >> r;
inputFile >> g;
inputFile >> b;
inputFile >> r;
inputFile >> g;
inputFile >> b;
point.r = static_cast<char>( r );
point.g = static_cast<char>( g );
point.b = static_cast<char>( b );
point.r = static_cast<char>( r );
point.g = static_cast<char>( g );
point.b = static_cast<char>( b );
cloud.push_back( point );
cloud.push_back( point );
}
}
else
{
inputFile.close();
pcl::ASCIIReader reader;
pcl::PCDWriter pcdWriter{};
auto ext = input.extension().string();
reader.setExtension( ext );
reader.read( input.string(), cloud );
}
pcdWriter.writeBinaryCompressed( output.string(), cloud );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment