CGAL没有计算完整的德劳内三角测量

CGAL is not computing a complete delaunay triangulation

本文关键字:三角 测量 计算 CGAL      更新时间:2023-10-16

我目前在使用 CGAL 库的 Delaunay 三角测量时遇到了错误。我计算三角测量如下

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Delaunay_triangulation_2<Kernel> DelaunayTriangulation;
auto triangulation = DelaunayTriangulation();
triangulation.insert(points.begin(),points.end());

其中points是给定的Points 向量。我在几个实例上运行代码,大多数情况下三角测量都是正确计算的。然而,有时(我无法在某个实例中重现它)三角测量只能给我预期的面的一小部分。我实现了以下帮助程序函数

auto face_count = [](DelaunayTriangulation &triangulation)
{
std::size_t face_count = 0;
for (auto it = triangulation.finite_faces_begin(); it < triangulation.finite_faces_end(); it++) {
face_count ++;
}
return face_count;
};
auto is_correct = [&convex_hull_size, &face_count, &points](DelaunayTriangulation &triangulation)
{
return face_count(triangulation) != 2*points.size() - convex_hull_size - 2;
};

以计算计算三角测量的面数。在某些情况下,可以重新计算相同点上的三角测量,从而产生正确数量的三角形。然而,在其他情况下,我总是得到零三角形,这真的很烦人。

我的问题是,是否有人在使用 CGAL 时遇到过类似的错误,并且知道如何调试它。由于实例读取过程,提供最小的工作示例很困难。

编辑:

为清楚起见:以下代码

do
{
triangulation = DelaunayTriangulation();
triangulation.insert(points.begin(),points.end());
std::cout << "Calculated triangulation with " << face_count(triangulation) << " faces the correct amount is " << 2*points.size() - convex_hull_size - 2 << std::endl;
} while(is_correct(triangulation));

生成以下输出:

Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 11 faces the correct amount is 60
Calculated triangulation with 11 faces the correct amount is 60
Calculated triangulation with 11 faces the correct amount is 60
Calculated triangulation with 11 faces the correct amount is 60
Calculated triangulation with 11 faces the correct amount is 60
Calculated triangulation with 11 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 0 faces the correct amount is 60
Calculated triangulation with 60 faces the correct amount is 60

在某些情况下(但并非总是如此)。对于其他实例,我反复得到 0 个面,while 循环不会终止。

for (auto it = triangulation.finite_faces_begin(); it < triangulation.finite_faces_end(); it++)

应替换为

for (auto it = triangulation.finite_faces_begin(); it !=triangulation.finite_faces_end(); it++)