BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Arrangement_on_surface_with_history_2.h
Go to the documentation of this file.
00001 // Copyright (c) 2006  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/Arrangement_on_surface_with_history_2.h $
00015 // $Id: Arrangement_on_surface_with_history_2.h 50366 2009-07-05 12:56:48Z efif $
00016 // 
00017 //
00018 // Author(s)     : Ron Wein         <wein@post.tau.ac.il>
00019 //                 Efi Fogel        <efif@post.tau.ac.il>
00020 //                 Baruch Zukerman  <baruchzu@post.tau.ac.il>
00021 
00022 #ifndef CGAL_ARRANGEMENT_ON_SURFACE_WITH_HISTORY_2_H
00023 #define CGAL_ARRANGEMENT_ON_SURFACE_WITH_HISTORY_2_H
00024 
00029 #include <CGAL/Arrangement_on_surface_2.h>
00030 #include <CGAL/Arr_overlay_2.h>
00031 #include <CGAL/Arr_consolidated_curve_data_traits_2.h>
00032 #include <CGAL/Arr_observer.h>
00033 #include <CGAL/In_place_list.h>
00034 #include <CGAL/Arrangement_2/Arr_with_history_accessor.h>
00035 
00036 #include <set>
00037 
00038 CGAL_BEGIN_NAMESPACE
00039 
00054 template <class GeomTraits_, class TopTraits_> 
00055 class Arrangement_on_surface_with_history_2 :
00056   public Arrangement_on_surface_2 
00057   <Arr_consolidated_curve_data_traits_2
00058      <GeomTraits_, typename GeomTraits_::Curve_2 *>,
00059    typename TopTraits_::template rebind
00060      <Arr_consolidated_curve_data_traits_2
00061        <GeomTraits_,
00062         typename GeomTraits_::Curve_2 *>,
00063       typename TopTraits_::Dcel::template rebind
00064       <Arr_consolidated_curve_data_traits_2
00065        <GeomTraits_,
00066         typename GeomTraits_::Curve_2 *> >::other>::other>
00067 {
00068 public:
00069 
00070   typedef GeomTraits_                                     Geometry_traits_2;
00071   typedef TopTraits_                                      Base_topology_traits;
00072   typedef Arrangement_on_surface_with_history_2<Geometry_traits_2,
00073                                                 Base_topology_traits>  Self;
00074 
00075   typedef typename Geometry_traits_2::Point_2             Point_2;
00076   typedef typename Geometry_traits_2::Curve_2             Curve_2;
00077   typedef typename Geometry_traits_2::X_monotone_curve_2  X_monotone_curve_2;
00078 
00079   typedef Arr_observer<Self>                              Observer;
00080 protected:
00081 
00082   friend class Arr_observer<Self>;
00083   friend class Arr_accessor<Self>;
00084   friend class Arr_with_history_accessor<Self>;
00085 
00086   // Define the data-traits class based on Geometry_traits_2.
00087   typedef Arr_consolidated_curve_data_traits_2<Geometry_traits_2,Curve_2*>
00088                                                      Data_traits_2;
00089   typedef typename Data_traits_2::Curve_2            Data_curve_2;
00090   typedef typename Data_traits_2::X_monotone_curve_2 Data_x_curve_2;
00091   typedef typename Data_traits_2::Data_iterator      Data_iterator;
00092 
00093   // Rebind the DCEL and the topology traits to the data-traits class.
00094   typedef typename Base_topology_traits::Dcel        Base_dcel;
00095   typedef typename Base_dcel::template 
00096                  rebind<Data_traits_2>               Dcel_rebind;
00097   typedef typename Dcel_rebind::other                Data_dcel;
00098 
00099   typedef typename Base_topology_traits::template 
00100                  rebind<Data_traits_2, Data_dcel>    Top_traits_rebind;
00101   typedef typename Top_traits_rebind::other          Data_top_traits;
00102 
00103   // The arrangement with history is based on the representation of an
00104   // arrangement, templated by the data-traits class and the rebound DCEL.
00105   typedef Arrangement_on_surface_2<Data_traits_2,
00106                                    Data_top_traits>  Base_arr_2;
00107 
00108 public:
00109   typedef Arr_traits_adaptor_2<Data_traits_2>        Traits_adaptor_2;
00110  
00111 public:
00112 
00113   typedef Data_top_traits                            Topology_traits;
00114   typedef Base_arr_2                                 Base_arrangement_2;
00115 
00116   // Types inherited from the base arrangement class:
00117   typedef typename Base_arr_2::Size                    Size;
00118 
00119   typedef typename Base_arr_2::Vertex                  Vertex;
00120   typedef typename Base_arr_2::Halfedge                Halfedge;
00121   typedef typename Base_arr_2::Face                    Face;
00122 
00123   typedef typename Base_arr_2::Vertex_iterator         Vertex_iterator;
00124   typedef typename Base_arr_2::Vertex_const_iterator   Vertex_const_iterator;
00125   typedef typename Base_arr_2::Halfedge_iterator       Halfedge_iterator;
00126   typedef typename Base_arr_2::Halfedge_const_iterator Halfedge_const_iterator;
00127   typedef typename Base_arr_2::Edge_iterator           Edge_iterator;
00128   typedef typename Base_arr_2::Edge_const_iterator     Edge_const_iterator;
00129   typedef typename Base_arr_2::Face_iterator           Face_iterator;
00130   typedef typename Base_arr_2::Face_const_iterator     Face_const_iterator;
00131   typedef typename Base_arr_2::Halfedge_around_vertex_circulator
00132                                       Halfedge_around_vertex_circulator;
00133   typedef typename Base_arr_2::Halfedge_around_vertex_const_circulator 
00134                                       Halfedge_around_vertex_const_circulator;
00135   typedef typename Base_arr_2::Ccb_halfedge_circulator
00136                                       Ccb_halfedge_circulator;
00137   typedef typename Base_arr_2::Ccb_halfedge_const_circulator
00138                                       Ccb_halfedge_const_circulator;
00139   typedef typename Base_arr_2::Outer_ccb_iterator       
00140                                       Outer_ccb_iterator;
00141   typedef typename Base_arr_2::Outer_ccb_const_iterator
00142                                       Outer_ccb_const_iterator;
00143   typedef typename Base_arr_2::Inner_ccb_iterator       
00144                                       Inner_ccb_iterator;
00145   typedef typename Base_arr_2::Inner_ccb_const_iterator
00146                                       Inner_ccb_const_iterator;
00147   typedef typename Base_arr_2::Isolated_vertex_iterator
00148                                       Isolated_vertex_iterator;
00149   typedef typename Base_arr_2::Isolated_vertex_const_iterator
00150                                       Isolated_vertex_const_iterator;
00151 
00152   typedef typename Base_arr_2::Vertex_handle           Vertex_handle;
00153   typedef typename Base_arr_2::Vertex_const_handle     Vertex_const_handle;
00154   typedef typename Base_arr_2::Halfedge_handle         Halfedge_handle;
00155   typedef typename Base_arr_2::Halfedge_const_handle   Halfedge_const_handle;
00156   typedef typename Base_arr_2::Face_handle             Face_handle;
00157   typedef typename Base_arr_2::Face_const_handle       Face_const_handle;
00158 
00159 protected:
00160  
00164   struct Less_halfedge_handle
00165   {
00166     bool operator() (Halfedge_handle h1, Halfedge_handle h2) const
00167     {
00168       return (&(*h1) < &(*h2));
00169     }
00170   };
00171 
00172   // Forward declaration:
00173   class Curve_halfedges_observer;
00174 
00179   class Curve_halfedges : public Curve_2,
00180                           public In_place_list_base<Curve_halfedges>
00181   {
00182     friend class Curve_halfedges_observer;
00183     friend class Arrangement_on_surface_with_history_2<GeomTraits_,
00184                                                        TopTraits_>;
00185     friend class Arr_with_history_accessor<Self>;
00186 
00187   private:
00188 
00189     typedef std::set<Halfedge_handle, Less_halfedge_handle>  Halfedges_set;
00190 
00191     // Data members:
00192     Halfedges_set m_halfedges;
00193 
00194   public:
00195 
00197     Curve_halfedges ()
00198     {}
00199 
00201     Curve_halfedges (const Curve_2& curve) :
00202       Curve_2(curve)
00203     {}
00204 
00205     typedef typename Halfedges_set::iterator             iterator;
00206     typedef typename Halfedges_set::const_iterator       const_iterator;
00207 
00208   private:
00209 
00211     Size _size () const
00212     {
00213       return (m_halfedges.size());
00214     }
00215 
00217     const_iterator _begin () const
00218     {
00219       return m_halfedges.begin();
00220     }
00221 
00223     iterator _begin ()
00224     {
00225       return m_halfedges.begin();
00226     }
00227     
00229     const_iterator _end () const
00230     {
00231       return m_halfedges.end();
00232     }
00233 
00235     iterator _end ()
00236     {
00237       return m_halfedges.end();
00238     }
00239 
00241     iterator _insert (Halfedge_handle he)
00242     {
00243       std::pair<iterator, bool> res = m_halfedges.insert(he);
00244       CGAL_assertion(res.second);
00245       return (res.first);
00246     }
00247     
00249     void _erase(iterator pos)
00250     {
00251       m_halfedges.erase(pos);
00252       return;
00253     }
00254     
00256     void _erase (Halfedge_handle he)
00257     {
00258       size_t res = m_halfedges.erase(he);
00259       if (res == 0)
00260         res = m_halfedges.erase(he->twin());
00261       CGAL_assertion(res != 0);
00262       return;
00263     }
00264 
00266     void _clear ()
00267     {
00268       m_halfedges.clear();
00269       return;
00270     }
00271   };
00272 
00273   typedef CGAL_ALLOCATOR(Curve_halfedges)               Curves_alloc;
00274   typedef In_place_list<Curve_halfedges, false>         Curve_halfedges_list;
00275 
00281   class Curve_halfedges_observer : public Arr_observer<Base_arr_2>
00282   {
00283   public:
00284 
00285     typedef typename Base_arr_2::Halfedge_handle     Halfedge_handle;
00286     typedef typename Base_arr_2::Vertex_handle       Vertex_handle;
00287     typedef typename Base_arr_2::X_monotone_curve_2  X_monotone_curve_2;
00288 
00293     virtual void after_create_edge (Halfedge_handle e)
00294     {
00295       _register_edge(e);
00296     }
00297 
00303     virtual void before_modify_edge (Halfedge_handle e,
00304                                      const X_monotone_curve_2& /* c */)
00305     {
00306       _unregister_edge(e);
00307     }
00308 
00313     virtual void after_modify_edge (Halfedge_handle e)
00314     {
00315       _register_edge(e);
00316     }
00317     
00324     virtual void before_split_edge (Halfedge_handle e,
00325                                     Vertex_handle /* v */,
00326                                     const X_monotone_curve_2& /* c1 */,
00327                                     const X_monotone_curve_2& /* c2 */)
00328     {
00329       _unregister_edge(e);
00330     }
00331 
00337     virtual void after_split_edge (Halfedge_handle e1, Halfedge_handle e2)
00338     {
00339       _register_edge(e1);
00340       _register_edge(e2);
00341     }
00342 
00349     virtual void before_merge_edge (Halfedge_handle e1, Halfedge_handle e2,
00350                                     const X_monotone_curve_2& /* c */)
00351     {
00352       _unregister_edge(e1);
00353       _unregister_edge(e2);
00354     }
00355 
00360     virtual void after_merge_edge (Halfedge_handle e)
00361     {
00362       _register_edge(e);
00363     }
00364 
00369     virtual void before_remove_edge (Halfedge_handle e)
00370     {
00371       _unregister_edge(e);
00372     }
00373 
00374   private:
00375     
00379     void _register_edge (Halfedge_handle e)
00380     {
00381       Curve_halfedges  *curve_halfedges;
00382       Data_iterator     di;
00383 
00384       for (di = e->curve().data().begin(); di != e->curve().data().end(); ++di)
00385       {
00386         curve_halfedges = static_cast<Curve_halfedges*>(*di);
00387         curve_halfedges->_insert(e);
00388       }
00389     }
00390 
00394     void _unregister_edge (Halfedge_handle e)
00395     {
00396       Curve_halfedges  *curve_halfedges;
00397       Data_iterator     di;
00398 
00399       for (di = e->curve().data().begin(); di != e->curve().data().end(); ++di)
00400       {
00401         curve_halfedges = static_cast<Curve_halfedges*>(*di);
00402         curve_halfedges->_erase(e);
00403       }
00404     }
00405   };
00406 
00407   // Data members:
00408   Curves_alloc              m_curves_alloc;
00409   Curve_halfedges_list      m_curves;
00410   Curve_halfedges_observer  m_observer;
00411   
00412 public:
00413 
00414   typedef typename Curve_halfedges_list::iterator        Curve_iterator;
00415   typedef typename Curve_halfedges_list::const_iterator  Curve_const_iterator;
00416 
00417   typedef Curve_iterator                                 Curve_handle;
00418   typedef Curve_const_iterator                           Curve_const_handle;
00419 
00421 
00422 
00424   Arrangement_on_surface_with_history_2 ();
00425 
00427   Arrangement_on_surface_with_history_2 (const Self& arr);
00428 
00430   Arrangement_on_surface_with_history_2 (const Geometry_traits_2 *tr);
00432 
00434 
00435 
00437   Self& operator= (const Self& arr);
00438 
00440   void assign (const Self& arr);
00442 
00444 
00445 
00447   virtual ~Arrangement_on_surface_with_history_2 ();
00448 
00450   virtual void clear ();
00452 
00454   inline const Geometry_traits_2 * geometry_traits () const
00455   {
00456     return (this->m_geom_traits);
00457   }
00458 
00460   inline Topology_traits * topology_traits ()
00461   {
00462     return (&(this->m_topol_traits));
00463   }
00464   
00466   inline const Topology_traits* topology_traits () const
00467   {
00468     return (&(this->m_topol_traits));
00469   }
00470 
00472 
00473   Size number_of_curves () const
00474   {
00475     return (m_curves.size());
00476   }
00477 
00478   Curve_iterator curves_begin ()
00479   {
00480     return (m_curves.begin());
00481   }
00482 
00483   Curve_iterator curves_end ()
00484   {
00485     return (m_curves.end());
00486   }
00487 
00488   Curve_const_iterator curves_begin () const
00489   {
00490     return (m_curves.begin());
00491   }
00492 
00493   Curve_const_iterator curves_end () const
00494   {
00495     return (m_curves.end());
00496   }
00498 
00503   class Originating_curve_iterator :
00504     public I_Dereference_iterator<Data_iterator,
00505                                   Curve_2,
00506                                   typename Data_iterator::difference_type,
00507                                   typename Data_iterator::iterator_category>
00508   {
00509     typedef I_Dereference_iterator<Data_iterator,
00510                                    Curve_2,
00511                                    typename Data_iterator::difference_type,
00512                                    typename Data_iterator::iterator_category>
00513                                                                           Base;
00514 
00515   public:
00516  
00517     Originating_curve_iterator ()
00518     {}
00519 
00520     Originating_curve_iterator (Data_iterator iter) :
00521       Base (iter)
00522     {}
00523 
00524     // Casting to a curve iterator.
00525     operator Curve_iterator () const
00526     {
00527       Curve_halfedges   *p_cv = static_cast<Curve_halfedges*>(this->ptr());
00528       return (Curve_iterator (p_cv));
00529     }
00530 
00531     operator Curve_const_iterator () const
00532     {
00533       const Curve_halfedges   
00534                         *p_cv = static_cast<Curve_halfedges*>(this->ptr());
00535       return (Curve_const_iterator  (p_cv));
00536     }    
00537   };
00538 
00540 
00541   Size number_of_originating_curves (Halfedge_const_handle e) const
00542   {
00543     return (e->curve().data().size());
00544   }
00545 
00546   Originating_curve_iterator
00547   originating_curves_begin (Halfedge_const_handle e) const
00548   {
00549     return Originating_curve_iterator (e->curve().data().begin());
00550   }
00551 
00552   Originating_curve_iterator
00553   originating_curves_end (Halfedge_const_handle e) const
00554   {
00555     return Originating_curve_iterator (e->curve().data().end());
00556   }
00558 
00559   typedef typename Curve_halfedges::const_iterator   Induced_edge_iterator;
00560 
00562 
00563   Size number_of_induced_edges (Curve_const_handle c) const
00564   {
00565     return (c->_size());
00566   }
00567 
00568   Induced_edge_iterator
00569   induced_edges_begin (Curve_const_handle c) const
00570   {
00571     return (c->_begin());
00572   }
00573 
00574   Induced_edge_iterator
00575   induced_edges_end (Curve_const_handle c) const
00576   {
00577     return (c->_end());
00578   }
00580 
00582 
00583 
00592   Halfedge_handle split_edge (Halfedge_handle e,
00593                               const Point_2& p);
00594 
00603   Halfedge_handle merge_edge (Halfedge_handle e1, 
00604                               Halfedge_handle e2);
00605 
00612   bool are_mergeable (Halfedge_const_handle e1,
00613                       Halfedge_const_handle e2) const;
00614 
00615 protected:
00616 
00618 
00619 
00624   void _register_observer (Observer *p_obs);
00625 
00631   bool _unregister_observer (Observer *p_obs);
00633 
00635 
00636 
00643   template <class PointLocation>
00644   Curve_handle _insert_curve (const Curve_2& cv,
00645                               const PointLocation& pl)
00646   {
00647     // Allocate an extended curve (with an initially empty set of edges)
00648     // and store it in the curves' list.
00649     Curve_halfedges   *p_cv = m_curves_alloc.allocate (1);
00650     
00651     m_curves_alloc.construct (p_cv, cv);
00652     m_curves.push_back (*p_cv);
00653 
00654     // Create a data-traits Curve_2 object, which is comprised of cv and
00655     // a pointer to the extended curve we have just created.
00656     // Insert this curve into the base arrangement. Note that the attached
00657     // observer will take care of updating the edges' set.
00658     Data_curve_2       data_curve (cv, p_cv);
00659     Base_arr_2&        base_arr = *this;
00660 
00661     CGAL::insert (base_arr, data_curve, pl);
00662     
00663     // Return a handle to the inserted curve (the last in the list).
00664     Curve_handle       ch = m_curves.end();
00665     return (--ch);
00666   }
00667 
00674   Curve_handle _insert_curve (const Curve_2& cv)
00675   {
00676     // Allocate an extended curve (with an initially empty set of edges)
00677     // and store it in the curves' list.
00678     Curve_halfedges   *p_cv = m_curves_alloc.allocate (1);
00679     
00680     m_curves_alloc.construct (p_cv, cv);
00681     m_curves.push_back (*p_cv);
00682 
00683     // Create a data-traits Curve_2 object, which is comprised of cv and
00684     // a pointer to the extended curve we have just created.
00685     // Insert this curve into the base arrangement. Note that the attached
00686     // observer will take care of updating the edges' set.
00687     Data_curve_2       data_curve (cv, p_cv);
00688     Base_arr_2&        base_arr = *this;
00689 
00690     CGAL::insert (base_arr, data_curve);
00691     
00692     // Return a handle to the inserted curve (the last in the list).
00693     Curve_handle       ch = m_curves.end();
00694     return (--ch);
00695   }
00696   
00702   template <class InputIterator>
00703   void _insert_curves (InputIterator begin, InputIterator end)
00704   {
00705     // Create a list of extended curves (with an initially empty sets of edges)
00706     std::list<Data_curve_2>   data_curves;
00707 
00708     while (begin != end)
00709     {
00710       Curve_halfedges   *p_cv = m_curves_alloc.allocate (1);
00711     
00712       m_curves_alloc.construct (p_cv, *begin);
00713       m_curves.push_back (*p_cv);
00714 
00715       data_curves.push_back (Data_curve_2 (*begin, p_cv));
00716 
00717       ++begin;
00718     }
00719 
00720     // Perform an aggregated insertion operation into the base arrangement.
00721     Base_arr_2&        base_arr = *this;
00722 
00723     CGAL::insert (base_arr, data_curves.begin(), data_curves.end());
00724     return;
00725   }
00726 
00732   Size _remove_curve (Curve_handle ch)
00733   {
00734     // Go over all edges the given curve induces.
00735     Curve_halfedges                           *p_cv = &(*ch); 
00736     typename Curve_halfedges::const_iterator   it = ch->_begin();
00737     Halfedge_handle                            he;
00738     Size                                       n_removed = 0;
00739 
00740     while (it != ch->_end())
00741     {
00742       // Check how many curves have originated the current edge.
00743       // Note we increment the iterator now, as the edge may be removed.
00744       he = *it;
00745       ++it;
00746 
00747       if (he->curve().data().size() == 1)
00748       {
00749         // The edge is induced only by out curve - remove it.
00750         CGAL_assertion (he->curve().data().front() == p_cv);
00751 
00752         Base_arr_2::remove_edge (he);
00753         n_removed++;
00754       }
00755       else
00756       {
00757         // The edge is induced by other curves as well, so we just remove
00758         // the pointer to out curve from its data container.
00759         he->curve().data().erase (p_cv);
00760       }
00761     }
00762 
00763     // Remove the extended curve object from the list and de-allocate it.
00764     m_curves.erase (p_cv);
00765     m_curves_alloc.destroy (p_cv);
00766     m_curves_alloc.deallocate (p_cv, 1);
00767 
00768     return (n_removed);
00769   }
00770 
00771 public:
00772 
00779   template <class TopTraits1, class TopTraits2, class OverlayTraits>
00780   void _overlay(const Arrangement_on_surface_with_history_2
00781                 <Geometry_traits_2, TopTraits1>& arr1,
00782                 const Arrangement_on_surface_with_history_2
00783                 <Geometry_traits_2, TopTraits2>& arr2,
00784                 OverlayTraits& overlay_tr)
00785   {
00786     // Clear the current contents of the arrangement.
00787     clear();
00788 
00789     // Detach the observer from the arrangement, as we do not want to update
00790     // cross-pointers between the halfedges and the curves during the
00791     // construction of overlay.
00792     m_observer.detach();
00793 
00794     // Perform overlay of the base arrnagements.
00795     typedef Arrangement_on_surface_with_history_2<Geometry_traits_2,
00796                                                   TopTraits1>  Arr_with_hist1;
00797     typedef typename Arr_with_hist1::Base_arr_2                T_base_arr1;
00798     typedef Arrangement_on_surface_with_history_2<Geometry_traits_2,
00799                                                   TopTraits2>  Arr_with_hist2;
00800     typedef typename Arr_with_hist2::Base_arr_2                T_base_arr2;
00801 
00802     const T_base_arr1&   base_arr1 = arr1;
00803     const T_base_arr2&   base_arr2 = arr2;
00804     Base_arr_2&          base_res = *this;
00805 
00806     CGAL::overlay (base_arr1, base_arr2, base_res, overlay_tr);
00807 
00808     // Create duplicates of the curves stored in both input arrangements
00809     // and map the curves of the original arrangement to their
00810     // corresponding duplicates.
00811     typedef std::map<const Curve_halfedges*,
00812                      Curve_halfedges*>             Curve_map;
00813     typedef typename Curve_map::value_type         Curve_map_entry;
00814 
00815     Curve_map                 cv_map;
00816     const Curve_2            *p_cv;
00817     Curve_halfedges          *dup_c;
00818 
00819     // Duplicate the curves from the first arrangement.
00820     typename Arr_with_hist1::Curve_const_iterator      ocit1;
00821 
00822     for (ocit1 = arr1.curves_begin(); ocit1 != arr1.curves_end(); ++ocit1)
00823     {
00824       // Create a duplicate of the current curve.
00825       dup_c = m_curves_alloc.allocate (1);
00826     
00827       p_cv = &(*ocit1);
00828       m_curves_alloc.construct (dup_c, *p_cv);
00829       m_curves.push_back (*dup_c);
00830 
00831       // Assign a map entry.
00832       cv_map.insert (Curve_map_entry (&(*ocit1), dup_c));
00833     }
00834 
00835     // Duplicate the curves from the second arrangement.
00836     typename Arr_with_hist2::Curve_const_iterator      ocit2;
00837 
00838     for (ocit2 = arr2.curves_begin(); ocit2 != arr2.curves_end(); ++ocit2)
00839     {
00840       // Create a duplicate of the current curve.
00841       dup_c = m_curves_alloc.allocate (1);
00842     
00843       p_cv = &(*ocit2);
00844       m_curves_alloc.construct (dup_c, *p_cv);
00845       m_curves.push_back (*dup_c);
00846 
00847       // Assign a map entry.
00848       cv_map.insert (Curve_map_entry (&(*ocit2), dup_c));
00849     }
00850 
00851     // Go over the list of halfedges in our arrangement. The curves associated
00852     // with these edges store pointers to the curves in the original
00853     // arrangement, so we now have to modify these pointers, according to the
00854     // mapping we have just created. While doing so, we also construct the set
00855     // of edges associated with each (duplicated) curve in our arrangement.
00856     Data_iterator                           dit;
00857     std::list<Curve_2*>                     dup_curves;
00858     typename std::list<Curve_2*>::iterator  iter;
00859     Edge_iterator                           eit;
00860     Halfedge_handle                         e;
00861     const Curve_halfedges                  *org_c;
00862 
00863     for (eit = this->edges_begin(); eit != this->edges_end(); ++eit)
00864     {
00865       e = eit;
00866       dup_curves.clear();
00867       for (dit = e->curve().data().begin();
00868            dit != e->curve().data().end(); ++dit)
00869       {
00870         org_c = static_cast<Curve_halfedges*>(*dit);
00871         dup_c = (cv_map.find (org_c))->second;
00872 
00873         dup_curves.push_back (dup_c);
00874         dup_c->_insert (e);
00875       }
00876 
00877       // Replace the curve pointers associated with the edge.
00878       e->curve().data().clear();
00879       for (iter = dup_curves.begin(); iter != dup_curves.end(); ++iter)
00880         e->curve().data().insert (*iter);
00881     }
00882 
00883     // Re-attach the observer to the arrangement.
00884     m_observer.attach (*this);
00885 
00886     return;
00887   }
00889 };
00890 
00891 //-----------------------------------------------------------------------------
00892 // Global insertion, removal and overlay functions.
00893 //-----------------------------------------------------------------------------
00894 
00903 template <class GeomTraits, class TopTraits, class PointLocation>
00904 typename Arrangement_on_surface_with_history_2<GeomTraits,
00905                                                TopTraits>::Curve_handle
00906 insert (Arrangement_on_surface_with_history_2<GeomTraits,TopTraits>& arr,
00907         const typename GeomTraits::Curve_2& c,
00908         const PointLocation& pl)
00909 {
00910   // Obtain an arrangement accessor and perform the insertion.
00911   typedef Arrangement_on_surface_with_history_2<GeomTraits,
00912                                                 TopTraits>     Arr_with_hist_2;
00913   Arr_with_history_accessor<Arr_with_hist_2>   arr_access (arr);
00914 
00915   return (arr_access.insert_curve (c, pl));
00916 }
00917 
00926 template <class GeomTraits, class TopTraits>
00927 typename Arrangement_on_surface_with_history_2<GeomTraits,
00928                                                TopTraits>::Curve_handle
00929 insert (Arrangement_on_surface_with_history_2<GeomTraits,TopTraits>& arr,
00930         const typename GeomTraits::Curve_2& c)
00931 {
00932   // Obtain an arrangement accessor and perform the insertion.
00933   typedef Arrangement_on_surface_with_history_2<GeomTraits,
00934                                                 TopTraits>     Arr_with_hist_2;
00935   Arr_with_history_accessor<Arr_with_hist_2>   arr_access (arr);
00936 
00937   return (arr_access.insert_curve (c));
00938 }
00939 
00940 
00950 template <class GeomTraits, class TopTraits, class InputIterator>
00951 void insert (Arrangement_on_surface_with_history_2<GeomTraits, TopTraits>& arr,
00952              InputIterator begin, InputIterator end)
00953 {
00954   // Obtain an arrangement accessor and perform the insertion.
00955   typedef Arrangement_on_surface_with_history_2<GeomTraits,
00956                                                 TopTraits>     Arr_with_hist_2;
00957   Arr_with_history_accessor<Arr_with_hist_2>   arr_access (arr);
00958 
00959   arr_access.insert_curves (begin, end);
00960   return;
00961 }
00962 
00968 template <class GeomTraits, class TopTraits>
00969 typename Arrangement_on_surface_with_history_2<GeomTraits,
00970                                                TopTraits>::Size
00971 remove_curve(Arrangement_on_surface_with_history_2<GeomTraits, TopTraits>& arr,
00972              typename Arrangement_on_surface_with_history_2
00973                <GeomTraits, TopTraits>::Curve_handle ch)
00974 {
00975   // Obtain an arrangement accessor and perform the removal.
00976   typedef Arrangement_on_surface_with_history_2<GeomTraits,
00977                                                 TopTraits>     Arr_with_hist_2;
00978   Arr_with_history_accessor<Arr_with_hist_2>   arr_access (arr);
00979 
00980   return (arr_access.remove_curve (ch));
00981 }
00982 
00994 template <class GeomTraits,
00995           class TopTraits1, class TopTraits2,
00996           class ResTopTraits, class OverlayTraits>
00997 void overlay (const Arrangement_on_surface_with_history_2<GeomTraits,
00998                                                           TopTraits1>& arr1,
00999               const Arrangement_on_surface_with_history_2<GeomTraits,
01000                                                           TopTraits2>& arr2,
01001               Arrangement_on_surface_with_history_2<GeomTraits,
01002                                                     ResTopTraits>& res,
01003               OverlayTraits& traits)
01004 {
01005   res._overlay (arr1, arr2, traits);
01006   return;
01007 }
01008 
01009 CGAL_END_NAMESPACE
01010 
01011 // The function definitions can be found under:
01012 #include <CGAL/Arrangement_2/Arr_on_surface_with_history_2_impl.h>
01013 
01014 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines