- #include
- #include
- #include
- #include
- #include
- #include
- #include
-
- int main()
- {
- std::string stl_file = "01.stl"; // 替换为您的 STL 文件路径,单写文件名放在cpp同目录
- std::string pcd_file = "01.pcd"; // 替换为您的输出 PCD 文件路径,单写文件名放在cpp同目录
-
- // 读取 STL 文件
- vtkSmartPointer
reader = vtkSmartPointer::New(); - reader->SetFileName(stl_file.c_str());
- reader->Update();
-
- vtkSmartPointer
polydata = vtkSmartPointer::New(); - polydata = reader->GetOutput();
- polydata->GetNumberOfPoints();
- polydata->BuildCells();
-
- // 将 vtkPolyData 转换为 PointCloud 对象
- pcl::PointCloud
::Ptr cloud(new pcl::PointCloud()) ; - pcl::io::vtkPolyDataToPointCloud(polydata, *cloud);
-
- // 保存为 PCD 文件
- pcl::io::savePCDFileBinary(pcd_file, *cloud);
-
- std::cout << "STL 文件已成功转换为 PCD 文件:" << pcd_file << std::endl;
-
- return 0;
- }