-
Notifications
You must be signed in to change notification settings - Fork 0
/
txt2pcd_main.cpp
65 lines (53 loc) · 1.62 KB
/
txt2pcd_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Created by mixiaoxin on 2018-11-23.
//
#include <iostream>
#include <string>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
typedef struct TXT_Point_XYZ
{
double x;
double y;
double z;
}TOPOINT_XYZ;
int main(int argc, char* argv[] ) {
std::cout << "Hello, World!" << std::endl;
char* input_filename = argv[1];
//读取txt文件
int num_txt;
std::vector<TXT_Point_XYZ> my_vTxtPoints;
FILE *fp_txt = fopen(input_filename, "r");
if (fp_txt)
{
float intensity;
float r, g, b;
while (!feof(fp_txt)){
TXT_Point_XYZ txt_points;
fscanf(fp_txt, "%lf %lf %lf %lf %lf %lf %lf", &txt_points.x, &txt_points.y, &txt_points.z,
&intensity, &r, &g, &b);
my_vTxtPoints.push_back(txt_points);
}
}
else{
std::cout << "fail to load txt file"<< std::endl;
}
num_txt = my_vTxtPoints.size();
//写入点云数据
pcl::PointCloud<pcl::PointXYZ> ::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->width = num_txt;
cloud->height = 1;
cloud->is_dense = false;
cloud->points.resize(cloud->width*cloud->height);
for (int i = 0; i < cloud->points.size(); ++i)
{
cloud->points[i].x = my_vTxtPoints[i].x;
cloud->points[i].y = my_vTxtPoints[i].y;
cloud->points[i].z = my_vTxtPoints[i].z;
}
pcl::io::savePCDFileASCII("test_txt_2_pcd_ASCLL.pcd", *cloud);
pcl::io::savePCDFile("test_txt_2_pcd.pcd", *cloud);
pcl::io::savePCDFileBinary("test_txt_2_pcd_binary.pcd", *cloud);
std::cout << cloud->points.size() << std::endl;
return 1;
}