读取*.3d格式数据
1、.3d格式数据是机器人常用的数据保存格式,Robotic 3D Scan Repository
2、注意:部分.3d数据,直接将.3d改为.txt可直接打开。
3、针对这样格式的数据,利用C++和pcl编写读取函数,将.3d转为pcl::PointXYZ:
using namespace std;
// 自定义读取函数
void load3DFile(const std::string& filename, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud) {
std::ifstream infile(filename);
std::string line;
while (std::getline(infile, line)) {
std::istringstream iss(line);
pcl::PointXYZ point;
if (!(iss >> point.x >> point.y >> point.z)) {
break; // Error
}
cloud->push_back(point);
}
}
int main(int argc, char** argv) {
string filename = "./Robotic 3D Scan Repository/25/wue_city/scan005.3d";
ofstream fout("scan005.txt");
std::ifstream infile(filename);
std::string line;
while (std::getline(infile, line)) {
std::istringstream iss(line);
float x = 0, y = 0, z = 0;
if (!(iss >> x >> y >> z)) {
break; // Error
}
fout << x << ' ' << y << ' ' << z << endl;
}
//pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
//load3DFile("./Robotic 3D Scan Repository/25/wue_cityscan005.3d", cloud);
//std::cout << "Loaded " << cloud->points.size() << " points" << std::endl;
//pcl::visualization::CloudViewer viewer("Cloud Viewer");
//viewer.showCloud(cloud);
//while (!viewer.wasStopped()) {
//}
//return 0;
}