mirror of https://github.com/CGAL/cgal
examples no longer use Object
This commit is contained in:
parent
4764e5d361
commit
ece2fa38d4
|
|
@ -24,7 +24,9 @@ double prob_2() {
|
|||
if(CGAL::orientation(p4, p5, p6) != CGAL::COUNTERCLOCKWISE) std::swap(p4, p6);
|
||||
T o2 = T(p4, p5, p6);
|
||||
|
||||
std::vector< CGAL::Object > res;
|
||||
typedef boost::result_of<CircularK::Intersect_2(T, T)>::type
|
||||
Intersection_result;
|
||||
std::vector<Intersection_result> res;
|
||||
CGAL::intersection(o1, o2, std::back_inserter(res));
|
||||
|
||||
prob += (res.size() != 0) ? 1.0 : 0.0;
|
||||
|
|
|
|||
|
|
@ -169,7 +169,6 @@ bool do_intersect(Type1<SphericalKernel> obj1, Type2<SphericalKernel> obj2, Type
|
|||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
\addtogroup intersection
|
||||
|
||||
|
|
@ -185,6 +184,7 @@ defined before any \cgal header is included.
|
|||
|
||||
#define CGAL_INTERSECTION_VERSION
|
||||
|
||||
|
||||
/*!
|
||||
\addtogroup intersection
|
||||
|
||||
|
|
@ -299,7 +299,7 @@ the value for `T...` in `boost::optional< boost::variant<
|
|||
<TABLE CELLPADDING=3 BORDER="1">
|
||||
<TR> <TH> Type1 </TH>
|
||||
<TH> Type2 </TH>
|
||||
<TH> Return Type: Object<Type> </TH>
|
||||
<TH> Return Type: `T...` </TH>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="CENTER" > Iso_rectangle_2 </TD>
|
||||
|
|
@ -382,7 +382,7 @@ the value for `T...` in `boost::optional< boost::variant<
|
|||
<TABLE CELLPADDING=3 BORDER="1">
|
||||
<TR> <TH> Type1 </TH>
|
||||
<TH> Type2 </TH>
|
||||
<TH> Return Type: Object<Type> </TH>
|
||||
<TH> Return Type: `T...` </TH>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="CENTER" > Line_3 </TD>
|
||||
|
|
@ -565,8 +565,8 @@ on the arguments, the function expects an output iterator on
|
|||
`boost::result_of<K::Intersect_2(Type1, Type2)>::type`, as
|
||||
presented below.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/// @{
|
||||
|
||||
/*!
|
||||
|
|
@ -619,6 +619,9 @@ intersection(const Type1 &obj1, const Type2 &obj2,
|
|||
When using a spherical kernel, in addition to the function overloads documented \ref intersection_linear "here",
|
||||
the following function overloads are also available.
|
||||
|
||||
The iterator versions of those functions can be used in conjunction
|
||||
`Dispatch_output_iterator`.
|
||||
|
||||
Since both the number of intersections, if any, and their type, depend
|
||||
on the arguments, the functions expects an output iterator on
|
||||
`boost::result_of<Kernel::Intersect_3(Type1, Type2)>::type`,
|
||||
|
|
@ -629,7 +632,7 @@ as presented below.
|
|||
/*!
|
||||
Copies in the output iterator the intersection elements between the
|
||||
two objects. `intersections` iterates on
|
||||
elements of type `CGAL::Object`, in lexicographic order,
|
||||
elements of type `result_of< Intersect_3(SphericalType1, SphericalType2) >`, in lexicographic order,
|
||||
when this ordering is defined on the computed objects,
|
||||
|
||||
where `SphericalType1` and `SphericalType2` can both be either:
|
||||
|
|
@ -643,7 +646,7 @@ where `SphericalType1` and `SphericalType2` can both be either:
|
|||
|
||||
|
||||
and depending on the types `SphericalType1` and `SphericalType2`, the computed
|
||||
`CGAL::Object`s can be assigned to
|
||||
type can be
|
||||
|
||||
- `std::pair<Circular_arc_point_3<SphericalKernel>, unsigned>`,
|
||||
where the unsigned integer is the multiplicity of the corresponding
|
||||
|
|
@ -668,7 +671,7 @@ intersection(const SphericalType1 &obj1, const SphericalType2 &obj2,
|
|||
/*!
|
||||
Copies in the output iterator the intersection elements between the
|
||||
three objects. `intersections` iterates on
|
||||
elements of type `CGAL::Object`, in lexicographic order
|
||||
elements of type `boost::variant< Circle_3, Plane_3, Sphere_3, std::pair< Circular_arc_point_3, unsigned > >`, in lexicographic order
|
||||
when this ordering is defined on the computed objects
|
||||
|
||||
where `Type1`, `Type2` and `Type3`
|
||||
|
|
@ -678,8 +681,7 @@ can be either
|
|||
- `Plane_3<SphericalKernel>`
|
||||
|
||||
|
||||
and depending of these types, the computed `CGAL::Object`s can be
|
||||
assigned to
|
||||
and depending of these types, the computed return value
|
||||
|
||||
- `std::pair<Circular_arc_point_3<SphericalKernel>, unsigned>`,
|
||||
where the unsigned integer is the multiplicity of the corresponding
|
||||
|
|
@ -689,7 +691,7 @@ assigned to
|
|||
`Type3` are equal, and if the three objets `obj1` and `obj2`
|
||||
and `obj3` are equal.
|
||||
*/
|
||||
template < typename Type1, typename Type2, typename OutputIterator >
|
||||
template < typename Type1, typename Type2, typename Type3, typename OutputIterator >
|
||||
OutputIterator
|
||||
intersection(const Type1 &obj1, const Type2 &obj2, const Type3 &obj3,
|
||||
OutputIterator intersections);
|
||||
|
|
|
|||
|
|
@ -488,35 +488,20 @@ especially integer types and rationals.
|
|||
|
||||
\subsection Kernel_23VariantReturnValues Intersections and Variant Return Types
|
||||
|
||||
Some functions can return different types of objects. To achieve this
|
||||
Some functions, for example `intersection()`, can return different types of objects. To achieve this
|
||||
in a type safe way \cgal uses return values of type
|
||||
`boost::optional< boost::variant< T \ldots\ > >` were `T...` is a
|
||||
list of all possible resulting geometric objects. The exact result
|
||||
type of an intersection can be determined through the metafunction
|
||||
`boost::result_of<Kernel::Intersect_2(Type1, Type2)>` or
|
||||
`boost::result_of<Kernel::Intersect_3(Type1, Type2)>`, where
|
||||
`Type1} and `Type2` are the types of the objects used in the
|
||||
`Type1` and `Type2` are the types of the objects used in the
|
||||
intersection computation. See
|
||||
<A HREF="http://www.boost.org/libs/utility/utility.htm#result_of">`boost::result_of`</A>
|
||||
for more information about this mechanism.
|
||||
|
||||
|
||||
Some functions can return different types of objects. A typical
|
||||
\cpp 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
|
||||
`Object` provides an abstraction.
|
||||
An object `obj` of the class `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 `Object` is *not* a common base class for the
|
||||
elementary classes. Therefore, there is no
|
||||
automatic conversion from these classes to `Object`. Rather
|
||||
this is done with the global function `make_object()`. This
|
||||
encapsulation mechanism requires the use of
|
||||
`object_cast` to access the encapsulated class (a less
|
||||
efficient way, which is now discouraged, used to be to
|
||||
use the `assign` function).
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
|
|
|||
|
|
@ -25,8 +25,13 @@ int main(){
|
|||
EK::Triangle_3 t2=to_exact(t1);
|
||||
EK::Line_3 l2=to_exact(l1);
|
||||
|
||||
CGAL::Object inter=CGAL::intersection(t2,l2);
|
||||
const EK::Point_3& exact_pt=CGAL::object_cast<EK::Point_3>(inter);
|
||||
boost::result_of<EK::Intersect_3(EK::Triangle_3, EK::Line_3)>::type
|
||||
inter = CGAL::intersection(t2,l2);
|
||||
|
||||
// As we are sure that there IS an intersection
|
||||
// and that the intersection IS a point
|
||||
// we do not have to check for this, or put it in a try/catch
|
||||
const EK::Point_3& exact_pt = boost::get<EK::Point_3>(*inter);
|
||||
|
||||
EK_to_IK to_inexact;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ typedef Random_points_on_circle_2<Point,Pt_creator> P2;
|
|||
typedef Creator_uniform_2< Point, Segment> Seg_creator;
|
||||
typedef Join_input_iterator_2< P1, P2, Seg_creator> Seg_iterator;
|
||||
|
||||
using boost::result_of;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
@ -33,15 +32,6 @@ int main()
|
|||
Seg_iterator g( p1, p2);
|
||||
std::copy_n( g, 200, std::back_inserter(input));
|
||||
|
||||
// intersection of two objects
|
||||
#if !defined(CGAL_CFG_NO_CPP0X_AUTO)
|
||||
// with C++11
|
||||
auto v = intersection(input.back(), input.front());
|
||||
#else
|
||||
// without C++11
|
||||
result_of<K::Intersect_2(Segment, Segment)>::type v
|
||||
= intersection(input.back(), input.front());
|
||||
#endif
|
||||
|
||||
// splitting results with Dispatch_output_iterator
|
||||
std::vector<Point> points;
|
||||
|
|
@ -56,17 +46,13 @@ int main()
|
|||
std::back_inserter(segments) );
|
||||
|
||||
// intersections of many objects, directly dispatched
|
||||
#if !defined(CGAL_CFG_NO_CPP0X_LAMBDA)
|
||||
// with C++11 lambdas
|
||||
auto& s1 = input.front();
|
||||
std::transform(input.begin(), input.end(), disp,
|
||||
[&s1] (const Segment& s) { return intersection(s1, s); });
|
||||
#else
|
||||
// without
|
||||
// intersects the first segment of input with all other segments
|
||||
// The resulting points or segments are written in the vectors with the same names
|
||||
|
||||
K::Intersect_2 intersector = K().intersect_2_object();
|
||||
std::transform(input.begin(), input.end(), disp,
|
||||
boost::bind(intersector, input.front(), _1));
|
||||
#endif
|
||||
|
||||
|
||||
std::cout << "Point intersections: " << points.size() << std::endl;
|
||||
std::cout << "Segment intersections: " << segments.size() << std::endl;
|
||||
|
|
|
|||
Loading…
Reference in New Issue