#include<pcl/visualization/cloud_viewer.h>
#include <vtkSTLReader.h>
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/vtk_lib_io.h>
int main()
{
std::string model_file = "hm.stl";
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
reader->SetFileName(model_file.c_str());
reader->Update();
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata = reader->GetOutput();
polydata->GetNumberOfPoints();
polydata->BuildCells();
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>());
pcl::io::vtkPolyDataToPointCloud(polydata, *cloud);
// 创建 PCLVisualizer 对象并显示点云
pcl::visualization::CloudViewer viewer("STL Point Cloud Viewer");
viewer.showCloud(cloud);
while (!viewer.wasStopped())
{
// 等待直到窗口关闭
}
return 0;
}
hm.stl是对应文件