Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

c++ - Customizing CGAL Kernel with my own Point class

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...