|
BWAPI
|
00001 // Copyright (c) 2005,2006 INRIA Sophia-Antipolis (France). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License as 00006 // published by the Free Software Foundation; version 2.1 of the License. 00007 // See the file LICENSE.LGPL distributed with CGAL. 00008 // 00009 // Licensees holding a valid commercial license may use this file in 00010 // accordance with the commercial license agreement provided with the software. 00011 // 00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 // 00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Filtered_kernel/include/CGAL/Lazy_kernel.h $ 00016 // $Id: Lazy_kernel.h 50673 2009-07-17 15:07:11Z afabri $ 00017 // 00018 // 00019 // Author(s) : Andreas Fabri, Sylvain Pion 00020 00021 #ifndef CGAL_LAZY_KERNEL_H 00022 #define CGAL_LAZY_KERNEL_H 00023 00024 #include <CGAL/basic.h> 00025 //#include <CGAL/Filtered_predicate.h> 00026 #include <CGAL/Filtered_kernel.h> 00027 #include <CGAL/Cartesian_converter.h> 00028 #include <CGAL/Simple_cartesian.h> 00029 #include <CGAL/Interval_nt.h> 00030 #include <CGAL/Kernel/Type_equality_wrapper.h> 00031 #include <CGAL/Filtered_kernel/Cartesian_coordinate_iterator_2.h> 00032 #include <CGAL/Filtered_kernel/Cartesian_coordinate_iterator_3.h> 00033 #include <CGAL/Lazy.h> 00034 #include <boost/mpl/if.hpp> 00035 00036 CGAL_BEGIN_NAMESPACE 00037 00038 // Exact_kernel = exact kernel that will be made lazy 00039 // Kernel = lazy kernel 00040 00041 // the Generic base simplies applies the generic magic functor stupidly. 00042 // then the real base fixes up a few special cases. 00043 template < typename EK_, typename AK_, typename E2A_, typename Kernel > 00044 class Lazy_kernel_generic_base 00045 // : public Filtered_kernel_base<EK_> 00046 // TODO : Static_filters_base too ? Check performance 00047 { 00048 public: 00049 typedef AK_ Approximate_kernel; 00050 typedef EK_ Exact_kernel; 00051 typedef E2A_ E2A; 00052 00053 // 3 synonyms identical to Filtered_kernel (TODO : cleanup !) 00054 typedef AK_ FK; 00055 //typedef E2A_ C2F; 00056 typedef Approx_converter<Kernel, Approximate_kernel> C2F; 00057 typedef Exact_converter<Kernel, Exact_kernel> C2E; 00058 00059 template < typename Kernel2 > 00060 struct Base { typedef Lazy_kernel_generic_base<Exact_kernel, Approximate_kernel, E2A, Kernel2> Type; }; 00061 00062 template < typename T > 00063 struct Ambient_dimension { 00064 typedef typename T::Ambient_dimension type; 00065 }; 00066 00067 template < typename T > 00068 struct Feature_dimension { 00069 typedef typename T::Feature_dimension type; 00070 }; 00071 00072 // What to do with the tag ? 00073 // Probably this should not exist, should it ? 00074 // struct filter_tag{}; 00075 // typedef filter_tag Kernel_tag; 00076 typedef typename Exact_kernel::Kernel_tag Kernel_tag; 00077 typedef typename Exact_kernel::Rep_tag Rep_tag; 00078 00079 // Types 00080 typedef CGAL::Lazy_exact_nt<typename Exact_kernel::FT> FT; 00081 typedef FT RT; 00082 00083 typedef typename Same_uncertainty_nt<bool, FT>::type 00084 Boolean; 00085 typedef typename Same_uncertainty_nt<CGAL::Sign, FT>::type 00086 Sign; 00087 typedef typename Same_uncertainty_nt<CGAL::Comparison_result, FT>::type 00088 Comparison_result; 00089 typedef typename Same_uncertainty_nt<CGAL::Orientation, FT>::type 00090 Orientation; 00091 typedef typename Same_uncertainty_nt<CGAL::Oriented_side, FT>::type 00092 Oriented_side; 00093 typedef typename Same_uncertainty_nt<CGAL::Bounded_side, FT>::type 00094 Bounded_side; 00095 typedef typename Same_uncertainty_nt<CGAL::Angle, FT>::type 00096 Angle; 00097 00098 typedef CGAL::Object Object_2; 00099 typedef CGAL::Object Object_3; 00100 00101 #define CGAL_Kernel_obj(X) \ 00102 typedef Lazy<typename Approximate_kernel::X, typename Exact_kernel::X, typename Exact_kernel::FT, E2A> X; 00103 00104 CGAL_Kernel_obj(Data_accessor_2) 00105 CGAL_Kernel_obj(Conic_2) 00106 00107 typedef Cartesian_coordinate_iterator_2<Kernel> Cartesian_const_iterator_2; 00108 typedef Cartesian_coordinate_iterator_3<Kernel> Cartesian_const_iterator_3; 00109 00110 // Aff_transformation_2/3 operations are not functorized, so treat it as 00111 // an exterior object for now. 00112 // CGAL_Kernel_obj(Aff_transformation_2) 00113 // CGAL_Kernel_obj(Aff_transformation_3) 00114 typedef CGAL::Aff_transformationC2<Kernel> Aff_transformation_2; 00115 typedef CGAL::Aff_transformationC3<Kernel> Aff_transformation_3; 00116 00117 00118 // We don't touch the predicates. 00119 // FIXME TODO : better use a layer of Filtered_kernel on top of everything, 00120 // so that semi-static filters are used as well (?). 00121 #define CGAL_Kernel_pred(P, Pf) \ 00122 typedef Filtered_predicate<typename Exact_kernel::P, typename Approximate_kernel::P, C2E, C2F> P; \ 00123 P Pf() const { return P(); } 00124 00125 00126 // We change the constructions. 00127 #ifdef CGAL_INTERSECT_WITH_ITERATORS_2 00128 #define CGAL_Kernel_cons(C, Cf) \ 00129 typedef typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C, typename Approximate_kernel::Intersect_with_iterators_2>, \ 00130 Lazy_intersect_with_iterators<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>, \ 00131 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, Bbox_2>, \ 00132 Lazy_construction_bbox<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>, \ 00133 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, typename Approximate_kernel::FT>,\ 00134 Lazy_construction_nt<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>,\ 00135 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, Object >,\ 00136 Lazy_construction_object<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>,\ 00137 Lazy_construction<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C> >::type >::type > ::type > ::type C; \ 00138 C Cf() const { return C(); } 00139 00140 CGAL_Kernel_cons(Intersect_with_iterators_2, 00141 intersect_with_iterators_2_object) 00142 #else 00143 #define CGAL_Kernel_cons(C, Cf) \ 00144 typedef typename boost::mpl::if_< boost::is_same<typename Approximate_kernel::C::result_type, typename Approximate_kernel::FT>,\ 00145 Lazy_construction_nt<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>,\ 00146 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, Object >,\ 00147 Lazy_construction_object<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>,\ 00148 Lazy_construction<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C> >::type >::type C; \ 00149 C Cf() const { return C(); } 00150 00151 #endif //CGAL_INTERSECT_WITH_ITERATORS_2 00152 00153 00154 #include <CGAL/Kernel/interface_macros.h> 00155 00156 }; 00157 00158 template < typename EK_, typename AK_, typename E2A_, typename Kernel_ > 00159 class Lazy_kernel_base 00160 : public Lazy_kernel_generic_base<EK_, AK_, E2A_, Kernel_> 00161 { 00162 public: 00163 typedef Kernel_ Kernel; 00164 typedef AK_ Approximate_kernel; 00165 typedef EK_ Exact_kernel; 00166 typedef E2A_ E2A; 00167 00168 template < typename Kernel2 > 00169 struct Base { typedef Lazy_kernel_base<Exact_kernel, Approximate_kernel, E2A, Kernel2> Type; }; 00170 00171 #if 0 00172 // We change the constructions. 00173 #ifdef CGAL_INTERSECT_WITH_ITERATORS_2 00174 #define CGAL_Kernel_cons(C, Cf) \ 00175 typedef typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C, typename Approximate_kernel::Intersect_with_iterators_2>, \ 00176 Lazy_intersect_with_iterators<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>, \ 00177 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, Bbox_2>, \ 00178 Lazy_construction_bbox<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>, \ 00179 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, typename Approximate_kernel::FT>,\ 00180 Lazy_construction_nt<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>,\ 00181 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, Object >,\ 00182 Lazy_construction_object<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>,\ 00183 Lazy_construction<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C> >::type >::type > ::type > ::type C; \ 00184 C Cf() const { return C(); } 00185 00186 CGAL_Kernel_cons(Intersect_with_iterators_2, 00187 intersect_with_iterators_2_object) 00188 #else 00189 #define CGAL_Kernel_cons(C, Cf) \ 00190 typedef typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C, typename Approximate_kernel::Construct_cartesian_const_iterator_2>, \ 00191 Lazy_cartesian_const_iterator_2<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>, \ 00192 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C, typename Approximate_kernel::Construct_cartesian_const_iterator_3>, \ 00193 Lazy_cartesian_const_iterator_3<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>, \ 00194 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, Bbox_2>, \ 00195 Lazy_construction_bbox<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>, \ 00196 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, Bbox_3>, \ 00197 Lazy_construction_bbox<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>, \ 00198 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, typename Approximate_kernel::FT>,\ 00199 Lazy_construction_nt<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>,\ 00200 typename boost::mpl::if_<boost::is_same<typename Approximate_kernel::C::result_type, Object >,\ 00201 Lazy_construction_object<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C>,\ 00202 Lazy_construction<Kernel,typename Approximate_kernel::C, typename Exact_kernel::C> >::type >::type >::type > ::type > ::type > ::type C; \ 00203 C Cf() const { return C(); } 00204 00205 #endif //CGAL_INTERSECT_WITH_ITERATORS_2 00206 00207 #endif // 0 00208 00209 typedef CommonKernelFunctors::Assign_2<Kernel> Assign_2; 00210 typedef CommonKernelFunctors::Assign_3<Kernel> Assign_3; 00211 typedef Lazy_construction_bbox<Kernel, typename Approximate_kernel::Construct_bbox_2, typename Exact_kernel::Construct_bbox_2> Construct_bbox_2; 00212 typedef Lazy_construction_bbox<Kernel, typename Approximate_kernel::Construct_bbox_3, typename Exact_kernel::Construct_bbox_3> Construct_bbox_3; 00213 typedef Lazy_cartesian_const_iterator_2<Kernel, typename Approximate_kernel::Construct_cartesian_const_iterator_2, typename Exact_kernel::Construct_cartesian_const_iterator_2> Construct_cartesian_const_iterator_2; 00214 typedef Lazy_cartesian_const_iterator_3<Kernel, typename Approximate_kernel::Construct_cartesian_const_iterator_3, typename Exact_kernel::Construct_cartesian_const_iterator_3> Construct_cartesian_const_iterator_3; 00215 00216 typedef CGAL::CartesianKernelFunctors::Compute_approximate_squared_length_3<Kernel> Compute_approximate_squared_length_3; 00217 typedef CGAL::CartesianKernelFunctors::Compute_approximate_area_3<Kernel> Compute_approximate_area_3; 00218 00219 // typedef void Compute_z_3; // to detect where .z() is called 00220 // typedef void Construct_point_3; // to detect where the ctor is called 00221 00222 Assign_2 00223 assign_2_object() const 00224 { return Assign_2(); } 00225 00226 Assign_3 00227 assign_3_object() const 00228 { return Assign_3(); } 00229 00230 Construct_bbox_2 00231 construct_bbox_2_object() const 00232 { return Construct_bbox_2(); } 00233 00234 Construct_bbox_3 00235 construct_bbox_3_object() const 00236 { return Construct_bbox_3(); } 00237 00238 Construct_cartesian_const_iterator_2 00239 construct_cartesian_const_iterator_2_object() const 00240 { return Construct_cartesian_const_iterator_2(); } 00241 00242 Construct_cartesian_const_iterator_3 00243 construct_cartesian_const_iterator_3_object() const 00244 { return Construct_cartesian_const_iterator_3(); } 00245 00246 Compute_approximate_squared_length_3 00247 compute_approximate_squared_length_3_object() const 00248 { return Compute_approximate_squared_length_3(); } 00249 00250 Compute_approximate_area_3 00251 compute_approximate_area_3_object() const 00252 { return Compute_approximate_area_3(); } 00253 }; 00254 00255 00256 template <class Exact_kernel, class Approximate_kernel, class E2A> 00257 struct Lazy_kernel_adaptor 00258 : public Lazy_kernel_base< Exact_kernel, Approximate_kernel, E2A, Lazy_kernel_adaptor<Exact_kernel,Approximate_kernel, E2A> > 00259 {}; 00260 00261 template <class Exact_kernel, class Approximate_kernel, class E2A> 00262 struct Lazy_kernel_without_type_equality 00263 : public Lazy_kernel_base< Exact_kernel, Approximate_kernel, E2A, Lazy_kernel_without_type_equality<Exact_kernel,Approximate_kernel, E2A> > 00264 {}; 00265 00266 template <class Exact_kernel, 00267 class Approximate_kernel = Simple_cartesian<Interval_nt_advanced>, 00268 class E2A = Cartesian_converter<Exact_kernel, Approximate_kernel> > 00269 struct Lazy_kernel 00270 : public Type_equality_wrapper< 00271 Lazy_kernel_base< Exact_kernel, Approximate_kernel, E2A, Lazy_kernel<Exact_kernel, Approximate_kernel, E2A> >, 00272 Lazy_kernel<Exact_kernel, Approximate_kernel, E2A> > 00273 {}; 00274 00275 CGAL_END_NAMESPACE 00276 00277 #endif // CGAL_LAZY_KERNEL_H
1.7.6.1