Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 使用PCL库将PLY格式转为VTK格式
生活随笔
收集整理的这篇文章主要介绍了
Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 使用PCL库将PLY格式转为VTK格式
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理。我们可以使用ParaView软件对VTK格式文件进行预览和简单处理,ParaView也可以打开PLY格式,但是就没有texture了,而且我们如果直接用ParaView导出VTK格式也没有texture的,这不是我们想要的结果。MeshLab虽然可以打开有texture的PLY文件,但是却不支持导出VTK格式,那么我们如何将PLY转为VTK格式并且保留texture呢?我们可以用PCL库来转换,PCL全称是Point Cloud Library,是专门处理点云的库,功能十分强大,提供saveVTKFile函数可以保存vtk,就是要注意参数的类型,做一些类型转换即可。
Using PCL 1.6.0:
// PCL 1.6.0 #include <iostream> #include <string> #include <pcl/io/vtk_io.h> #include <pcl/io/ply_io.h> #include <pcl/point_cloud.h> #include <pcl/point_types.h> #include <pcl/ros/conversions.h> #include <sensor_msgs/PointCloud2.h> typedef pcl::PointXYZRGB PointT; typedef pcl::PointCloud<PointT> PointCloudT; int main() {std::string filename = "in.ply";PointCloudT::Ptr pc(new PointCloudT);if (pcl::io::loadPLYFile (filename, *pc) == -1) {PCL_ERROR("Error reading point cloud %s\n", filename.c_str());return 0;}sensor_msgs::PointCloud2 cloud2;pcl::toROSMsg(*pc, cloud2)pcl::io::saveVTKFile("out.vtk", cloud2);return 0; }Using PCL 1.8.0:
// PCL 1.8.0 #include <iostream> #include <string> #include <pcl/io/vtk_io.h> #include <pcl/io/ply_io.h> #include <pcl/point_cloud.h> #include <pcl/point_types.h> #include <pcl/PCLPointCloud2.h> #include <pcl/conversions.h> typedef pcl::PointXYZRGB PointT; typedef pcl::PointCloud<PointT> PointCloudT; int main() {std::string filename = "in.ply";PointCloudT::Ptr pc(new PointCloudT);if (pcl::io::loadPLYFile (filename, *pc) == -1) {PCL_ERROR("Error reading point cloud %s\n", filename.c_str());return 0;}pcl::PCLPointCloud2 cloud2;pcl::toPCLPointCloud2(*pc, cloud2);pcl::io::saveVTKFile("out.vtk", cloud2);return 0; }本文转自博客园Grandyang的博客,原文链接:使用PCL库将PLY格式转为VTK格式Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 ,如需转载请自行联系原博主。
总结
以上是生活随笔为你收集整理的Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 使用PCL库将PLY格式转为VTK格式的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 重构——71将领域和表述/显示分开(Se
- 下一篇: 以太坊智能合约开发:让合约接受转账