CGAL顶点可见性

时间:2019-05-24 03:58:49

标签: c++ cgal

我正在寻找从多边形的给定点可以看到的所有顶点。

例如,我有以下多边形:

Polygon_2(
  PointC2(2396, 5284)
  PointC2(2656, 2938)
  PointC2(4342, 102)
  PointC2(4120, 2278)
  PointC2(4384, 2988)
  PointC2(5136, 2280)
  PointC2(8598, 2632)
  PointC2(11738, 1550)
  PointC2(8898, 4170)
  PointC2(6634, 5416)
)

我想知道点PointC2(4342, 102)可以看到哪些顶点。

在查看CGAL时,我看到了Visability_2,我一直在尝试实施,但是有两个主要麻烦。

1)运行程序时,出现以下错误

  

CGAL错误:违反声明!

     

表情:!face-> is_unbounded()

2)如果我在多边形中选择一个点作为检查其可见性的点,则会得到segmentation fault

这是我尝试过的代码(主要来自上述链接中的示例):

    auto poly_it = polygon.vertices_begin();

    std::vector<Segment_2> segments;
    while(poly_it != polygon.vertices_end()) {
        if (poly_it+1 ==  polygon.vertices_end()) {
            segments.push_back(
                Segment_2(
                    *poly_it, 
                    *polygon.vertices_begin()
            ));
            break;
        }
        else
        {
            segments.push_back(
                Segment_2(
                    *poly_it, 
                    *(++poly_it)
            ));
        }
    }

    for(auto v : segments) std::cout << v << "\n";

    Point_2 start, pocket_begin, pocket_end;

    // Find beginning point

    poly_it = polygon.vertices_begin();
    for(; unordered_hull.find(start) != unordered_hull.end(); poly_it++) {}
    start = *poly_it;
    pocket_begin = start;

    Arrangement_2 env;

    CGAL::insert_non_intersecting_curves(env, segments.begin(), segments.end());

    Point_2 q(8898, 4170);   

    Arrangement_2::Face_const_handle * face;
    CGAL::Arr_naive_point_location<Arrangement_2> pl(env);
    CGAL::Arr_point_location_result<Arrangement_2>::Type obj = pl.locate(q);
    // The query point locates in the interior of a face
    face = boost::get<Arrangement_2::Face_const_handle> (&obj);

    // compute non regularized visibility area 
    // Define visibiliy object type that computes regularized visibility area
    Arrangement_2 regular_output;
    RSPV regular_visibility(env);
    regular_visibility.compute_visibility(q, *face, regular_output);
    std::cout << "Regularized visibility region of q has "
                << regular_output.number_of_edges()
                << " edges:" << std::endl;
    for (Edge_const_iterator eit = regular_output.edges_begin(); eit != regular_output.edges_end(); ++eit)
        std::cout << "[" << eit->source()->point() << " -> " << eit->target()->point() << "]" << std::endl;

这是什么意思?解决这个问题的任何帮助都很好。

0 个答案:

没有答案