New documentation for intersections in Kernel_23 and Kernel_d, removed old IT2/3, documentation

for overload, added examples for overload and dispatch_outputiterator
This commit is contained in:
Philipp Möller 2011-08-25 14:02:05 +00:00
parent 5b925d6f6e
commit 03caf9fe95
20 changed files with 248 additions and 177 deletions

8
.gitattributes vendored
View File

@ -1827,8 +1827,7 @@ Jet_fitting_3/doc_tex/Jet_fitting_3_ref/template_dependence.jpg -text svneol=uns
Jet_fitting_3/doc_tex/Jet_fitting_3_ref/template_dependence.pdf -text svneol=unset#application/pdf
Jet_fitting_3/examples/Jet_fitting_3/data/ellipe0.003.off -text svneol=unset#application/octet-stream
Kernel_23/doc_tex/Kernel_23/fig/pointSegmentTriangle.png -text
Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_2.tex -text
Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_3.tex -text
Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits.tex -text
Kernel_23/doc_tex/Kernel_23_ref/Kernel_ConstructRadicalLine_2.tex -text
Kernel_23/doc_tex/Kernel_23_ref/compare_lexicographically.tex -text
Kernel_23/doc_tex/Kernel_23_ref/fig/IsoCuboid.gif -text svneol=unset#image/gif
@ -1858,13 +1857,13 @@ Kernel_23/examples/Kernel_23/MyConstruct_coord_iterator.h -text
Kernel_23/examples/Kernel_23/MyConstruct_point_2.h -text
Kernel_23/examples/Kernel_23/MyPointC2_iostream.h -text
Kernel_23/examples/Kernel_23/cartesian_converter.cpp -text
Kernel_23/examples/Kernel_23/intersections.cpp -text
Kernel_23/include/CGAL/functions_on_enums.h -text
Kernel_23/include/CGAL/internal/Projection_traits_3.h -text
Kernel_23/test/Kernel_23/CMakeLists.txt -text
Kernel_23/test/Kernel_23/overload_bug.cpp -text
Kernel_d/doc_tex/Kernel_d/hypercube.png -text
Kernel_d/doc_tex/Kernel_d_ref/Do_intersect_d.tex -text
Kernel_d/doc_tex/Kernel_d_ref/Intersection_traits_d.tex -text
Kernel_d/doc_tex/Kernel_d_ref/Kernel_Compute_coordinate_d.tex -text
Kernel_d/doc_tex/Kernel_d_ref/Kernel_Less_coordinate_d.tex -text
Kernel_d/doc_tex/Kernel_d_ref/Kernel_Point_dimension_d.tex -text
@ -3339,6 +3338,9 @@ Ridges_3/examples/Ridges_3/skip_vcproj_auto_generation -text
Ridges_3/test/Ridges_3/data/ellipsoid.off -text svneol=unset#application/octet-stream
Robustness/demo/Robustness/help/index.html svneol=native#text/html
STL_Extension/doc_tex/STL_Extension/plusplus.png -text
STL_Extension/doc_tex/STL_Extension_ref/overload.tex -text
STL_Extension/examples/STL_Extension/Dispatch_output_iterator.cpp -text
STL_Extension/examples/STL_Extension/Overload.cpp -text
STL_Extension/include/CGAL/Overload.h -text
STL_Extension/include/CGAL/internal/boost/array_binary_tree.hpp -text
STL_Extension/include/CGAL/internal/boost/mutable_heap.hpp -text

View File

@ -91,6 +91,7 @@
\ccRefIdfierPage{CGAL::do_intersect} \\
\ccRefIdfierPage{CGAL::intersection} \\
\ccRefIdfierPage{CGAL::Intersection_traits<Kernel, A<Kernel>, B<Kernel>} \\
\ccRefIdfierPage{CGAL::squared_distance} \\
\subsubsection*{Predicates and Constructions}

View File

@ -62,28 +62,19 @@ There are number types on which no \ccStyle{sqrt} operation is defined,
especially integer types and rationals.
\end{itemize}
\subsection{Polymorphic Return Values}
Some functions can return different types of objects. A typical
\CC\ solution to this problem is to derive all possible return
types from a common base class, to return a pointer to this
class and to perform a dynamic cast on this pointer. The class
\ccc{Object} provides an abstraction.
An object \ccStyle{obj} of the class \ccc{Object} can
represent an arbitrary class. The only operations it provides is
to make copies and assignments, so that you can put them in lists
or arrays. Note that \ccc{Object} is NOT a common base class for the
elementary classes. Therefore, there is no
automatic conversion from these classes to \ccc{Object}. Rather
this is done with the global function \ccc{make_object()}. This
encapsulation mechanism requires the use of
\ccc{object_cast} to access the encapsulated class (a less
efficient way, which is now discouraged, used to be to
use the \ccc{assign} function).
\subsection{Intersections and variant return values}
Some functions can return different types of objects. To achieve this
in a type safe way {\cgal} uses return values of
\ccStyle{boost::optional< boost::variant< T \ldots\ >} were
T\textellipsis\ is a list of all possible resulting geometric objects.
The exact result type of an intersection can be determined by using the
\ccStyle{Intersection_traits} class.
\ccExample
In the following example, the object class is used as return value for the
\ccHtmlNoLinksFrom{intersection} computation, as there are possibly different return values.
In the following example, the traits class is used to provide the return value for the
\ccHtmlNoLinksFrom{intersection} computation:
\ccHtmlLinksOff%
\begin{cprog}
{
typedef Cartesian<double> K;
@ -93,54 +84,23 @@ In the following example, the object class is used as return value for the
Segment_2 segment_1, segment_2;
std::cin >> segment_1 >> segment_2;
Object obj = intersection(segment_1, segment_2);
if (const Point_2 *point = object_cast<Point_2>(&obj)) {
/* do something with *point */
} else if (const Segment_2 *segment = object_cast<Segment_2>(&obj)) {
/* do something with *segment*/
/* IT is an alias for Intersection_traits */
IT< K, Segment_2, Segment_2>::result_type
v = intersection(s1, s2);
if(v) {
/* not empty */
if (const Point_2 *p = boost::get<Point_2>(&*v) ) {
/* do something with *p */
} else if (const Segment_2 *s = boost::get<Segment_2>(&*v) ) {
/* do something with *s */
}
} else {
/* empty intersection */
}
\end{cprog}
\ccHtmlLinksOff%
\begin{cprog}
/* there was no intersection */
}
\end{cprog}
\ccHtmlLinksOn%
\medskip
The \ccHtmlNoLinksFrom{intersection} routine itself looks roughly as follows:
\begin{cprog}
template < class Kernel >
Object intersection(Segment_2<Kernel> s1, Segment_2<Kernel> s2)
{
\end{cprog}
\ccHtmlLinksOff%
\begin{cprog}
if (/* intersection in a point */ ) {
\end{cprog}
\ccHtmlLinksOn%
\begin{cprog}
Point_2<Kernel> p = ... ;
return make_object(p);
\end{cprog}
\ccHtmlLinksOff%
\begin{cprog}
} else if (/* intersection in a segment */ ) {
\end{cprog}
\ccHtmlLinksOn%
\begin{cprog}
Segment_2<Kernel> s = ... ;
return make_object(s);
}
return Object();
}
\end{cprog}
\subsection{Constructive Predicates}
For testing where a point $p$ lies with respect to a plane defined by three
points $q$, $r$ and $s$, one may be tempted to construct the plane

View File

@ -0,0 +1,18 @@
\begin{ccRefClass}{Intersection_traits<Kernel, A<Kernel>, B<Kernel>}
\ccInclude{CGAL/Intersection_traits.h}
\ccDefinition
The traits class \ccClassTemplateName\ provides a typedef for the
return type of the \ccc{intersection} function objects belonging to a
model of \ccc{Kernel}. The value of \ccStyle{result_type} can be found
in the \ccc{intersection} documentation of the corresponding kernel.
For convenience the alias \ccStyle{IT} is provided.
\ccTypes
\ccStyle{result_type} The type of the resulting intersection between \ccStyle{A} and \ccStyle{B}.
\end{ccRefClass}

View File

@ -1,17 +0,0 @@
\begin{ccRefClass}{Intersection_traits_2< Kernel, A<Kernel>, B<Kernel> >}
\ccInclude{CGAL/Intersection_traits_2.h}
\ccDefinition
The traits class \ccClassTemplateName\ provides a typedef for the
return type of the \ccc{intersection} function when called on
2-dimensional objects belonging to a model of \ccc{Kernel}.
For convenience the alias \ccStyle{IT2} is provided.
\ccTypes
\ccStyle{result_type} The type of the resulting intersection between A and B
\end{ccRefClass}

View File

@ -1,17 +0,0 @@
\begin{ccRefClass}{Intersection_traits_3< Kernel, A<Kernel>, B<Kernel> >}
\ccInclude{CGAL/Intersection_traits_3.h}
\ccDefinition
The traits class \ccClassTemplateName\ provides a typedef for the
return type of the \ccc{intersection} function when called on
3-dimensional objects belonging to a model of \ccc{Kernel}.
For convenience the alias \ccStyle{IT3} is provided.
\ccTypes
\ccStyle{result_type} The type of the resulting intersection between A and B
\end{ccRefClass}

View File

@ -4,6 +4,15 @@ Depending on which \cgal\ \ccHtmlNoLinksFrom{kernel} is used,
different versions of this global function are available. This is
described below.
\paragraph{Notes on Backwards compatibility}
The \ccStyle{intersection} function used to return
\ccStyle{CGAL::Object} but starting with {\cgal} VERSION HERE the
return type is determined by a dedicated traits class. To preserve
backwards compatibility \ccStyle{CGAL::Object} can be constructed from
the new return types implicitly, but switching to the new style is
advocated.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{With the basic 2D and 3D Kernel} (see Chapter~\ref{chapter-kernel-23})
@ -11,7 +20,7 @@ described below.
\ccUnchecked{
\ccRefLabel{Kernel::intersection}
\ccFunction{Object intersection(Type1<Kernel> obj1, Type2<Kernel> obj2);}
\ccFunction{IT< Kernel, Type1<Kernel>, Type2<Kernel> >::result_type intersection(Type1<Kernel> obj1, Type2<Kernel> obj2);}
{Two objects \ccStyle{obj1} and \ccStyle{obj2} intersect if there is a point
\ccStyle{p} that is part of both \ccStyle{obj1} and \ccStyle{obj2}.
The \ccHtmlNoLinksFrom{intersection} region of those two objects is defined as the set of all
@ -22,10 +31,10 @@ If a segment lies completely inside a triangle, then those two objects
intersect and the \ccHtmlNoLinksFrom{intersection} region is the complete segment.
}}
The possible value for types \ccStyle{Type1} and \ccStyle{Type2} and the
possible return values wrapped in \ccc{Object} are the
following:
The same functionality is also available through the functors \ccc{Kernel::Intersect_2} and \ccc{Kernel::Intersect_2}.
The possible values for types \ccStyle{Type1} and \ccStyle{Type2} and
the value for T\ldots in \ccStyle{boost::optional< boost::variant< T\ldots >} are the following:
\begin{ccTexOnly}
\begin{longtable}[c]{|l|l|l|}
@ -105,6 +114,13 @@ type A & type B & \parbox{4 cm}{\vspace{1 mm}{return type}} \\
\\ \ccStyle{Segment_2}
\vspace{1 mm}} \\
\hline
\ccStyle{Iso_rectangle_2} & \ccStyle{Triangle_2} & \parbox{4 cm}{\vspace{1 mm}
\ccStyle{Point_2}
\\ \ccStyle{Segment_2}
\\ \ccStyle{Triangle_2}
\\ \ccStyle{_2}
\vspace{1 mm}} \\
\hline
\ccStyle{Iso_rectangle_2} & \ccStyle{Iso_rectangle_2} & \parbox{4 cm}{\vspace{1 mm}
\ccStyle{Iso_rectangle_2}
\vspace{1 mm}} \\
@ -470,9 +486,10 @@ type A & type B & \parbox{4 cm}{\vspace{1 mm}{return type}} \\
There is also an intersection function between 3 planes.
\ccFunction{Object intersection(const Plane_3<Kernel>& pl1,
const Plane_3<Kernel>& pl2,
const Plane_3<Kernel>& pl3);}
\ccFunction{optional< variant< Point_3, Line_3, Plane_3 > >
intersection(const Plane_3<Kernel>& pl1,
const Plane_3<Kernel>& pl2,
const Plane_3<Kernel>& pl3);}
{returns the intersection of 3 planes, which can be either a point, a line,
a plane, or empty.}
@ -485,9 +502,12 @@ If this kernel is used, in addition to the function and the
combination of 2D types described above, another version of the function
is provided.
The iterator versions of those functions can be used in conjunction
with \ccc{CGAL::Dispatch_output_iterator<V,O>}.
Since both the number of intersections, if any, and their type,
depend on the arguments, the function returns an output
iterator on \ccc{Object}'s, as presented below.
depend on the arguments, the function expects an output
iterator on \ccc{Intersection_Traits< K, Type1<K>, Type2<K> >}, as presented below.
\ccFunction{template < class OutputIterator >
OutputIterator
@ -495,7 +515,7 @@ intersection(const Type1 &obj1, const Type2 &obj2,
OutputIterator intersections);}
{Copies in the output iterator the intersection elements between the
two objects. \ccc{intersections} iterates on
elements of type \ccc{CGAL::Object}, in lexicographic order,}
elements of type \ccStyle{IT< K, Type1<K>, Type2<K> >}, in lexicographic order,}
where \ccStyle{Type1} and \ccStyle{Type2} can both be either
\begin{itemize}
@ -529,9 +549,12 @@ If this kernel is used, in addition to the function and the
combination of 3D types described above, two other versions of the function
are provided.
The iterator versions of those functions can be used in conjunction
with \ccc{CGAL::Dispatch_output_iterator<V,O>}.
Since both the number of intersections, if any, and their type,
depend on the arguments, the functions return an output
iterator on \ccStyle{Object}'s, as presented below.
depend on the arguments, the functions expects an output
iterator on \ccStyle{Intersection_Traits<Kernel, Type1<Kernel>, Type2<Kernel>}, as presented below.
The \textbf{first function} is:
@ -541,7 +564,7 @@ intersection(const Type1 &obj1, const Type2 &obj2,
OutputIterator intersections);}
{Copies in the output iterator the intersection elements between the
two objects. \ccc{intersections} iterates on
elements of type \ccStyle{CGAL::Object}, in lexicographic order,
elements of type \ccStyle{IT<Kernel, A<Kernel>, B<Kernel>}, in lexicographic order,
when this ordering is defined on the computed objects,}
where \ccStyle{Type1} and \ccStyle{Type2} can both be either:
@ -555,7 +578,7 @@ where \ccStyle{Type1} and \ccStyle{Type2} can both be either:
\end{itemize}
and depending on the types \ccStyle{Type1} and \ccStyle{Type2}, the computed
\ccStyle{CGAL::Object}s can be assigned to
type can be:
\begin{itemize}
\item {} \ccStyle{std::pair<Circular_arc_point_3<SphericalKernel>, unsigned>},
where the unsigned integer is the multiplicity of the corresponding
@ -580,7 +603,8 @@ intersection(const Type1 &obj1, const Type2 &obj2, const Type3 &obj3,
OutputIterator intersections);}
{Copies in the output iterator the intersection elements between the
three objects. \ccc{intersections} iterates on
elements of type \ccStyle{CGAL::Object}, in lexicographic order
elements of type \ccStyle{boost::optional< boost::variant< std::pair<Circular_arc_point_3<SphericalKernel>, unsigned>,
Circle_3<SphericalKernel>, Sphere_3<SphericalKernel>, Plane_3<SphericalKernel> >}, in lexicographic order
when this ordering is defined on the computed objects}
where \ccStyle{Type1}, \ccStyle{Type2} and \ccStyle{Type3}
@ -590,8 +614,7 @@ can be either
\item {} \ccStyle{Plane_3<SphericalKernel>}
\end{itemize}
and depending of these types, the computed \ccStyle{CGAL::Object}s can be
assigned to
and depending of these types, the computed return value
\begin{itemize}
\item {} \ccStyle{std::pair<Circular_arc_point_3<SphericalKernel>, unsigned>},
where the unsigned integer is the multiplicity of the corresponding
@ -607,35 +630,23 @@ and \ccc{obj3} are equal.
The following example demonstrates the most common use of
\ccc{intersection} routines with the basic 2D and 3D Kernels.
\ccHtmlLinksOff%
\begin{verbatim}
#include <CGAL/intersections.h>
void foo(CGAL::Segment_2<Kernel> seg, CGAL::Line_2<Kernel> line)
template<typename R>
struct Intersection_visitor {
typedef result_type void;
void operator()(const Point_2<R>& p) const { /* handle point */ }
void operator()(const Segment_2<R>& s) const { /* handle segment */ }
};
template <class R>
void foo(Segment_2<R> seg, Line_2<R> lin)
{
CGAL::Object result = CGAL::intersection(seg, line);
if (const CGAL::Point_2<Kernel> *ipoint = CGAL::object_cast<CGAL::Point_2<Kernel> >(&result)) {
\end{verbatim}%
\ccHtmlLinksOff%
\begin{verbatim}
// handle the point intersection case with *ipoint.
\end{verbatim}%
\ccHtmlLinksOn%
\begin{verbatim}
} else
if (const CGAL::Segment_2<Kernel> *iseg = CGAL::object_cast<CGAL::Segment_2<Kernel> >(&result)) {
\end{verbatim}%
\ccHtmlLinksOff%
\begin{verbatim}
// handle the segment intersection case with *iseg.
\end{verbatim}%
\ccHtmlLinksOn%
\begin{verbatim}
} else {
\end{verbatim}%
\ccHtmlLinksOff%
\begin{verbatim}
// handle the no intersection case.
}
ITd< R, Segment_2<R>, Line_2<R> >::result_type result = intersection(seg, lin);
if(result) { boost::apply_visitor(Intersection_visitor(), *result); }
else { /* no intersection */ }
}
\end{verbatim}%
\ccHtmlLinksOn%
@ -646,8 +657,9 @@ in Chapters~\ref{chapter-circular-kernel}
and~\ref{chapter-spherical-kernel}.
\ccSeeAlso
% \ccRefIdfierPage{CGAL::assign} \\
\ccRefIdfierPage{CGAL::do_intersect} \\
\ccRefIdfierPage{CGAL::Object} \\
\ccRefIdfierPage{CGAL::do_intersect}, \\
\ccRefIdfierPage{CGAL::Intersection_traits<Kernel, A<Kernel>, B<Kernel>}, \\
\ccAnchor{www.boost.org/doc/libs/release/libs/optional/index.html}{boost::optional}, \\
\ccAnchor{www.boost.org/doc/html/variant.html}{boost::variant}
\end{ccRefFunction}

View File

@ -44,8 +44,6 @@ in the kernel.
\input{Kernel_23_ref/Simple_cartesian.tex}
\input{Kernel_23_ref/Simple_homogeneous.tex}
\input{Kernel_23_ref/Projection_traits_xy_3.tex}
\input{Kernel_23_ref/Intersection_traits_2.tex}
\input{Kernel_23_ref/Intersection_traits_3.tex}
\clearpage
\section{Predefined Kernels}
@ -191,6 +189,7 @@ in the kernel.
\input{Kernel_23_ref/has_smaller_signed_distance_to_line.tex}
\input{Kernel_23_ref/has_smaller_signed_distance_to_plane.tex}
\input{Kernel_23_ref/intersection.tex}
\input{Kernel_23_ref/Intersection_traits.tex}
\input{Kernel_23_ref/left_turn.tex}
\input{Kernel_23_ref/lexicographically_xyz_smaller.tex}
\input{Kernel_23_ref/lexicographically_xyz_smaller_or_equal.tex}

View File

@ -0,0 +1,51 @@
#include <CGAL/intersections.h>
#include <CGAL/iterator.h>
#include <boost/bind.hpp>
using namespace CGAL;
typedef Cartesian<double> K;
typedef K::Point_2 Point;
typedef Creator_uniform_2<double,Point> Pt_creator;
typedef K::Segment_2 Segment;
int main()
{
std::vector<Segment> input;
// Prepare point generator for the horizontal segment, length 200.
typedef Random_points_on_segment_2<Point,Pt_creator> P1;
P1 p1( Point(-100,0), Point(100,0));
// Prepare point generator for random points on circle, radius 250.
typedef Random_points_on_circle_2<Point,Pt_creator> P2;
P2 p2( 250);
// Create segments.
typedef Creator_uniform_2< Point, Segment> Seg_creator;
typedef Join_input_iterator_2< P1, P2, Seg_creator> Seg_iterator;
Seg_iterator g( p1, p2);
copy_n( g, seg_count, std::back_inserter(input));
std::vector<Point> points;
std::vector<Segment> segments;
typedef Dispatch_output_iterator<
cpp0x::tuple<Point,Segment>, cpp0x::tuple< std::back_insert_iterator<std::vector<Point> >,
std::back_insert_iterator<std::vector<Segment> > > >
Dispatcher;
Dispatcher disp = dispatch_output<Point,Segment>( std::back_inserter(points),std::back_inserter(segments) );
// intersections of many objects, directly dispatched
std::transform(input.begin(), input.end(), disp,
// XXX fix binder
boost::bind(intersection, input.front(), _1));
std::cout << "Point intersections: " << points.size() << std::endl;
std::cout << "Segment intersections: " << segments.size() << std::endl;
// intersections of a single object
IT2<K, Segment, Segment> v = intersection(input.back(), input.front());
return 0;
}

View File

@ -44,6 +44,6 @@
\subsubsection*{Intersection operations}
\ccRefIdfierPage{CGAL::do_intersect}\\
\ccRefIdfierPage{CGAL::intersection}
\ccRefIdfierPage{CGAL::intersection}\\
\ccRefIdfierPage{CGAL::Intersection_traits}

View File

@ -58,7 +58,7 @@ routine, The problem of a distance routine is that it needs the
defined, especially integer types and rationals.
\end{itemize}
\subsection{Intersection}
\subsection{Intersections}
Intersections on kernel objects currently cover only those objects
that are part of flats (\ccc{Segment_d<R>}, \ccc{Ray_d<R>},
@ -67,7 +67,7 @@ $o1$, $o2$ of these types the operation \ccc{intersection(o1,o2)}
returns a \ccStyle{boost::optional< boost::variant< T \ldots\ >}
were T\textellipsis\ is a list of all possible resulting geometric objects.
The traits class \ccc{Intersection_traits_d} provides a typedef for
The traits class \ccc{Intersection_traits} provides a typedef for
the \ccStyle{result_type} of the \ccc{intersection} function when called with
d-dimensional kernel objects.
@ -79,7 +79,7 @@ d-dimensional kernel objects.
typedef Segment_d< K > Segment;
Segment s1, s2;
std::cin >> s1 >> s2;
ITd< K, Segment, Segment>::result_type
IT<K, Segment, Segment>::result_type
v = intersection(s1, s2);
if(v) {
/* not empty */

View File

@ -1,17 +0,0 @@
\begin{ccRefClass}{Intersection_traits_d< Kernel, A<Kernel>, B<Kernel> >}
\ccInclude{CGAL/Intersection_traits_d.h}
\ccDefinition
The traits class \ccClassTemplateName\ provides a typedef for the
return type of the \ccc{intersection} function when called on objects
belonging to a model of \ccc{Kernel_d}.
For convenience the alias \ccStyle{ITd} is provided.
\ccTypes
\ccStyle{result_type} The type of the resulting intersection between A and B
\end{ccRefClass}

View File

@ -4,7 +4,7 @@ A model for this must provide:
\ccCreationVariable{fo}
\ccMemberFunction{
Intersection_traits_d<K, Type1<K>, Type2<K> >::result_type
Intersection_traits<K, Type1<K>, Type2<K> >::result_type
operator()(const Type1<K>& p, const Type2<K>& q);}
{returns the result of the intersection of $p$ and $q$ in form of a
polymorphic object. \ccc{Kernel_object} may be any of

View File

@ -1,7 +1,7 @@
\begin{ccRefFunction}{intersection}
\ccInclude{CGAL/intersections_d.h}
\ccFunction{Intersection_traits_d<R, Type1<R>, Type2<R> >::result_type
\ccFunction{Intersection_traits<R, Type1<R>, Type2<R> >::result_type
intersection(Type1<R> f1, Type2<R> f2);} { returns the intersection
result of $f1$ and $f2$.
\ccPrecond The objects are of the same dimension.}
@ -152,25 +152,25 @@ The following example demonstrates the most common use of
\begin{verbatim}
#include <CGAL/intersections_d.h>
template<typename R>
struct Intersection_visitor {
typedef result_type void;
void operator()(const Point_d<R>& p) { /* handle point */ }
void operator()(const Segment_d<R>& s) { /* handle segment */ }
void operator()(const Point_d<R>& p) const { /* handle point */ }
void operator()(const Segment_d<R>& s) const { /* handle segment */ }
};
template <class R>
void foo(Segment_d<R> seg, Line_d<R> lin)
{
ITd< R, Segment_d<R>, Line_d<R> >::result_type result = intersection(seg, lin);
if(result) { boost::apply_visitor(Intersection_visitor(), *result); }
if(result) { boost::apply_visitor(Intersection_visitor<R>(), *result); }
else { /* no intersection */ }
}
\end{verbatim}%
\ccHtmlLinksOn%
\ccSeeAlso \ccc{do_intersect}, \ccc{Kernel::Intersect_d} ,
\ccc{Kernel::Do_intersect_d}, \ccc{Intersection_traits_d},
\ccAnchor{www.boost.org/doc/libs/release/libs/optional/index.html}{boost::optional},
\ccc{Kernel::Do_intersect_d}, \ccAnchor{www.boost.org/doc/libs/release/libs/optional/index.html}{boost::optional},
\ccAnchor{www.boost.org/doc/html/variant.html}{boost::variant}
\end{ccRefFunction}

View File

@ -86,7 +86,6 @@
\input{Kernel_d_ref/Kernel_Equal_d.tex}
\input{Kernel_d_ref/Kernel_Has_on_positive_side_d.tex}
\input{Kernel_d_ref/Kernel_Intersect_d.tex}
\input{Kernel_d_ref/Intersection_traits_d.tex}
\input{Kernel_d_ref/Kernel_Less_lexicographically_d.tex}
\input{Kernel_d_ref/Kernel_Less_or_equal_lexicographically_d.tex}
\input{Kernel_d_ref/Kernel_Less_coordinate_d.tex}

View File

@ -35,6 +35,7 @@
\input{STL_Extension_ref/tuple.tex}
\input{STL_Extension_ref/Complexity_tags.tex}
\input{STL_Extension_ref/Default.tex}
\input{STL_Extension_ref/overload.tex}
%%\cgalColumnLayout

View File

@ -0,0 +1,22 @@
\begin{ccRefClass}{Overload}
\ccInclude{CGAL/Overload.h}
\ccDefinition
A class to bundle multiple unary \ccStyle{std::function} or
\ccStyle{boost::function} objects into a single overload of
\ccStyle{operator()}. The return type of \ccStyle{operator()} is the
result_type of the first function of the \ccStyle{tuple} it was created from.
\ccOperations
\ccMethod{template<typename T> result_type operator()(T& t);}
{Calls the function that matches the arguments best.}
\ccFunctionTemplate{T}{template <class T> Overload<T> make_overload(T&& c);}
{Creates an \ccStyle{Overload} from the \ccStyle{cpp0x::tuple} \ccStyle{c}.}
\ccIncludeExampleCode{STL_Extension/Overload.cpp}
\end{ccRefClass}

View File

@ -244,6 +244,8 @@
dispatch_output(O... o);}
{returns a \ccc{Dispatch_output_iterator} constructed from the arguments.}
\ccIncludeExampleCode{STL_Extension/Dispatch_output_iterator.cpp}
\ccSeeAlso
\ccRefIdfierPage{CGAL::Dispatch_or_drop_output_iterator<V,O>}

View File

@ -0,0 +1,36 @@
#include <vector>
#include <CGAL/iterator.h>
#include <boost/variant.hpp>
#include <boost/optional.hpp>
int main()
{
std::vector<int> a;
std::vector<double> b;
std::vector<char> c;
typedef CGAL::Dispatch_output_iterator<
CGAL::cpp0x::tuple<int, double, char>,
CGAL::cpp0x::tuple<std::back_insert_iterator< std::vector<int> >,
std::back_insert_iterator< std::vector<double> >,
std::back_insert_iterator< std::vector<char> >
> > Dispatch;
Dispatch disp = CGAL::dispatch_output<int, double, char>(
std::back_inserter(a),
std::back_inserter(b),
std::back_inserter(c));
var va = 23; var vb = 4.2; var vc = 'x';
// goes to a
*disp++ = va;
// goes to b
*disp++ = vb;
// goes to c
*disp++ = vc;
// goes to a
*disp++ = 42;
return 0;
}

View File

@ -0,0 +1,19 @@
#include <iostream>
#include <CGAL/Overload.h>
// This file requires a compiler with support for the C++0x features auto and lambda
int main()
{
auto overload = make_overload(
std::make_tuple(
function<int(int)>([](int) { return 1; }),
function<int(char)>([](char) { return 2; }),
function<int(double)>([](double) { return 3; })
)
);
std::cout << o(1) << o('a') << " " << o(2.0) << std::endl;
return 0;
}