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的,大功告成!

最新文章

  1. UWP 判断windows mobile是使用的实体键还是虚拟按键
  2. layer弹框
  3. 【读书笔记】iOS-使用Web Service-基于客户端服务器结构的网络通信(一)
  4. Sonar+Hudson+Maven构建系列之二:迁移Sonar
  5. 最新RubyMine2016.2开发Ruby ON Rails(ROR)程序的流程
  6. Android网络编程系列 一 TCP/IP协议族之传输层
  7. python连接字符串的方式
  8. linux入门教程(一) 关于linux的历史
  9. puppet中anchor的作用
  10. [转] 考验你的JavaScript底细
  11. 数据结构——Currency System in Geraldion
  12. orcad10.5启动加速
  13. C#中static void Main(string[] args) 参数详解
  14. Django导入外部js、css、图片等巨大的坑
  15. Appium+Python3+iOS真机环境搭建
  16. Java并发框架AbstractQueuedSynchronizer(AQS)
  17. luogu P3191 [HNOI2007]紧急疏散EVACUATE
  18. python学习之for循环
  19. Best Practices in Asynchronous Programming
  20. Kafka &ndash; kafka consumer

热门文章

  1. [leetcode]Rotate List @ Python
  2. 版本控制-git(二)
  3. hadoop from rookie to ninja - 1. Basic Architecture(基础架构)
  4. 【Zookeeper】源码分析之Leader选举(二)之FastLeaderElection
  5. win32 进程崩溃时禁止弹出错误对话框
  6. CART决策树(分类回归树)分析及应用建模
  7. Effective Java 第三版——52. 明智而审慎地使用重载
  8. Chrome 调试技巧: 调整网速
  9. JEECG中表单提交的中断
  10. Android使用腾讯浏览服务X5内核