【问题标题】:CGAL 2D APOLLONIUS diagram for Weighted Voronoi - How to generate and get the faces and vertices?加权 Voronoi 的 CGAL 2D APOLLONIUS 图 - 如何生成和获取面和顶点?
【发布时间】:2013-08-16 13:32:54
【问题描述】:

我正在尝试根据阿波罗图生成加权 voronoi。我正在使用 CGAL 库。我找不到如何从 apollonius 获取面和顶点的好例子。 我有以下类型定义:

typedef double                                                                  NT;
typedef CGAL::Cartesian< NT>                                                    KernelCartes;
typedef CGAL::Ray_2<KernelCartes>                                               Cartes_Ray;
typedef CGAL::Line_2<KernelCartes>                                              Cartes_Line;
typedef CGAL::Segment_2<KernelCartes>                                           Cartes_Segment;
typedef std::list<Cartes_Ray>                                                   Cartes_RayList;
typedef std::list<Cartes_Line>                                                  Cartes_LineList;
typedef std::list<Cartes_Segment>                                               Cartes_SegmentList;
typedef CGAL::Point_2<KernelCartes>                                             Cartes_Point;
typedef CGAL::Apollonius_graph_traits_2<KernelCartes>                           ApoTraits;
typedef CGAL::Apollonius_graph_2<ApoTraits>                                     Apo_Graph;
typedef Apo_Graph::Site_2                                                       Apo_Site;

在下面,我正在尝试创建 Apollonius 图。 WVD是加权voronoi图(Apo_Graph)。

    WVD.clear();
    double Weight;
    foreach(QPointF point,List_Nodes)
    {
        Weight = NewRandomNumber(1,10);
        Apo_Site k(Cartes_Point(point.x(),point.y()),Weight);
        WVD.insert(k);
    }

现在,我需要知道如何访问加权 voronoi 和生成的面(以及之后每个面的顶点)。

【问题讨论】:

    标签: c++ qt cgal


    【解决方案1】:

    最后我这样做了:

    typedef CGAL::Apollonius_graph_traits_2<Kernel_Exact>             APT;
    typedef CGAL::Apollonius_site_2<Kernel_Exact>                   Site_2_Apo;
    typedef Site_2_Apo::Point_2                                     Site_2_Point_2;
    typedef Site_2_Apo::Weight                                      Site_2_Weight;
    
    typedef CGAL::Apollonius_graph_traits_2<Kernel_Exact>                              AGT2_K;
    typedef CGAL::Apollonius_graph_2<AGT2_K>                                            AG2;
    typedef CGAL::Apollonius_graph_adaptation_traits_2<AG2>                            AG2_Trait;
    typedef CGAL::Apollonius_graph_caching_degeneracy_removal_policy_2<AG2>            AG2_Policy;
    typedef CGAL::Voronoi_diagram_2<AG2,AG2_Trait,AG2_Policy>                          VD_AG2;
    

    加载一些点:

    std::vector<Site_2_Apo> List_Nodes;
        for (int i = 0; i<= 100; i = i++)
        {
            for(int j = 0; j <= 100; j = j++)
            {
                List_Nodes.push_back(Site_2_Apo(Site_2_Point_2(i+NewRandomNumber(0,30),j+NewRandomNumber(0,30)),Site_2_Weight(NewRandomNumber(1,50))));
            }
        }
    

    其他:

    VD_AG2 VDA;      //Voronoi Apol 
    
        ///Voronoi Generation
        VDA.clear();
        VDA.insert(List_Nodes.begin(),List_Nodes.end());
    

    以及访问面和顶点:

      for(A_Bounded_faces_iterator f = VDA.bounded_faces_begin(); f != VDA.bounded_faces_end(); f++)
        {
    
            A_Ccb_halfedge_circulator ec_start = (f)->ccb();
            A_Ccb_halfedge_circulator ec = ec_start;
            poly.clear();
            do {
                x = ((A_Halfedge_handle)ec)->source()->point().x();
                y = ((A_Halfedge_handle)ec)->source()->point().y();
                poly.push_back(QPointF(x,y));
            } while ( ++ec != ec_start );        
            List_Poly.push_back(poly);
        }
    

    结果如下:

    http://i.stack.imgur.com/Esv8c.png

    【讨论】:

      【解决方案2】:

      模板类CGAL::Apollonius_graph_2 与CGAL 2D Delaunay 三角剖分共享其大部分API。该 API 总结在 concept DelaunayGraph_2 中。 CGAL::Apollonius_graph_2&lt;ApoTraits&gt; 是该概念的典范。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多