BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Arrangement_zone_2.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/Arrangement_zone_2.h $
00015 // $Id: Arrangement_zone_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 //                 (based on old version by Eyal Flato)
00021 
00022 #ifndef CGAL_ARRANGEMENT_ZONE_2_H
00023 #define CGAL_ARRANGEMENT_ZONE_2_H
00024 
00029 #include <boost/mpl/assert.hpp>
00030 #include <CGAL/Arr_tags.h>
00031 #include <CGAL/Arrangement_2/Arr_traits_adaptor_2.h>
00032 
00033 #include <list>
00034 #include <map>
00035 #include <set>
00036 
00037 CGAL_BEGIN_NAMESPACE
00038 
00056 template <class Arrangement_, class ZoneVisitor_>
00057 class Arrangement_zone_2
00058 {
00059 public:
00060 
00061   typedef Arrangement_                                   Arrangement_2;
00062   typedef typename Arrangement_2::Geometry_traits_2      Geometry_traits_2;
00063   typedef typename Arrangement_2::Topology_traits        Topology_traits;
00064 
00065 protected:
00066   
00067   typedef Arr_traits_adaptor_2<Geometry_traits_2>        Traits_adaptor_2;
00068 
00069   typedef typename Traits_adaptor_2::Arr_left_side_tag   Arr_left_side_tag;
00070   typedef typename Traits_adaptor_2::Arr_bottom_side_tag Arr_bottom_side_tag;
00071   typedef typename Traits_adaptor_2::Arr_top_side_tag    Arr_top_side_tag;
00072   typedef typename Traits_adaptor_2::Arr_right_side_tag  Arr_right_side_tag;
00073 
00074   BOOST_MPL_ASSERT(
00075       (typename 
00076        Arr_sane_identified_tagging< Arr_left_side_tag, Arr_bottom_side_tag, 
00077        Arr_top_side_tag, Arr_right_side_tag >::result)
00078   );
00079 
00080 public:
00081   
00082   typedef ZoneVisitor_                                   Visitor;
00083 
00084   typedef typename Arrangement_2::Vertex_handle          Vertex_handle;
00085   typedef typename Arrangement_2::Halfedge_handle        Halfedge_handle;
00086   typedef typename Arrangement_2::Face_handle            Face_handle;
00087 
00088   typedef std::pair<Halfedge_handle, bool>               Visitor_result;
00089 
00090   typedef typename Geometry_traits_2::Point_2            Point_2;
00091   typedef typename Geometry_traits_2::X_monotone_curve_2 X_monotone_curve_2;
00092 
00093 protected:
00094 
00095   typedef typename Arr_are_all_sides_oblivious_tag< 
00096                      Arr_left_side_tag, Arr_bottom_side_tag, 
00097                      Arr_top_side_tag, Arr_right_side_tag >::result
00098   Are_all_sides_oblivious_tag;
00099   
00100   typedef typename Arrangement_2::Vertex_const_handle    Vertex_const_handle;
00101   typedef typename Arrangement_2::Halfedge_const_handle  Halfedge_const_handle;
00102   typedef typename Arrangement_2::Face_const_handle      Face_const_handle;
00103 
00104   // Types used for caching intersection points:
00105   typedef std::pair<Point_2, unsigned int>        Intersect_point_2;
00106   typedef std::list<CGAL::Object>                 Intersect_list;
00107   typedef std::map<const X_monotone_curve_2*,
00108                    Intersect_list>                Intersect_map;
00109   typedef typename Intersect_map::iterator        Intersect_map_iterator;
00110 
00111   typedef std::set<const X_monotone_curve_2*>     Curves_set;
00112   typedef typename Curves_set::iterator           Curves_set_iterator;
00113 
00114   // Data members:
00115   Arrangement_2&          arr;          // The associated arrangement.
00116   const Traits_adaptor_2 * m_geom_traits; // Its associated geometry traits.
00117   Arr_accessor<Arrangement_2> arr_access; // An accessor for the arrangement.
00118            
00119   Visitor                *visitor;      // The zone visitor.
00120 
00121   Intersect_map           inter_map;    // Stores all computed intersections.
00122 
00123   const Vertex_handle     invalid_v;    // An invalid vertex handle.
00124   const Halfedge_handle   invalid_he;   // An invalid halfedge handle.
00125 
00126   X_monotone_curve_2  cv;               // The current portion of the
00127                                         // inserted curve.
00128   CGAL::Object        obj;              // The location of the left endpoint.
00129   bool                has_left_pt;      // Is the left end of the curve
00130                                         // bounded.
00131   bool                left_on_boundary; // Is the left point on the boundary.
00132   Point_2             left_pt;          // Its current left endpoint.
00133   bool                has_right_pt;     // Is the right end of the curve
00134                                         // bounded.
00135   bool                right_on_boundary;// Is the right point on the boundary.
00136   Point_2             right_pt;         // Its right endpoint (if bounded).
00137 
00138   Vertex_handle       left_v;           // The arrangement vertex associated
00139                                         // with the current left_pt (if any).
00140   Halfedge_handle     left_he;          // If left_v is valid, left_he is the
00141                                         // predecessor for cv around this
00142                                         // vertex. Otherwise, if it is valid,
00143                                         // it is the halfedge that contains
00144                                         // the left endpoint it its interior.
00145 
00146   Vertex_handle       right_v;          // The arrangement vertex associated
00147                                         // with the current right_pt (if any).
00148   Halfedge_handle     right_he;         // If right_v is valid, left_he is the
00149                                         // predecessor for cv around this
00150                                         // vertex. Otherwise, if it is valid,
00151                                         // it is the halfedge that contains
00152                                         // the right endpoint it its interior.
00153 
00154   Point_2             intersect_p;      // The next intersection point.
00155   unsigned int        ip_mult;          // Its multiplicity
00156                                         // (0 in case of an overlap).
00157   bool                found_intersect;  // Have we found an intersection
00158                                         // (or an overlap).
00159   X_monotone_curve_2  overlap_cv;       // The currently discovered overlap.
00160   bool                found_overlap;    // Have we found an overlap.
00161   bool                found_iso_vert;   // Check if an isolated vertex induces
00162                                         // the next intersection.
00163   Vertex_handle       intersect_v;      // The vertex that intersects cv.
00164   Halfedge_handle     intersect_he;     // The halfedge that intersects cv
00165                                         // (or overlaps it).
00166 
00167   X_monotone_curve_2  sub_cv1;          // Auxiliary variable (for curve split).
00168   X_monotone_curve_2  sub_cv2;          // Auxiliary variable (for curve split).
00169 
00170 public:
00171 
00177   Arrangement_zone_2 (Arrangement_2& _arr, Visitor *_visitor) :
00178     arr (_arr),
00179     arr_access (_arr),
00180     visitor (_visitor),
00181     invalid_v (),
00182     invalid_he ()
00183   {
00184     m_geom_traits = static_cast<const Traits_adaptor_2*> (arr.geometry_traits());
00185 
00186     CGAL_assertion (visitor != NULL);
00187 
00188     // Initialize the visitor.
00189     visitor->init (&arr);
00190   }
00191 
00197   template <class PointLocation>
00198   void init (const X_monotone_curve_2& _cv, const PointLocation& pl)
00199   {
00200     // Set the curve and check whether its left end has boundary conditions.
00201     cv = _cv;
00202 
00203     const Arr_parameter_space  bx1 =
00204       m_geom_traits->parameter_space_in_x_2_object()(cv, ARR_MIN_END);
00205     const Arr_parameter_space  by1 =
00206       m_geom_traits->parameter_space_in_y_2_object()(cv, ARR_MIN_END);
00207 
00208     if (bx1 == ARR_INTERIOR && by1 == ARR_INTERIOR) {
00209       // The curve has a finite left endpoint with no boundary conditions:
00210       // locate it in the arrangement.
00211       has_left_pt = true;
00212       left_on_boundary = (bx1 != ARR_INTERIOR || by1 != ARR_INTERIOR);
00213       left_pt = m_geom_traits->construct_min_vertex_2_object() (cv);
00214 
00215       obj = pl.locate (left_pt);
00216     }
00217     else {
00218       // The left end of the curve has boundary conditions: use the topology
00219       // traits use the arrangement accessor to locate it.
00220       // Note that if the curve-end is unbounded, left_pt does not exist.
00221       // Note that if the curve-end is unbounded, left_pt does not exist.
00222       has_left_pt = m_geom_traits->is_closed_2_object()(cv, ARR_MIN_END);
00223       left_on_boundary = true;
00224       if (has_left_pt)
00225         left_pt = m_geom_traits->construct_min_vertex_2_object() (cv);
00226       obj = arr_access.locate_curve_end (cv, ARR_MIN_END, bx1, by1);
00227     }
00228 
00229     // Check the boundary conditions of th right curve end.
00230     if (m_geom_traits->is_closed_2_object()(cv, ARR_MAX_END)) {
00231       const Arr_parameter_space  bx2 =
00232         m_geom_traits->parameter_space_in_x_2_object()(cv, ARR_MAX_END);
00233       const Arr_parameter_space  by2 =
00234         m_geom_traits->parameter_space_in_y_2_object()(cv, ARR_MAX_END);
00235 
00236       // The right endpoint is valid.
00237       has_right_pt = true;
00238       right_pt = m_geom_traits->construct_max_vertex_2_object() (cv);
00239       right_on_boundary = (bx2 != ARR_INTERIOR) || (by2 != ARR_INTERIOR);
00240     }
00241     else {
00242       // The right end of the curve lies at infinity.
00243       has_right_pt = false;
00244       right_on_boundary = true;
00245     }
00246 
00247     return;
00248   }
00249 
00257   void init_with_hint (const X_monotone_curve_2& _cv, const Object& _obj);
00258 
00263   void compute_zone ();
00264 
00265 private:
00266 
00275   bool _find_prev_around_vertex (Vertex_handle v, Halfedge_handle& he);
00276 
00291   Halfedge_handle
00292   _direct_intersecting_edge_to_right(const X_monotone_curve_2& cv_ins,
00293                                      const Point_2& cv_left_pt,
00294                                      Halfedge_handle query_he);
00295 
00308   Halfedge_handle
00309   _direct_intersecting_edge_to_left(const X_monotone_curve_2& cv_ins,
00310                                     Halfedge_handle query_he);
00311 
00326   CGAL::Object _compute_next_intersection (Halfedge_handle he,
00327                                            bool skip_first_point,
00328                                            bool& intersect_on_right_boundary);
00329 
00336   void _remove_next_intersection (Halfedge_handle he);
00337 
00345   bool _is_to_left(const Point_2& p, Halfedge_handle he) const
00346   {
00347     return (_is_to_left_impl(p, he, Are_all_sides_oblivious_tag()));
00348   }
00349 
00350   bool _is_to_left_impl(const Point_2& p, Halfedge_handle he,
00351                         Arr_all_sides_oblivious_tag) const
00352   {
00353     return ((he->direction() == ARR_LEFT_TO_RIGHT &&
00354              m_geom_traits->compare_xy_2_object() 
00355              (p, he->source()->point()) == SMALLER) ||
00356             (he->direction() == ARR_RIGHT_TO_LEFT &&
00357              m_geom_traits->compare_xy_2_object() 
00358              (p, he->target()->point()) == SMALLER));
00359   }
00360 
00361   bool _is_to_left_impl(const Point_2& p, Halfedge_handle he,
00362                         Arr_not_all_sides_oblivious_tag) const;
00363   
00371   bool _is_to_right(const Point_2& p, Halfedge_handle he) const
00372   {
00373     return (_is_to_right_impl(p, he, Are_all_sides_oblivious_tag()));
00374   }
00375 
00376   bool _is_to_right_impl(const Point_2& p, Halfedge_handle he,
00377                          Arr_all_sides_oblivious_tag) const
00378   {
00379     return ((he->direction() == ARR_LEFT_TO_RIGHT &&
00380              m_geom_traits->compare_xy_2_object() 
00381              (p, he->target()->point()) == LARGER) ||
00382             (he->direction() == ARR_RIGHT_TO_LEFT &&
00383              m_geom_traits->compare_xy_2_object() 
00384              (p, he->source()->point()) == LARGER));
00385   }
00386 
00387   bool _is_to_right_impl(const Point_2& p, Halfedge_handle he,
00388                          Arr_not_all_sides_oblivious_tag) const;
00389 
00400   void _leftmost_intersection_with_face_boundary (Face_handle face,
00401                                                   bool on_boundary);
00402 
00419   bool _zone_in_face (Face_handle face,
00420                       bool on_boundary);
00421 
00431   bool _zone_in_overlap ();
00432 };
00433 
00434 CGAL_END_NAMESPACE
00435 
00436 // The function definitions can be found under:
00437 #include <CGAL/Arrangement_2/Arrangement_zone_2_impl.h>
00438 
00439 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines