From 2bef56c005f4fb5991bbd6b2d81ed20c7db34c0c Mon Sep 17 00:00:00 2001 From: Ophir Setter Date: Thu, 23 Aug 2007 10:14:05 +0000 Subject: [PATCH] Added zone and do_intersect functions to Arrangement_on_surface_2 --- .gitattributes | 2 + .../arr_do_intersect.tex | 12 +- .../Arrangement_on_surface_2_ref/arr_zone.tex | 16 +- .../Arrangement_2/Arr_compute_zone_visitor.h | 1 - .../Arr_do_intersect_zone_visitor.h | 1 - .../Arrangement_on_surface_2_global.h | 185 ++++++++++++++++++ .../include/CGAL/Arrangement_on_surface_2.h | 57 ++++++ .../test/Arrangement_on_surface_2/cgal_test | 5 +- .../test_do_intersect.cpp | 55 ++++++ .../Arrangement_on_surface_2/test_zone.cpp | 57 ++++++ 10 files changed, 373 insertions(+), 18 deletions(-) create mode 100644 Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_do_intersect.cpp create mode 100644 Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp diff --git a/.gitattributes b/.gitattributes index 12c60546700..7495692fc35 100644 --- a/.gitattributes +++ b/.gitattributes @@ -835,6 +835,8 @@ Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/spherical_arcs/compa Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/spherical_arcs/intersect -text Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/spherical_arcs/is_vertical -text Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/spherical_arcs/vertex -text +Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_do_intersect.cpp -text +Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp -text Arrangement_on_surface_2/test/Sweep_line_2/CompareCurveList.h eol=lf Arrangement_on_surface_2/test/Sweep_line_2/DATA/conics/con01.txt eol=lf Arrangement_on_surface_2/test/Sweep_line_2/DATA/conics/con02.txt eol=lf diff --git a/Arrangement_on_surface_2/doc_tex/Arrangement_on_surface_2_ref/arr_do_intersect.tex b/Arrangement_on_surface_2/doc_tex/Arrangement_on_surface_2_ref/arr_do_intersect.tex index fb08f40180b..d4d5cb2c3bc 100644 --- a/Arrangement_on_surface_2/doc_tex/Arrangement_on_surface_2_ref/arr_do_intersect.tex +++ b/Arrangement_on_surface_2/doc_tex/Arrangement_on_surface_2_ref/arr_do_intersect.tex @@ -26,9 +26,11 @@ instance of the class \ccInclude{CGAL/Arrangement_2.h} -\ccGlobalFunction{template - bool do_intersect (Arrangement_2& arr, - const typename Traits::Curve_2& c, const PointLocation& pl);} +\ccGlobalFunction{template + bool do_intersect ( + Arrangement_on_surface_2& arr, + const Curve& c, const PointLocation& pl);} Checks if the given curve or $x$-monotone curve \ccc{c} intersects edges or vertices of the existing arrangement \ccc{arr}. \ccPrecond{If provided, \ccc{pl} must be attached to the given arrangement @@ -38,9 +40,9 @@ Checks if the given curve or $x$-monotone curve \ccc{c} intersects \ccRequirements \begin{itemize} -\item If \ccc{c} is $x$-monotone then the instantiated \ccc{Traits} +\item If \ccc{c} is $x$-monotone then the instantiated \ccc{GeomTraits} class must model the \ccc{ArrangementXMonotoneTraits_2} concept. If - \ccc{c} is a curve then the instantiated \ccc{Traits} class must + \ccc{c} is a curve then the instantiated \ccc{GeomTraits} class must model the \ccc{ArrangementTraits_2} concept. That is, it should define the \ccc{Curve_2} type, and support its subdivision into $x$-monotone subcurves (and perhaps isolated points). diff --git a/Arrangement_on_surface_2/doc_tex/Arrangement_on_surface_2_ref/arr_zone.tex b/Arrangement_on_surface_2/doc_tex/Arrangement_on_surface_2_ref/arr_zone.tex index af964cc7ca9..385960ac238 100644 --- a/Arrangement_on_surface_2/doc_tex/Arrangement_on_surface_2_ref/arr_zone.tex +++ b/Arrangement_on_surface_2/doc_tex/Arrangement_on_surface_2_ref/arr_zone.tex @@ -19,13 +19,13 @@ class \ccc{Arr_walk_along_line_point_location >}. \ccInclude{CGAL/Arrangement_2.h} -\ccGlobalFunction{template - OutputIterator zone ( - Arrangement_2& arr, - const typename Traits::X_monotone_curve_2& c, - OutputIterator oi, - const PointLocation& pl);} +\ccGlobalFunction{template + OutputIterator zone ( + Arrangement_on_surface_2& arr, + const typename GeomTraits::X_monotone_curve_2& c, + OutputIterator oi, + const PointLocation& pl);} Compute the zone of the given $x$-monotone curve \ccc{c} in the arrangement \ccc{arr}. \ccPrecond{If provided, \ccc{pl} must be attached to the given arrangement @@ -35,7 +35,7 @@ arrangement \ccc{arr}. \ccRequirements \begin{itemize} -\item The instantiated \ccc{Traits} class must model the +\item The instantiated \ccc{GeomTraits} class must model the \ccc{ArrangementXMonotoneTraits_2} concept. \item The point-location object \ccc{pl}, must model the \ccc{ArrangementPointLocation_2} concept. diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_compute_zone_visitor.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_compute_zone_visitor.h index bb83cd1751f..a19c86b7b2e 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_compute_zone_visitor.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_compute_zone_visitor.h @@ -41,7 +41,6 @@ public: typedef OutputIterator_ OutputIterator; typedef Arrangement_ Arrangement_2; - typedef typename Arrangement_2::Traits_2 Traits_2; typedef typename Arrangement_2::Vertex_handle Vertex_handle; typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_do_intersect_zone_visitor.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_do_intersect_zone_visitor.h index aa6846a64a4..2596562f1a1 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_do_intersect_zone_visitor.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arr_do_intersect_zone_visitor.h @@ -37,7 +37,6 @@ class Arr_do_intersect_zone_visitor public: typedef Arrangement_ Arrangement_2; - typedef typename Arrangement_2::Traits_2 Traits_2; typedef typename Arrangement_2::Vertex_handle Vertex_handle; typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h index 31a52f77108..ff774acedee 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include #include @@ -1204,6 +1206,189 @@ bool is_valid (const Arrangement_on_surface_2& arr) return (true); } +//----------------------------------------------------------------------------- +// Compute the zone of the given x-monotone curve in the existing arrangement. +// Meaning, it output the arrangment's vertices, edges and faces that the +// x-monotone curve intersects. +template +OutputIterator zone (Arrangement_on_surface_2& arr, + const typename GeomTraits::X_monotone_curve_2& c, + OutputIterator oi, + const PointLocation& pl) +{ + // Obtain an arrangement accessor. + typedef Arrangement_on_surface_2 + Arrangement_on_surface_2; + + // Define a zone-computation object an a visitor that performs the + // intersection check. + typedef Arr_compute_zone_visitor + Zone_visitor; + + Zone_visitor visitor (oi); + Arrangement_zone_2 + arr_zone (arr, &visitor); + + arr_zone.init (c, pl); + arr_zone.compute_zone(); + + return (oi); +} + +//----------------------------------------------------------------------------- +// Compute the zone of the given x-monotone curve in the existing arrangement.b +// Overloaded version with no point location object - the walk point-location +// strategy is used as default. +// +template +OutputIterator zone (Arrangement_on_surface_2& arr, + const typename GeomTraits::X_monotone_curve_2& c, + OutputIterator oi) +{ + typedef Arrangement_on_surface_2 + Arrangement_on_surface_2; + + // Create a default point-location object and use it to insert the curve. + typename TopTraits::Default_point_location_strategy def_pl (arr); + + //insert the curve using the walk point location + zone (arr, c, oi, def_pl); + return oi; +} + + +//----------------------------------------------------------------------------- +// Checks if the given x-monotone curve intersects the existing arrangement. +// The last parameter is used to resolve ambiguity between this function and +// do_intersect of Curve_2 in case that X_monotone_curve_2 and Curve_2 are the +// same class. The last parameter should be boost::true_type but we used a +// workaround since it didn't compile in FC3_g++-3.4.4 with the error of: +// +// error: no matching function for call to `do_intersect(Arrangement_on_surface_2<>&, +// const Arr_segment_2&, const Arr_walk_along_line_point_location<>&, mpl_::bool_< true>)' +// +template +bool do_intersect (Arrangement_on_surface_2& arr, + const typename GeomTraits::X_monotone_curve_2& c, + const PointLocation& pl, boost::is_same::type) +{ + // Obtain an arrangement accessor. + typedef Arrangement_on_surface_2 + Arrangement_on_surface_2; + + // Define a zone-computation object an a visitor that performs the + // intersection check. + typedef Arr_do_intersect_zone_visitor Zone_visitor; + + Zone_visitor visitor; + Arrangement_zone_2 + arr_zone (arr, &visitor); + + arr_zone.init (c, pl); + arr_zone.compute_zone(); + + return (visitor.do_intersect()); +} + +//----------------------------------------------------------------------------- +// Checks if the given curve intersects the existing arrangement. +// The last parameter is used to resolve ambiguity between this function and +// do_intersect of X_monotone_curve_2 in case that X_monotone_curve_2 and +// Curve_2 are the same class. +// The last parameter should be boost::false_type but we used a +// workaround since it didn't compile in FC3_g++-3.4.4 with the error of: +// +// error: no matching function for call to `do_intersect(Arrangement_on_surface_2<>&, +// const Arr_segment_2&, const Arr_walk_along_line_point_location<>&, mpl_::bool_< true>)' +// +template +bool do_intersect (Arrangement_on_surface_2& arr, + const typename GeomTraits::X_monotone_curve_2& c, + const PointLocation& pl, boost::is_same::type) +{ + // Obtain an arrangement accessor. + typedef Arrangement_on_surface_2 + Arrangement_on_surface_2; + + // Break the input curve into x-monotone subcurves and isolated points. + typedef Arr_traits_adaptor_2 Traits_adaptor_2; + + Traits_adaptor_2 *traits = + static_cast (arr.get_traits()); + + std::list x_objects; + std::list::const_iterator obj_iter; + const typename GeomTraits::X_monotone_curve_2 *x_curve; + const typename GeomTraits::Point_2 *iso_p; + + traits->make_x_monotone_2_object() (c, + std::back_inserter (x_objects)); + + // Insert each x-monotone curve into the arrangement. + for (obj_iter = x_objects.begin(); obj_iter != x_objects.end(); ++obj_iter) + { + // Act according to the type of the current object. + x_curve = object_cast + (&(*obj_iter)); + if (x_curve != NULL) + { + // Check if the x-monotone subcurve intersects the arrangement. + if (do_intersect(arr, *x_curve, pl) == true) + return true; + } + else + { + iso_p = object_cast (&(*obj_iter)); + CGAL_assertion (iso_p != NULL); + + // Check whether the isolated point lies inside a face (otherwise, + // it conincides with a vertex or an edge). + CGAL::Object obj = pl.locate (*iso_p); + + return (object_cast(&obj) != NULL); + } + } + + // If we reached here, the curve does not intersect the arrangement. + return (false); +} + +//----------------------------------------------------------------------------- +// Common interface for the do_intersect of the Curve_2 and X_monotone_curve_2 +template +bool do_intersect (Arrangement_on_surface_2& arr, + const Curve& c, const PointLocation& pl) +{ + typedef typename GeomTraits::X_monotone_curve_2 X_monotone_curve_2; + + typedef typename boost::is_same::type + Is_x_monotone; + + return do_intersect(arr, c, pl, Is_x_monotone()); +} + +//----------------------------------------------------------------------------- +// Checks if the given curve intersects the existing arrangement. +// Overloaded version with no point location object - the walk point-location +// strategy is used as default. +template +bool do_intersect (Arrangement_on_surface_2& arr, + const Curve& c) +{ + typedef Arrangement_on_surface_2 + Arrangement_on_surface_2; + + // Create a default point-location object and use it to insert the curve. + typename TopTraits::Default_point_location_strategy def_pl (arr); + + // check if the curve intersects the arrangement using the walk point + // location. + return do_intersect (arr, c, def_pl); +} + + CGAL_END_NAMESPACE #endif diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_on_surface_2.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_on_surface_2.h index 217aa84aae1..e5c4b7f86e8 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_on_surface_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_on_surface_2.h @@ -2724,6 +2724,63 @@ remove_vertex (Arrangement_on_surface_2& arr, template bool is_valid (const Arrangement_on_surface_2& arr); +/*! + * Compute the zone of the given x-monotone curve in the existing arrangement. + * Meaning, it output the arrangment's vertices, edges and faces that the + * x-monotone curve intersects. + * \param arr The arrangement. + * \param c The x-monotone curve that its zone was computed. + * \param oi Output iterator of CGAL::Object to insert the zone elements to. + * \param pi The point location strategy that is used to locate the starting + * point. + * \return The output iterator that the curves were inserted to. + */ +template +OutputIterator zone (Arrangement_on_surface_2& arr, + const typename GeomTraits::X_monotone_curve_2& c, + OutputIterator oi, + const PointLocation& pl); + +/*! + * Compute the zone of the given x-monotone curve in the existing arrangement. + * Overloaded version with no point location object - the walk point-location + * strategy is used as default. + * \param arr The arrangement. + * \param c The x-monotone curve that its zone was computed. + * \param oi Output iterator of CGAL::Object to insert the zone elements to. + * \return The output iterator that the curves were inserted to. + */ +template +OutputIterator zone (Arrangement_on_surface_2& arr, + const typename GeomTraits::X_monotone_curve_2& c, + OutputIterator oi); + +/*! + * Checks if the given curve/x-monotone curve intersects the existing arrangement. + * \param arr The arrangement. + * \param c The curve/x-monotone curve. + * \param pi The point location strategy that is used to locate the starting + * point. + * \return True if the curve intersect the arrangement, false otherwise. + */ +template +bool do_intersect (Arrangement_on_surface_2& arr, + const Curve& c, const PointLocation& pl); + +/*! + * Checks if the given curve/x-monotone curve intersects the existing arrangement. + * Overloaded version with no point location object - the walk point-location + * strategy is used as default. + * \param arr The arrangement. + * \param c The x-monotone curve/curve. + * \return True if the curve intersect the arrangement, false otherwise. + */ +template +bool do_intersect (Arrangement_on_surface_2& arr, + const Curve& c); + + CGAL_END_NAMESPACE // The function definitions can be found under: diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test index 47ff853f277..4d079a2a330 100755 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test @@ -513,9 +513,8 @@ else compile_and_run test_construction compile_and_run test_dual - -# compile_and_run test_do_intersect_curve -# compile_and_run test_compute_curve_zone + compile_and_run test_do_intersect + compile_and_run test_zone fi #if any error occured then appened the the full error description file to error file diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_do_intersect.cpp b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_do_intersect.cpp new file mode 100644 index 00000000000..4821269ee7d --- /dev/null +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_do_intersect.cpp @@ -0,0 +1,55 @@ +// Testing the do_intersect function + +#include +#include +#include +#include +#include + +#include + +typedef CGAL::Quotient Number_type; +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Arr_segment_traits_2 Traits_2; +typedef Traits_2::Point_2 Point_2; +typedef Traits_2::X_monotone_curve_2 Segment_2; +typedef CGAL::Arrangement_2 Arrangement_2; +typedef Arrangement_2::Halfedge_handle Halfedge_handle; + +#define N_SEGMENTS 3 + +int main () +{ + Arrangement_2 arr; + Segment_2 segs[N_SEGMENTS]; + bool expected_intersect[N_SEGMENTS]; + int k; + + segs[0] = Segment_2 (Point_2 (-2, -2), Point_2 (-1, -1)); + segs[1] = Segment_2 (Point_2 (-1, 1), Point_2 (0, 1)); + segs[2] = Segment_2 (Point_2 (-1, 0), Point_2 (0, 0)); + + expected_intersect[0] = false; + expected_intersect[1] = true; + expected_intersect[2] = true; + + insert_curve(arr, Segment_2(Point_2(0, 0), Point_2(2, 0))); + insert_curve(arr, Segment_2(Point_2(2, 0), Point_2(2, 2))); + insert_curve(arr, Segment_2(Point_2(2, 2), Point_2(0, 2))); + insert_curve(arr, Segment_2(Point_2(0, 2), Point_2(0, 0))); + + for (k = 0; k < N_SEGMENTS; k++) + { + bool do_inter = do_intersect(arr, segs[k]); + + std::cout << "Segment: " << segs[k]; + std::cout << " Expected: " << expected_intersect[k]; + std::cout << " Actual: " << do_inter << std::endl; + + if (expected_intersect[k] != do_inter) + return (1); + } + + return (0); +} + diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp new file mode 100644 index 00000000000..108f6debda1 --- /dev/null +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_zone.cpp @@ -0,0 +1,57 @@ +// Testing the compute zone function + +#include +#include +#include +#include +#include + +#include + +typedef CGAL::Quotient Number_type; +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Arr_segment_traits_2 Traits_2; +typedef Traits_2::Point_2 Point_2; +typedef Traits_2::X_monotone_curve_2 Segment_2; +typedef CGAL::Arrangement_2 Arrangement_2; +typedef Arrangement_2::Halfedge_handle Halfedge_handle; + +#define N_SEGMENTS 3 + +int main () +{ + Arrangement_2 arr; + Segment_2 segs[N_SEGMENTS]; + long zone_expected_comp[N_SEGMENTS]; + int k; + + segs[0] = Segment_2 (Point_2 (-2, -2), Point_2 (-1, -1)); + segs[1] = Segment_2 (Point_2 (-1, 1), Point_2 (1, 1)); + segs[2] = Segment_2 (Point_2 (0, 0), Point_2 (3, 0)); + + zone_expected_comp[0] = 1; + zone_expected_comp[1] = 3; + zone_expected_comp[2] = 4; + + insert_curve(arr, Segment_2(Point_2(0, 0), Point_2(2, 0))); + insert_curve(arr, Segment_2(Point_2(2, 0), Point_2(2, 2))); + insert_curve(arr, Segment_2(Point_2(2, 2), Point_2(0, 2))); + insert_curve(arr, Segment_2(Point_2(0, 2), Point_2(0, 0))); + + for (k = 0; k < N_SEGMENTS; k++) + { + std::list zone_elems; + zone(arr, segs[k], std::back_inserter(zone_elems)); + int zone_actual_comp = zone_elems.size(); + + std::cout << "Segment: " << segs[k]; + std::cout << " Expected: " << zone_expected_comp[k]; + std::cout << " Actual: " << zone_actual_comp << std::endl; + + if (zone_expected_comp[k] != zone_actual_comp) + return (1); + } + + return (0); +} +