Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGAL Visibility computes wrong visibility polygon (Simple Polygon Visibility algorithm)

Tags:

c++

cgal

I have to compute the visibility polygons of some vertices of a given polygon. I'm using CGALs visibility computation library, but for this example polygon and its 35th vertex (and a few more points), the following (obviously wrong) result is computed, where one edge of the visibility polygon intersects an edge of the original one.

I used the following code for construction:

typedef CGAL::Arrangement_2<CGAL::Arr_segment_traits_2<Epeck>> Arrangement_2;

Arrangement_2 polygon_arr;
CGAL::insert(polygon_arr, polygon.edges_begin(), polygon.edges_end());

Arrangement_2 vp_output;             
CGAL::Simple_polygon_visibility_2<Arrangement_2, CGAL::Tag_false> non_regular_visibility(polygon_arr);


// ci is vertex circulator
Arrangement_2::Halfedge_const_handle preceding_he =
    std::find_if(polygon_arr.halfedges_begin(),polygon_arr.halfedges_end(),
        [&ci](const typename Arrangement_2::Halfedge &e) {
            return !e.face()->is_unbounded() && e.target()->point() == *ci;
         }
);

non_regular_visibility.compute_visibility(*ci, preceding_he, vp_output);
for (auto eit = vp_output.edges_begin(); eit != vp_output.edges_end(); ++eit)
{
    segments.push_back(eit->curve());
}

Is that a bug in CGALs implementation or is it a bug in my code?

Edit: Changing the algorithm to CGAL::Triangular_expansion_visibility_2<Arrangement_2> tev(polygon_arr); (l. 7) solves the problem, so it's probably a bug in CGAL.

like image 698
Yannic Avatar asked Dec 06 '25 19:12

Yannic


1 Answers

You are right, it is a bug in CGAL. I created an issue for this : https://github.com/CGAL/cgal/issues/4289

like image 53
mgimeno Avatar answered Dec 08 '25 11:12

mgimeno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!