我目前在使用 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/