【问题标题】:CGAL is not computing a complete delaunay triangulationCGAL 没有计算完整的德劳内三角剖分
【发布时间】:2019-04-24 09:32:31
【问题描述】:

我目前在使用 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());

其中pointsPoints 的给定向量。我在几个实例上运行代码,并且大部分时间三角剖分计算正确。但是有时(我无法在某些情况下重现它)三角剖分只给了我预期面孔的一小部分。我实现了以下辅助函数

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 循环不会终止。

【问题讨论】:

  • 我会检查 triangulation.dimension() 是否返回 2,如果不是这种情况,可能会解释为什么您的 is_correct() 函数返回 false
  • 我的三角测量维度是-1。我必须手动设置吗?
  • 这意味着三角剖分是空的 IIRC(没有插入点)。
  • 哦,你是对的,我很抱歉我把结果打印在错误的行。插入点后,三角剖分维度为 2,但三角剖分仍然不完整:Triangulation dimension 2 Calculated triangulation with 12 faces the correct amount is 61
  • 在你的 cout 中使用 std::set&lt;Point&gt;(points.begin(), points.end()).size() 而不是 points.size()

标签: c++ cgal


【解决方案1】:

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

应该替换为

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

【讨论】:

    猜你喜欢
    • 2012-04-27
    • 2020-05-12
    • 1970-01-01
    • 2022-01-09
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2013-11-18
    相关资源
    最近更新 更多