1 
2 #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
3 #include <CGAL/Triangular_expansion_visibility_2.h>
4 #include <CGAL/Arr_segment_traits_2.h>
5 #include <CGAL/Arrangement_2.h>
6 #include <iostream>
7 #include <vector>
8 
9 // Define the used kernel and arrangement
10 typedef CGAL::Exact_predicates_exact_constructions_kernel       Kernel;
11 typedef Kernel::Point_2                                         Point_2;
12 typedef Kernel::Segment_2                                       Segment_2;
13 typedef CGAL::Arr_segment_traits_2<Kernel>                      Traits_2;
14 typedef CGAL::Arrangement_2<Traits_2>                           Arrangement_2;
15 typedef Arrangement_2::Halfedge_const_handle                    Halfedge_const_handle;
16 typedef Arrangement_2::Face_handle                              Face_handle;
17 
18 // Define the used visibility class
19 typedef CGAL::Triangular_expansion_visibility_2<Arrangement_2>  TEV;
20 
main()21 int main() {
22   // Defining the input geometry
23   Point_2 p1(1,2), p2(12, 3), p3(19,-2), p4(12,6), p5(14,14), p6( 9,5);
24   Point_2 h1(8,3), h2(10, 3), h3( 8, 4), h4(10,6), h5(11, 6), h6(11,7);
25   std::vector<Segment_2> segments;
26   segments.push_back(Segment_2(p1,p2));
27   segments.push_back(Segment_2(p2,p3));
28   segments.push_back(Segment_2(p3,p4));
29   segments.push_back(Segment_2(p4,p5));
30   segments.push_back(Segment_2(p5,p6));
31   segments.push_back(Segment_2(p6,p1));
32 
33   segments.push_back(Segment_2(h1,h2));
34   segments.push_back(Segment_2(h2,h3));
35   segments.push_back(Segment_2(h3,h1));
36   segments.push_back(Segment_2(h4,h5));
37   segments.push_back(Segment_2(h5,h6));
38   segments.push_back(Segment_2(h6,h4));
39 
40   // insert geometry into the arrangement
41   Arrangement_2 env;
42   CGAL::insert_non_intersecting_curves(env,segments.begin(),segments.end());
43 
44   //Find the halfedge whose target is the query point.
45   //(usually you may know that already by other means)
46   Point_2 query_point = p4;
47   Halfedge_const_handle he = env.halfedges_begin();
48   while (he->source()->point() != p3 || he->target()->point() != p4)
49     he++;
50 
51   //visibility query
52   Arrangement_2 output_arr;
53   TEV tev(env);
54   Face_handle fh = tev.compute_visibility(query_point, he, output_arr);
55 
56   //print out the visibility region.
57   std::cout << "Regularized visibility region of q has "
58             << output_arr.number_of_edges()
59             << " edges." << std::endl;
60 
61   std::cout << "Boundary edges of the visibility region:" << std::endl;
62   Arrangement_2::Ccb_halfedge_circulator curr = fh->outer_ccb();
63   std::cout << "[" << curr->source()->point() << " -> " << curr->target()->point() << "]" << std::endl;
64   while (++curr != fh->outer_ccb())
65     std::cout << "[" << curr->source()->point() << " -> " << curr->target()->point() << "]"<< std::endl;
66   return 0;
67 }
68