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
- 下一篇: 以太坊智能合约开发:让合约接受转账