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 ,如需转载请自行联系原博主。

相关文章
|
数据可视化 C++
msvc编译opencascade和vtk
1.opencascade源码 我下载的时候最新版本是7.7.0
275 0
|
5月前
|
计算机视觉
vs2019_qt6.2.4_dcmtk3.6.7_vtk9.2.2_itk5.3_opencv4.6.0编译记录
这篇文章记录了使用VS2019编译Qt6.2.4、DCMTK3.6.7、VTK9.2.2、ITK5.3和OpenCV4.6.0的过程,包括下载和编译步骤,并提供了遇到编译错误时的解决方案和参考链接。
112 0
vs2019_qt6.2.4_dcmtk3.6.7_vtk9.2.2_itk5.3_opencv4.6.0编译记录
|
9月前
|
C++
cpp ofstream ifstreram binary 文档读写
cpp ofstream ifstreram binary 文档读写
67 0
|
计算机视觉
Opencv生成视频转h264格式
Opencv生成视频转h264格式
423 0
|
C++ 计算机视觉
vs安装pcl库,遇到的问题总结(全)
vs安装pcl库,遇到的问题总结(全)
441 0
|
存储 算法
pcd格式的点云文件详解
pcd格式的点云文件详解
905 0
|
计算机视觉
【opencv】无法打开源文件opencv2/nonfree/features2d.hpp
【opencv】无法打开源文件opencv2/nonfree/features2d.hpp
629 0
【opencv】无法打开源文件opencv2/nonfree/features2d.hpp
|
计算机视觉
交叉编译opencv:undefined reference to `png_riffle_palette_neon
交叉编译opencv:undefined reference to `png_riffle_palette_neon
219 0
使用jpeglib直接把NV12转为jpeg文件的代码
使用jpeglib直接把NV12转为jpeg文件的代码
170 0
|
计算机视觉
Qt+OpenCV小项目:灰度图转换
Qt+OpenCV小项目:灰度图转换
243 0