如何打印Voronoi图的面? [英] How to print the faces of a Voronoi diagram?

查看:234
本文介绍了如何打印Voronoi图的面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码段落假设输入是点数,而不是线段(错误)。

Code bellow assumes input is points, not line segments (which is wrong).

=http://doc.cgal.org/latest/Voronoi_diagram_2/index.html#secvda2examples =nofollow> 2D Voronoi图适配器示例,我想写一个程序,其中输入行

Following this 2D Voronoi Diagram Adaptor example, I am trying to write a program which takes as input line segments and prints the vertices of the faces of the Voronoi diagram.

这里是我的尝试(保持includes / typedefs的例子):

Here is my attempt (keeping includes/typedefs of the example):

// standard includes
#include <iostream>
#include <fstream>
#include <cassert>
// includes for defining the Voronoi diagram adaptor
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Delaunay_triangulation_adaptation_traits_2.h>
#include <CGAL/Delaunay_triangulation_adaptation_policies_2.h>
// typedefs for defining the adaptor
typedef CGAL::Exact_predicates_inexact_constructions_kernel                  K;
typedef CGAL::Delaunay_triangulation_2<K>                                    DT;
typedef CGAL::Delaunay_triangulation_adaptation_traits_2<DT>                 AT;
typedef CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2<DT> AP;
typedef CGAL::Voronoi_diagram_2<DT,AT,AP>                                    VD;
// typedef for the result type of the point location
typedef AT::Site_2                    Site_2;
typedef AT::Point_2                   Point_2;
typedef VD::Locate_result             Locate_result;
typedef VD::Vertex_handle             Vertex_handle;
typedef VD::Face_handle               Face_handle;
typedef VD::Halfedge_handle           Halfedge_handle;
typedef VD::Ccb_halfedge_circulator   Ccb_halfedge_circulator;

int main()
{
    std::ifstream ifs("data.cin");
    assert( ifs );
    VD vd;
    Site_2 t;
    while ( ifs >> t ) { vd.insert(t); }
    ifs.close();
    assert( vd.is_valid() );
    Face_handle* f = boost::get<Face_handle>(vd);
    std::cout << "Exiting...\n";
    return 0;
}

这会收到编译错误:

/home/gsamaras/CGAL-4.7/code/voronoi_adaptor/voronoi_adaptor.cpp:46:48: error: no matching function for call to ‘get(VD&)’
     Face_handle* f = boost::get<Face_handle>(vd);
                                                ^
/home/gsamaras/CGAL-4.7/code/voronoi_adaptor/voronoi_adaptor.cpp:46:48: note: candidates are:
In file included from /usr/include/boost/variant.hpp:22:0,
                 from /home/gsamaras/CGAL-4.7/code/voronoi_adaptor/../../include/CGAL/Object.h:36,
                 from /home/gsamaras/CGAL-4.7/code/voronoi_adaptor/../../include/CGAL/kernel_basic.h:33,
                 from /home/gsamaras/CGAL-4.7/code/voronoi_adaptor/../../include/CGAL/basic.h:46,
                 from /home/gsamaras/CGAL-4.7/code/voronoi_adaptor/../../include/CGAL/Cartesian/Cartesian_base.h:28,
                 from /home/gsamaras/CGAL-4.7/code/voronoi_adaptor/../../include/CGAL/Simple_cartesian.h:28,
                 from /home/gsamaras/CGAL-4.7/code/voronoi_adaptor/../../include/CGAL/Exact_predicates_inexact_constructions_kernel.h:28,
                 from /home/gsamaras/CGAL-4.7/code/voronoi_adaptor/voronoi_adaptor.cpp:6:
/usr/include/boost/variant/get.hpp:141:1: note: template<class U, class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13, class T14, class T15, class T16, class T17, class T18, class T19> typename boost::add_pointer<T>::type boost::get(boost::variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>*)
 get(
 ^
/usr/include/boost/variant/get.hpp:141:1: note:   template argument deduction/substitution failed:
/home/gsamaras/CGAL-4.7/code/voronoi_adaptor/voronoi_adaptor.cpp:46:48: note:   mismatched types ‘boost::variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>*’ and ‘CGAL::Voronoi_diagram_2<CGAL::Delaunay_triangulation_2<CGAL::Epick>, CGAL::Delaunay_triangulation_adaptation_traits_2<CGAL::Delaunay_triangulation_2<CGAL::Epick> >, CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2<CGAL::Delaunay_triangulation_2<CGAL::Epick> > >’
     Face_handle* f = boost::get<Face_handle>(vd);
                                                ^
...


推荐答案

Panagiotis Mike给了我答案:

Panagiotis Mike gave me the answer:

// standard includes
#include <iostream>
#include <string>
#include <fstream>
#include <cassert>
// includes for defining the Voronoi diagram adaptor
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Segment_Delaunay_graph_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_policies_2.h>
#include <CGAL/Segment_2.h>
#include <CGAL/Segment_Delaunay_graph_traits_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Segment_Delaunay_graph_traits_2<K> Gt;
typedef CGAL::Segment_Delaunay_graph_2<Gt> DT;
typedef CGAL::Segment_Delaunay_graph_adaptation_traits_2<DT> AT;
typedef CGAL::Segment_Delaunay_graph_degeneracy_removal_policy_2<DT> AP;
typedef CGAL::Voronoi_diagram_2<DT, AT, AP> VD;
typedef AT::Site_2                    Site_2;
typedef VD::Face_handle               Face_handle;

int main()
{
    std::ifstream ifs("data.cin");
    assert( ifs );
    VD vd;
    Site_2 t;
    while ( ifs >> t ) { vd.insert(t); }
    ifs.close();
    assert( vd.is_valid() );
    std::cout << vd.number_of_faces() << std::endl;
    VD::Face_iterator it = vd.faces_begin(),       
    beyond = vd.faces_end();
    for (int f=0; it != beyond; ++f, ++it) {
        std::cout << "Face" << f << ": \n";
        VD::Ccb_halfedge_circulator hec = it->ccb();
        do {
            VD::Halfedge_handle heh = static_cast<VD::Halfedge_handle>(hec);
                if (heh->has_target())
                    std::cout << heh->target()->point() << "\n";
                else
                    std::cout << "point at infinity\n";

        } while (++hec != it->ccb());
        std::cout << std::endl;
    }  
    return 0;
}

这篇关于如何打印Voronoi图的面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆