BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Sweep_line_2/Arr_construction_event.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  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_construction_event.h $
00015 // $Id: Arr_construction_event.h 50366 2009-07-05 12:56:48Z efif $
00016 // 
00017 //
00018 // Author(s)     : Tali Zvi <talizvi@post.tau.ac.il>
00019 //                 Baruch Zukerman <baruchzu@post.tau.ac.il>
00020 //                 Efi Fogel <efif@post.tau.ac.il>
00021 
00022 #ifndef CGAL_ARR_CONSTRUCTION_EVENT_H
00023 #define CGAL_ARR_CONSTRUCTION_EVENT_H
00024 
00029 #include <CGAL/Sweep_line_2/Sweep_line_event.h>
00030 #include <CGAL/assertions.h>
00031 #include <vector>
00032 
00033 CGAL_BEGIN_NAMESPACE
00034 
00051 template<class Traits_, class Subcurve_, class Arrangement_>
00052 class Arr_construction_event : 
00053   public Sweep_line_event<Traits_, Subcurve_>
00054 {
00055 public:
00056 
00057   typedef Traits_                                         Traits_2;
00058   typedef Subcurve_                                       Subcurve;
00059   typedef Arrangement_                                    Arrangement_2;
00060   typedef typename Arrangement_2::Vertex_handle           Vertex_handle;
00061   typedef typename Arrangement_2::Halfedge_handle         Halfedge_handle;
00062  
00063   typedef typename Traits_2::X_monotone_curve_2           X_monotone_curve_2;
00064   typedef typename Traits_2::Point_2                      Point_2;
00065 
00066   typedef Sweep_line_event<Traits_2,
00067                            Subcurve>                      Base;
00068 
00069   typedef Arr_construction_event<Traits_2,
00070                                  Subcurve,
00071                                  Halfedge_handle>         Self;
00072 
00073   typedef typename Base::Subcurve_container         Subcurve_container;
00074   typedef typename Base::Subcurve_iterator          Subcurve_iterator;
00075   typedef typename Base::Subcurve_reverse_iterator  Subcurve_reverse_iterator;
00076    
00077 protected:
00078 
00079   // Data members:
00080   std::vector<bool>  m_isCurveInArr;          // Stores for each incident
00081                                               // subcurve whether it has been
00082                                               // inserted into the arrangement.
00083 
00084   Halfedge_handle    m_halfedge;              // A halfedge handle.
00085   Vertex_handle      m_vertex;                // A vertex handle.
00086   
00087   unsigned int       m_right_curves_counter;  // Number of subcurves defined
00088                                               // to the event's right that 
00089                                               // haven't been added to the
00090                                               // arrangement, when that counter
00091                                               // is zero, we can deallocate the
00092                                               // event.
00093 
00094 public:
00095 
00097   Arr_construction_event():
00098     m_halfedge(),
00099     m_vertex(),
00100     m_right_curves_counter(0)
00101   {}
00102 
00104   ~Arr_construction_event()
00105   {}
00106 
00108   std::pair<bool, Subcurve_iterator>
00109   add_curve_to_right (Subcurve *curve,
00110                       const Traits_2 * tr)
00111   {
00112     std::pair<bool,Subcurve_iterator> res = 
00113       Base::add_curve_to_right(curve, tr);
00114     
00115     if(res.second != this->m_rightCurves.end() && res.first == false)
00116       ++m_right_curves_counter;
00117 
00118     return res;
00119   }
00120 
00122   std::pair<bool, Subcurve_iterator>
00123   add_curve_pair_to_right (Subcurve *sc1, Subcurve *sc2)
00124   {
00125     //increment twice the counter of right curves
00126     m_right_curves_counter+=2;
00127     return (Base::add_curve_pair_to_right(sc1, sc2));
00128   }
00129 
00135   int compute_halfedge_jump_count(Subcurve *curve)
00136   {
00137     int          i = 0;
00138     int          skip = 0;
00139     int          counter = 0;
00140     unsigned int j;
00141 
00142     for (j = 0 ; j < m_isCurveInArr.size() ; j++ )
00143     {
00144       if (m_isCurveInArr[j]) 
00145         skip++;
00146     }
00147     skip--;  // now 'skip' holds the amount of the right curves of the event
00148              // that are already inserted to the planar map  - 1 (minus 1)
00149 
00150     Subcurve_iterator  iter = this->m_rightCurves.end();
00151     unsigned int       num_left_curves = this->number_of_left_curves();
00152     
00153     for (--iter; iter != this->m_rightCurves.begin() ; --iter, ++counter)
00154     {
00155       if (curve == (*iter))
00156       {
00157         m_isCurveInArr[counter] = true;
00158         
00159         if ((i == 0) && (num_left_curves == 0)) 
00160           return (skip);
00161         if (num_left_curves == 0)
00162           return (i - 1);
00163     
00164         return (i);
00165       }
00166       
00167       if (m_isCurveInArr[counter])
00168         i++;
00169     }
00170 
00171     CGAL_assertion(curve == (*iter));
00172     m_isCurveInArr[counter] = true;
00173     
00174     if (num_left_curves == 0)
00175       i--;
00176 
00177     return (i);
00178   }
00179 
00184   bool is_curve_largest (Subcurve *curve)
00185   {
00186     int counter = 0;
00187 
00188     Subcurve_reverse_iterator  rev_iter;
00189     for (rev_iter = this->m_rightCurves.rbegin();
00190          rev_iter != this->m_rightCurves.rend() && curve != (*rev_iter) ;
00191          ++rev_iter, ++ counter)
00192     {
00193       if(m_isCurveInArr[counter] == true)
00194          return false;
00195     }
00196     return true;
00197   }
00198 
00203   void init_subcurve_in_arrangement_flags (unsigned int n)
00204   {
00205     m_isCurveInArr.resize (n, false);
00206     return;
00207   }
00208 
00210   bool is_subcurve_in_arrangement (unsigned int i) const
00211   {
00212     return (m_isCurveInArr[i]);
00213   }
00214 
00218   void set_subcurve_in_arrangement (unsigned int i, bool flag)
00219   {
00220     m_isCurveInArr[i] = flag;
00221     return;
00222   }
00223 
00225   void set_halfedge_handle (Halfedge_handle h)
00226   {
00227     m_halfedge = h;
00228   }
00229 
00231   Halfedge_handle halfedge_handle() const
00232   {
00233     return m_halfedge;
00234   }
00235   
00237   void set_vertex_handle (Vertex_handle v)
00238   {
00239     m_vertex = v;
00240   }
00241 
00243   Vertex_handle vertex_handle() const
00244   {
00245     return m_vertex;
00246   }
00247 
00250   unsigned int dec_right_curves_counter()
00251   {
00252     return (--m_right_curves_counter);
00253   }
00254 
00258   unsigned int right_curves_counter() const
00259   {
00260     return (m_right_curves_counter);
00261   }
00262   
00263 };
00264 
00265 CGAL_END_NAMESPACE
00266 
00267 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines