Advertisement
hamzaalloush

Search_traits_adapter.h

Jun 4th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.08 KB | None | 0 0
  1. // Copyright (c) 2011 GeometryFactory (France).
  2. // All rights reserved.
  3. //
  4. // This file is part of CGAL (www.cgal.org).
  5. // You can redistribute it and/or modify it under the terms of the GNU
  6. // General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. //
  9. // Licensees holding a valid commercial license may use this file in
  10. // accordance with the commercial license agreement provided with the software.
  11. //
  12. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  13. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  14. //
  15. // $URL$
  16. // $Id$
  17. //
  18. //
  19. // Author(s)     : Sebastien Loriot
  20.  
  21. #ifndef CGAL_SEARCH_TRAITS_WITH_INFO
  22. #define CGAL_SEARCH_TRAITS_WITH_INFO
  23.  
  24. #include <CGAL/Kd_tree_rectangle.h>
  25. #include <CGAL/Euclidean_distance.h> //for default distance specialization
  26. #include <CGAL/property_map.h>
  27.  
  28. #include <boost/mpl/has_xxx.hpp>
  29. #include <boost/static_assert.hpp>
  30. #include <boost/type_traits/is_same.hpp>
  31.  
  32. namespace CGAL{
  33.  
  34. using ::get;
  35.  
  36. template <class Point_with_info,class PointPropertyMap,class Base_traits>
  37. class Search_traits_adapter;
  38.  
  39. template <class Point_with_info,class PointPropertyMap,class Base_distance>
  40. class Distance_adapter;
  41.  
  42. namespace internal{
  43.  
  44. BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_typedef_Iso_box_d,Iso_box_d,false)
  45.  
  46. template <class T,bool Has_iso_box_d=Has_typedef_Iso_box_d<T>::value >
  47. struct Get_iso_box_d;
  48.  
  49. template <class T>
  50. struct Get_iso_box_d<T,false>
  51. {
  52.   typedef void type;
  53. };
  54.  
  55. template <class T>
  56. struct Get_iso_box_d<T,true>
  57. {
  58.   typedef typename T::Iso_box_d type;
  59. };
  60.  
  61.   template <class Point_with_info,class PointPropertyMap,class Base_traits>
  62.   struct Spatial_searching_default_distance< ::CGAL::Search_traits_adapter<Point_with_info,PointPropertyMap,Base_traits> >{
  63.     typedef ::CGAL::Distance_adapter<Point_with_info,
  64.                                                  PointPropertyMap,
  65.                                                  typename Spatial_searching_default_distance<Base_traits>::type> type;
  66.   };
  67.  
  68. } //namespace internal
  69.  
  70.  
  71. template <class Point_with_info,class PointPropertyMap,class Base_traits>
  72. class Search_traits_adapter : public Base_traits{
  73.   PointPropertyMap ppmap;
  74.  
  75.   BOOST_STATIC_ASSERT( ( boost::is_same< boost::lvalue_property_map_tag,
  76.                            typename boost::property_traits<PointPropertyMap>::category
  77.                          >::value ) );
  78. public:
  79.   typedef Base_traits Base;
  80.   typedef typename internal::Get_iso_box_d<Base>::type Iso_box_d;
  81.  
  82.   Search_traits_adapter(const PointPropertyMap& ppmap_=PointPropertyMap(),
  83.                           const Base_traits& base=Base_traits()
  84.   ):Base_traits(base),ppmap(ppmap_){}
  85.  
  86.   typedef typename Base_traits::Cartesian_const_iterator_d      Cartesian_const_iterator_d;
  87.   typedef Point_with_info                                       Point_d;
  88.   typedef typename Base_traits::FT                              FT;
  89.  
  90.   struct Construct_cartesian_const_iterator_d: public Base_traits::Construct_cartesian_const_iterator_d{
  91.     PointPropertyMap ppmap;
  92.     using Base_traits::Construct_cartesian_const_iterator_d::operator();
  93.    
  94.     Construct_cartesian_const_iterator_d(const typename Base_traits::Construct_cartesian_const_iterator_d& base, const PointPropertyMap& ppmap_)
  95.       :Base_traits::Construct_cartesian_const_iterator_d(base), ppmap(ppmap_){}
  96.    
  97.     typename Base_traits::Cartesian_const_iterator_d operator()(const Point_with_info& p) const
  98.     { return this->operator() (get(ppmap,p)); }
  99.  
  100.     typename Base_traits::Cartesian_const_iterator_d operator()(const Point_with_info& p, int)  const
  101.     { return this->operator() (get(ppmap,p),0); }
  102.   };
  103.  
  104.   struct Construct_iso_box_d: public Base::Construct_iso_box_d{
  105.     PointPropertyMap ppmap;
  106.     typedef typename Base_traits::FT  FT; // needed for VC++, because otherwise it is taken from the private typedef of the base class
  107.  
  108.     Iso_box_d operator() () const {
  109.       return static_cast<const typename Base::Construct_iso_box_d* >(this)->operator() ();
  110.     }
  111.     Iso_box_d operator() (const Point_with_info& p, const Point_with_info& q) const
  112.     {
  113.       return static_cast<const typename Base::Construct_iso_box_d* >(this)->operator() (get(ppmap,p),get(ppmap,q));
  114.     }
  115.   };
  116.  
  117.   const PointPropertyMap& point_property_map() const {return ppmap;}
  118.  
  119.   Construct_cartesian_const_iterator_d construct_cartesian_const_iterator_d_object() const {
  120.     return Construct_cartesian_const_iterator_d(
  121.       static_cast<const Base*>(this)->construct_cartesian_const_iterator_d_object(),
  122.       ppmap);
  123.   }
  124. };
  125.  
  126. template <class Point_with_info,class PointPropertyMap,class Base_distance>
  127. class Distance_adapter : public Base_distance {
  128.   PointPropertyMap ppmap;
  129.   typedef typename Base_distance::FT FT;
  130.  
  131.   BOOST_STATIC_ASSERT( ( boost::is_same< boost::lvalue_property_map_tag,
  132.                            typename boost::property_traits<PointPropertyMap>::category
  133.                          >::value ) );
  134. public:
  135.    
  136.   Distance_adapter( const PointPropertyMap& ppmap_=PointPropertyMap(),
  137.                          const Base_distance& distance=Base_distance()
  138.   ):Base_distance(distance),ppmap(ppmap_){}
  139.  
  140.   using Base_distance::transformed_distance;
  141.  
  142.   typedef Point_with_info Point_d;
  143.   typedef typename Base_distance::Query_item Query_item;
  144.  
  145.   const PointPropertyMap& point_property_map() const {return ppmap;}    
  146.  
  147.   FT transformed_distance(const Query_item& p1, const Point_with_info& p2) const
  148.   {
  149.     return this->transformed_distance(p1,get(ppmap,p2));
  150.   }
  151.  
  152.   template <class FT>
  153.   FT min_distance_to_rectangle(const Query_item& p, const CGAL::Kd_tree_rectangle<FT>& b) const
  154.   {
  155.     return static_cast<const Base_distance*>(this)->min_distance_to_rectangle(p,b);
  156.   }
  157.  
  158.   template <class FT>
  159.   FT max_distance_to_rectangle(const Query_item& p,const CGAL::Kd_tree_rectangle<FT>& b) const
  160.   {
  161.     return static_cast<const Base_distance*>(this)->max_distance_to_rectangle(p,b);
  162.   }  
  163. };
  164.  
  165. }//namespace CGAL
  166.  
  167. #endif //CGAL_SEARCH_TRAITS_WITH_INFO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement