目前,我在使用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的一个给定向量,我在几个实例上运行代码,并且大多数情况下三角剖分是正确计算的。然而,有时(我不能在某一情况下再现)三角剖分只给我一小部分期望的面孔。我实现了以下帮助函数
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 faces,while循环不终止。
发布于 2019-04-24 12:42:26
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++)
https://stackoverflow.com/questions/55826846
复制相似问题