BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Sweep_line_2/Sweep_line_2_visitors.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/Sweep_line_2_visitors.h $
00015 // $Id: Sweep_line_2_visitors.h 49772 2009-06-03 21:25:53Z eric $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 //                 Ron Wein        <wein@post.tau.ac.il>
00020 
00021 #ifndef CGAL_SWEEP_LINE_2_VISITORS_H
00022 #define CGAL_SWEEP_LINE_2_VISITORS_H
00023 
00029 #include <CGAL/Sweep_line_2/Sweep_line_event.h>
00030 #include <CGAL/Sweep_line_2/Sweep_line_subcurve.h>
00031 #include <CGAL/Sweep_line_2/Sweep_line_2_utils.h>
00032 #include <CGAL/Sweep_line_empty_visitor.h>
00033 #include <vector>
00034 #include <iterator>
00035 
00036 CGAL_BEGIN_NAMESPACE
00037 
00042 template <class Traits_, class OutputIerator_>
00043 class Sweep_line_points_visitor :
00044   public Sweep_line_empty_visitor<Traits_>
00045 {
00046   typedef Traits_                                             Traits_2;
00047   typedef OutputIerator_                                      OutputIerator;
00048   typedef Sweep_line_points_visitor<Traits_2,OutputIerator>   Self;
00049 
00050   typedef Sweep_line_empty_visitor<Traits_2>           Base;
00051   typedef typename Base::Event                         Event;
00052   typedef typename Base::Subcurve                      Subcurve;
00053   typedef typename Base::Event_subcurve_iterator       Event_subcurve_iterator;
00054   typedef typename Base::Status_line_iterator          Status_line_iterator;
00055 
00056    
00057   typedef typename Traits_2::X_monotone_curve_2        X_monotone_curve_2;
00058   typedef typename Traits_2::Point_2                   Point_2;
00059 
00060   typedef CGAL::Sweep_line_2<Traits_2, Self>           Sweep_line_2;
00061 
00062 protected:
00063 
00064   OutputIerator    m_out;                // The output points.
00065   bool             m_includeEndPoints;   // Should we include endpoints.
00066 
00067 public:
00068 
00069 
00070   Sweep_line_points_visitor (OutputIerator out,
00071                              bool endpoints) :
00072     m_out(out),
00073     m_includeEndPoints (endpoints)
00074   {}
00075 
00076   template <class CurveIterator>
00077   void sweep (CurveIterator begin, CurveIterator end)
00078   {
00079     std::vector<X_monotone_curve_2> curves_vec;
00080     std::vector<Point_2>            points_vec;
00081 
00082     curves_vec.reserve (std::distance (begin,end));
00083     make_x_monotone (begin,
00084                      end,
00085                      std::back_inserter(curves_vec),
00086                      std::back_inserter(points_vec),
00087                      this->traits());
00088    
00089     //Perform the sweep
00090     Sweep_line_2  *sl = reinterpret_cast<Sweep_line_2*> (this->sweep_line());
00091 
00092     sl->sweep (curves_vec.begin(),
00093                curves_vec.end(),
00094                points_vec.begin(),
00095                points_vec.end());
00096   }
00097 
00098   bool after_handle_event (Event* event,
00099                            Status_line_iterator /* iter */,
00100                            bool /* flag */)
00101   {
00102     if ((m_includeEndPoints ||
00103          event->is_intersection() ||
00104          event->is_weak_intersection()) && event->is_closed())
00105     {
00106       *m_out = event->point();
00107       ++m_out;
00108     }
00109     return (true);
00110   }
00111 
00112 
00113   OutputIerator output_iterator()
00114   {
00115     return (m_out);
00116   }
00117 
00118 };
00119 
00124 template <class Traits_, class OutputIerator_>
00125 class Sweep_line_subcurves_visitor :
00126   public Sweep_line_empty_visitor<Traits_>
00127 {
00128   typedef Traits_                                              Traits_2;
00129   typedef OutputIerator_                                       OutputIerator;
00130   typedef Sweep_line_subcurves_visitor<Traits_2,OutputIerator> Self;
00131 
00132   typedef typename Traits_2::X_monotone_curve_2        X_monotone_curve_2;
00133   typedef typename Traits_2::Point_2                   Point_2;
00134 
00135   typedef Sweep_line_empty_visitor<Traits_2>           Base;
00136   typedef typename Base::Event                         Event;
00137   typedef typename Base::Subcurve                      Subcurve;
00138   typedef typename Base::Status_line_iterator          Status_line_iterator;
00139 
00140   typedef CGAL::Sweep_line_2<Traits_2, Self>           Sweep_line_2;
00141 
00142 protected:
00143 
00144   // Data members:
00145   OutputIerator m_out;           // The output curves.
00146   bool          m_overlapping;   // Should we report overlapping curves twice.
00147 
00148 public:
00149 
00150   Sweep_line_subcurves_visitor (OutputIerator out,
00151                                 bool overlapping) : 
00152     m_out(out),
00153     m_overlapping(overlapping)
00154   {}
00155 
00156   template <class CurveIterator>
00157   void sweep (CurveIterator begin, CurveIterator end)
00158   {
00159     std::vector<X_monotone_curve_2>  curves_vec;
00160     std::vector<Point_2>             points_vec;
00161 
00162     curves_vec.reserve (std::distance(begin,end));
00163     make_x_monotone (begin,
00164                      end,
00165                      std::back_inserter(curves_vec),
00166                      std::back_inserter(points_vec),
00167                      this->traits());
00168    
00169     // Perform the sweep.
00170     Sweep_line_2  *sl = reinterpret_cast<Sweep_line_2*> (this->sweep_line());
00171 
00172     sl->sweep (curves_vec.begin(),
00173                curves_vec.end(),
00174                points_vec.begin(),
00175                points_vec.end());
00176   }
00177        
00178   void add_subcurve (const X_monotone_curve_2& cv, Subcurve *sc)
00179   {
00180     if (!m_overlapping)
00181     {
00182       // Report the curve once, whether it represents an overlap or not.
00183       *m_out = cv;
00184       ++m_out;
00185     }
00186     else
00187     {
00188       unsigned int overlap_depth = sc->overlap_depth();
00189       for(unsigned int i = 0 ; i < overlap_depth ; ++i)
00190       {
00191         *m_out = cv;
00192         ++m_out;
00193       }
00194     }
00195     
00196     return;
00197   }
00198 
00199   OutputIerator output_iterator()
00200   {
00201     return (m_out);
00202   }
00203 };
00204 
00209 template <class Traits_>
00210 class Sweep_line_do_curves_x_visitor :
00211   public Sweep_line_empty_visitor<Traits_>
00212 {
00213   typedef Traits_                                      Traits_2;
00214   typedef Sweep_line_do_curves_x_visitor<Traits_2>     Self;
00215 
00216   typedef typename Traits_2::X_monotone_curve_2        X_monotone_curve_2;
00217   typedef typename Traits_2::Point_2                   Point_2;
00218 
00219   typedef Sweep_line_empty_visitor<Traits_2>           Base;
00220   typedef typename Base::Event                         Event;
00221   typedef typename Base::Subcurve                      Subcurve;
00222   typedef typename Base::Status_line_iterator          Status_line_iterator;
00223 
00224   typedef CGAL::Sweep_line_2<Traits_2, Self>           Sweep_line_2;
00225 
00226 protected:
00227 
00228   // Data members:
00229   bool     m_found_x;           // Have we found an intersection so far.
00230 
00231 public:
00232 
00233   Sweep_line_do_curves_x_visitor() :
00234     m_found_x(false)
00235   {}
00236 
00237   template <class CurveIterator>
00238   void sweep(CurveIterator begin, CurveIterator end)
00239   {
00240     std::vector<X_monotone_curve_2>  curves_vec;
00241     std::vector<Point_2>             points_vec;
00242 
00243     curves_vec.reserve (std::distance (begin,end));
00244     make_x_monotone (begin,
00245                      end,
00246                      std::back_inserter(curves_vec),
00247                      std::back_inserter(points_vec),
00248                      this-> traits());
00249    
00250     // Perform the sweep.
00251     Sweep_line_2  *sl = reinterpret_cast<Sweep_line_2*> (this->sweep_line());
00252 
00253     sl->sweep (curves_vec.begin(),
00254                curves_vec.end(),
00255                points_vec.begin(),
00256                points_vec.end());
00257   }
00258 
00259   void update_event (Event* /* e */,
00260                      Subcurve* /* sc1 */,
00261                      Subcurve* /* sc2 */,
00262                      bool /* is_new */)
00263   {
00264     m_found_x = true;
00265   }
00266 
00267   void update_event (Event* /* e */,
00268                      Subcurve* /* sc1 */)
00269   {
00270     m_found_x = true;
00271   }
00272 
00273   void update_event (Event* /* e */,
00274                      const Point_2& /* end_point */,
00275                      const X_monotone_curve_2& /* cv */,
00276                      Arr_curve_end /* cv_end */,
00277                      bool /* is_new */)
00278   {}
00279 
00280   void update_event (Event* /* e */,
00281                      const Point_2& /* pt */,
00282                      bool /* is_new */)
00283   {}
00284 
00285   template <class XCurveIterator>
00286   void sweep_xcurves (XCurveIterator begin, XCurveIterator end)
00287   {
00288     // Perform the sweep.
00289     Sweep_line_2  *sl = reinterpret_cast<Sweep_line_2*> (this->sweep_line());
00290 
00291     sl->sweep(begin, end);
00292   }
00293 
00294   void found_overlap (Subcurve* /* sc1 */,
00295                       Subcurve* /* sc2 */,
00296                       Subcurve* /* ov_sc */)
00297   {
00298     m_found_x = true;
00299   }
00300 
00301   bool after_handle_event (Event* /* event */,
00302                            Status_line_iterator /* iter */,
00303                            bool /* flag */)
00304   {
00305     if(m_found_x)
00306     {
00307        Sweep_line_2  *sl = reinterpret_cast<Sweep_line_2*> (this->sweep_line());
00308        sl->stop_sweep();
00309     }
00310     return (true);
00311   }
00312 
00313   bool found_intersection ()
00314   {
00315     return (m_found_x);
00316   }
00317 };
00318 
00319 CGAL_END_NAMESPACE
00320 
00321 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines