cgal/Kernel_23/doc_tex/Kernel_23/extensible_kernel.tex

97 lines
3.1 KiB
TeX

\section{Extensible Kernel\label{section-extensible-kernel}}
This manual section describe how users can plug user defined
geometric classes in existing \cgal\ kernels. This is best
illustrated by an example.
\subsection{Introduction}
\cgal\ defines the concept of a geometry kernel. Such a kernel provides types,
construction objects and generalized predicates. Most implementations
of Computational Geometry algorithms and data structures in the basic
library of \cgal\ were done in a way that classes or functions can be
parametrized with a geometric traits class.
In most cases this geometric traits class must be a model of the \cgal\ geometry
kernel concept (but there are some exceptions).
\subsection{An Extensive Example}
Assume you have the following point class, where the coordinates are
stored in an array of \ccc{doubles}, where we have another data member
\ccc{color}, which shows up in the constructor.
\ccIncludeExampleCode{Kernel_23/MyPointC2.h}
As said earlier the class is pretty minimalistic, for
example it has no \ccc{bbox()} method. One
might assume that a basic library algorithm which computes
a bounding box (e.g, to compute the bounding box of a polygon),
will not compile. Luckily it will, because it does not
use of member functions of geometric objects, but it makes
use of the functor \ccc{Kernel::Construct_bbox_2}.
To make the right thing happen with \ccc{MyPointC2} we
have to provide the following functor.
\ccIncludeExampleCode{Kernel_23/MyConstruct_bbox_2.h}
Things are similar for random access to the \ccHtmlNoLinksFrom{Cartesian}
coordinates of a point. As the coordinates are stored
in an array of \ccc{doubles} we can use \ccc{double*} as
random access iterator.
\ccIncludeExampleCode{Kernel_23/MyConstruct_coord_iterator.h}
The last functor we have to provide is the one which constructs
points. That is you are not forced to add the constructor
with the \ccc{Origin} as parameter to your class, nor the constructor with
homogeneous coordinates.
The functor is a kind of glue layer between the \cgal\ algorithms
and your class.
\ccIncludeExampleCode{Kernel_23/MyConstruct_point_2.h}
Now we are ready to put the puzzle together. We won't explain it in
detail, but you see that there are \ccc{typedefs} to the new point
class and the functors. All the other types are inherited.
\ccIncludeExampleCode{Kernel_23/MyKernel.h}
Finally, we give an example how this new kernel can be used.
Predicates and constructions work with the new point, they
can be a used to construct segments and triangles with, and
data structures from the Basic Library, as the Delaunay
triangulation work with them.
The kernel itself can be
made robust by plugging it in the \ccc{Filtered_kernel}.
\ccIncludeExampleCode{Kernel_23/MyKernel.cpp}
\subsection{Limitations}
The point class must have member functions \ccc{x()} and \ccc{y()}
(and \ccc{z()} for the 3d point). We will probably
introduce function objects that take care of coordinate
access.
As we enforce type equality between \ccc{MyKernel::Point_2} and \ccc{Point_2<MyKernel>},
the constructor with the color as third argument is not available.