mirror of https://github.com/CGAL/cgal
add a example
This commit is contained in:
parent
970b9a3401
commit
bd1d9bd828
|
|
@ -1,3 +1,4 @@
|
|||
/*!
|
||||
\example Visibility_2/simple_polygon_visibility_2.cpp
|
||||
\example Visibility_2/general_polygon_example.cpp
|
||||
*/
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
|
|
@ -72,6 +72,13 @@ The following example shows how to obtain the regularized and non-regularized vi
|
|||
Two different visibility regions in the example above.
|
||||
\cgalFigureEnd
|
||||
|
||||
\section general_polygon_example Example of Visibility in a Polygon with Holes
|
||||
The following example shows how to obtain the regularized visibility region by model `Triangular_expansion_visibility_2`. The query point \f$ q \f$ is on a vertex.
|
||||
\cgalExample{Visibility_2/general_polygon_example.cpp}
|
||||
\cgalFigureBegin{general_polygon, general_polygon_example.png}
|
||||
The visibility region of \f$ q \f$ in a polygon with hole.
|
||||
\cgalFigureEnd
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
#include <CGAL/basic.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Gmpq.h>
|
||||
#include <CGAL/Arr_segment_traits_2.h>
|
||||
#include <CGAL/Arrangement_2.h>
|
||||
#include <CGAL/test_model_methods.h>
|
||||
#include <CGAL/test_utils.h>
|
||||
#include <CGAL/Triangular_expansion_visibility_2_.h>
|
||||
#include <CGAL/test_utils.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
typedef CGAL::Gmpq Number_type;
|
||||
typedef CGAL::Cartesian<Number_type> Kernel;
|
||||
typedef Kernel::Point_2 Point_2;
|
||||
typedef Kernel::Segment_2 Segment_2;
|
||||
typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2;
|
||||
typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;
|
||||
typedef Arrangement_2::Vertex_const_handle Vertex_const_handle;
|
||||
typedef Arrangement_2::Halfedge_const_handle Halfedge_const_handle;
|
||||
typedef Arrangement_2::Face_handle Face_handle;
|
||||
typedef CGAL::Triangular_expansion_visibility_2<Arrangement_2, CGAL::Tag_true>
|
||||
TEV;
|
||||
int main() {
|
||||
Point_2 p1(1, 2), p2(12, 3), p3(19, -2), p4(12, 6), p5(14, 14), p6(9, 5);
|
||||
Point_2 h1(8,3), h2(10, 3), h3(8, 4), h4(10, 6), h5(11, 6), h6(11, 7);
|
||||
Segment_2 s[12];
|
||||
s[0] = Segment_2(p1, p2);
|
||||
s[1] = Segment_2(p2, p3);
|
||||
s[2] = Segment_2(p3, p4);
|
||||
s[3] = Segment_2(p4, p5);
|
||||
s[4] = Segment_2(p5, p6);
|
||||
s[5] = Segment_2(p6, p1);
|
||||
|
||||
s[6] = Segment_2(h1, h2);
|
||||
s[7] = Segment_2(h2, h3);
|
||||
s[8] = Segment_2(h3, h1);
|
||||
s[9] = Segment_2(h4, h5);
|
||||
s[10] = Segment_2(h5, h6);
|
||||
s[11] = Segment_2(h6, h4);
|
||||
Arrangement_2 env;
|
||||
CGAL::insert_curves(env, &s[0], &s[12]);
|
||||
//find the halfedge whose target is the query point.
|
||||
Point_2 query_point = p4;
|
||||
Halfedge_const_handle he = env.halfedges_begin();
|
||||
while (he->source()->point() != p3 || he->target()->point() != p4)
|
||||
he++;
|
||||
//visibility query
|
||||
Arrangement_2 output_arr;
|
||||
TEV tev(env);
|
||||
Face_handle fh = tev.compute_visibility(query_point, he, output_arr);
|
||||
//print out the visibility region.
|
||||
std::cout << "Regularized visibility region of q has "
|
||||
<< output_arr.number_of_edges()
|
||||
<< " edges." << std::endl;
|
||||
Arrangement_2::Ccb_halfedge_circulator curr = fh->outer_ccb();
|
||||
std::cout << "Traverse the face of the visibility region." << std::endl;
|
||||
std::cout << "[" << curr->curve() << "]"<< std::endl;
|
||||
while (++curr != fh->outer_ccb())
|
||||
std::cout << "[" << curr->curve() << "]" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -2,9 +2,7 @@
|
|||
#include <CGAL/Arrangement_2.h>
|
||||
#include <CGAL/Arr_segment_traits_2.h>
|
||||
#include <CGAL/Simple_polygon_visibility_2.h>
|
||||
#include <CGAL/Point_2.h>
|
||||
#include <CGAL/Arr_naive_point_location.h>
|
||||
#include <CGAL/Segment_2.h>
|
||||
#include <istream>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
|
|
@ -12,6 +10,13 @@ typedef Kernel::Point_2 Point_2;
|
|||
typedef Kernel::Segment_2 Segment_2;
|
||||
typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2;
|
||||
typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;
|
||||
typedef Arrangement_2::Edge_const_iterator Edge_const_iterator;
|
||||
typedef Arrangement_2::Face_handle Face_handle;
|
||||
typedef Arrangement_2::Ccb_halfedge_circulator Ccb_halfedge_circulator;
|
||||
typedef CGAL::Simple_polygon_visibility_2<Arrangement_2, CGAL::Tag_false>
|
||||
NSPV;
|
||||
typedef CGAL::Simple_polygon_visibility_2<Arrangement_2, CGAL::Tag_true>
|
||||
RSPV;
|
||||
|
||||
int main() {
|
||||
//create environment
|
||||
|
|
@ -33,14 +38,28 @@ int main() {
|
|||
CGAL::assign(face, obj);
|
||||
//visibility query
|
||||
Arrangement_2 non_regular_output;
|
||||
CGAL::Simple_polygon_visibility_2<Arrangement_2, CGAL::Tag_false> non_regular_visibility(env);
|
||||
non_regular_visibility.visibility_region(query_point, face, non_regular_output);
|
||||
std::cout<<"Non-regularized visibility region of p has "<<non_regular_output.number_of_vertices()<<" vertices."<<std::endl;
|
||||
|
||||
NSPV non_regular_visibility(env);
|
||||
Face_handle non_regular_fh = non_regular_visibility.compute_visibility(query_point, face, non_regular_output);
|
||||
std::cout << "Non-regularized visibility region of q has "
|
||||
<< non_regular_output.number_of_edges()
|
||||
<< " edges:" << std::endl;
|
||||
for (Edge_const_iterator eit = non_regular_output.edges_begin(); eit != non_regular_output.edges_end(); ++eit)
|
||||
std::cout << "[" << eit->curve() << "]" << std::endl;
|
||||
Arrangement_2 regular_output;
|
||||
CGAL::Simple_polygon_visibility_2<Arrangement_2, CGAL::Tag_true> regular_visibility(env);
|
||||
regular_visibility.visibility_region(query_point, face, regular_output);
|
||||
std::cout<<"Regularized visibility region of p has "<<regular_output.number_of_vertices()<<" vertices."<<std::endl;
|
||||
RSPV regular_visibility(env);
|
||||
Face_handle regular_fh = regular_visibility.compute_visibility(query_point, face, regular_output);
|
||||
Ccb_halfedge_circulator curr = regular_fh->outer_ccb();
|
||||
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->curve() << "]" << std::endl;
|
||||
|
||||
//For a regular face, we can also get its whole boundary by traversing its outer CCB.
|
||||
std::cout << "Traverse the face of the regularized visibility region:" << std::endl;
|
||||
std::cout << "[" << curr->curve() << "]"<< std::endl;
|
||||
while (++curr != regular_fh->outer_ccb())
|
||||
std::cout << "[" << curr->curve() << "]" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public:
|
|||
Naive_visibility_2(const Arrangement_2 &arr):arr_in(arr), attach_tag(true) {}
|
||||
Naive_visibility_2(): attach_tag(false) {}
|
||||
|
||||
Face_handle visibility_region(const Point_2 &q, const Halfedge_const_handle e, Arrangement_2 &out_arr) {
|
||||
Face_handle compute_visibility(const Point_2 &q, const Halfedge_const_handle e, Arrangement_2 &out_arr) {
|
||||
Arrangement_2 arrc = arr_in ; //copy of arr;
|
||||
Halfedge_handle ec; //copy of edge;
|
||||
for (Halfedge_handle eh = arrc.edges_begin(); eh != arrc.edges_end(); eh++) {
|
||||
|
|
@ -258,7 +258,7 @@ public:
|
|||
|
||||
}
|
||||
|
||||
Face_handle visibility_region(const Point_2 &q, const Face_const_handle fh, Arrangement_2 &out_arr) {
|
||||
Face_handle compute_visibility(const Point_2 &q, const Face_const_handle fh, Arrangement_2 &out_arr) {
|
||||
std::vector<Point_2> polygon;
|
||||
visibility_region_impl(q, fh, polygon);
|
||||
build_arr(polygon, out_arr);
|
||||
|
|
|
|||
|
|
@ -74,14 +74,14 @@ public:
|
|||
return *p_arr;
|
||||
}
|
||||
|
||||
void visibility_region(Point_2 &q,
|
||||
void compute_visibility(Point_2 &q,
|
||||
const Face_const_handle face,
|
||||
Output_Arrangement_2 &out_arr
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
void visibility_region(const Point_2 &q,
|
||||
void compute_visibility(const Point_2 &q,
|
||||
const Halfedge_const_handle he,
|
||||
Output_Arrangement_2 &out_arr
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public:
|
|||
return *p_arr;
|
||||
}
|
||||
|
||||
Face_handle visibility_region(Point_2 &q, const Face_const_handle face,
|
||||
Face_handle compute_visibility(Point_2 &q, const Face_const_handle face,
|
||||
Output_arrangement_2 &out_arr) {
|
||||
|
||||
// CGAL::Visibility_2::print_arrangement_by_face<Input_arrangement_2>(*p_arr);
|
||||
|
|
@ -214,7 +214,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
Face_handle visibility_region(const Point_2 &q, const Halfedge_const_handle he,
|
||||
Face_handle compute_visibility(const Point_2 &q, const Halfedge_const_handle he,
|
||||
Output_arrangement_2 &out_arr ) {
|
||||
|
||||
query_pt_is_vertex = false;
|
||||
|
|
|
|||
|
|
@ -75,14 +75,14 @@ public:
|
|||
return *p_arr;
|
||||
}
|
||||
|
||||
void visibility_region(Point_2 &q,
|
||||
void compute_visibility(Point_2 &q,
|
||||
const Face_const_handle face,
|
||||
Output_Arrangement_2 &out_arr
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
void visibility_region(const Point_2 &q,
|
||||
void compute_visibility(const Point_2 &q,
|
||||
const Halfedge_const_handle he,
|
||||
Output_Arrangement_2 &out_arr
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ public:
|
|||
|
||||
}
|
||||
|
||||
Face_handle visibility_region(Point_2 &q,
|
||||
Face_handle compute_visibility(Point_2 &q,
|
||||
const Face_const_handle face,
|
||||
Output_arrangement_2 &out_arr
|
||||
){
|
||||
|
|
@ -396,7 +396,7 @@ public:
|
|||
return output(raw_output,out_arr);
|
||||
}
|
||||
|
||||
Face_handle visibility_region(const Point_2 &q,
|
||||
Face_handle compute_visibility(const Point_2 &q,
|
||||
const Halfedge_const_handle he,
|
||||
Output_arrangement_2 &out_arr) {
|
||||
//std::cout << "visibility_region he" << std::endl;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void test_model_methods_for_arr(
|
|||
// First consider query point in the unbounded face
|
||||
Point_2 query_pt(1, 1);
|
||||
// Check returned face_handle
|
||||
Face_handle face_check = visibility.visibility_region(query_pt, fit, arr_out);
|
||||
Face_handle face_check = visibility.compute_visibility(query_pt, fit, arr_out);
|
||||
Face_handle face;
|
||||
if (arr_out.faces_begin()->is_unbounded()) {
|
||||
face = ++arr_out.faces_begin();
|
||||
|
|
@ -76,13 +76,13 @@ void test_model_methods_for_arr(
|
|||
assert(false == visibility.is_attached());
|
||||
visibility.attach(arr);
|
||||
|
||||
visibility.visibility_region(query_pt, fit, arr_out_check);
|
||||
visibility.compute_visibility(query_pt, fit, arr_out_check);
|
||||
assert(true == test_are_equal<Output_arrangement_2>
|
||||
(arr_out_check, arr));
|
||||
assert(true == test_are_equal<Output_arrangement_2>
|
||||
(arr_out, arr_out_check));
|
||||
arr_out.clear();
|
||||
visibility.visibility_region(query_pt, fit, arr_out);
|
||||
visibility.compute_visibility(query_pt, fit, arr_out);
|
||||
assert(true == test_are_equal<Output_arrangement_2>
|
||||
(arr_out, arr_out_check));
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ void test_model_methods_for_arr(
|
|||
|
||||
if (hit->source()->point() == Point_2(0, 8) && hit->target()->point() == Point_2(0, 0)) {
|
||||
std::cout << "Running halfedge case...\n";
|
||||
face_check_he = visibility.visibility_region(query_pt, hit, arr_out);
|
||||
face_check_he = visibility.compute_visibility(query_pt, hit, arr_out);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ void test_model_methods_for_arr(
|
|||
assert(true == test_are_equal<Output_arrangement_2>
|
||||
(arr_out, arr));
|
||||
arr_out_check.clear();
|
||||
visibility.visibility_region(query_pt, hit, arr_out_check);
|
||||
visibility.compute_visibility(query_pt, hit, arr_out_check);
|
||||
assert(true == test_are_equal<Output_arrangement_2>
|
||||
(arr_out, arr_out_check));
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ void test_model_methods_for_arr(
|
|||
for (hit_snd = arr.halfedges_begin(); hit_snd != arr.halfedges_end(); ++hit_snd) {
|
||||
if(!hit_snd->face()->is_unbounded()){
|
||||
arr_out.clear();
|
||||
Face_handle face_check_he_snd = visibility.visibility_region(hit_snd->target()->point(), hit_snd, arr_out);
|
||||
Face_handle face_check_he_snd = visibility.compute_visibility(hit_snd->target()->point(), hit_snd, arr_out);
|
||||
assert(!face_check_he_snd->is_unbounded());
|
||||
if (arr_out.faces_begin()->is_unbounded()) {
|
||||
face = ++arr_out.faces_begin();
|
||||
|
|
|
|||
|
|
@ -355,15 +355,15 @@ bool run_test_case_from_file(Visibility_2 visibility, std::ifstream &input) {
|
|||
|
||||
if (CGAL::assign (f, obj)) {
|
||||
if (!f->is_unbounded()) {
|
||||
visibility.visibility_region(query_pt, f, arr_out);
|
||||
visibility.compute_visibility(query_pt, f, arr_out);
|
||||
}
|
||||
}
|
||||
else if (CGAL::assign(e, obj)) {
|
||||
if (e->source()->point() == reference_pt) {
|
||||
visibility.visibility_region(query_pt, e, arr_out);
|
||||
visibility.compute_visibility(query_pt, e, arr_out);
|
||||
}
|
||||
else {
|
||||
visibility.visibility_region(query_pt, e->twin(), arr_out);
|
||||
visibility.compute_visibility(query_pt, e->twin(), arr_out);
|
||||
}
|
||||
}
|
||||
else if (CGAL::assign(v, obj)) {
|
||||
|
|
@ -372,7 +372,7 @@ bool run_test_case_from_file(Visibility_2 visibility, std::ifstream &input) {
|
|||
Halfedge_around_vertex_const_circulator he_curr = he_circ;
|
||||
do {
|
||||
if (he_curr->source()->point() == reference_pt) {
|
||||
visibility.visibility_region(query_pt, he_curr, arr_out);
|
||||
visibility.compute_visibility(query_pt, he_curr, arr_out);
|
||||
}
|
||||
} while (++he_curr != he_circ);
|
||||
}
|
||||
|
|
@ -769,10 +769,10 @@ void benchmark_one_unit(
|
|||
timer.start();
|
||||
Face_handle f_fst;
|
||||
if (choice == FACE) {
|
||||
f_fst = visibility_fst.visibility_region(curr_query_pt, fit, out_arr_fst);
|
||||
f_fst = visibility_fst.compute_visibility(curr_query_pt, fit, out_arr_fst);
|
||||
}
|
||||
else {
|
||||
f_fst = visibility_fst.visibility_region(curr_query_pt, he, out_arr_fst);
|
||||
f_fst = visibility_fst.compute_visibility(curr_query_pt, he, out_arr_fst);
|
||||
}
|
||||
timer.stop();
|
||||
|
||||
|
|
@ -785,10 +785,10 @@ void benchmark_one_unit(
|
|||
timer.start();
|
||||
Face_handle f_snd;
|
||||
if (choice == FACE) {
|
||||
f_snd = visibility_snd.visibility_region(curr_query_pt, fit, out_arr_snd);
|
||||
f_snd = visibility_snd.compute_visibility(curr_query_pt, fit, out_arr_snd);
|
||||
}
|
||||
else {
|
||||
f_snd = visibility_snd.visibility_region(curr_query_pt, he, out_arr_snd);
|
||||
f_snd = visibility_snd.compute_visibility(curr_query_pt, he, out_arr_snd);
|
||||
}
|
||||
timer.stop();
|
||||
if ( !is_star_shape<Visibility_2_snd>(curr_query_pt, f_snd) ) {
|
||||
|
|
@ -995,10 +995,10 @@ void test_star_shape_one_face( const typename Visibility_2::Input_arrangement_2
|
|||
Output_arrangement_2 out_arr;
|
||||
Face_handle fh;
|
||||
if (choice == FACE) {
|
||||
fh = visibility.visibility_region(curr_query_pt, fit, out_arr);
|
||||
fh = visibility.compute_visibility(curr_query_pt, fit, out_arr);
|
||||
}
|
||||
else {
|
||||
fh = visibility.visibility_region(curr_query_pt, he, out_arr);
|
||||
fh = visibility.compute_visibility(curr_query_pt, he, out_arr);
|
||||
}
|
||||
if ( !is_star_shape<Visibility_2>(curr_query_pt, fh)) {
|
||||
std::cout << RED << " The face is not a star shape to qpoint." << RESET << std::endl;
|
||||
|
|
|
|||
Loading…
Reference in New Issue