0
votes

I have a point cloud (.pcd) file, from which I have generated normals. Now I want to display the input point cloud along with the generated normals in the same viewer window (not in multiple viewports). The code I have developed is

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/features/integral_image_normal.h>

int main ()
{
  // load point cloud
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

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

  std::cout << "Loaded "
            << cloud->width * cloud->height
            << " data points from test_pcd.pcd with the following fields: "
            << std::endl;

  std::cout << "Input cloud Point Size "
            << cloud->points.size ()            
            << std::endl;

  // organized or unorganized normal estimation
  pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
  if (cloud->isOrganized ())
  {
    std::cout << "Computing normals Inside organized block " << std::endl;
    pcl::IntegralImageNormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
    ne.setInputCloud (cloud);
    ne.setNormalEstimationMethod (ne.AVERAGE_3D_GRADIENT);    
    ne.setNormalSmoothingSize (float (0.03));
    ne.setDepthDependentSmoothing (true);
    ne.compute (*cloud_normals);    
  }
  else
  {
    std::cout << "Computing normals Inside non-organized block " << std::endl;
    pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
    ne.setInputCloud (cloud);
    pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
    ne.setSearchMethod (tree);    
    ne.setRadiusSearch (0.03);
    ne.compute (*cloud_normals);
  }

  std::cout << "cloud_normals Point Size "<< cloud_normals->points.size () << std::endl;

  //write the normals to a PCD file
  pcl::PCDWriter writer;
  writer.write("computed_normals.pcd", *cloud_normals, false);

    // visualize normals
    pcl::visualization::PCLVisualizer viewer("PCL Viewer");
    viewer.setBackgroundColor (0.0, 0.0, 0.0);      
    viewer.addPointCloud< pcl::PointXYZRGB >( cloud, "cloud", 0);

    viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, cloud_normals);    

    while (!viewer.wasStopped ())
    {
        viewer.spinOnce ();
    }
    return 0;
}

When I try to debug the code, I am getting an error

no instance of overloaded function "pcl::visualization::PCLVisualizer::addPointCloud" matches the argument list

in the line

viewer.addPointCloud< pcl::PointXYZRGB >( cloud, "cloud", 0);

I have referred the documentation and spent quite some time in the web to solve this problem without success.

Am I adding point cloud to the viewer correctly? If not please let me know the correct way of adding the point cloud to the viewer along with the generated normals.

1

1 Answers

0
votes

You have tried to add the wrong type of point cloud. Change the line to:

viewer.addPointCloud< pcl::PointXYZ >( cloud, "cloud", 0);

This question was also answered here:

http://www.pcl-users.org/Point-Cloud-Library-Error-while-adding-point-cloud-to-PCL-Visualizer-viewer-td4046232.html

For more information about types of point clouds, reference the PCL library here: http://pointclouds.org/documentation/tutorials/adding_custom_ptype.php#what-pointt-types-are-available-in-pcl