码迷,mamicode.com
首页 > 其他好文 > 详细

pcl之I/O输入输出

时间:2018-11-20 00:01:49      阅读:396      评论:0      收藏:0      [点我收藏+]

标签:输入   ntc   als   The   file   ios   att   char   could   

pcl之I/O输入输出

Reading Point Cloud data from PCD files

#include <iostream>

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

  if (pcl::io::loadPCDFile<pcl::PointXYZ> ("test_pcd.pcd", *cloud) == -1) //* load the file
  {
    PCL_ERROR ("Couldn't read file test_pcd.pcd \n");
    return (-1);
  }

  return (0);
}

Writing Point Cloud data to PCD files

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ> cloud;

  // Fill in the cloud data
  cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);

  for (size_t i = 0; i < cloud.points.size (); ++i)
  {
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }

  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;

  for (size_t i = 0; i < cloud.points.size (); ++i)
    std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;

  return (0);
}

Concatenate the points of two Point Clouds

  • If we are trying to concatenate points then the code below:
    cloud_c  = cloud_a;
    cloud_c += cloud_b;

creates cloud_c by concatenating the points of cloud_a and cloud_b together.

  • Otherwise if we are attempting to concatenate fields then the code below:
    pcl::concatenateFields (cloud_a, n_cloud_b, p_n_cloud_c);

creates p_n_cloud_c by concatenating the fields of cloud_a and cloud_b together.

pcl之I/O输入输出

标签:输入   ntc   als   The   file   ios   att   char   could   

原文地址:https://www.cnblogs.com/ChrisCoder/p/9986345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!