Power test.

This commit is contained in:
Marc Glisse 2014-05-28 16:40:14 +02:00
parent 8ac34ad7a6
commit a7417b582d
10 changed files with 245 additions and 2 deletions

View File

@ -87,6 +87,7 @@ struct Cartesian_LA_base_d : public Dimension_base<Dim_>
::add<Segment_tag>::type
::add<Hyperplane_tag>::type
::add<Sphere_tag>::type
::add<Weighted_point_tag>::type
Object_list;
typedef typeset< Point_cartesian_const_iterator_tag>::type

View File

@ -117,5 +117,17 @@ template <class K1, class K2> struct KO_converter<Sphere_tag,K1,K2>{
}
};
template <class K1, class K2> struct KO_converter<Weighted_point_tag,K1,K2>{
typedef typename Get_type<K1, Weighted_point_tag>::type argument_type;
typedef typename Get_type<K2, Weighted_point_tag>::type result_type;
template <class C>
result_type operator()(K1 const& k1, K2 const& k2, C const& conv, argument_type const& s) const {
typename Get_functor<K1, Point_drop_weight_tag>::type pdw(k1);
typename Get_functor<K1, Point_weight_tag>::type pw(k1);
typename Get_functor<K2, Construct_ttag<Weighted_point_tag> >::type cwp(k2);
return cwp(conv(pdw(s)),conv(pw(s)));
}
};
}
#endif

View File

@ -50,7 +50,8 @@ template <class R_> struct Construct_weighted_point : Store_kernel<R_> {
template <class R_> struct Point_drop_weight {
CGAL_FUNCTOR_INIT_IGNORE(Point_drop_weight)
typedef typename Get_type<R_, Weighted_point_tag>::type argument_type;
typedef typename Get_type<R_, Point_tag>::type const& result_type;
typedef typename Get_type<R_, Point_tag>::type result_type;
// Returning a reference would be too fragile
result_type operator()(argument_type const&s)const{
return s.point();
@ -60,17 +61,37 @@ template <class R_> struct Point_drop_weight {
template <class R_> struct Point_weight {
CGAL_FUNCTOR_INIT_IGNORE(Point_weight)
typedef typename Get_type<R_, Weighted_point_tag>::type argument_type;
typedef typename Get_type<R_, FT_tag>::type const& result_type;
typedef typename Get_type<R_, FT_tag>::type result_type;
result_type operator()(argument_type const&s)const{
return s.weight();
}
};
template<class R_> struct Power_test : private Store_kernel<R_> {
CGAL_FUNCTOR_INIT_STORE(Power_test)
typedef R_ R;
typedef typename Get_type<R, Oriented_side_tag>::type result_type;
template<class Iter, class Pt>
result_type operator()(Iter const& f, Iter const& e, Pt const& p0) const {
typename Get_functor<R, Power_test_raw_tag>::type ptr(this->kernel());
typename Get_functor<R, Point_drop_weight_tag>::type pdw(this->kernel());
typename Get_functor<R, Point_weight_tag>::type pw(this->kernel());
return ptr (
make_transforming_iterator (f, pdw),
make_transforming_iterator (e, pdw),
make_transforming_iterator (f, pw),
pdw (p0),
pw (p0));
}
};
}
CGAL_KD_DEFAULT_TYPE(Weighted_point_tag,(CGAL::Weighted_point<K>),(Point_tag),());
CGAL_KD_DEFAULT_FUNCTOR(Construct_ttag<Weighted_point_tag>,(CartesianDKernelFunctors::Construct_weighted_point<K>),(Weighted_point_tag,Point_tag),());
CGAL_KD_DEFAULT_FUNCTOR(Point_drop_weight_tag,(CartesianDKernelFunctors::Point_drop_weight<K>),(Weighted_point_tag,Point_tag),());
CGAL_KD_DEFAULT_FUNCTOR(Point_weight_tag,(CartesianDKernelFunctors::Point_weight<K>),(Weighted_point_tag,Point_tag),());
CGAL_KD_DEFAULT_FUNCTOR(Power_test_tag,(CartesianDKernelFunctors::Power_test<K>),(Weighted_point_tag),(Power_test_raw_tag,Point_drop_weight_tag,Point_weight_tag));
} // namespace CGAL
#endif

View File

@ -28,6 +28,7 @@
#include <CGAL/NewKernel_d/Wrapper/Segment_d.h>
#include <CGAL/NewKernel_d/Wrapper/Sphere_d.h>
#include <CGAL/NewKernel_d/Wrapper/Hyperplane_d.h>
#include <CGAL/NewKernel_d/Wrapper/Weighted_point_d.h>
#include <CGAL/NewKernel_d/Wrapper/Ref_count_obj.h>
@ -106,6 +107,7 @@ CGAL_REGISTER_OBJECT_WRAPPER(Vector);
CGAL_REGISTER_OBJECT_WRAPPER(Segment);
CGAL_REGISTER_OBJECT_WRAPPER(Sphere);
CGAL_REGISTER_OBJECT_WRAPPER(Hyperplane);
CGAL_REGISTER_OBJECT_WRAPPER(Weighted_point);
#undef CGAL_REGISTER_OBJECT_WRAPPER
// Note: this tends to be an all or nothing thing currently, wrapping

View File

@ -0,0 +1,129 @@
// Copyright (c) 2014
// INRIA Saclay-Ile de France (France)
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
// Author(s) : Marc Glisse
#ifndef CGAL_WRAPPER_WEIGHTED_POINT_D_H
#define CGAL_WRAPPER_WEIGHTED_POINT_D_H
#include <CGAL/representation_tags.h>
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>
#include <CGAL/Kernel/Return_base_tag.h>
#include <CGAL/Dimension.h>
#ifndef CGAL_CXX11
#include <boost/preprocessor/repetition.hpp>
#endif
#include <boost/utility/result_of.hpp>
namespace CGAL {
namespace Wrap {
template <class R_>
class Weighted_point_d : public Get_type<typename R_::Kernel_base, Weighted_point_tag>::type
{
typedef typename Get_type<R_, FT_tag>::type FT_;
typedef typename R_::Kernel_base Kbase;
typedef typename Get_type<R_, Point_tag>::type Point_;
typedef typename Get_functor<Kbase, Construct_ttag<Weighted_point_tag> >::type CWPBase;
typedef typename Get_functor<Kbase, Point_drop_weight_tag>::type PDWBase;
typedef typename Get_functor<Kbase, Point_weight_tag>::type PWBase;
typedef Weighted_point_d Self;
BOOST_STATIC_ASSERT((boost::is_same<Self, typename Get_type<R_, Weighted_point_tag>::type>::value));
public:
typedef Tag_true Is_wrapper;
typedef typename R_::Default_ambient_dimension Ambient_dimension;
typedef Dimension_tag<0> Feature_dimension;
typedef typename Get_type<Kbase, Weighted_point_tag>::type Rep;
const Rep& rep() const
{
return *this;
}
Rep& rep()
{
return *this;
}
typedef R_ R;
#ifdef CGAL_CXX11
template<class...U,class=typename std::enable_if<!std::is_same<std::tuple<typename std::decay<U>::type...>,std::tuple<Weighted_point_d> >::value>::type> explicit Weighted_point_d(U&&...u)
: Rep(CWPBase()(std::forward<U>(u)...)){}
// // called from Construct_point_d
// template<class...U> explicit Point_d(Eval_functor&&,U&&...u)
// : Rep(Eval_functor(), std::forward<U>(u)...){}
template<class F,class...U> explicit Weighted_point_d(Eval_functor&&,F&&f,U&&...u)
: Rep(std::forward<F>(f)(std::forward<U>(u)...)){}
#if 0
// the new standard may make this necessary
Point_d(Point_d const&)=default;
Point_d(Point_d &);//=default;
Point_d(Point_d &&)=default;
#endif
// try not to use these
Weighted_point_d(Rep const& v) : Rep(v) {}
Weighted_point_d(Rep& v) : Rep(static_cast<Rep const&>(v)) {}
Weighted_point_d(Rep&& v) : Rep(std::move(v)) {}
#else
Weighted_point_d() : Rep(CWPBase()()) {}
Weighted_point_d(Rep const& v) : Rep(v) {} // try not to use it
#define CGAL_CODE(Z,N,_) template<BOOST_PP_ENUM_PARAMS(N,class T)> \
explicit Weighted_point_d(BOOST_PP_ENUM_BINARY_PARAMS(N,T,const&t)) \
: Rep(CWPBase()( \
BOOST_PP_ENUM_PARAMS(N,t))) {} \
\
template<class F,BOOST_PP_ENUM_PARAMS(N,class T)> \
Weighted_point_d(Eval_functor,F const& f,BOOST_PP_ENUM_BINARY_PARAMS(N,T,const&t)) \
: Rep(f(BOOST_PP_ENUM_PARAMS(N,t))) {}
/*
template<BOOST_PP_ENUM_PARAMS(N,class T)> \
Point_d(Eval_functor,BOOST_PP_ENUM_BINARY_PARAMS(N,T,const&t)) \
: Rep(Eval_functor(), BOOST_PP_ENUM_PARAMS(N,t)) {}
*/
BOOST_PP_REPEAT_FROM_TO(1,11,CGAL_CODE,_)
#undef CGAL_CODE
#endif
//TODO: use references?
Point_ point()const{
return Point_(Eval_functor(),PDWBase(),rep());
}
FT_ weight()const{
return PWBase()(rep());
}
};
} //namespace Wrap
} //namespace CGAL
#endif // CGAL_WRAPPER_SPHERE_D_H

View File

@ -529,6 +529,60 @@ template<class R_> struct Orientation<R_,false> : private Store_kernel<R_> {
}
#endif
namespace CartesianDKernelFunctors {
template<class R_> struct Power_test_raw : private Store_kernel<R_> {
CGAL_FUNCTOR_INIT_STORE(Power_test_raw)
typedef R_ R;
typedef typename Get_type<R, RT_tag>::type RT;
typedef typename Get_type<R, FT_tag>::type FT;
typedef typename Get_type<R, Point_tag>::type Point;
typedef typename Get_type<R, Oriented_side_tag>::type result_type;
typedef typename Increment_dimension<typename R::Default_ambient_dimension>::type D1;
typedef typename Increment_dimension<typename R::Max_ambient_dimension>::type D2;
typedef typename R::LA::template Rebind_dimension<D1,D2>::Other LA;
typedef typename LA::Square_matrix Matrix;
template<class IterP, class IterW, class Pt, class Wt>
result_type operator()(IterP f, IterP const& e, IterW fw, Pt const& p0, Wt const& w0) const {
typedef typename Get_functor<R, Squared_distance_to_origin_tag>::type Sqdo;
typename Get_functor<R, Compute_point_cartesian_coordinate_tag>::type c(this->kernel());
typename Get_functor<R, Point_dimension_tag>::type pd(this->kernel());
int d=pd(p0);
Matrix m(d+1,d+1);
if(CGAL::Is_stored<Sqdo>::value) {
Sqdo sqdo(this->kernel());
FT const& h0 = sqdo(p0) - w0;
for(int i=0;f!=e;++f,++fw,++i) {
Point const& p=*f;
for(int j=0;j<d;++j){
RT const& x=c(p,j);
m(i,j)=x-c(p0,j);
}
m(i,d) = sqdo(p) - *fw - h0;
}
} else {
for(int i=0;f!=e;++f,++fw,++i) {
Point const& p=*f;
m(i,d) = w0 - *fw;
for(int j=0;j<d;++j){
RT const& x=c(p,j);
m(i,j)=x-c(p0,j);
m(i,d)+=CGAL::square(m(i,j));
}
}
}
if(d%2)
return -LA::sign_of_determinant(CGAL_MOVE(m));
else
return LA::sign_of_determinant(CGAL_MOVE(m));
}
};
}
CGAL_KD_DEFAULT_FUNCTOR(Power_test_raw_tag,(CartesianDKernelFunctors::Power_test_raw<K>),(Point_tag),(Point_dimension_tag,Squared_distance_to_origin_tag,Compute_point_cartesian_coordinate_tag));
// TODO: make Side_of_oriented_sphere call Power_test_raw
namespace CartesianDKernelFunctors {
template<class R_> struct Side_of_oriented_sphere : private Store_kernel<R_> {
CGAL_FUNCTOR_INIT_STORE(Side_of_oriented_sphere)

View File

@ -307,6 +307,8 @@ namespace CGAL {
CGAL_DECL_PREDICATE(Affinely_independent);
CGAL_DECL_PREDICATE(Contained_in_linear_hull);
CGAL_DECL_PREDICATE(Contained_in_simplex);
CGAL_DECL_PREDICATE(Power_test_raw);
CGAL_DECL_PREDICATE(Power_test);
#undef CGAL_DECL_PREDICATE
#define CGAL_DECL_MISC(X) struct X##_tag {}; \

View File

@ -520,12 +520,16 @@ void test3(){
typedef typename CGAL::Get_functor<K1, CGAL::Construct_ttag<CGAL::Weighted_point_tag> >::type CWP;
typedef typename CGAL::Get_functor<K1, CGAL::Point_drop_weight_tag>::type PDW;
typedef typename CGAL::Get_functor<K1, CGAL::Point_weight_tag>::type PW;
typedef typename CGAL::Get_functor<K1, CGAL::Power_test_tag>::type PT;
CWP cwp (k);
PDW pdw (k);
PW pw (k);
PT pt (k);
WP wp = cwp (x1, 2);
assert (pw(wp) == 2);
assert (ed(pdw(wp), x1));
WP tabw[]={cwp(x1,0),cwp(x2,0),cwp(x3,0),cwp(x4,0),cwp(x5,0)};
assert(pt(tabw+0,tabw+4,tabw[4])==CGAL::ON_POSITIVE_SIDE);
}
template struct CGAL::Epick_d<CGAL::Dimension_tag<2> >;
template struct CGAL::Epick_d<CGAL::Dimension_tag<3> >;

View File

@ -155,6 +155,17 @@ namespace Eigen {
MulCost = 100
};
};
namespace internal {
template<>
struct significant_decimals_impl<CGAL::Gmpq>
{
static inline int run()
{
return 0;
}
};
}
}
//since types are included by Gmp_coercion_traits.h:

View File

@ -1283,6 +1283,13 @@ namespace Eigen {
MulCost = 10
};
};
namespace internal {
template<class> struct significant_decimals_impl;
template<bool b>
struct significant_decimals_impl<CGAL::Interval_nt<b> >
: significant_decimals_impl<typename CGAL::Interval_nt<b>::value_type> { };
}
}
#endif // CGAL_INTERVAL_NT_H