BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Sweep_line_2/Arr_basic_insertion_sl_visitor.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_basic_insertion_sl_visitor.h $
00015 // $Id: Arr_basic_insertion_sl_visitor.h 41108 2007-12-06 15:26:30Z efif $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 //                 Ron Wein        <wein@post.tau.ac.il>
00020 //                 Efi Fogel       <efif@post.tau.ac.il>
00021 
00022 #ifndef CGAL_ARR_BASIC_INSERTION_SL_VISITOR_H
00023 #define CGAL_ARR_BASIC_INSERTION_SL_VISITOR_H
00024 
00029 CGAL_BEGIN_NAMESPACE
00030 
00036 template <class Helper_> 
00037 class Arr_basic_insertion_sl_visitor : 
00038   public Helper_::Parent_visitor
00039 {
00040 public:
00041   
00042   typedef Helper_                                      Helper;
00043 
00044   typedef typename Helper::Traits_2                    Traits_2;
00045   typedef typename Helper::Arrangement_2               Arrangement_2;
00046   typedef typename Helper::Parent_visitor              Base;
00047   typedef typename Helper::Event                       Event;
00048   typedef typename Helper::Subcurve                    Subcurve;
00049   
00050   typedef typename Traits_2::X_monotone_curve_2        X_monotone_curve_2;
00051   typedef typename Traits_2::Point_2                   Point_2;
00052 
00053 protected:
00054 
00055   typedef typename Base::Status_line_iterator          Status_line_iterator;
00056   typedef typename Base::Vertex_handle                 Vertex_handle;
00057   typedef typename Base::Halfedge_handle               Halfedge_handle;
00058   typedef typename Base::Face_handle                   Face_handle;
00059   typedef typename Base::Event_subcurve_iterator       Event_subcurve_iterator;
00060   typedef typename Base::Event_subcurve_reverse_iterator
00061                                                Event_subcurve_reverse_iterator;
00062   
00063 public:
00064 
00066   Arr_basic_insertion_sl_visitor (Arrangement_2 *arr) :
00067     Base (arr)
00068   {}
00069 
00071 
00072 
00073   /* A notification issued before the sweep process starts. */
00074   void before_sweep ();
00075 
00080   void before_handle_event (Event* event);
00081 
00083   void add_subcurve (const X_monotone_curve_2& cv, Subcurve* sc);
00084 
00086   void update_event()
00087   {}
00088 
00089   void update_event (Event* /* e */,
00090                      const Point_2& /* end_point */,
00091                      const X_monotone_curve_2& /* cv */,
00092                      Arr_curve_end /* cv_end */,
00093                      bool /* is_new */)
00094   {}
00095 
00096   void update_event (Event* /* e */,
00097                      const X_monotone_curve_2& /* cv */,
00098                      Arr_curve_end /* cv_end */,
00099                      bool /* is_new */)
00100   {}
00101 
00102   void update_event(Event* /* e */,
00103                     Subcurve* /* sc1 */,
00104                     Subcurve* /* sc2 */,
00105                     bool /* is_new */)
00106   {}
00107 
00108   void update_event (Event* /* e */,
00109                      Subcurve* /* sc1 */)
00110   {}
00111 
00112   void update_event (Event* e,
00113                      const Point_2& pt,
00114                      bool /* is_new */)
00115   {
00116     Vertex_handle  invalid_v;
00117     if(e->point().vertex_handle() == invalid_v)
00118       e->point().set_vertex_handle(pt.vertex_handle());
00119   }
00121 
00128   virtual Halfedge_handle
00129   insert_in_face_interior (const X_monotone_curve_2& cv,
00130                            Subcurve* sc);
00131 
00139   virtual Halfedge_handle
00140   insert_from_left_vertex (const X_monotone_curve_2& cv,
00141                            Halfedge_handle he,
00142                            Subcurve* sc);
00143 
00151   virtual Halfedge_handle
00152   insert_from_right_vertex (const X_monotone_curve_2& cv,
00153                             Halfedge_handle prev,
00154                             Subcurve* sc);
00155 
00165   virtual Halfedge_handle insert_at_vertices (const X_monotone_curve_2& cv,
00166                                               Halfedge_handle prev1,
00167                                               Halfedge_handle prev2,
00168                                               Subcurve* sc,
00169                                               bool &new_face_created);
00170 
00177   virtual Vertex_handle insert_isolated_vertex (const Point_2& pt,
00178                                                 Status_line_iterator iter);
00180 
00182 
00183 
00188   virtual bool is_split_event(Subcurve* /*sc*/, Event* /*event*/)
00189   {
00190     // In our case there are no splits:
00191     return (false);
00192   }
00193 
00197   virtual Halfedge_handle split_edge (Halfedge_handle /*he*/,
00198                                       Subcurve* /*sc*/,
00199                                       const Point_2& /*pt*/)
00200   {
00201     return Halfedge_handle();
00202   }  
00204 
00205 protected:
00206 
00208 
00209 
00211   Halfedge_handle _insert_in_face_interior (const X_monotone_curve_2& cv,
00212                                             Subcurve* sc);
00213 
00215   Halfedge_handle _insert_from_left_vertex (const X_monotone_curve_2& cv,
00216                                             Halfedge_handle he,
00217                                             Subcurve* sc);
00218 
00220   Halfedge_handle _insert_from_right_vertex (const X_monotone_curve_2& cv,
00221                                              Halfedge_handle he,
00222                                              Subcurve* sc);
00223 
00225   Halfedge_handle _insert_at_vertices (const X_monotone_curve_2& cv,
00226                                        Halfedge_handle hhandle,
00227                                        Halfedge_handle prev,
00228                                        Subcurve* sc,
00229                                        bool &new_face_created);
00230 
00232   Face_handle _ray_shoot_up (Subcurve* sc);
00234 };
00235 
00236 //-----------------------------------------------------------------------------
00237 // Memeber-function definitions:
00238 //-----------------------------------------------------------------------------
00239 
00240 //-----------------------------------------------------------------------------
00241 // A notification issued before the sweep process starts.
00242 //
00243 template <class Hlpr> 
00244 void Arr_basic_insertion_sl_visitor<Hlpr>::before_sweep ()
00245 {
00246   // We just have to notify the helper that the sweep process now starts.
00247   this->m_helper.before_sweep ();
00248 
00249   return;
00250 }
00251 
00252 //-----------------------------------------------------------------------------
00253 // A notification invoked before the sweep-line starts handling the given
00254 // event.
00255 //
00256 template <class Hlpr> 
00257 void Arr_basic_insertion_sl_visitor<Hlpr>::before_handle_event
00258     (Event* event)
00259 {
00260   // First we notify the helper class on the event.
00261   this->m_helper.before_handle_event (event);
00262 
00263   const Halfedge_handle   invalid_he;
00264 
00265   event->init_subcurve_in_arrangement_flags (event->number_of_right_curves());
00266   
00267   if (! event->has_right_curves())
00268   {
00269     // Update the event with the highest left halfedge.
00270     Event_subcurve_reverse_iterator  left_it;
00271     Halfedge_handle                  he;
00272  
00273     for (left_it = event->left_curves_rbegin();
00274          left_it != event->left_curves_rend();
00275          ++left_it)
00276     {
00277       he = (*left_it)->last_curve().halfedge_handle();
00278       if (he != invalid_he)
00279       {
00280         event->set_halfedge_handle(he->twin());
00281         return;
00282       }
00283     }
00284   }
00285   
00286   if (! event->has_left_curves())
00287   {
00288     // Indicates if there's halfedge to the right of the event.
00289     Event_subcurve_reverse_iterator  right_it;
00290     Halfedge_handle                  he;
00291     int                              i = 0;
00292 
00293     for (right_it = event->right_curves_rbegin();
00294          right_it != event->right_curves_rend();
00295          ++right_it, ++i)
00296     {
00297       // Update the event with the highest right halfedge.
00298       he = (*right_it)->last_curve().halfedge_handle();
00299       if(he != invalid_he)
00300       {
00301         event->set_subcurve_in_arrangement (i, true);
00302         if (event->halfedge_handle() == invalid_he)
00303           event->set_halfedge_handle (he);
00304       }
00305     }
00306     return;
00307   }
00308 
00309   // The event has left and right curves.
00310   Event_subcurve_reverse_iterator  iter;
00311   Halfedge_handle                  he;
00312   bool                             exist_right_halfedge = false; 
00313   int                              i = 0;
00314 
00315   for (iter = event->right_curves_rbegin();
00316        iter != event->right_curves_rend();
00317        ++iter, ++i)
00318   {
00319     he = (*iter)->last_curve().halfedge_handle();
00320     if (he != invalid_he)
00321     {
00322       exist_right_halfedge = true;
00323       event->set_subcurve_in_arrangement (i, true);
00324       if(!is_split_event(*iter, event))
00325       {
00326         // halfedge will not be split. 
00327         event->set_halfedge_handle(he);
00328       }
00329       else
00330       {
00331         he = split_edge ((*iter)->last_curve().halfedge_handle(),
00332                          (*iter),
00333                          event->point());
00334         
00335         // 'he' has the same source as the split halfedge.
00336         event->set_halfedge_handle(he);
00337         X_monotone_curve_2& last_curve =
00338           const_cast<X_monotone_curve_2&>((*iter)->last_curve());
00339         last_curve.set_halfedge_handle(he);
00340         
00341         //there cannot be another existing halfedge that need to be split
00342         // because they are disjoint
00343         return;
00344       }
00345     }
00346   }
00347   
00348   if (exist_right_halfedge)
00349   {
00350     return;
00351   }
00352 
00353   // if we have reached here, there are no halfedges to the right of 
00354   // the event, but still can be on the left of the event
00355   for (iter = event->left_curves_rbegin();
00356        iter != event->left_curves_rend();
00357        ++iter)
00358   {
00359     he =(*iter)->last_curve().halfedge_handle();
00360     if (he != invalid_he)
00361     {
00362       event->set_halfedge_handle(he->twin());
00363       return;
00364     }
00365   }
00366 
00367   return;
00368 }
00369 
00370 //-----------------------------------------------------------------------------
00371 // A notification invoked when a new subcurve is created.
00372 //
00373 template <class Hlpr> 
00374 void Arr_basic_insertion_sl_visitor<Hlpr>::add_subcurve
00375     (const X_monotone_curve_2& cv, Subcurve* sc)
00376 {
00377   const Halfedge_handle   invalid_he;
00378   
00379   if(cv.halfedge_handle() == invalid_he)
00380   {
00381     // The curve will be inserted into the arrangement:
00382     Base::add_subcurve(cv,sc);
00383   }
00384   else
00385   {
00386     // sc is an overlap Subcurve of existing edge and new curve,
00387     // which means that the edeg will have to be modified
00388     if (sc->originating_subcurve1())
00389     {
00390       this->m_arr->modify_edge
00391         (this->current_event()->halfedge_handle()->next()->twin(),
00392          cv.base());
00393     }
00394 
00395     Halfedge_handle next_ccw_he = 
00396       this->current_event()->halfedge_handle()->next()->twin();
00397                                                                 
00398     this->current_event()->set_halfedge_handle(next_ccw_he);
00399   }
00400 }
00401 
00402 //-----------------------------------------------------------------------------
00403 // Insert the given subcurve in the interior of an arrangement face.
00404 //
00405 template <class Hlpr>
00406 typename Arr_basic_insertion_sl_visitor<Hlpr>::Halfedge_handle
00407 Arr_basic_insertion_sl_visitor<Hlpr>::insert_in_face_interior
00408     (const X_monotone_curve_2& cv,
00409      Subcurve* sc)
00410 {
00411   Event          *lastEvent = this->last_event_on_subcurve(sc);
00412   Vertex_handle  last_v = lastEvent->point().vertex_handle();
00413   Vertex_handle  curr_v =
00414     this->current_event()->point().vertex_handle();
00415   Vertex_handle  null_v;
00416 
00417   if(last_v == null_v && curr_v == null_v)
00418     return (this->_insert_in_face_interior(cv, sc));
00419 
00420   if(last_v == null_v && curr_v != null_v)
00421   {
00422     Halfedge_handle he = this->m_arr->insert_from_right_vertex (cv.base(),
00423                                                                 curr_v);
00424     return (he->twin());
00425   }
00426    
00427   if(last_v != null_v && curr_v == null_v)
00428     return (this->m_arr->insert_from_left_vertex (cv.base(), last_v));
00429 
00430   CGAL_assertion(last_v != null_v && curr_v != null_v);
00431   return (this->m_arr->insert_at_vertices (cv.base(), last_v, curr_v));
00432 }
00433 
00434 //-----------------------------------------------------------------------------
00435 // Insert the given subcurve from a vertex that corresponds to its left end.
00436 //
00437 template <class Hlpr>
00438 typename Arr_basic_insertion_sl_visitor<Hlpr>::Halfedge_handle
00439 Arr_basic_insertion_sl_visitor<Hlpr>::insert_from_left_vertex
00440     (const X_monotone_curve_2& cv,
00441      Halfedge_handle he,
00442      Subcurve* sc)
00443 {
00444   Vertex_handle curr_v =
00445     this->current_event()->point().vertex_handle();
00446 
00447   if (curr_v != Vertex_handle())
00448     return (this->m_arr->insert_at_vertices (cv.base(), he, curr_v));
00449 
00450   return (_insert_from_left_vertex(cv, he, sc));
00451 }
00452 
00453 //-----------------------------------------------------------------------------
00454 // Insert the given subcurve from a vertex that corresponds to its right end.
00455 //
00456 template <class Hlpr>
00457 typename Arr_basic_insertion_sl_visitor<Hlpr>::Halfedge_handle
00458 Arr_basic_insertion_sl_visitor<Hlpr>::insert_from_right_vertex
00459     (const X_monotone_curve_2& cv,
00460      Halfedge_handle he,
00461      Subcurve* sc)
00462 {
00463   Event         *lastEvent = this->last_event_on_subcurve(sc);
00464   Vertex_handle  last_v = lastEvent->point().vertex_handle();
00465 
00466   if (last_v != Vertex_handle())
00467     return (this->m_arr->insert_at_vertices (cv.base(), he, last_v));
00468     
00469   return (_insert_from_right_vertex(cv, he, sc));
00470 }
00471 
00472 //-----------------------------------------------------------------------------
00473 // Insert the given subcurve using its two end-vertices.
00474 //
00475 template <class Hlpr>
00476 typename Arr_basic_insertion_sl_visitor<Hlpr>::Halfedge_handle
00477 Arr_basic_insertion_sl_visitor<Hlpr>::insert_at_vertices
00478     (const X_monotone_curve_2& cv,
00479      Halfedge_handle prev1,
00480      Halfedge_handle prev2,
00481      Subcurve* sc,
00482      bool &new_face_created)
00483 {
00484   return (_insert_at_vertices (cv, prev1, prev2, sc, new_face_created));
00485 }
00486 
00487 //-----------------------------------------------------------------------------
00488 // Insert an isolated vertex into the arrangement.
00489 //
00490 template <class Hlpr>
00491 typename Arr_basic_insertion_sl_visitor<Hlpr>::Vertex_handle
00492 Arr_basic_insertion_sl_visitor<Hlpr>::insert_isolated_vertex
00493     (const Point_2& pt,
00494      Status_line_iterator iter)
00495 {
00496   Vertex_handle  res;
00497 
00498   if (pt.vertex_handle() != Vertex_handle())
00499   {
00500     // The isolated vertex is already at the arrangement:
00501     return (res);
00502   }
00503 
00504   // Choose the right face to insert the vertex.
00505   if (iter == this->status_line_end())
00506   {
00507     // Insert the vertex inside the current top face (as given by the
00508     // helper class).
00509     res = this->m_arr->insert_in_face_interior (pt.base(),
00510                                                 this->m_helper.top_face());
00511   }
00512   else
00513   {
00514     // Look up and insert the isolated vertex in the incident face of the
00515     // halfedge we see.
00516     Face_handle   f = _ray_shoot_up(*iter);
00517 
00518     res = this->m_arr->insert_in_face_interior (pt.base(),
00519                                                 f);
00520   }
00521 
00522   return (res);
00523 }
00524 
00525 //-----------------------------------------------------------------------------
00526 // Perform the actual insertion
00527 //
00528 template <class Hlpr>
00529 typename Arr_basic_insertion_sl_visitor<Hlpr>::Halfedge_handle
00530 Arr_basic_insertion_sl_visitor<Hlpr>::_insert_in_face_interior
00531     (const X_monotone_curve_2& cv,
00532      Subcurve* sc)
00533 {
00534   // Check if the vertex to be associated with the left end of the curve has
00535   // already been created.
00536   Event         *last_event = this->last_event_on_subcurve(sc);
00537   Vertex_handle  v1 = last_event->vertex_handle();
00538   bool           create_v1 = false;
00539 
00540   if (v1 == this->m_invalid_vertex)
00541   {
00542     // Mark that we should create the vertex v1 later on (if we created it
00543     // now, and ended up calling _insert_from_right_vertex(), this vertex
00544     // would be constructed twice!)
00545     create_v1 = true;
00546   }
00547   else if (v1->degree() > 0)
00548   {
00549     // In this case the left vertex v1 is a boundary vertex which already has
00550     // some incident halfedges. We look for the predecessor halfedge and
00551     // and insert the curve from this left vertex.
00552     Arr_parameter_space   bx = last_event->parameter_space_in_x();
00553     Arr_parameter_space   by = last_event->parameter_space_in_y();
00554 
00555     CGAL_assertion (bx != ARR_INTERIOR || by != ARR_INTERIOR);
00556 
00557     Halfedge_handle l_prev =
00558       Halfedge_handle
00559       (this->m_top_traits->locate_around_boundary_vertex (&(*v1), cv.base(),
00560                                                           ARR_MIN_END, bx, by));
00561     
00562     return (_insert_from_left_vertex (cv, l_prev, sc));
00563   }
00564 
00565   // Check if the vertex to be associated with the right end of the curve has
00566   // already been created.
00567   Event         *curr_event = this->current_event();
00568   Vertex_handle  v2 = curr_event->vertex_handle();
00569 
00570   if (v2 == this->m_invalid_vertex)
00571   {
00572     // Create the vertex to be associated with the right end of the curve.
00573     v2 = this->m_arr_access.create_vertex (curr_event->point().base());
00574   }
00575   else if (v2->degree() > 0)
00576   {
00577     // In this case the right vertex v2 is a boundary vertex which already has
00578     // some incident halfedges. We look for the predecessor halfedge and
00579     // and insert the curve from this right vertex.
00580     Arr_parameter_space   bx = curr_event->parameter_space_in_x();
00581     Arr_parameter_space   by = curr_event->parameter_space_in_y();
00582 
00583     CGAL_assertion (bx != ARR_INTERIOR || by != ARR_INTERIOR);
00584 
00585     Halfedge_handle r_prev =
00586       Halfedge_handle
00587       (this->m_top_traits->locate_around_boundary_vertex (&(*v2), cv.base(),
00588                                                           ARR_MAX_END, bx, by));
00589     
00590     return (_insert_from_right_vertex (cv, r_prev, sc));
00591   }
00592 
00593   // If necessary, create the vertex to be associated with the left end
00594   // of the curve.
00595   if (create_v1)
00596     v1 = this->m_arr_access.create_vertex (last_event->point().base());
00597 
00598   // Look up and insert the edge in the interior of the incident face of the
00599   // halfedge we see.
00600   Face_handle   f = _ray_shoot_up(sc);
00601 
00602   return (this->m_arr_access.insert_in_face_interior_ex (cv.base(),
00603                                                          f,
00604                                                          v1,
00605                                                          v2,
00606                                                          SMALLER));
00607 }
00608 
00609 //-----------------------------------------------------------------------------
00610 // Perform the actual insertion
00611 //
00612 template <class Hlpr>
00613 typename Arr_basic_insertion_sl_visitor<Hlpr>::Halfedge_handle
00614 Arr_basic_insertion_sl_visitor<Hlpr>::_insert_from_left_vertex
00615     (const X_monotone_curve_2& cv,
00616      Halfedge_handle prev,
00617      Subcurve* sc)
00618 {
00619   // Check if the vertex to be associated with the right end of the curve has
00620   // already been created.
00621   Event         *curr_event = this->current_event();
00622   Vertex_handle  v = curr_event->vertex_handle();
00623 
00624   if (v == this->m_invalid_vertex)
00625   {
00626     // Create the vertex to be associated with the right end of the curve.
00627     v = this->m_arr_access.create_vertex (curr_event->point().base());
00628   }
00629   else if (v->degree() > 0)
00630   {
00631     // In this case the left vertex v is a boundary vertex which already has
00632     // some incident halfedges. We look for the predecessor halfedge and
00633     // and insert the curve from this right vertex.
00634     Arr_parameter_space   bx = curr_event->parameter_space_in_x();
00635     Arr_parameter_space   by = curr_event->parameter_space_in_y();
00636 
00637     CGAL_assertion (bx != ARR_INTERIOR || by != ARR_INTERIOR);
00638 
00639     Halfedge_handle r_prev =
00640       Halfedge_handle
00641       (this->m_top_traits->locate_around_boundary_vertex (&(*v), cv.base(),
00642                                                           ARR_MAX_END, bx, by));
00643     bool            dummy;
00644 
00645     return (_insert_at_vertices (cv, r_prev, prev, sc, dummy));
00646   }
00647 
00648   // Perform the insertion using the vertex v.
00649   return (this->m_arr_access.insert_from_vertex_ex (cv.base(),
00650                                                     prev, v,
00651                                                     SMALLER));
00652 }
00653 
00654 //-----------------------------------------------------------------------------
00655 // Perform the actual insertion
00656 //
00657 template <class Hlpr>
00658 typename Arr_basic_insertion_sl_visitor<Hlpr>::Halfedge_handle
00659 Arr_basic_insertion_sl_visitor<Hlpr>::_insert_from_right_vertex
00660     (const X_monotone_curve_2& cv,
00661      Halfedge_handle prev,
00662      Subcurve* sc)
00663 {
00664   // Check if the vertex to be associated with the left end of the curve has
00665   // already been created.
00666   Event         *last_event = this->last_event_on_subcurve(sc);
00667   Vertex_handle  v = last_event->vertex_handle();
00668 
00669   if (v == this->m_invalid_vertex)
00670   {
00671     // Create the vertex to be associated with the left end of the curve.
00672     v = this->m_arr_access.create_vertex (last_event->point().base());
00673   }
00674   else if (v->degree() > 0)
00675   {
00676     // In this case the left vertex v is a boundary vertex which already has
00677     // some incident halfedges. We look for the predecessor halfedge and
00678     // and insert the curve between two existing vertices.
00679     Arr_parameter_space   bx = last_event->parameter_space_in_x();
00680     Arr_parameter_space   by = last_event->parameter_space_in_y();
00681 
00682     CGAL_assertion (bx != ARR_INTERIOR || by != ARR_INTERIOR);
00683 
00684     Halfedge_handle l_prev =
00685       Halfedge_handle
00686       (this->m_top_traits->locate_around_boundary_vertex (&(*v), cv.base(),
00687                                                           ARR_MIN_END, bx, by));
00688     bool            dummy;
00689 
00690     return (_insert_at_vertices (cv, prev, l_prev, sc, dummy));
00691   }
00692 
00693   // Perform the insertion using the vertex v.
00694   return (this->m_arr_access.insert_from_vertex_ex (cv.base(),
00695                                                     prev, v,
00696                                                     LARGER));
00697 }
00698 
00699 //-----------------------------------------------------------------------------
00700 // Perform the actual insertion
00701 //
00702 template <class Hlpr>
00703 typename Arr_basic_insertion_sl_visitor<Hlpr>::Halfedge_handle
00704 Arr_basic_insertion_sl_visitor<Hlpr>::_insert_at_vertices
00705     (const X_monotone_curve_2& cv,
00706      Halfedge_handle prev1,
00707      Halfedge_handle prev2,
00708      Subcurve* ,
00709      bool &new_face_created)
00710 {
00711   bool        prev1_before_prev2 = true;
00712 
00713   if (this->m_arr_access.are_on_same_inner_component(prev1, prev2))
00714   {
00715     // If prev1 and prev2 are on different components, the insertion of the
00716     // new curve does not generate a new face, so the way we send these
00717     // halfedge pointers to the auxiliary function _insert_at_vertices() does
00718     // not matter.
00719     // However, in our case, where the two halfedges are reachable from one
00720     // another and are located on the same hole, a new face will be created
00721     // and form a hole inside their current incident face. In this case we
00722     // have to arrange prev1 and prev2 so that the new face (hole) will be
00723     // incident to the correct halfedge, directed from prev1's target to
00724     // prev2's target.
00725     // To do this, we check whether prev1 lies inside the new face we are
00726     // about to create (or alternatively, whether prev2 does not lie inside
00727     // this new face).
00728     const unsigned int  dist1 =
00729       this->m_arr_access.halfedge_distance (prev1, prev2);
00730     const unsigned int  dist2 =
00731       this->m_arr_access.halfedge_distance (prev2, prev1);
00732 
00733     prev1_before_prev2 = (dist1 > dist2) ?
00734       (this->m_arr_access.is_inside_new_face (prev1, prev2, cv.base())) :
00735       (! this->m_arr_access.is_inside_new_face (prev2, prev1, cv.base()));
00736   }
00737 
00738   // Perform the insertion.
00739   new_face_created = false;
00740   Halfedge_handle  new_he = (prev1_before_prev2) ?
00741     this->m_arr_access.insert_at_vertices_ex (cv.base(),
00742                                               prev1,
00743                                               prev2,
00744                                               LARGER,
00745                                               new_face_created) :
00746     this->m_arr_access.insert_at_vertices_ex (cv.base(),
00747                                               prev2,
00748                                               prev1,
00749                                               SMALLER,
00750                                               new_face_created);
00751 
00752   if (new_face_created)
00753   {
00754     // In case a new face has been created (pointed by the new halfedge we
00755     // obtained), we have to examine the holes and isolated vertices in the
00756     // existing face (pointed by the twin halfedge) and move the relevant
00757     // holes and isolated vertices into the new face.
00758     this->m_arr_access.relocate_in_new_face (new_he);
00759   }
00760 
00761   // Return a handle to the new halfedge directed from prev1's target to
00762   // prev2's target. Note that this may be the twin halfedge of the one
00763   // returned by _insert_at_vertices();
00764   if (! prev1_before_prev2)
00765     new_he = new_he->twin();
00766 
00767   return (new_he);
00768 }
00769 
00770 //-----------------------------------------------------------------------------
00771 // Locate the face containing the current object in its interior.
00772 //
00773 template <class Hlpr>
00774 typename Arr_basic_insertion_sl_visitor<Hlpr>::Face_handle
00775 Arr_basic_insertion_sl_visitor<Hlpr>::_ray_shoot_up (Subcurve* sc)
00776 {
00777   // Go up the status line and try to locate a curve which is associated
00778   // with a valid arrangement halfedge.
00779   Halfedge_handle       he_above;
00780   Status_line_iterator  iter;
00781   const Halfedge_handle invalid_he;
00782   Halfedge_handle       he;
00783 
00784   for (iter = this->status_line_position(sc);
00785        iter != this->status_line_end();
00786        ++iter)
00787   {
00788     he = (*iter)->last_curve().halfedge_handle();
00789     if (he != invalid_he)
00790     {
00791       // Return the incident face of the halfedge we found.
00792       he_above = he;
00793       return (he_above->face());
00794     }
00795   }
00796 
00797   // If we reached here, there is no arrangement halfedge above the given
00798   // subcurve. We therefore return the top face, as given by the helper class.
00799   return (this->m_helper.top_face());
00800 }
00801 
00802 CGAL_END_NAMESPACE
00803 
00804 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines