Added zone and do_intersect functions to Arrangement_on_surface_2

This commit is contained in:
Ophir Setter 2007-08-23 10:14:05 +00:00
parent b774212016
commit 2bef56c005
10 changed files with 373 additions and 18 deletions

2
.gitattributes vendored
View File

@ -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

View File

@ -26,9 +26,11 @@ instance of the class
\ccInclude{CGAL/Arrangement_2.h}
\ccGlobalFunction{template <class Traits, class Dcel, class PointLocation>
bool do_intersect (Arrangement_2<Traits,Dcel>& arr,
const typename Traits::Curve_2& c, const PointLocation& pl);}
\ccGlobalFunction{template <class GeomTraits, class TopTraits,
class Curve, class PointLocation>
bool do_intersect (
Arrangement_on_surface_2<GeomTraits, TopTraits>& 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).

View File

@ -19,13 +19,13 @@ class \ccc{Arr_walk_along_line_point_location<Arrangement_2<Traits,Dcel> >}.
\ccInclude{CGAL/Arrangement_2.h}
\ccGlobalFunction{template <class Traits, class Dcel,
class OutputIterator, class PointLocation>
OutputIterator zone (
Arrangement_2<Traits,Dcel>& arr,
const typename Traits::X_monotone_curve_2& c,
OutputIterator oi,
const PointLocation& pl);}
\ccGlobalFunction{template <class GeomTraits, class TopTraits,
class OutputIterator, class PointLocation>
OutputIterator zone (
Arrangement_on_surface_2<GeomTraits, TopTraits>& 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.

View File

@ -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;

View File

@ -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;

View File

@ -31,6 +31,8 @@
#include <CGAL/Basic_sweep_line_2.h>
#include <CGAL/Sweep_line_2.h>
#include <CGAL/Arrangement_zone_2.h>
#include <CGAL/Arrangement_2/Arr_compute_zone_visitor.h>
#include <CGAL/Arrangement_2/Arr_do_intersect_zone_visitor.h>
#include <CGAL/Arrangement_2/Arr_traits_adaptor_2.h>
#include <CGAL/Sweep_line_2/Sweep_line_2_utils.h>
#include <CGAL/Sweep_line_2/Sweep_line_2_visitors.h>
@ -1204,6 +1206,189 @@ bool is_valid (const Arrangement_on_surface_2<GeomTraits, TopTraits>& 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 <class GeomTraits, class TopTraits,
class OutputIterator, class PointLocation>
OutputIterator zone (Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
const typename GeomTraits::X_monotone_curve_2& c,
OutputIterator oi,
const PointLocation& pl)
{
// Obtain an arrangement accessor.
typedef Arrangement_on_surface_2<GeomTraits,TopTraits>
Arrangement_on_surface_2;
// Define a zone-computation object an a visitor that performs the
// intersection check.
typedef Arr_compute_zone_visitor<Arrangement_on_surface_2, OutputIterator>
Zone_visitor;
Zone_visitor visitor (oi);
Arrangement_zone_2<Arrangement_on_surface_2, Zone_visitor>
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 <class GeomTraits, class TopTraits, class OutputIterator>
OutputIterator zone (Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
const typename GeomTraits::X_monotone_curve_2& c,
OutputIterator oi)
{
typedef Arrangement_on_surface_2<GeomTraits, TopTraits>
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 <class GeomTraits, class TopTraits, class PointLocation>
bool do_intersect (Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
const typename GeomTraits::X_monotone_curve_2& c,
const PointLocation& pl, boost::is_same<int, int>::type)
{
// Obtain an arrangement accessor.
typedef Arrangement_on_surface_2<GeomTraits,TopTraits>
Arrangement_on_surface_2;
// Define a zone-computation object an a visitor that performs the
// intersection check.
typedef Arr_do_intersect_zone_visitor<Arrangement_on_surface_2> Zone_visitor;
Zone_visitor visitor;
Arrangement_zone_2<Arrangement_on_surface_2, Zone_visitor>
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 <class GeomTraits, class TopTraits, class PointLocation>
bool do_intersect (Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
const typename GeomTraits::X_monotone_curve_2& c,
const PointLocation& pl, boost::is_same<int, double>::type)
{
// Obtain an arrangement accessor.
typedef Arrangement_on_surface_2<GeomTraits,TopTraits>
Arrangement_on_surface_2;
// Break the input curve into x-monotone subcurves and isolated points.
typedef Arr_traits_adaptor_2<GeomTraits> Traits_adaptor_2;
Traits_adaptor_2 *traits =
static_cast<Traits_adaptor_2*> (arr.get_traits());
std::list<CGAL::Object> x_objects;
std::list<CGAL::Object>::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<typename GeomTraits::X_monotone_curve_2>
(&(*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<typename GeomTraits::Point_2> (&(*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<typename
Arrangement_on_surface_2::Face_const_handle>(&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 <class GeomTraits, class TopTraits, class Curve, class PointLocation>
bool do_intersect (Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
const Curve& c, const PointLocation& pl)
{
typedef typename GeomTraits::X_monotone_curve_2 X_monotone_curve_2;
typedef typename boost::is_same<Curve, X_monotone_curve_2>::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 <class GeomTraits, class TopTraits, class Curve>
bool do_intersect (Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
const Curve& c)
{
typedef Arrangement_on_surface_2<GeomTraits, TopTraits>
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

View File

@ -2724,6 +2724,63 @@ remove_vertex (Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
template <class GeomTraits, class TopTraits>
bool is_valid (const Arrangement_on_surface_2<GeomTraits, TopTraits>& 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 <class GeomTraits, class TopTraits,
class OutputIterator, class PointLocation>
OutputIterator zone (Arrangement_on_surface_2<GeomTraits, TopTraits>& 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 <class GeomTraits, class TopTraits, class OutputIterator>
OutputIterator zone (Arrangement_on_surface_2<GeomTraits, TopTraits>& 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 <class GeomTraits, class TopTraits, class Curve, class PointLocation>
bool do_intersect (Arrangement_on_surface_2<GeomTraits, TopTraits>& 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 <class GeomTraits, class TopTraits, class Curve>
bool do_intersect (Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
const Curve& c);
CGAL_END_NAMESPACE
// The function definitions can be found under:

View File

@ -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

View File

@ -0,0 +1,55 @@
// Testing the do_intersect function
#include <CGAL/Quotient.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/IO/Arr_iostream.h>
#include <list>
typedef CGAL::Quotient<int> Number_type;
typedef CGAL::Simple_cartesian<Number_type> Kernel;
typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2;
typedef Traits_2::Point_2 Point_2;
typedef Traits_2::X_monotone_curve_2 Segment_2;
typedef CGAL::Arrangement_2<Traits_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);
}

View File

@ -0,0 +1,57 @@
// Testing the compute zone function
#include <CGAL/Quotient.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/IO/Arr_iostream.h>
#include <list>
typedef CGAL::Quotient<int> Number_type;
typedef CGAL::Simple_cartesian<Number_type> Kernel;
typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2;
typedef Traits_2::Point_2 Point_2;
typedef Traits_2::X_monotone_curve_2 Segment_2;
typedef CGAL::Arrangement_2<Traits_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<CGAL::Object> 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);
}