【问题标题】:Customizing CGAL Kernel with my own Point class用我自己的 Point 类自定义 CGAL 内核
【发布时间】:2010-03-10 15:56:44
【问题描述】:

我想使用带有 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);

【问题讨论】:

    标签: c++ segmentation-fault cgal


    【解决方案1】:

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

    我认为你有两个选择:

    1. 为您的类型编写ConstrainedTriangulationTraits_2 的完整特征接口。

    2. 使用应该做你想做的事的Extensible Kernel机制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 2013-06-21
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      相关资源
      最近更新 更多