// 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_KD_TYPE_WP_H #define CGAL_KD_TYPE_WP_H #include #include namespace CGAL { namespace KerD { template class Weighted_point { typedef typename Get_type::type FT_; typedef typename Get_type::type Point_; Point_ c_; FT_ w_; public: Weighted_point(Point_ const&p, FT_ const&w): c_(p), w_(w) {} // TODO: Add a piecewise constructor? Point_ const& point()const{return c_;} FT_ const& weight()const{return w_;} }; } namespace CartesianDKernelFunctors { template struct Construct_weighted_point : Store_kernel { CGAL_FUNCTOR_INIT_STORE(Construct_weighted_point) typedef typename Get_type::type result_type; typedef typename Get_type::type Point; typedef typename Get_type::type FT; result_type operator()(Point const&a, FT const&b)const{ return result_type(a,b); } // Not really needed result_type operator()()const{ typename Get_functor >::type cp(this->kernel()); return result_type(cp(),0); } }; template struct Point_drop_weight { CGAL_FUNCTOR_INIT_IGNORE(Point_drop_weight) typedef typename Get_type::type argument_type; typedef typename Get_type::type const& result_type; // Returning a reference is fragile result_type operator()(argument_type const&s)const{ return s.point(); } }; template struct Point_weight { CGAL_FUNCTOR_INIT_IGNORE(Point_weight) typedef typename Get_type::type argument_type; typedef typename Get_type::type result_type; result_type operator()(argument_type const&s)const{ return s.weight(); } }; template struct Power_distance : private Store_kernel { CGAL_FUNCTOR_INIT_STORE(Power_distance) typedef typename Get_type::type first_argument_type; typedef first_argument_type second_argument_type; typedef typename Get_type::type result_type; result_type operator()(first_argument_type const&a, second_argument_type const&b)const{ typename Get_functor::type pdw(this->kernel()); typename Get_functor::type pw(this->kernel()); typename Get_functor::type sd(this->kernel()); return sd(pdw(a),pdw(b))-pw(a)-pw(b); } }; template struct Power_distance_to_point : private Store_kernel { CGAL_FUNCTOR_INIT_STORE(Power_distance_to_point) typedef typename Get_type::type first_argument_type; typedef typename Get_type::type second_argument_type; typedef typename Get_type::type result_type; result_type operator()(first_argument_type const&a, second_argument_type const&b)const{ typename Get_functor::type pdw(this->kernel()); typename Get_functor::type pw(this->kernel()); typename Get_functor::type sd(this->kernel()); return sd(pdw(a),b)-pw(a); } }; template struct Power_side_of_power_sphere : private Store_kernel { CGAL_FUNCTOR_INIT_STORE(Power_side_of_power_sphere) typedef R_ R; typedef typename Get_type::type result_type; template result_type operator()(Iter const& f, Iter const& e, Pt const& p0) const { typename Get_functor::type ptr(this->kernel()); typename Get_functor::type pdw(this->kernel()); typename Get_functor::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)); } }; template struct In_flat_power_side_of_power_sphere : private Store_kernel { CGAL_FUNCTOR_INIT_STORE(In_flat_power_side_of_power_sphere) typedef R_ R; typedef typename Get_type::type result_type; template result_type operator()(Fo const& fo, Iter const& f, Iter const& e, Pt const& p0) const { typename Get_functor::type ptr(this->kernel()); typename Get_functor::type pdw(this->kernel()); typename Get_functor::type pw(this->kernel()); return ptr ( fo, make_transforming_iterator (f, pdw), make_transforming_iterator (e, pdw), make_transforming_iterator (f, pw), pdw (p0), pw (p0)); } }; // Construct a point at (weighted) distance 0 from all the input template struct Power_center : Store_kernel { CGAL_FUNCTOR_INIT_STORE(Power_center) typedef typename Get_type::type WPoint; typedef WPoint result_type; typedef typename Get_type::type Point; typedef typename Get_type::type FT; template result_type operator()(Iter f, Iter e)const{ // 2*(x-y).c == (x^2-wx^2)-(y^2-wy^2) typedef typename R_::LA LA; typedef typename LA::Square_matrix Matrix; typedef typename LA::Vector Vec; typedef typename LA::Construct_vector CVec; typename Get_functor::type c(this->kernel()); typename Get_functor >::type cp(this->kernel()); typename Get_functor::type pd(this->kernel()); typename Get_functor::type sdo(this->kernel()); typename Get_functor::type pdp(this->kernel()); typename Get_functor::type pdw(this->kernel()); typename Get_functor::type pw(this->kernel()); typename Get_functor >::type cwp(this->kernel()); WPoint const& wp0 = *f; Point const& p0 = pdw(wp0); int d = pd(p0); FT const& n0 = sdo(p0) - pw(wp0); Matrix m(d,d); Vec b = typename CVec::Dimension()(d); // Write the point coordinates in lines. int i; for(i=0; ++f!=e; ++i) { WPoint const& wp=*f; Point const& p=pdw(wp); FT const& np = sdo(p) - pw(wp); for(int j=0;j),(Point_tag),()); CGAL_KD_DEFAULT_FUNCTOR(Construct_ttag,(CartesianDKernelFunctors::Construct_weighted_point),(Weighted_point_tag,Point_tag),()); CGAL_KD_DEFAULT_FUNCTOR(Point_drop_weight_tag,(CartesianDKernelFunctors::Point_drop_weight),(Weighted_point_tag,Point_tag),()); CGAL_KD_DEFAULT_FUNCTOR(Point_weight_tag,(CartesianDKernelFunctors::Point_weight),(Weighted_point_tag,Point_tag),()); CGAL_KD_DEFAULT_FUNCTOR(Power_side_of_power_sphere_tag,(CartesianDKernelFunctors::Power_side_of_power_sphere),(Weighted_point_tag),(Power_side_of_power_sphere_raw_tag,Point_drop_weight_tag,Point_weight_tag)); CGAL_KD_DEFAULT_FUNCTOR(In_flat_power_side_of_power_sphere_tag,(CartesianDKernelFunctors::In_flat_power_side_of_power_sphere),(Weighted_point_tag),(In_flat_power_side_of_power_sphere_raw_tag,Point_drop_weight_tag,Point_weight_tag)); CGAL_KD_DEFAULT_FUNCTOR(Power_distance_tag,(CartesianDKernelFunctors::Power_distance),(Weighted_point_tag,Point_tag),(Squared_distance_tag,Point_drop_weight_tag,Point_weight_tag)); CGAL_KD_DEFAULT_FUNCTOR(Power_distance_to_point_tag,(CartesianDKernelFunctors::Power_distance_to_point),(Weighted_point_tag,Point_tag),(Squared_distance_tag,Point_drop_weight_tag,Point_weight_tag)); CGAL_KD_DEFAULT_FUNCTOR(Power_center_tag,(CartesianDKernelFunctors::Power_center),(Weighted_point_tag,Point_tag),(Compute_point_cartesian_coordinate_tag,Construct_ttag,Construct_ttag,Point_dimension_tag,Squared_distance_to_origin_tag,Point_drop_weight_tag,Point_weight_tag,Power_distance_to_point_tag)); } // namespace CGAL #endif