10

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();
Adri C.S.
  • 2,909
  • 5
  • 36
  • 63
GeoGecco
  • 437
  • 4
  • 21
  • Have you checked you're not loading the same `PCD`? – Adri C.S. Nov 22 '13 at 15:04
  • I'm actually loading only one pcd but I'm copying it and move it 10 meters away from the other point cloud. copyPointCloud(*cloud, *cloud2);/ After copying I do cloud2->sensor_origin_ = p; – GeoGecco Nov 22 '13 at 15:25
  • Ok. Then, try loading the file twice, instead of copying. I don't think this will solve it, but just in case... – Adri C.S. Nov 22 '13 at 15:33
  • Hm no...that won't do it either. While debugging I noticed that the points in my cloud2 object disappear as soon as I do cloud2->sensor_origin_ = p. Is there another way of moving an existing cloud? – GeoGecco Nov 22 '13 at 16:32

3 Answers3

8

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.

Dexter
  • 2,482
  • 27
  • 40
3

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);   
    }
GeoGecco
  • 437
  • 4
  • 21
3

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).

elaheh r
  • 474
  • 3
  • 11