CGAL:手动创建用于形状检测的点集



我正在尝试根据CGAL 4.13.1中的"基本平面形状检测"示例使用CGAL的形状检测算法。但是,不是从文件中读入数据

CGAL::read_xyz_points(stream,
      std::back_inserter(points),
      CGAL::parameters::point_map(Point_map()).
      normal_map(Normal_map()))

我想将我的点从现有pcl::PointCloud加载到必要的 CGAL 类型。我只是不确定如何创建此 CGAL 类型。根据示例(摘录(

typedef std::pair<Kernel::Point_3, Kernel::Vector_3> Point_with_normal;
typedef std::vector<Point_with_normal> Pwn_vector;
Pwn_vector points;
typedef CGAL::Shape_detection_3::Efficient_RANSAC<Traits> Efficient_ransac;
EfficientRansac.set_input(points);

我只需要创建Pwn_vector.所以我的问题是

  1. 我可以只在Pwn_vector中插入点吗?
  2. 在 CGAL 中获得法线的最佳方法是什么?是CGAL::jet_estimate_normals吗?
  3. 我需要Point_mapNormal_map的属性地图吗?我不明白他们是如何交给Efficient_ransac.
  4. 还有什么必要的吗?

我从以下代码开始:

  // Points with normals.
  cgal::Pwn_vector points;
  // load points from pcl cloud
  for (auto point : cloud.points) {
    cgal::Point_with_normal pwn;
    pwn.first = cgal::ShapeKernel::Point_3(point.x, point.y, point.z);
    points.push_back(pwn);
  }

(PCL 对此问题不感兴趣,因为很清楚如何访问单个坐标。

为了逐点回答,我会说:

  1. 你需要提供点和法线,所以我会说不。

  2. 您可以使用[喷射](https://doc.cgal.org/latest/Point_set_processing_3/group__PkgPointSetProcessing3Algorithms.html#ga0cd0f87de690d4edf82740e856efa491(,PCA或VCM正常估计,如您所愿。

  3. 如果使用与示例中相同的类型,则不需要它们。默认值就可以了。

  4. 基本上,您只需要用您的点数和正常估计的结果填充Pwn_vector,其余的应该在示例中完全正常工作。

要完成mgimeno的答案(这是正确的(,您不一定需要复制要点。属性映射的兴趣在于,您只需要提供一个函数get(),该函数将范围的value_type动态转换为CGAL::Point_3(法线CGAL::Vector_3(。

例如,对于 PCL,我想你会做这样的事情(我不是 PCL 的用户,所以这可能不正确,但这只是为了给你一个想法(:

struct PCL_point_map
{
   typedef pcl::PointCloud::value_type key_type;
   typedef CGAL::Point_3<Kernel> value_type;
   typedef CGAL::Point_3<Kernel> reference;
   typedef boost::readable_property_map_tag category;
   friend reference get (const PCL_point_map&, const key_type& k)
   {
      return CGAL::Point_3<Kernel> (k.x, k.y, k.z);
   }
};
法线

也有类似的东西(确实需要计算法线才能进行形状检测,CGAL::jet_estimate_normals是一个不错的选择(。然后,如果您只是使用自己的地图对特征进行模板化,则可以直接在PCL点云上调用RANSAC算法。

最新更新