使用我自己的 Point 类自定义 CGAL 内核

发布于 2024-08-24 10:05:24 字数 1266 浏览 3 评论 0原文

我想使用带有 CGAL 约束 delaunay 三角剖分的自定义 Point 类。但是,使用以下 MyPoint 类(其行为应该与 CGAL::Point_2 完全相同,不是吗?),我遇到了分段错误。如果我将 MyKernel 内的 Point_2 typedef 设置为 CGAL::Exact_predicates_inexact_constructions_kernel::Point_2,它会完美地工作。我做错了什么?

template<class P>
struct MyPoint : public P {
    MyPoint() : P() {}
    MyPoint(const MyPoint& p) : P(p) {}

    MyPoint( int x, int y) : P(x,y) {}
    MyPoint( double x, double y) : P(x,y) {}
};

struct MyKernel : CGAL::Exact_predicates_inexact_constructions_kernel {
    typedef MyPoint<CGAL::Exact_predicates_inexact_constructions_kernel::Point_2> Point_2;
};

typedef MyKernel K;

typedef CGAL::Triangulation_vertex_base_2<K>                     Vb;
typedef CGAL::Constrained_triangulation_face_base_2<K>           Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb>              TDS;
typedef CGAL::Exact_predicates_tag                               Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> CDT;
typedef CDT::Point          Point;

最后一行出现段错误的代码:

CDT cdt;
Point cgal_p1;
Point cgal_p2;
cgal_p1 = Point(p1[1],p1[2]);
cgal_p2 = Point(p2[1],p2[2]);
cdt.insert_constraint(cgal_p1,
                      cgal_p2);

I would like to use a custom Point class with the CGAL constrained delaunay triangulation. However, with the following MyPoint class (which should behave the exact same as a CGAL::Point_2 no?) I get segmentation faults. It works perfectly if I set the Point_2 typedef inside MyKernel to CGAL::Exact_predicates_inexact_constructions_kernel::Point_2. What am I doing wrong?

template<class P>
struct MyPoint : public P {
    MyPoint() : P() {}
    MyPoint(const MyPoint& p) : P(p) {}

    MyPoint( int x, int y) : P(x,y) {}
    MyPoint( double x, double y) : P(x,y) {}
};

struct MyKernel : CGAL::Exact_predicates_inexact_constructions_kernel {
    typedef MyPoint<CGAL::Exact_predicates_inexact_constructions_kernel::Point_2> Point_2;
};

typedef MyKernel K;

typedef CGAL::Triangulation_vertex_base_2<K>                     Vb;
typedef CGAL::Constrained_triangulation_face_base_2<K>           Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb>              TDS;
typedef CGAL::Exact_predicates_tag                               Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> CDT;
typedef CDT::Point          Point;

Code which segfaults at last line:

CDT cdt;
Point cgal_p1;
Point cgal_p2;
cgal_p1 = Point(p1[1],p1[2]);
cgal_p2 = Point(p2[1],p2[2]);
cdt.insert_constraint(cgal_p1,
                      cgal_p2);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗳卜坏 2024-08-31 10:05:24

更改内核很棘手。这里发生的事情是,从三角测量类来看,与内核相比唯一改变的是点类型,通过从它派生。这对于谓词函子来说已经足够了,但对于构​​造函子来说就不够了,比如 CDT 所需的交集。

我认为你有两个选择:

  1. ConstrainedTriangulationTraits_2 适合您的类型。

  2. 使用可扩展内核应该执行您想要的操作的机制。

Changing the kernel is tricky. What happens here is that, seen from the triangulation class, the only thing that changes compared to the kernel is the point type, by deriving from it. This can be good enough for predicates functors, but not for constructions functors, like the intersection that is required by the CDT.

I think you have two options :

  1. Write the full traits interface for ConstrainedTriangulationTraits_2 for your types.

  2. Use the Extensible Kernel mechanism that is supposed to do what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文