我使用Constrained_Delaunay_triangulation_2来获得一组简单的点和约束。当我遍历每个边并在它们上调用is_constrained()时,是否保证使用insert_constraint()提供的约束段返回?我期望如果segment(5 8)(2 5)是一个约束,如果我查询该边,它将是一个受约束的边。
在下面的示例中,我提供了5个约束,但是我收到了6个边缘约束。这可能是由于近似误差造成的吗?感谢。
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 CGALPoint;
typedef K::Segment_2 CGALSegment;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, CGAL::Default,
CGAL::No_intersection_tag> CDT;
typedef CDT::Vertex_handle Vertex_handle;
...
CDT* cdt = new CDT();
Vertex_handle v0 = cdt->insert(CGALPoint(5, 8));
Vertex_handle v1 = cdt->insert(CGALPoint(0, 4));
Vertex_handle v2 = cdt->insert(CGALPoint(1, 9));
Vertex_handle v3 = cdt->insert(CGALPoint(0, 1));
Vertex_handle v4 = cdt->insert(CGALPoint(10, 3));
Vertex_handle v5 = cdt->insert(CGALPoint(1, 1));
Vertex_handle v6 = cdt->insert(CGALPoint(4, 7));
Vertex_handle v7 = cdt->insert(CGALPoint(3, 9));
Vertex_handle v8 = cdt->insert(CGALPoint(2, 5));
Vertex_handle v9 = cdt->insert(CGALPoint(4, 10));
cdt->insert_constraint(v0, v8); // (5 8) (2 5)
cdt->insert_constraint(v0, v3); // (5 8) (0 1)
cdt->insert_constraint(v1, v9); // (0 4) (4 10)
cdt->insert_constraint(v1, v3); // (0 4) (0 1)
cdt->insert_constraint(v6, v3); // (4 7) (0 1)
for (CDT::Edge_iterator eit = cdt->edges_begin(); eit != cdt->edges_end(); ++eit) {
CDT::Edge e = *eit;
if (cdt->is_constrained(e))
std::cout << "Constraint ";
else
std::cout << "Unconstraint ";
CGALSegment s = cdt->segment(e);
const CGALPoint& p1 = s.point(0);
const CGALPoint& p2 = s.point(1);
std::cout << "(" << p1 << ") (" << p2 << ")" << std::endl;
}
输出(为了便于阅读而重新订购)
Constraint (4 10) (0 4)
Constraint (0 1) (0 4)
Constraint (2 5) (4 7)
Constraint (0 1) (4 7)
Constraint (5 8) (0 1)
Constraint (4 7) (5 8)
Unconstraint (0 4) (1 9)
Unconstraint (0 4) (2 5)
Unconstraint (2 5) (4 10)
Unconstraint (4 10) (1 9)
Unconstraint (1 9) (3 9)
Unconstraint (3 9) (4 10)
Unconstraint (1 1) (0 1)
Unconstraint (4 10) (10 3)
Unconstraint (4 7) (4 10)
Unconstraint (10 3) (1 1)
Unconstraint (0 4) (3 9)
Unconstraint (5 8) (4 10)
Unconstraint (5 8) (10 3)
Unconstraint (5 8) (1 1)
Unconstraint (0 1) (2 5)