我正在尝试根据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
.所以我的问题是
- 我可以只在
Pwn_vector
中插入点吗? - 在 CGAL 中获得法线的最佳方法是什么?是
CGAL::jet_estimate_normals
吗? - 我需要
Point_map
和Normal_map
的属性地图吗?我不明白他们是如何交给Efficient_ransac
. - 还有什么必要的吗?
我从以下代码开始:
// 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 对此问题不感兴趣,因为很清楚如何访问单个坐标。
为了逐点回答,我会说:
-
你需要提供点和法线,所以我会说不。
-
您可以使用[喷射](https://doc.cgal.org/latest/Point_set_processing_3/group__PkgPointSetProcessing3Algorithms.html#ga0cd0f87de690d4edf82740e856efa491(,PCA或VCM正常估计,如您所愿。
-
如果使用与示例中相同的类型,则不需要它们。默认值就可以了。
-
基本上,您只需要用您的点数和正常估计的结果填充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算法。