-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPointIO.cpp
executable file
·91 lines (76 loc) · 1.48 KB
/
PointIO.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "PointIO.h"
td::PointIO::PointIO()
: cloud(0)
{
}
td::PointIO::PointIO(std::string path)
{
std::ifstream infile;
infile.open(path.c_str(), std::ios::in);
if (!infile)
{
std::cerr << "文件有误" << std::endl;
return;
}
std::string line, str;
//暂时读入x,y,z形式的文件
while (!infile.eof())
{
/*getline(infile,line);
istringstream stream(line);
stream>>tempx>>str>>tempy>>str>>tempz;*/
Point point;
infile >> point.x;
infile >> point.y;
infile >> point.z;
cloud.push_back(point);
}
infile.close();
}
td::PointIO::~PointIO()
{
}
td::PointCloud td::PointIO::getPointCloud()
{
return cloud;
}
// 读入文件
void td::PointIO::open(std::string path)
{
std::ifstream infile;
infile.open(path.c_str(), std::ios::in);
if (!infile)
{
std::cerr << "文件有误" << std::endl;
return;
}
std::string line, str;
//暂时读入x,y,z形式的文件
while (!infile.eof())
{
Point point;
infile >> point.x;
infile >> point.y;
infile >> point.z;
cloud.push_back(point);
}
infile.close();
}
void td::PointIO::save(std::string path)
{
std::ofstream ofile;
ofile.open(path.c_str(), std::ios::out);
if (!ofile)
{
std::cerr << "文件有误" << std::endl;
return;
}
//暂时读入x,y,z形式的文件
for (size_t i = 0; i < cloud.size();++i)
{
ofile << cloud[i].x;
ofile << cloud[i].y;
ofile << cloud[i].z;
}
ofile.close();
}