BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Sweep_line_2/Arr_insertion_traits_2.h
Go to the documentation of this file.
00001 // Copyright (c) 1997  Tel-Aviv University (Israel).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Arrangement_on_surface_2/include/CGAL/Sweep_line_2/Arr_insertion_traits_2.h $
00015 // $Id: Arr_insertion_traits_2.h 50366 2009-07-05 12:56:48Z efif $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 //                 Efi Fogel <efif@post.tau.ac.il>
00020 
00021 #ifndef CGAL_ARR_INSERTION_TRAITS_2_H
00022 #define CGAL_ARR_INSERTION_TRAITS_2_H
00023 
00028 #include <CGAL/Sweep_line_2/Arr_basic_insertion_traits_2.h>
00029 
00030 CGAL_BEGIN_NAMESPACE
00031 
00037 template <typename Traits_, typename Arrangement_>
00038 class Arr_insertion_traits_2 : 
00039   public Arr_basic_insertion_traits_2<Traits_, Arrangement_>
00040 {
00041 public:
00042 
00043   typedef Traits_                                     Traits_2;
00044   typedef Arr_basic_insertion_traits_2<Traits_,
00045                                        Arrangement_>  Base;
00046 
00047   typedef typename Traits_2::Intersect_2              Base_intersect_2;
00048   typedef typename Traits_2::Split_2                  Base_split_2;
00049   typedef typename Base::Base_x_monotone_curve_2      Base_x_monotone_curve_2;
00050   typedef typename Base::X_monotone_curve_2           X_monotone_curve_2;
00051   typedef typename Base::Halfedge_handle              Halfedge_handle;
00052   typedef typename Base::Base_point_2                 Base_point_2;
00053   typedef typename Base::Point_2                      Point_2;
00054 
00055   typedef typename Base::Has_left_category            Has_left_category;
00056 
00057   // should be ok, as basic_insertion (=Base) completes incomplete tags
00058   typedef typename Base::Arr_left_side_tag            Arr_left_side_tag;
00059   typedef typename Base::Arr_bottom_side_tag          Arr_bottom_side_tag;
00060   typedef typename Base::Arr_top_side_tag             Arr_top_side_tag;
00061   typedef typename Base::Arr_right_side_tag           Arr_right_side_tag;
00062 
00063   /* Insertion is implemented as sweep-line visitor. The sweep-line algorithm
00064    * never never performs merging of curves. Therefore, AreMergeable_2 and
00065    * Merge_2 are not needed either.
00066    */
00067   typedef Tag_false                                   Has_merge_category;
00068   
00069 public:
00070 
00072   Arr_insertion_traits_2 (const Traits_2& tr) :
00073     Base (tr)
00074   {}
00075 
00079   class Intersect_2 {
00080   protected:
00082     Base_intersect_2      m_base_intersect;
00083     Halfedge_handle       invalid_he;
00084 
00090     Intersect_2 (const Base_intersect_2& base) :
00091       m_base_intersect (base),
00092       invalid_he()
00093     {}
00094 
00096     friend class Arr_insertion_traits_2<Traits_2, Arrangement_>;
00097     
00098   public:
00099     template<typename OutputIterator>
00100     OutputIterator operator() (const X_monotone_curve_2& cv1,
00101                                const X_monotone_curve_2& cv2,
00102                                OutputIterator oi)
00103     {
00104       if(cv1.halfedge_handle() != invalid_he &&
00105          cv2.halfedge_handle() != invalid_he)
00106       {
00107         // The curves are interior-disjoint as both of them are already in
00108         //  the arrangement.
00109         return (oi);
00110       }
00111 
00112       OutputIterator           oi_end = m_base_intersect(cv1.base(),
00113                                                          cv2.base(), oi);
00114       const Base_x_monotone_curve_2                *base_overlap_cv;
00115       const std::pair<Base_point_2, unsigned int>  *intersect_p;
00116 
00117       // convert objects that are associated with Base_x_monotone_curve_2 to
00118       // X_monotone_curve_2 
00119       for(; oi != oi_end; ++oi)
00120       {
00121         base_overlap_cv = object_cast<Base_x_monotone_curve_2> (&(*oi));
00122         if (base_overlap_cv != NULL)
00123         {
00124           // Add halfedge handles to the resulting curve.
00125           Halfedge_handle  he;
00126 
00127           if (cv1.halfedge_handle() != invalid_he)
00128             he = cv1.halfedge_handle();
00129           else if (cv2.halfedge_handle() != invalid_he)
00130             he = cv2.halfedge_handle();
00131 
00132           X_monotone_curve_2    overlap_cv (*base_overlap_cv, he);
00133 
00134           overlap_cv.set_overlapping();
00135           *oi = make_object (overlap_cv);
00136         }
00137         else
00138         {
00139           intersect_p = 
00140             object_cast<std::pair<Base_point_2, unsigned int> > (&(*oi));
00141 
00142           CGAL_assertion (intersect_p != NULL);
00143 
00144           *oi = make_object (std::make_pair (Point_2(intersect_p->first),
00145                                              intersect_p->second));
00146         }
00147       }
00148 
00149       // Return a past-the-end iterator.
00150       return oi_end;
00151     }
00152   };
00153 
00155   Intersect_2 intersect_2_object () const
00156   {
00157     return (Intersect_2 (this->m_base_traits->intersect_2_object())); 
00158   }
00159 
00161   class Split_2 {
00162   protected:
00164     Base_split_2    m_base_split;
00165 
00171     Split_2(const Base_split_2& base) : m_base_split (base) {}
00172 
00174     friend class Arr_insertion_traits_2<Traits_2, Arrangement_>;
00175     
00176   public:
00177     void operator() (const X_monotone_curve_2& cv, const Point_2 & p,
00178                      X_monotone_curve_2& c1, X_monotone_curve_2& c2)
00179     {
00180       m_base_split(cv.base(), p.base(), c1.base(), c2.base());
00181       c1.set_halfedge_handle(cv.halfedge_handle());
00182       c2.set_halfedge_handle(cv.halfedge_handle());
00183     }
00184   };
00185 
00187   Split_2 split_2_object () const
00188   {
00189     return (Split_2 (this->m_base_traits->split_2_object()));
00190   }
00191 };
00192 
00193 CGAL_END_NAMESPACE
00194 
00195 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines