BWAPI
|
00001 // Copyright (c) 2006-2007 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/Arr_topology_traits/Arr_spherical_construction_helper.h $ 00015 // $Id: Arr_spherical_construction_helper.h 41118 2007-12-07 14:25:32Z efif $ 00016 // 00017 // 00018 // Author(s) : Ron Wein <wein@post.tau.ac.il> 00019 // Efi Fogel <efif@post.tau.ac.il> 00020 00021 #ifndef CGAL_ARR_SPHERICAL_CONSTRUCTION_HELPER_H 00022 #define CGAL_ARR_SPHERICAL_CONSTRUCTION_HELPER_H 00023 00028 #include <CGAL/Sweep_line_empty_visitor.h> 00029 #include <CGAL/Unique_hash_map.h> 00030 00031 CGAL_BEGIN_NAMESPACE 00032 00038 template <class Traits_, class Arrangement_, class Event_, class Subcurve_> 00039 class Arr_spherical_construction_helper 00040 { 00041 public: 00042 typedef Traits_ Traits_2; 00043 typedef Arrangement_ Arrangement_2; 00044 typedef Event_ Event; 00045 typedef Subcurve_ Subcurve; 00046 00047 typedef typename Traits_2::X_monotone_curve_2 X_monotone_curve_2; 00048 typedef typename Traits_2::Point_2 Point_2; 00049 00050 typedef Sweep_line_empty_visitor<Traits_2, Subcurve, Event> 00051 Base_visitor; 00052 00053 typedef typename Arrangement_2::Vertex_handle Vertex_handle; 00054 typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; 00055 typedef typename Arrangement_2::Face_handle Face_handle; 00056 00057 typedef typename Subcurve::Halfedge_indices_list Indices_list; 00058 typedef Unique_hash_map<Halfedge_handle, Indices_list> Halfedge_indices_map; 00059 00060 protected: 00061 typedef typename Arrangement_2::Topology_traits Topology_traits; 00062 00063 typedef typename Topology_traits::Vertex DVertex; 00064 typedef typename Topology_traits::Halfedge DHalfedge; 00065 00066 // Data members: 00067 00069 Topology_traits * m_top_traits; 00070 00072 Arr_accessor<Arrangement_2> m_arr_access; 00073 00075 Face_handle m_spherical_face; 00076 00078 Indices_list m_subcurves_at_nf; 00079 00081 // (stored in the visitor class) 00082 Halfedge_indices_map * m_he_ind_map_p; 00083 00084 public: 00086 Arr_spherical_construction_helper(Arrangement_2 * arr) : 00087 m_top_traits(arr->topology_traits()), 00088 m_arr_access(*arr), 00089 m_he_ind_map_p(NULL) 00090 {} 00091 00093 virtual ~Arr_spherical_construction_helper() {} 00094 00096 00097 00098 /* A notification issued before the sweep process starts. */ 00099 virtual void before_sweep() 00100 { 00101 // Get the unbounded face. 00102 m_spherical_face = Face_handle(m_top_traits->spherical_face()); 00103 } 00104 00108 virtual void before_handle_event(Event * event) 00109 { 00110 // Act according to the boundary type: 00111 Arr_parameter_space ps_x = event->parameter_space_in_x(); 00112 Arr_parameter_space ps_y = event->parameter_space_in_y(); 00113 00114 if (ps_y == ARR_BOTTOM_BOUNDARY) { 00115 // Bootom contraction boundary: 00116 // The event has only one (right or left) curve. 00117 CGAL_assertion(((event->number_of_left_curves() == 0) && 00118 (event->number_of_right_curves() == 1)) || 00119 ((event->number_of_left_curves() == 1) && 00120 (event->number_of_right_curves() == 0))); 00121 Arr_curve_end ind = (event->number_of_left_curves() == 0 && 00122 event->number_of_right_curves() == 1) ? 00123 ARR_MIN_END : ARR_MAX_END; 00124 const X_monotone_curve_2 & xc = (ind == ARR_MIN_END) ? 00125 (*(event->right_curves_begin()))->last_curve() : 00126 (*(event->left_curves_begin()))->last_curve(); 00127 00128 // Check whether we have a vertex that corresponds to the south pole. 00129 // If not, we create one. 00130 if (m_top_traits->south_pole() == NULL) 00131 { 00132 Vertex_handle v = 00133 m_arr_access.create_boundary_vertex (xc, ind, ps_x, ps_y); 00134 event->set_vertex_handle(v); 00135 } 00136 else 00137 { 00138 event->set_vertex_handle(Vertex_handle (m_top_traits->south_pole())); 00139 } 00140 return; 00141 } 00142 00143 if (ps_y == ARR_TOP_BOUNDARY) { 00144 // Top contraction boundary: 00145 // The event has only one (right or left) curve. 00146 CGAL_assertion(((event->number_of_left_curves() == 0) && 00147 (event->number_of_right_curves() == 1)) || 00148 ((event->number_of_left_curves() == 1) && 00149 (event->number_of_right_curves() == 0))); 00150 Arr_curve_end ind = (event->number_of_left_curves() == 0 && 00151 event->number_of_right_curves() == 1) ? 00152 ARR_MIN_END : ARR_MAX_END; 00153 00154 const X_monotone_curve_2 & xc = (ind == ARR_MIN_END) ? 00155 (*(event->right_curves_begin()))->last_curve() : 00156 (*(event->left_curves_begin()))->last_curve(); 00157 00158 // Check whether we have a vertex that corresponds to the north pole. 00159 // If not, we create one. 00160 if (m_top_traits->north_pole() == NULL) 00161 { 00162 Vertex_handle v = 00163 m_arr_access.create_boundary_vertex (xc, ind, ps_x, ps_y); 00164 event->set_vertex_handle(v); 00165 00166 // Since this is the first event corresponding to the north pole, 00167 // the list m_subcurves_at_nf contains all subcurves whose minimal 00168 // endpoint lies between the curve of discontinuity and the current 00169 // curve incident to the north pole. In case these subcurves represent 00170 // holes, these holes should stay in the "north face" that contains the 00171 // line of discontinuity, and we should not keep track of them in order 00172 // to later move them to another face. 00173 m_subcurves_at_nf.clear(); 00174 } 00175 else 00176 { 00177 event->set_vertex_handle(Vertex_handle (m_top_traits->north_pole())); 00178 00179 DHalfedge * dprev = 00180 m_top_traits->locate_around_boundary_vertex(m_top_traits-> 00181 north_pole(), xc, ind, 00182 ps_x, ps_y); 00183 00184 if (dprev != NULL) 00185 { 00186 Halfedge_handle prev = Halfedge_handle(dprev); 00187 event->set_halfedge_handle(prev); 00188 00189 // Associate all curve indices of subcurves that "see" the top face 00190 // from below with the left portion of the twin of the predecessor. 00191 if (m_he_ind_map_p != NULL) { 00192 Indices_list & list_ref = (*m_he_ind_map_p)[prev->twin()]; 00193 list_ref.splice(list_ref.end(), m_subcurves_at_nf); 00194 } 00195 else 00196 { 00197 m_subcurves_at_nf.clear(); 00198 } 00199 CGAL_assertion(m_subcurves_at_nf.empty()); 00200 } 00201 return; 00202 } 00203 00204 return; 00205 } 00206 00207 if (ps_x == ARR_LEFT_BOUNDARY) { 00208 // The event has only right curves. 00209 CGAL_assertion(event->number_of_left_curves() == 0 && 00210 event->number_of_right_curves() == 1); 00211 const X_monotone_curve_2 & xc = 00212 (*(event->right_curves_begin()))->last_curve(); 00213 DVertex * v = m_top_traits->discontinuity_vertex(xc, ARR_MIN_END); 00214 00215 // Check whether a corresponding vertex already exists on the line 00216 // of discontinuity. If not, create one now. 00217 if (v == NULL) 00218 { 00219 Vertex_handle vh = 00220 m_arr_access.create_boundary_vertex (xc, ARR_MIN_END, ps_x, ps_y); 00221 event->set_vertex_handle(vh); 00222 } 00223 else 00224 { 00225 event->set_vertex_handle(Vertex_handle(v)); 00226 } 00227 return; 00228 } 00229 00230 if (ps_x == ARR_RIGHT_BOUNDARY) { 00231 // The event has only left curves. 00232 CGAL_assertion(event->number_of_left_curves() == 1 && 00233 event->number_of_right_curves() == 0); 00234 const X_monotone_curve_2 & xc = 00235 (*(event->left_curves_begin()))->last_curve(); 00236 DVertex * v = m_top_traits->discontinuity_vertex(xc, ARR_MAX_END); 00237 00238 // Check whether a corresponding vertex already exists on the line 00239 // of discontinuity. If not, create one now. 00240 if (v == NULL) 00241 { 00242 Vertex_handle vh = 00243 m_arr_access.create_boundary_vertex (xc, ARR_MAX_END, ps_x, ps_y); 00244 event->set_vertex_handle(vh); 00245 } 00246 else 00247 { 00248 event->set_vertex_handle(Vertex_handle(v)); 00249 } 00250 return; 00251 } 00252 } 00253 00255 virtual void add_subcurve(Halfedge_handle he, Subcurve * sc) { return; } 00256 00259 void add_subcurve_in_top_face(unsigned int index) 00260 { 00261 m_subcurves_at_nf.push_back(index); 00262 return; 00263 } 00264 00266 void before_deallocate_event(Event * event) { return; } 00268 00272 void set_halfedge_indices_map(Halfedge_indices_map & table) 00273 { 00274 m_he_ind_map_p = &table; 00275 return; 00276 } 00277 00281 bool swap_predecessors (Event * event) const 00282 { 00283 // If we insert an edge whose right end lies on the north pole, we have 00284 // to flip the order of predecessor halfegdes. 00285 return (event->parameter_space_in_x() == ARR_INTERIOR && 00286 event->parameter_space_in_y() == ARR_TOP_BOUNDARY); 00287 } 00288 00290 Face_handle top_face() const { return m_spherical_face; } 00291 }; 00292 00293 CGAL_END_NAMESPACE 00294 00295 #endif