From c44035aa57f7897c1658e2ff5eee834473b22e5f Mon Sep 17 00:00:00 2001 From: Ron Wein Date: Sun, 4 Jun 2006 15:07:56 +0000 Subject: [PATCH] New example programs for constructing arrangements of unbounded curves. --- .gitattributes | 3 + .../ex_infinite_edge_insertion.C | 86 +++++++++++++++++++ .../Arrangement_2/ex_infinite_insert.C | 74 ++++++++++++++++ .../ex_infinite_non_intersecting.C | 54 ++++++++++++ 4 files changed, 217 insertions(+) create mode 100644 Arrangement_2/examples/Arrangement_2/ex_infinite_edge_insertion.C create mode 100644 Arrangement_2/examples/Arrangement_2/ex_infinite_insert.C create mode 100644 Arrangement_2/examples/Arrangement_2/ex_infinite_non_intersecting.C diff --git a/.gitattributes b/.gitattributes index bc7d622b258..d4a73537ea0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -248,6 +248,9 @@ Arrangement_2/doc_tex/Arrangement_2/fig/triangle.pstex_t -text Arrangement_2/doc_tex/Sweep_line_2/sl_simple.gif -text svneol=unset#unset Arrangement_2/doc_tex/Sweep_line_2/sl_simple.pdf -text svneol=unset#unset Arrangement_2/doc_tex/Sweep_line_2/sl_simple.ps -text +Arrangement_2/examples/Arrangement_2/ex_infinite_edge_insertion.C -text +Arrangement_2/examples/Arrangement_2/ex_infinite_insert.C -text +Arrangement_2/examples/Arrangement_2/ex_infinite_non_intersecting.C -text Benchmark/examples/Benchmark/bbox/Makefile.mak -text Benchmark/examples/Benchmark/bbox/bbox.C -text Benchmark/examples/Benchmark/leftturn/Makefile.mak -text diff --git a/Arrangement_2/examples/Arrangement_2/ex_infinite_edge_insertion.C b/Arrangement_2/examples/Arrangement_2/ex_infinite_edge_insertion.C new file mode 100644 index 00000000000..56848842ea3 --- /dev/null +++ b/Arrangement_2/examples/Arrangement_2/ex_infinite_edge_insertion.C @@ -0,0 +1,86 @@ +//! \file examples/Arrangement_2/ex_infinite_edge_insertion.C +// Constructing an arrangement of unbounded linear objects using the simple +// edge-insertion functions. + +#include +#include +#include +#include + +typedef int Number_type; +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Arr_linear_traits_2 Traits_2; +typedef Traits_2::Point_2 Point_2; +typedef Traits_2::Segment_2 Segment_2; +typedef Traits_2::Ray_2 Ray_2; +typedef Traits_2::Line_2 Line_2; +typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2; +typedef CGAL::Arrangement_2 Arrangement_2; +typedef Arrangement_2::Vertex_handle Vertex_handle; +typedef Arrangement_2::Halfedge_handle Halfedge_handle; +typedef CGAL::Arr_naive_point_location Naive_pl; + +int main () +{ + Arrangement_2 arr; + Naive_pl naive_pl (arr); + + Ray_2 ray1 (Point_2 (0, 1), Point_2 (0, 2)); + X_monotone_curve_2 cv1 (ray1); + Line_2 line2 (Point_2 (0, 0), Point_2 (1, 1)); + X_monotone_curve_2 cv2 (line2); + Ray_2 ray3 (Point_2 (0, 1), Point_2 (1, 2)); + X_monotone_curve_2 cv3 (ray3); + Ray_2 ray4 (Point_2 (0, 1), Point_2 (-1, 2)); + X_monotone_curve_2 cv4 (ray4); + + Halfedge_handle e1 = arr.insert_in_face_interior (cv1, + arr.unbounded_face()); + Vertex_handle v1 = e1->source(); + Halfedge_handle e2 = arr.insert_in_face_interior (cv2, + arr.unbounded_face()); + Halfedge_handle e3 = arr.insert_from_left_vertex (cv3, v1); + Halfedge_handle e4 = arr.insert_from_right_vertex (cv4, v1); + + // Print out the size of the resulting arrangement. + std::cout << "The arrangement size:" << std::endl + << " V = " << arr.number_of_vertices() + << " (" << arr.number_of_vertices_at_infinity() + << " at infinity)" + << ", E = " << arr.number_of_edges() + << ", F = " << arr.number_of_faces() << std::endl; + + CGAL::Object obj; + Arrangement_2::Face_const_handle f; + Arrangement_2::Ccb_halfedge_const_circulator first, circ; + + obj = naive_pl.locate (Point_2 (1, 3)); + if (CGAL::assign (f ,obj)) + { + std::cout << "Face is " << (f->is_unbounded() ? "unbounded." : "bounded.") + << std::endl; + first = circ = f->outer_ccb(); + do + { + if (! circ->is_fictitious()) + std::cout << " " << circ->curve() << std::endl; + ++circ; + } while (circ != first); + } + + obj = naive_pl.locate (Point_2 (3, -3)); + if (CGAL::assign (f ,obj)) + { + std::cout << "Face is " << (f->is_unbounded() ? "unbounded." : "bounded.") + << std::endl; + first = circ = f->outer_ccb(); + do + { + if (! circ->is_fictitious()) + std::cout << " " << circ->curve() << std::endl; + ++circ; + } while (circ != first); + } + + return (0); +} diff --git a/Arrangement_2/examples/Arrangement_2/ex_infinite_insert.C b/Arrangement_2/examples/Arrangement_2/ex_infinite_insert.C new file mode 100644 index 00000000000..9e08c5ffc71 --- /dev/null +++ b/Arrangement_2/examples/Arrangement_2/ex_infinite_insert.C @@ -0,0 +1,74 @@ +//! \file examples/Arrangement_2/ex_infinite_non_intersecting.C +// Constructing an arrangement of unbounded linear objects using the insertion +// function for non-intersecting curves. + +#include +#include +#include +#include +#include +#include + +typedef CGAL::Gmpq Number_type; +typedef CGAL::Cartesian Kernel; +typedef CGAL::Arr_linear_traits_2 Traits_2; +typedef Traits_2::Point_2 Point_2; +typedef Traits_2::Segment_2 Segment_2; +typedef Traits_2::Ray_2 Ray_2; +typedef Traits_2::Line_2 Line_2; +typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2; +typedef CGAL::Arrangement_2 Arrangement_2; +typedef CGAL::Arr_naive_point_location Naive_pl; +typedef CGAL::Arr_walk_along_line_point_location Walk_pl; + +int main () +{ + // Construct 3 lines and 2 rays. + const int n_curves = 5; + X_monotone_curve_2 curves[5]; + + curves[0] = Line_2 (Point_2 (0, 0), Point_2 (2, 1)); + curves[1] = Line_2 (Point_2 (0, 0), Point_2 (-2, 1)); + curves[2] = Ray_2 (Point_2 (0, 2), Point_2 (-2, 0)); + curves[3] = Ray_2 (Point_2 (0, 2), Point_2 (2, 0)); + curves[4] = Line_2 (Point_2 (-1, 4), Point_2 (1, 4)); + + // Construct the arrangement by inserting the curves incermentally. + Arrangement_2 arr; + // Naive_pl naive_pl (arr); + Walk_pl walk_pl (arr); + int k; + + for (k = 0; k < n_curves; k++) + { + std::cout << "Inserting curve no. " << k + 1 << std::endl; + insert_x_monotone_curve (arr, curves[k], walk_pl); + } + + // Print out the size of the resulting arrangement. + Arrangement_2::Face_const_iterator fit; + unsigned int n_unb_faces = 0; + + for (fit = arr.faces_begin(); fit != arr.faces_end(); ++fit) + { + if (fit->is_unbounded()) + n_unb_faces++; + } + + std::cout << "The arrangement size:" << std::endl + << " V = " << arr.number_of_vertices() + << " (" << arr.number_of_vertices_at_infinity() + << " at infinity)" + << ", E = " << arr.number_of_edges() + << ", F = " << arr.number_of_faces() + << " (" << n_unb_faces << " unbounded)" << std::endl; + + // Print the vertices. + Arrangement_2::Vertex_const_iterator vit; + + std::cout << "The vertices:" << std::endl; + for (vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) + std::cout << " (" << vit->point() << ")" << std::endl; + + return (0); +} diff --git a/Arrangement_2/examples/Arrangement_2/ex_infinite_non_intersecting.C b/Arrangement_2/examples/Arrangement_2/ex_infinite_non_intersecting.C new file mode 100644 index 00000000000..afce775204e --- /dev/null +++ b/Arrangement_2/examples/Arrangement_2/ex_infinite_non_intersecting.C @@ -0,0 +1,54 @@ +//! \file examples/Arrangement_2/ex_infinite_non_intersecting.C +// Constructing an arrangement of unbounded linear objects using the insertion +// function for non-intersecting curves. + +#include +#include +#include +#include + +typedef int Number_type; +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Arr_linear_traits_2 Traits_2; +typedef Traits_2::Point_2 Point_2; +typedef Traits_2::Segment_2 Segment_2; +typedef Traits_2::Ray_2 Ray_2; +typedef Traits_2::Line_2 Line_2; +typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2; +typedef CGAL::Arrangement_2 Arrangement_2; +typedef CGAL::Arr_naive_point_location Naive_pl; + +int main () +{ + // Construct 3 rays and 6 line segments. + const int n_curves = 9; + X_monotone_curve_2 curves[9]; + + curves[0] = Ray_2 (Point_2 (-5, -1), Point_2 (-6, -2)); + curves[1] = Segment_2 (Point_2 (-5, -1), Point_2 (5, -1)); + curves[2] = Segment_2 (Point_2 (-5, -1), Point_2 (0, 8)); + curves[3] = Segment_2 (Point_2 (-1, 2), Point_2 (1, 2)); + curves[4] = Segment_2 (Point_2 (-1, 2), Point_2 (0, 0)); + curves[5] = Segment_2 (Point_2 (0, 0), Point_2 (1, 2)); + curves[6] = Ray_2 (Point_2 (0, 8), Point_2 (0, 9)); + curves[7] = Segment_2 (Point_2 (0, 8), Point_2 (5, -1)); + curves[8] = Ray_2 (Point_2 (5, -1), Point_2 (6, -2)); + + // Construct the arrangement by inserting the curves incermentally. + Arrangement_2 arr; + Naive_pl naive_pl (arr); + int k; + + for (k = 0; k < n_curves; k++) + insert_non_intersecting_curve (arr, curves[k], naive_pl); + + // Print out the size of the resulting arrangement. + std::cout << "The arrangement size:" << std::endl + << " V = " << arr.number_of_vertices() + << " (" << arr.number_of_vertices_at_infinity() + << " at infinity)" + << ", E = " << arr.number_of_edges() + << ", F = " << arr.number_of_faces() << std::endl; + + return (0); +}