Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding two different point clouds to viewer (Point Cloud Library (PCL))

I just started to use the great point cloud library and wanted to display two point clouds within one viewer but each in a different colour.

When I use one point cloud object (pointer?!) it works just fine but if I want to add a second one, only the second one will be displayed in the viewer.

I'm using pcl version 1.6 and did it pretty much like in this tutorial.
Maybe you guys have a suggetion.

The relevant code snippet is below. Thanks in advance!!!

  boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer_two_clouds (new pcl::visualization::PCLVisualizer("3D Viewer"));
  viewer_two_clouds->setBackgroundColor(0,0,0);

     // cloud: green / cloud2: red
  pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> single_color1 (cloud, 0, 255, 0);
  pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> single_color2 (cloud2, 255, 0, 0);

  //add both
  viewer_two_clouds->addPointCloud<pcl::PointXYZRGB> (cloud, single_color1, "sample_cloud_1");
  viewer_two_clouds->addPointCloud<pcl::PointXYZRGB> (cloud2, single_color2, "sample_cloud_2");

  // set coordinateSystem and init camera
  viewer_two_clouds->addCoordinateSystem(1.0);
  viewer_two_clouds->initCameraParameters();

  while(!viewer_two_clouds->wasStopped())
  {
      viewer_two_clouds->spinOnce();
      boost::this_thread::sleep (boost::posix_time::microseconds(100000));
  }

  viewer_two_clouds->close();
like image 743
GeoGecco Avatar asked Nov 22 '13 13:11

GeoGecco


3 Answers

In order to apply transformations (such as rotations and translations) to a point cloud you already loaded you should use the pcl::transformPointCloud function (see here). This function takes 3 arguments: the input cloud, the output cloud and an Eigen::Transform. Simply define a translation transformation and feed it into the function in order to translate your cloud correctly.

There is a good Eigen tutorial (here) that shows you how to define and use space transformations.

like image 54
Dexter Avatar answered Oct 09 '22 04:10

Dexter


Dexter helped me alot =)

here is what I used to transform the Pointcloud so that others can use it as well!

  void trans (); 
    { 
       Eigen::Affine3f t;

       pcl::getTransformation(10.0,5.0,20.0,0.0,0.0,0.0,t);
       pcl::transformPointCloud(*cloud, *cloud2, t);   
    }
like image 20
GeoGecco Avatar answered Oct 09 '22 05:10

GeoGecco


there is other ways to display two point clouds within one viewer.you can create two differet viewports on the window, some think like this:

viewer_two_clouds->createViewPort (0.0,0.0,0.5,1.0,0);
viewer_two_clouds->setBackgroundColor(0,0,0,0); // background color dark
viewer_two_clouds->addText("sample_cloud_1", 10, 10, "right", 0);
viewer_two_clouds->addPointCloud(cloud,  "sample_cloud_1", 0);

viewer_two_clouds->createViewPort (0.5,0.0,0.1,1.0,0);
viewer_two_clouds->setBackgroundColor(0.1,0.1,0.1,0); // background color light
viewer_two_clouds->addText("sample_cloud_2", 10, 10, "left", 0);
viewer_two_clouds->addPointCloud(cloud2,  "sample_cloud_2", 0);

this way, you can see two point clouds besides each other (and not overlapping).

like image 43
elaheh r Avatar answered Oct 09 '22 06:10

elaheh r