【问题标题】:Voronoi Diagram using CGAL: extract only edge points (convex hull)使用 CGAL 的 Voronoi 图:仅提取边缘点(凸包)
【发布时间】:2017-09-08 09:28:25
【问题描述】:

我想使用 Voronoi 图提取边缘点(点位于凸包边界的边缘)。我知道 unbounded 单元格包含边界站点点,但如何使用迭代器访问该信息?

解决方案

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

【问题讨论】:

    标签: c++ computational-geometry cgal voronoi


    【解决方案1】:

    阅读CGAL 2D Delaunay Triangulation: How to get edges as vertex id pairs,并牢记Voronoi 和Delaunay 之间的关系,请查看example

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

    如果这不能回答您的问题,请从中获得灵感并尝试一下。

    【讨论】:

      猜你喜欢
      • 2011-05-14
      • 2014-06-29
      • 2017-03-17
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      相关资源
      最近更新 更多