首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何打印Delaunay图的边?

如何打印Delaunay图的边?
EN

Stack Overflow用户
提问于 2016-05-25 13:33:59
回答 1查看 200关注 0票数 2

下面是:How to print the faces of a Voronoi diagram?,我现在有:

代码语言:javascript
运行
AI代码解释
复制
#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)简单地打印边缘。该怎么做呢?

下面是另一次尝试中的错误:

代码语言:javascript
运行
AI代码解释
复制
/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;
                           ^
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-25 16:31:16

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

代码语言:javascript
运行
AI代码解释
复制
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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37447998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档