如何打印Delaunay Graph的边缘?

时间:2016-05-25 21:33:59

标签: c++ computational-geometry cgal delaunay voronoi

在此之后:How to print the faces of a Voronoi diagram?,我现在有:

#include <iostream>
#include <fstream>
#include <cassert>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Segment_Delaunay_graph_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_policies_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;

int main() {

    std::ifstream ifs("data.cin");
    assert( ifs );
    DT         vd;
    DT::Site_2 site;
    // read the sites from the stream and insert them in the diagram
    while ( ifs >> site ) { vd.insert( site ); }
    ifs.close();
    // validate the diagram
    assert( vd.is_valid(true, 1) );
    std::cout << std::endl << std::endl;
    // Iterate over edges
    DT::Finite_edges_iterator eit = vd.finite_edges_begin();
    for (int k = 1; eit != vd.finite_edges_end(); ++eit, ++k) {
        DT::Edge e = *eit;
        //std::cout << e << std::endl;
    }
}

但是,无法打印边缘(使用cout)。怎么做?

以下是另一次尝试的错误:

/home/gsamaras/CGAL-4.7/code/DelaunayTOvoronoi/delTovor.cpp:30:27: error: ‘CGAL::Triangulation_ds_edge_iterator_2<CGAL::Triangulation_data_structure_2<CGAL::Segment_Delaunay_graph_vertex_base_2<CGAL::Segment_Delaunay_graph_storage_traits_2<CGAL::Segment_Delaunay_graph_traits_2<CGAL::Epick> >, CGAL::Triangulation_ds_vertex_base_2<void> >, CGAL::Segment_Delaunay_graph_face_base_2<CGAL::Segment_Delaunay_graph_traits_2<CGAL::Epick>, CGAL::Triangulation_ds_face_base_2<void> > >, true>::Edge’ has no member named ‘site’
         std::cout << eit->site() << std::endl;
                           ^

1 个答案:

答案 0 :(得分:1)

您可以打印形成边缘的网站,如下所示:

for (int k = 1; eit != vd.finite_edges_end(); ++eit, ++k) {
    DT::Edge e = *eit;
    std::cout << "k = " << k << std::endl;
    if ( vd.is_infinite(e.first->vertex( vd.ccw(e.second) )) )
        std::cout << "infinite\n";
    else
        std::cout << e.first->vertex( vd.ccw(e.second) )->site() << std::endl;
    if ( vd.is_infinite(e.first->vertex( vd.cw(e.second) )) )
        std::cout << "infinite\n";
    else
        std::cout << e.first->vertex( vd.cw(e.second) )->site() << std::endl;
    if ( vd.is_infinite(e.first->vertex( e.second )) )
        std::cout << "infinite\n";
    else
        std::cout << e.first->vertex( e.second )->site() << std::endl;
    if ( vd.is_infinite(vd.tds().mirror_vertex(e.first, e.second) ) )
        std::cout << "infinite\n";
    else
        std::cout << vd.tds().mirror_vertex(e.first, e.second)->site() << std::endl;
}