Reuse existing static filter

This commit is contained in:
Marc Glisse 2011-10-28 17:38:26 +00:00
parent 38f2c13c86
commit e12e4f0705
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,60 @@
#ifndef CGAL_KD_CARTESIAN_STATIC_FILTERS_H
#define CGAL_KD_CARTESIAN_STATIC_FILTERS_H
#include <CGAL/functor_tags.h>
#include <CGAL/Dimension.h>
#include <CGAL/internal/Static_filters/tools.h> // bug, should be included by the next one
#include <CGAL/internal/Static_filters/Orientation_2.h>
namespace CGAL {
namespace SFA { // static filter adapter
// Note that this would be quite a bit simpler without stateful kernels
template <class R_> struct Orientation_of_points_2 : private Store_kernel<R_> {
CGAL_FUNCTOR_INIT_STORE(Orientation_of_points_2);
typedef typename R_::template Type<Point_tag>::type Point;
typedef typename R_::Orientation result_type;
typedef typename R_::FT FT;
typedef typename R_::template Functor<Compute_cartesian_coordinate_tag>::type CC;
typedef typename R_::template Functor<Orientation_of_points_tag>::type Orientation_base;
// TODO: Move this out for easy reuse
struct Adapter {
struct Point_2 {
R_ const&r; CC const&c; Point const& p;
Point_2(R_ const&r_, CC const&c_, Point const&p_):r(r_),c(c_),p(p_){}
FT x()const{return c(p,0);}
FT y()const{return c(p,1);}
};
struct Vector_2 {};
struct Circle_2 {};
struct Orientation_2 {
typedef Orientation_of_points_2::result_type result_type; // really?
template<class Iter> result_type operator()(Point_2 const&A, Point_2 const&B, Point_2 const&C)const{
Point_2 t[3]={&A.p,&B.p,&C.p};
return Orientation_base(A.r)(t+0,t+3);
}
};
};
template<class Iter> result_type operator()(Iter f, Iter e)const{
CC c(this->kernel());
Point const& A=*f;
Point const& B=*++f;
Point const& C=*++f;
CGAL_assertion(++f==e);
typedef typename Adapter::Point_2 P;
return typename internal::Static_filters_predicates::Orientation_2<Adapter>()(P(*this,c,A),P(*this,c,B),P(*this,c,C));
}
};
}
template <class Dim_, class R_, class Derived_> struct Cartesian_static_filters : public R_ {};
template <class R_, class Derived_> struct Cartesian_static_filters<Dimension_tag<2>, R_, Derived_> : public R_ {
//TODO: Functor<*,No_filter_tag>
template <class T, class=void> struct Functor : R_::template Functor<T> {};
template <class D> struct Functor <Orientation_of_points_tag,D> {
typedef SFA::Orientation_of_points_2<Derived_> type;
};
};
}
#endif

View File

@ -1,6 +1,7 @@
#include <typeinfo>
#include <CGAL/myeigen.h>
#include <CGAL/Kernel_d/Cartesian_base.h>
#include <CGAL/Kernel_d/Cartesian_static_filters.h>
#include <CGAL/Kernel_d/Cartesian_filter_NT.h>
#include <CGAL/Kernel_d/Cartesian_filter_K.h>
#include <CGAL/Kernel_d/Lazy_cartesian.h>
@ -13,6 +14,7 @@ typedef CGAL::Cartesian_base_d<CGAL::Interval_nt_advanced,CGAL::Dimension_tag<2>
typedef CGAL::Cartesian_base_d<CGAL::Gmpq,CGAL::Dimension_tag<2> > KE;
struct RC: public
CGAL::Cartesian_static_filters<CGAL::Dimension_tag<2>, // Yes, it is silly to put it there.
CGAL::Cartesian_complete_predicates<
CGAL::Cartesian_complete_constructors<
CGAL::Cartesian_complete_computes<
@ -23,6 +25,7 @@ CGAL::Cartesian_LA_base_d<double,CGAL::Dimension_tag<2> >
>, false, RC
>, false, RC
>, false, RC
>, RC
>
{
RC(){}