Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pcl::gpu::NormalEstimation] Unexpected Results #5731

Closed
yu-sheng-vincent opened this issue May 30, 2023 · 2 comments
Closed

[pcl::gpu::NormalEstimation] Unexpected Results #5731

yu-sheng-vincent opened this issue May 30, 2023 · 2 comments
Labels

Comments

@yu-sheng-vincent
Copy link

Describe the bug

I was trying pcl::gpu::NormalEstimation() and found that the normal vectors act weird (point horizontally to the surface) under certain range of radius. I also ran pcl::NormalEstimationOMP() with the same searching radius and it went well.

Context

Generate normal surface using pcl::gpu::NormalEstimation().

Current Behavior

Part of the normal vectors point horizontally to the surface when running pcl::gpu::NormalEstimation(), while pcl::NormalEstimationOMP() works well with the same searching radius. Pictures are shown in the following section.

To Reproduce

To showcase the issue, I use this cutting blade object from Artec3D:
https://www.artec3d.com/3d-models/metal-cutting-blade

Screenshots/Code snippets

Snippet 1 - Using pcl::gpu::NormalEstimation()

#define SEARCH_RADIUS  (1)

int test_gpu(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::PointCloud<pcl::Normal>::Ptr cloud_normals)
{
  printf("Test with GPU\n");
  // Getinfo();

  typedef pcl::gpu::DeviceArray<pcl::PointXYZ>  g_PointXYZ;
  typedef pcl::gpu::DeviceArray<pcl::Normal>    g_Normal;

  g_PointXYZ dev_cloud(cloud->size());
  dev_cloud.upload(cloud->points.data(), cloud->size());
  
  printf("Normal Estimation...\n");
  pcl::gpu::NormalEstimation gne;
  gne.setInputCloud(dev_cloud);
  gne.setRadiusSearch(SEARCH_RADIUS * 100, 500);  // setRadiusSearch(float radius, int max_results);  What is max_results??
  gne.setViewPoint(-5, 5, 5);
  
  pcl::gpu::NormalEstimation::Normals dev_normals;
  gne.compute(dev_normals);

  std::vector<pcl::PointXYZ> normals;
  dev_normals.download(normals);
  
  //pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
  cloud_normals->resize(normals.size());
  for (size_t i = 0; i < normals.size(); ++i)
    {
      cloud_normals->points[i].normal_x = normals[i].x;
      cloud_normals->points[i].normal_y = normals[i].y;
      cloud_normals->points[i].normal_z = normals[i].z;
      cloud_normals->points[i].curvature = 0; // Curvature is not estimated in the GPU-based method
    }

  printf("Cloud Normal Size: %lu data points.\n", cloud_normals->size());

  return 0;
}

Screenshot from 2023-05-30 11-23-30

Snippet 2 - pcl::NormalEstimationOOP()

int test_pcl(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::PointCloud<pcl::Normal>::Ptr cloud_normals)
{
  printf("Test with CPU\n");

  // ==============================
  // Normal Estimation
  // ==============================
  pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> ne;
  ne.setInputCloud(cloud);

  // KdTree to search K nearest
  pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
  ne.setSearchMethod (tree);

  // parameters
  ne.setRadiusSearch(SEARCH_RADIUS);  // Consider all the points within the radius
  //ne.setKSearch(K_NEIGHBOR);  // mutex with setRadiusSearch
  ne.setViewPoint(-5, 5, 5);

  // place to store normal
  ne.compute(*cloud_normals);

  printf("Cloud Normal Size: %lu data points.\n", cloud_normals->size());

  return EXIT_SUCCESS;
}

Screenshot from 2023-05-30 11-24-50

Your Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Compiler: GCC 9.4.0
  • PCL Version: 1.13.1
  • CUDA Version: 12.1
@yu-sheng-vincent yu-sheng-vincent added kind: bug Type of issue status: triage Labels incomplete labels May 30, 2023
@mvieth
Copy link
Member

mvieth commented Sep 2, 2023

@yu-sheng-vincent Sorry for the late response. I tried to reproduce the problem, but the results I get seem correct. Could you share your whole code? Especially how you save the cloud normals to a file? You use meshlab to visualize the cloud and normals, is that correct?

@mvieth
Copy link
Member

mvieth commented Nov 4, 2023

We found the problem, please see here: #5846

@mvieth mvieth closed this as completed Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants