简体   繁体   English

使用CGAL的Voronoi图:仅提取边缘点(凸包)

[英]Voronoi Diagram using CGAL: extract only edge points (convex hull)

I want to extract edge points (points lie on an edge of the boundary of the convex hull) using Voronoi diagram. 我想使用Voronoi图提取边缘点(点位于凸包边界的边缘)。 I know that an unbounded cell contains a boundary site point, but how can I access to that information using iterators? 我知道无界单元格包含边界站点,但是如何使用迭代器访问该信息呢?

Solution

VD vd;
//initialise your voronoi diagram
VD::Face_iterator it = vd.faces_begin(), beyond = vd.faces_end();
for (int f = 0; it != beyond; ++f, ++it) 
{
  std::cout << "Face " << f << ": \n";
  if (it->is_unbounded()) 
  {
    // it's a boundary point
  }
}

Read CGAL 2D Delaunay Triangulation: How to get edges as vertex id pairs , and having in mind the relation between Voronoi and Delaunay check this example : 阅读CGAL 2D Delaunay三角剖分:如何将边缘作为顶点id对 ,并考虑到Voronoi和Delaunay之间的关系,请检查此示例

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K>  Triangulation;
typedef Triangulation::Edge_iterator  Edge_iterator;
typedef Triangulation::Point          Point;
int main( )
{
  std::ifstream in("data/voronoi.cin");
  std::istream_iterator<Point> begin(in);
  std::istream_iterator<Point> end;
  Triangulation T;
  T.insert(begin, end);
  int ns = 0;
  int nr = 0;
  Edge_iterator eit =T.edges_begin();
  for ( ; eit !=T.edges_end(); ++eit) {
    CGAL::Object o = T.dual(eit);
    if (CGAL::object_cast<K::Segment_2>(&o)) {++ns;}
    else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;}
  }
  std::cout << "The Voronoi diagram has " << ns << " finite edges "
        << " and " << nr << " rays" << std::endl;
  return 0;
}

If this doesn't answer your question, then get inspired by it and play around. 如果这不能回答你的问题,那就得到它的启发和玩耍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM