c++ - CGAL 不计算完整的 delaunay 三角剖分

标签 c++ cgal

我目前在使用 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 是给定的 Point vector 。我在多个实例上运行代码,大多数时候三角剖分计算正确。但是有时(我无法在某些情况下重现它)三角测量只给了我预期面孔的一小部分。我实现了以下辅助函数

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++)

关于c++ - CGAL 不计算完整的 delaunay 三角剖分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55826846/

相关文章:

geometry - (可能是无界的)凸多边形与半平面的交集

c++ - 在 CGAL 中使用时从 geomview 窗口中删除几何对象

配置:错误:找不到 CGAL 库

c++ - 从源代码构建 CGAL 库的说明

c++ - 在 g++ 中使用版本脚本导出 c++ 构造函数

c++ - Clang 为使用的类型别名发出 "unused type alias"警告

c++ - 警告匿名命名空间在结构内部使用函数指针

c++ - 如何在c中调用一个dll文件。我想向它传输一个xml文件

android - Android 上有类似 Linux free 命令的东西吗?

c++ - CGAL - boost 创建无向图