1

I am receiving ROS message of type

sensor_msgs::PointCloud2ConstPtr

in my callback function then I transform it to pointer of type

pcl::PointCloud<pcl::PointXYZ>::Ptr

using function

pcl::fromROSMsg.

After that using this code from pcl tutorials for normal estimation:

void OrganizedCloudToNormals(
      const pcl::PointCloud<pcl::PointXYZ>::Ptr &_inputCloud,
      pcl::PointCloud<pcl::PointNormal>::Ptr &cloud_normals
      )
{ 
      pcl::console::print_highlight ("Estimating scene normals...\n");
      pcl::NormalEstimationOMP<pcl::PointXYZ,pcl::PointNormal> nest;
      nest.setRadiusSearch (0.001);
      nest.setInputCloud (_inputCloud);
      nest.compute (*cloud_normals);
    
      //write 0 wherever is NaN as value
      for(int i=0; i < cloud_normals->points.size(); i++)
      {
        cloud_normals->points.at(i).normal_x = isnan(cloud_normals->points.at(i).normal_x) ? 0 : cloud_normals->points.at(i).normal_x;
        cloud_normals->points.at(i).normal_y = isnan(cloud_normals->points.at(i).normal_y) ? 0 : cloud_normals->points.at(i).normal_y;
        cloud_normals->points.at(i).normal_z = isnan(cloud_normals->points.at(i).normal_z) ? 0 : cloud_normals->points.at(i).normal_z;
        cloud_normals->points.at(i).curvature = isnan(cloud_normals->points.at(i).curvature) ? 0 : cloud_normals->points.at(i).curvature;
      }
}

after that I have point cloud of the type pcl::PointNormal and trying to downsample it

const float leaf = 0.001f; //0.005f;
pcl::VoxelGrid<pcl::PointNormal> gridScene;
gridScene.setLeafSize(leaf, leaf, leaf);
gridScene.setInputCloud(_scene);
gridScene.filter(*_scene);

where _scene is of the type

pcl::PointCloud<pcl::PointNormal>::Ptr _scene (new pcl::PointCloud<pcl::PointNormal>); 

then after filtering I end up with my point cloud _scene and it has only 1 point inside. I have tried to change leaf size but that doesn't change outcome.

Does anyone knows what am I doing wrong?

Thanks in advance

LBajlo
  • 95
  • 3
  • 12

1 Answers1

0

I have found where was the problem. Type pcl::PoinNormal has fields x,y,z,normal_x, normal_y and normal_z but in my function OrganizedCloudToNormals I filled only fields normal_x, normal_y and normal_z and fields x, y and z had value 0 for each point. When I filled fields x,y and z from input point cloud problem with filtering (downsampling) disappeared I have filtered cloud with more than 1 point inside. Probably lack of values in x,y and z fields caused problems later in filter method of the voxel grid object.

LBajlo
  • 95
  • 3
  • 12