简介:由于PLY1.12版本IO模块提供了PCD和PLY两种格式的读取接口,因此需要用VTK进行格式转换,完成STL到PLY格式的转换,或掩码图像到PLY格式的转换,然后用PCL进行读取并进行处理。
1、VTK 将STL转换为 PLY格式
void stl2ply()
{
std::string filename = "P:\\CBCT\\tooth\\upper.stl";
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
reader->SetFileName(filename.c_str());
reader->Update();
vtkSmartPointer<vtkPLYWriter> plyWriter = vtkSmartPointer<vtkPLYWriter>::New();
plyWriter->SetFileName("P:\\CBCT\\tooth\\upper1.ply");
plyWriter->SetInputConnection(reader->GetOutputPort());
plyWriter->SetFileTypeToASCII();
plyWriter->SetColorModeToOff();
plyWriter->Update();
plyWriter->Write();
}
2 、 PCL读取并显示PLY格式文件
int main()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
char strfilepath[256] = "E:\\CBCT\\lower.ply";
if (-1 == pcl::io::loadPLYFile(strfilepath, *cloud)) {
cout << "error input!" << endl;
return 0;
}
cout << cloud->points.size() << endl;
pcl::visualization::CloudViewer viewer("Cloud Viewer"); //创建viewer对象
viewer.showCloud(cloud);
viewer.runOnVisualizationThreadOnce(viewerOneOff);
system("pause");
return 0;
}
3、显示结果
![](https://img-blog.csdnimg.cn/20210830175628592.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LyN5b-D,size_20,color_FFFFFF,t_70,g_se,x_16)
![](https://img-blog.csdnimg.cn/20210830175639940.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LyN5b-D,size_20,color_FFFFFF,t_70,g_se,x_16)
4、 一直报 [pcl::PLYReader] E:\CBCT\lower.ply:10: property 'list uint8 int32 vertex_index' of element 'face' is not handled 错误,目前还没找到问题出在哪里?不过点云数据应该是读取正确了,下一步把 分割的掩码数据转位点云数据。