CGAL 6.0.2 - 2D and 3D Linear Geometry Kernel

Loading...
Searching...
No Matches
List of all members
CGAL::Filtered_predicate< EP, FP, C2E, C2F > Class Template Reference
2D and 3D Linear Geometry Kernel Reference » Kernel Classes

`#include <CGAL/Filtered_predicate.h>`

## Definition

template<typename EP, typename FP, typename C2E, typename C2F>
class CGAL::Filtered_predicate< EP, FP, C2E, C2F >

`Filtered_predicate` is an adaptor for predicate function objects that allows one to produce efficient and exact predicates.

It is used to build `CGAL::Filtered_kernel<CK>` and can be used for other predicates too.

`EP` is the exact but supposedly slow predicate that is able to evaluate the predicate correctly. It will be called only when the filtering predicate, `FP`, cannot compute the correct result. This failure of `FP` must be done by throwing an exception.

To convert the geometric objects that are the arguments of the predicate, we use the function objects `C2E` and `C2F`, which must be of the form `Cartesian_converter` or `Homogeneous_converter`.

Example

The following example defines an efficient and exact version of the orientation predicate over three points using the Cartesian representation with double coordinates and without reference counting (`Simple_cartesian::Point_2`). Of course, the orientation predicate can already be found in the kernel, but you can follow this example to filter your own predicates. It uses the fast but inexact predicate based on interval arithmetic for filtering and the slow but exact predicate based on multi-precision floats when the filtering predicate fails.

File Filtered_kernel/Filtered_predicate.cpp

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Filtered_predicate.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Cartesian_converter.h>
typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Simple_cartesian<CGAL::Interval_nt_advanced> FK;
typedef CGAL::Simple_cartesian<CGAL::MP_Float> EK;
typedef CGAL::Cartesian_converter<K, EK> C2E;
typedef CGAL::Cartesian_converter<K, FK> C2F;
// Define my predicate, parameterized by a kernel.
template < typename K >
struct My_orientation_2
{
typedef typename K::RT RT;
typedef typename K::Point_2 Point_2;
typedef typename K::Orientation result_type;
result_type
operator()(const Point_2 &p, const Point_2 &q, const Point_2 &r) const
{
RT prx = p.x() - r.x();
RT pry = p.y() - r.y();
RT qrx = q.x() - r.x();
RT qry = q.y() - r.y();
return CGAL::sign( prx*qry - qrx*pry );
}
};
typedef CGAL::Filtered_predicate<My_orientation_2<EK>,
My_orientation_2<FK>, C2E, C2F> Orientation_2;
int main()
{
K::Point_2 p(1,2), q(2,3), r(3,4);
Orientation_2 orientation;
orientation(p, q, r);
return 0;
}
MP_Float.h
CGAL::Cartesian_converter
Cartesian_converter converts objects from the kernel traits K1 to the kernel traits K2 using NTConver...
Definition: Cartesian_converter.h:33
CGAL::Filtered_predicate
Filtered_predicate is an adaptor for predicate function objects that allows one to produce efficient ...
Definition: Filtered_predicate.h:37
CGAL::Filtered_predicate::result_type
FP::result_type result_type
The return type of the function operators.
Definition: Filtered_predicate.h:47
CGAL::Point_2
An object p of the class Point_2 is a point in the two-dimensional Euclidean plane .
Definition: Point_2.h:37
CGAL::Point_2::x
Kernel::FT x() const
returns the Cartesian coordinate, that is hx()/hw().
CGAL::Point_2::y
Kernel::FT y() const
returns the Cartesian coordinate, that is hy()/hw().
CGAL::sign
result_type sign(const NT &x)
CGAL::orientation
Orientation orientation(ForwardIterator first, ForwardIterator last)
CGAL::Simple_cartesian
A model for a Kernel using Cartesian coordinates to represent the geometric objects.
Definition: Simple_cartesian.h:31

Examples
  Filtered_kernel/Filtered_predicate.cpp.

## Types
typedef FP::result_type | result_type
| The return type of the function operators.

## Creation
| Filtered_predicate ()
| Default constructor.

## Operations
template<class ... A>
result_type | operator() (A a...)
| The function operator for predicates.

## Member Typedef Documentation

## ◆ result_type

template<typename EP , typename FP , typename C2E , typename C2F >

typedef FP::result_type CGAL::Filtered_predicate< EP, FP, C2E, C2F >::result_type

The return type of the function operators.

It must also be the same type as `EP::result_type`.