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) == -) {
PCL_ERROR("Error reading point cloud %s\n", filename.c_str());
return ;
} sensor_msgs::PointCloud2 cloud2;
pcl::toROSMsg(*pc, cloud2)
pcl::io::saveVTKFile("out.vtk", cloud2); return ;
}

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) == -) {
PCL_ERROR("Error reading point cloud %s\n", filename.c_str());
return ;
} pcl::PCLPointCloud2 cloud2;
pcl::toPCLPointCloud2(*pc, cloud2);
pcl::io::saveVTKFile("out.vtk", cloud2); return ;
}

VTK格式的点云关于texture的存储方式有两种,第一种是需要有texture的图片,然后每个点存储上该点在图片中的x,y坐标,一般会normalize到[0,1]之间。第二种方法是直接存每个点的rgb值,上面的方法用的是第二种,因为导入的PLY格式就直接存储的texture的rgb值,并没有额外提供texture图片,这种方法导出的vtk格式,在VTK库的viewer中显示是有texture的,大功告成!

Convert PLY to VTK Using PCL 1.6.0 使用PCL库将PLY格式转为VTK格式的更多相关文章

  1. Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 使用PCL库将PLY格式转为VTK格式

    PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理.我们可以使用Par ...

  2. PCL 1.6.0 VS2010 Configuration

    Open VS2010, create a new project, then open Property Manager, double-click Microsoft.Cpp.win32.user ...

  3. PCL 1.4.0 VS 2010 Configuration

    Open VS2010, create a new project, then open Property Manager, double-click Microsoft.Cpp.win32.user ...

  4. macOS 安装 pcl 1.8.0

    Mac 上的 pcl 一直有问题. 找不到 pcl_viewer 查看 pcd 文件.写个程序用 pcl::visualization::CloudViewer 查看点云,遇到 Runtime Exc ...

  5. ros pcl sensor::pointcloud2 转换成pcl::pointcloud

    #include <pcl_conversions/pcl_conversions.h> #include <pcl/point_types.h> #include <p ...

  6. PCL(Point Cloud Library)的第三方库简单介绍(boost,eigen,flann,vtk,qhull)

    PCL由于融合了大量的第三方开源库,导致学习成本升高~在学习之前我们最好还是了解一下这些库都是干嘛的,以便有的放矢.在之后更好的使用 boost: C++的标准库的备用版,擅长从数学库到智能指针,从模 ...

  7. Ubuntu 16.04 上安装 PCL 1.8.0

    Ubuntu16.04之后安装pcl可以直接apt-get sudo apt-get install libpcl-dev pcl-tools 安装之前,准备一些依赖库 sudo apt-get up ...

  8. Qt 4.8.6 PCL 1.8.0 VS 2010 联合编译常见错误

    在Qt和PCL联合编译的过程中,会出现各种各样的错误,解决这些错误的过程真是痛苦万分,所以总结一些常见错误方便自己也方便他人.比如我们要编译PCL1.8.0中的apps中的point_cloud_ed ...

  9. linux下关于PCL(point cloud library)库的安装,三行命令错误的问题

    最近想再看看PCL,所以进行了安装,在之前的接触的过程中,由于之前的网络存在问题,导致以下三个命令: sudo add-apt-repository ppa:v-launchpad-jochen-sp ...

随机推荐

  1. Python模块之configpraser

    Python模块之configpraser   一. configpraser简介 用于处理特定格式的文件,其本质还是利用open来操作文件. 配置文件的格式: 使用"[]"内包含 ...

  2. c/c++ string

    string类的定义.操作. #include<iostream> #include<string> using namespace std; int main() { // ...

  3. 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法

    "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...

  4. 等差数列(bzoj 3357)

    Description     约翰发现奶牛经常排成等差数列的号码.他看到五头牛排成这样的序号:"1,4,3,5,7" 很容易看出"1,3,5,7"是等差数列. ...

  5. MySQL的一些知识。

    新MySQL而言:对于myisam引擎的表select默认是会锁定该表(共享锁)的 ,会导致其他操作挂起,处于等待状态.对于innodb引擎的表select默认是不会锁表(也不会锁行,简而言之就是不加 ...

  6. CrashMonkey4IOS App测试

    下载地址:https://github.com/vigossjjj/CrashMonkey4IOS 根据下载地址里面的说明安装一下,以下进行配置 1.进入CrashMonkey4IOS-master/ ...

  7. webServer-----Spring 集成cxf笔录

    目前webserver主要有俩中方式:1,传统的webserver标准集成方式-生成WSDL的xml文档.       2, 基于restful风格的webserver java RESTful We ...

  8. 从源代码剖析Mahout推荐引擎

    转载自:http://blog.fens.me/mahout-recommend-engine/ Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pi ...

  9. C++ 系列:内存管理

    1.内存分配方式 内存分配方式有三种: (1)从静态存储区域分配. 内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量,static变量. (2)在栈上创建. 在执行函 ...

  10. CSS3 Loading(加载)动画效果

    1.html 部分 <div class="spinner"> <div class="rect1"></div> < ...