BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Sweep_line_2/Arr_batched_pl_sl_visitor.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_batched_pl_sl_visitor.h $
00015 // $Id: Arr_batched_pl_sl_visitor.h 40007 2007-08-23 13:51:38Z efif $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 //                 Ron Wein <wein@post.tau.ac.il>
00020 
00021 #ifndef CGAL_ARR_BATCHED_PL_SL_VISITOR_H
00022 #define CGAL_ARR_BATCHED_PL_SL_VISITOR_H
00023 
00028 CGAL_BEGIN_NAMESPACE
00029 
00030 #include <CGAL/Object.h>
00031 
00036 template <class Helper_, class OutputIterator_>
00037 class Arr_batched_pl_sl_visitor :
00038   public Helper_::Base_visitor
00039 {
00040 public:
00041 
00042   typedef Helper_                                      Helper;
00043   typedef OutputIterator_                              OutputIterator;
00044 
00045   typedef typename Helper::Traits_2                    Traits_2;
00046   typedef typename Helper::Arrangement_2               Arrangement_2;
00047   typedef typename Helper::Base_visitor                Base;
00048   typedef typename Helper::Event                       Event;
00049   typedef typename Helper::Subcurve                    Subcurve;
00050 
00051 protected:
00052 
00053   typedef typename Base::Status_line_iterator           Status_line_iterator;
00054   typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle;
00055   typedef typename Arrangement_2::Vertex_const_handle   Vertex_const_handle;
00056 
00057   // Data members:
00058   Helper                   m_helper;    // The helper class.
00059   OutputIterator          *m_out;       // An output iterator for the result.
00060 
00061 public:
00062 
00068   Arr_batched_pl_sl_visitor (const Arrangement_2 *arr,
00069                              OutputIterator *oi) :
00070     m_helper (arr),
00071     m_out (oi)
00072   {}
00073   
00074   /* A notification issued before the sweep process starts. */
00075   void before_sweep ();
00076 
00085   bool after_handle_event (Event* event,
00086                            Status_line_iterator above,
00087                            bool on_above);
00088 };
00089 
00090 //-----------------------------------------------------------------------------
00091 // Memeber-function definitions:
00092 //-----------------------------------------------------------------------------
00093 
00094 //-----------------------------------------------------------------------------
00095 // A notification issued before the sweep process starts.
00096 //
00097 template <class Hlpr, class OutIt>
00098 void Arr_batched_pl_sl_visitor<Hlpr, OutIt>::before_sweep ()
00099 {
00100   // We just have to notify the helper that the sweep process now starts.
00101   m_helper.before_sweep();
00102 
00103   return;
00104 }
00105 
00106 //-----------------------------------------------------------------------------
00107 // A notification invoked after the sweep-line finishes handling the given
00108 // event.
00109 //
00110 template <class Hlpr, class OutIt>
00111 bool Arr_batched_pl_sl_visitor<Hlpr, OutIt>::after_handle_event
00112     (Event* event,
00113      Status_line_iterator above, bool on_above)
00114 {
00115   // Notify the helper on the event.
00116   m_helper.after_handle_event (event);
00117 
00118   // We are only interested in events associated with query points:
00119   if (! event->is_query())
00120     return true;
00121 
00122   // Check on what kind of feature does the current query point lie.
00123   if (event->is_action())
00124   {
00125     // The query point coincides with an isolated arrangement vertex:
00126     Vertex_const_handle  vh = event->point().vertex_handle();
00127       
00128     *(*m_out) = std::make_pair (event->point().base(), 
00129                                 CGAL::make_object(vh));
00130     ++(*m_out);
00131     return (true);
00132   }
00133 
00134   if (event->has_right_curves() || event->has_left_curves())
00135   {
00136     // The point is located on an arrangement vertex:
00137     Vertex_const_handle  vh;
00138 
00139     if (event->has_right_curves())
00140     {
00141       // Take the target vertex of one of the halfedges to the right.
00142       Subcurve              *sc = *(event->right_curves_begin());
00143       Halfedge_const_handle  he = sc->last_curve().halfedge_handle();
00144 
00145       vh = he->target();
00146     }
00147     else
00148     {
00149       // Take the source vertex of one of the halfedges to the right.
00150       Subcurve              *sc = *(event->left_curves_begin());
00151       Halfedge_const_handle  he = sc->last_curve().halfedge_handle();
00152 
00153       vh = he->source();
00154     }
00155 
00156     *(*m_out) = std::make_pair (event->point().base(), 
00157                                 CGAL::make_object (vh));
00158     ++(*m_out);
00159     return (true);
00160   }
00161 
00162   if (above == this->status_line_end())
00163   {
00164     // There are no valid edges above the query point, so we use the helper
00165     // class to obtain the current top face.
00166     *(*m_out) = std::make_pair (event->point().base(),
00167                                 CGAL::make_object (m_helper.top_face()));
00168     ++(*m_out);
00169     return (true);
00170   }
00171 
00172   if (on_above)
00173   {
00174     // The query point lies on the halfedge associated with the subcurve
00175     // that the status-line iterator refers to.
00176     Halfedge_const_handle  he = (*above)->last_curve().halfedge_handle();
00177       
00178     *(*m_out) = std::make_pair (event->point().base(),
00179                                 CGAL::make_object (he));
00180     ++(*m_out);
00181     return (true);
00182   }
00183 
00184   // If we reached here, the status-line iterator refers to a halfedge above
00185   // the query point, such that the query point is located in the incident
00186   // face of this halfedge.
00187   Halfedge_const_handle  he = (*above)->last_curve().halfedge_handle();
00188 
00189   *(*m_out) = std::make_pair (event->point().base(),
00190                               CGAL::make_object (he->face()));
00191   ++(*m_out);
00192   return (true);
00193 }
00194 
00195 CGAL_END_NAMESPACE
00196 
00197 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines