【发布时间】:2009-05-12 23:57:26
【问题描述】:
如何在 CGAL 中的三角剖分上下文中使用三角剖分的继承类?
基本上我有以下代码:
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_with_info_2<int,K> Vb;
typedef CGAL::Triangulation_face_base_with_info_2<int,K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Delaunay;
typedef CGAL::Triangulation_2<K,Tds> Triangulation;
typedef Triangulation::Point Point;
...
Triangulation *t = new Delaunay;
...
// x and y are properly defined and instantiated
t->insert(Point(x,y));
当然,Delaunay_triangulation_2 继承自 Triangulation_2
所以,当我执行此代码时,链接是针对 Triangulation_2 类完成的,换句话说,它不执行 delaunay 三角剖分,而是执行普通三角剖分(执行父类方法而不是子方法) .
我认为这是因为 Triangulation_2 的插入方法未声明为虚拟,因此重新定义将不起作用。
你知道解决这个问题的方法吗?也许使用 Constrained_triangulation_2 和 Constrained_delaunay_triangulation_2? (这些类定义了一些虚拟方法,但我已经阅读了源代码,我认为如果不添加显式约束就不能使用它们)
有什么想法吗?
【问题讨论】: