如何打印 Delaunay 图的边?

How to print Edges of Delaunay Graph?

接着:,我现在有:

#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;
                           ^

您可以像这样打印形成边缘的站点:

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;
}