overlay with different geometry traits

This commit is contained in:
Ophir Setter 2008-08-31 13:24:26 +00:00
parent 8db83a466a
commit 0081acb19a
3 changed files with 64 additions and 29 deletions

View File

@ -16,11 +16,15 @@ see, e.g.,~\cite{cgal:behhms-cbcab-02}).
The function \ccc{overlay (arr_a, arr_b, ovl_arr, ovl_traits)} accepts The function \ccc{overlay (arr_a, arr_b, ovl_arr, ovl_traits)} accepts
two input arrangement instances \ccc{arr_a} and \ccc{arr_b}, and constructs two input arrangement instances \ccc{arr_a} and \ccc{arr_b}, and constructs
their overlay instance \ccc{ovl_arr}. All three arrangements must use the their overlay instance \ccc{ovl_arr}. All three arrangements must use the
same geometric primitives. In other words, their types must be defined same geometric primitives. More precisely, let \ccc{arr_a} be of
using the same geometric traits-class. Let us assume that \ccc{arr_a} is of type \ccc{Arrangement_2<Traits_A,Dcel_A>}, \ccc{arr_b} be of type
type \ccc{Arrangement_2<Traits,Dcel_A>}, \ccc{arr_b} is of type \ccc{Arrangement_2<Traits_B,Dcel_B>} and the resulting \ccc{ovl_arr} be of type
\ccc{Arrangement_2<Traits,Dcel_B>} and the resulting \ccc{ovl_arr} is of type \ccc{Arrangement_2<Traits_R,Dcel_R>}. All types nested in geometry
\ccc{Arrangement_2<Traits,Dcel_R>}. The \ccc{ovl_traits} parameter is traits \ccc{Traits_A}, e.g., \ccc{Point_2} and
\ccc{X_monotone_curve_2}, must be convertible to the corresponding
types nested in geometry traits \ccc{Traits_R}. The same holds for all
types nested in geometry traits \ccc{Traits_B}.
The \ccc{ovl_traits} parameter is
an instance of an {\em overlay traits-class}, which enables the creation of an instance of an {\em overlay traits-class}, which enables the creation of
\ccc{Dcel_R} records in the overlaid arrangement from the \dcel\ features \ccc{Dcel_R} records in the overlaid arrangement from the \dcel\ features
of \ccc{arr_a} and \ccc{arr_b} that they correspond to. of \ccc{arr_a} and \ccc{arr_b} that they correspond to.

View File

@ -5,22 +5,29 @@
\ccDefinition \ccDefinition
The function \ccRefName\ computes the overlay of two input arrangement The function \ccRefName\ computes the overlay of two input arrangement
objects, and returns the overlaid arrangement. All three arrangements objects, and returns the overlaid arrangement.
are instantiated using the same geometric traits class, but may be All three arrangements can be instantiated with different geometric
represented using different \dcel{} classes. A given overlay-traits object traits classes and different \dcel{} (encapsulated in the various
is used to properly construct the overlaid \dcel{} that represents the topology-traits classes) classes.
resulting arrangement. The geometry traits of the result arrangement is
used to construct the result arrangement. This means that all
the types (e.g., \ccc{Traits::Point_2}, \ccc{Traits::Curve_2} and
\ccc{Traits::Point_2}) of both input arrangements have to convertible
to the types in the result arrangement.
A given overlay-traits object is used to properly construct the
overlaid \dcel{} that represents the resulting arrangement.
%%%% %%%%
\ccInclude{CGAL/Arr_overlay.h} \ccInclude{CGAL/Arr_overlay_2.h}
\ccGlobalFunction{template<typename Traits, typename Dcel1, typename Dcel2, \ccGlobalFunction{template <class GeomTraitsA, class GeomTraitsB,
typename ResDcel, typename OverlayTraits> class GeomTraitsRes, class TopTraitsA, class TopTraitsB, class
void overlay (const Arrangement_2<Traits,Dcel1>& arr1, TopTraitsRes, class OverlayTraits>
const Arrangement_2<Traits,Dcel2>& arr2, void overlay (const Arrangement_on_surface_2<GeomTraitsA, TopTraitsA>& arr1,
Arrangement_2<Traits,ResDcel>& res, const Arrangement_on_surface_2<GeomTraitsB, TopTraitsB>& arr2,
OverlayTraits& ovl_tr);} Arrangement_on_surface_2<GeomTraitsRes, TopTraitsRes>& arr_res,
OverlayTraits& ovl_tr);}
Computes the overlay of two arrangements \ccc{arr1} and \ccc{arr2}, and sets Computes the overlay of two arrangements \ccc{arr1} and \ccc{arr2}, and sets
the output arrangement \ccc{res} to represent the overlaid arrangement. the output arrangement \ccc{res} to represent the overlaid arrangement.
\ccPrecond{\ccc{res} does not refer to either \ccc{arr1} or \ccc{arr2} \ccPrecond{\ccc{res} does not refer to either \ccc{arr1} or \ccc{arr2}

View File

@ -31,7 +31,10 @@
#include <vector> #include <vector>
#include <boost/mpl/if.hpp> #include <boost/mpl/if.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/static_assert.hpp>
CGAL_BEGIN_NAMESPACE CGAL_BEGIN_NAMESPACE
@ -40,26 +43,47 @@ CGAL_BEGIN_NAMESPACE
* \param arr1 The first arrangement. * \param arr1 The first arrangement.
* \param arr2 The second arrangement. * \param arr2 The second arrangement.
* \param arr_res Output: The resulting arrangement. * \param arr_res Output: The resulting arrangement.
* \param ovl_tr An overlay-traits class. As arr1, arr2 and res are all * \param ovl_tr An overlay-traits class. As arr1, arr2 and res can be
* templated with the same arrangement-traits class but with * templated with different geometry-traits class and
* different DCELs (encapsulated in the various topology-traits * different DCELs (encapsulated in the various topology-traits
* classes), the overlay-traits class defines the various * classes). The geometry-traits of the result arrangement is
* used to construct the result arrangement. This means that all
* the types (e.g., Point_2, Curve_2 and X_monotone_2) of both
* arr1 and arr2 have to be convertible to the types
* in the result geometry-traits.
* The overlay-traits class defines the various
* overlay operations of pairs of DCEL features from * overlay operations of pairs of DCEL features from
* TopTraitsA and TopTraitsB to the resulting ResDcel. * TopTraitsA and TopTraitsB to the resulting ResDcel.
*/ */
template <class GeomTraits, template <class GeomTraitsA,
class GeomTraitsB,
class GeomTraitsRes,
class TopTraitsA, class TopTraitsA,
class TopTraitsB, class TopTraitsB,
class TopTraitsRes, class TopTraitsRes,
class OverlayTraits> class OverlayTraits>
void overlay (const Arrangement_on_surface_2<GeomTraits, TopTraitsA>& arr1, void overlay (const Arrangement_on_surface_2<GeomTraitsA, TopTraitsA>& arr1,
const Arrangement_on_surface_2<GeomTraits, TopTraitsB>& arr2, const Arrangement_on_surface_2<GeomTraitsB, TopTraitsB>& arr2,
Arrangement_on_surface_2<GeomTraits, TopTraitsRes>& arr_res, Arrangement_on_surface_2<GeomTraitsRes, TopTraitsRes>& arr_res,
OverlayTraits& ovl_tr) OverlayTraits& ovl_tr)
{ {
typedef Arrangement_on_surface_2<GeomTraits, TopTraitsA> ArrA; typedef Arrangement_on_surface_2<GeomTraitsA, TopTraitsA> ArrA;
typedef Arrangement_on_surface_2<GeomTraits, TopTraitsB> ArrB; typedef Arrangement_on_surface_2<GeomTraitsB, TopTraitsB> ArrB;
typedef Arrangement_on_surface_2<GeomTraits, TopTraitsRes> ArrRes; typedef Arrangement_on_surface_2<GeomTraitsRes, TopTraitsRes> ArrRes;
// some type assertions (not all, but better then nothing).
BOOST_STATIC_ASSERT((boost::is_convertible< \
typename GeomTraitsA::Point_2, \
typename GeomTraitsRes::Point_2 >::value));
BOOST_STATIC_ASSERT((boost::is_convertible< \
typename GeomTraitsB::Point_2, \
typename GeomTraitsRes::Point_2 >::value));
BOOST_STATIC_ASSERT((boost::is_convertible< \
typename GeomTraitsA::X_monotone_curve_2, \
typename GeomTraitsRes::X_monotone_curve_2 >::value));
BOOST_STATIC_ASSERT((boost::is_convertible< \
typename GeomTraitsB::X_monotone_curve_2, \
typename GeomTraitsRes::X_monotone_curve_2 >::value));
typedef typename TopTraitsRes::template typedef typename TopTraitsRes::template
Sweep_line_overlay_visitor<ArrA, ArrB, OverlayTraits> Sweep_line_overlay_visitor<ArrA, ArrB, OverlayTraits>
@ -107,7 +131,7 @@ void overlay (const Arrangement_on_surface_2<GeomTraits, TopTraitsA>& arr1,
} }
// Obtain a extended traits-class object and define the sweep-line visitor. // Obtain a extended traits-class object and define the sweep-line visitor.
GeomTraits *geom_traits = arr_res.geometry_traits(); GeomTraitsRes *geom_traits = arr_res.geometry_traits();
/* We would like to avoid copy construction of the geometry traits class. /* We would like to avoid copy construction of the geometry traits class.
* Copy construction is undesired, because it may results with data * Copy construction is undesired, because it may results with data
@ -121,7 +145,7 @@ void overlay (const Arrangement_on_surface_2<GeomTraits, TopTraitsA>& arr1,
* Use the form 'A a(*b);' and not ''A a = b;' to handle the case where A has * Use the form 'A a(*b);' and not ''A a = b;' to handle the case where A has
* only an implicit constructor, (which takes *b as a parameter). * only an implicit constructor, (which takes *b as a parameter).
*/ */
typename boost::mpl::if_<boost::is_same<GeomTraits, Ovl_traits_2>, typename boost::mpl::if_<boost::is_same<GeomTraitsRes, Ovl_traits_2>,
Ovl_traits_2&, Ovl_traits_2>::type Ovl_traits_2&, Ovl_traits_2>::type
ex_traits(*geom_traits); ex_traits(*geom_traits);