gpt4 book ai didi

c++ - 如何打印 Delaunay 图的边?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:13:14 25 4
gpt4 key购买 nike

接着是: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;
^

最佳答案

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

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

关于c++ - 如何打印 Delaunay 图的边?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37447998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com