Customizing CGAL Kernel with my own Point class(用我自己的 Point 类自定义 CGAL 内核)
问题描述
我想使用带有 CGAL 约束 delaunay 三角剖分的自定义 Point 类.但是,使用以下 MyPoint 类(其行为应该与 CGAL::Point_2 不完全相同?)我得到分段错误.如果我将 MyKernel 中的 Point_2 typedef 设置为 CGAL::Exact_predicates_inexact_constructions_kernel::Point_2,它会完美运行.我做错了什么?
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);
推荐答案
更改内核很棘手.这里发生的情况是,从三角剖分类来看,与内核相比唯一改变的是点类型,通过派生而来.这对于谓词函子来说已经足够了,但对于构造函子(例如 CDT 所需的交集)来说就不够了.
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.
我认为你有两个选择:
为 ConstrainedTriangulationTraits_2 适合您的类型.
使用 可扩展内核 应该做你想做的事情的机制.
Use the Extensible Kernel mechanism that is supposed to do what you want.
这篇关于用我自己的 Point 类自定义 CGAL 内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用我自己的 Point 类自定义 CGAL 内核


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01