BWAPI
|
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/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_agg_op.h $ 00015 // $Id: Gps_agg_op.h 50368 2009-07-05 13:14:14Z efif $ $Date: 2009-07-05 15:14:14 +0200 (Sun, 05 Jul 2009) $ 00016 // 00017 // 00018 // Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il> 00019 // Ophir Setter <ophir.setter@cs.tau.ac.il> 00020 00021 #ifndef CGAL_GPS_AGG_OP_H 00022 #define CGAL_GPS_AGG_OP_H 00023 00035 #include <CGAL/Boolean_set_operations_2/Gps_agg_meta_traits.h> 00036 #include <CGAL/Boolean_set_operations_2/Gps_agg_op_sweep.h> 00037 #include <CGAL/Sweep_line_2/Arr_construction_subcurve.h> 00038 #include <CGAL/Sweep_line_2/Arr_construction_event.h> 00039 00040 #include <CGAL/Boolean_set_operations_2/Gps_agg_op_visitor.h> 00041 #include <CGAL/Boolean_set_operations_2/Gps_bfs_scanner.h> 00042 //#include <CGAL/Boolean_set_operations_2/Gps_insertion_meta_traits.h> 00043 #include <CGAL/Unique_hash_map.h> 00044 #include <CGAL/Arr_accessor.h> 00045 #include <CGAL/iterator.h> 00046 00047 CGAL_BEGIN_NAMESPACE 00048 00049 template <class Arrangement_, class Bfs_visitor_> 00050 class Gps_agg_op 00051 { 00052 typedef Arrangement_ Arrangement_2; 00053 typedef typename Arrangement_2::Traits_adaptor_2 Traits_2; 00054 typedef typename Traits_2::Curve_const_iterator Curve_const_iterator; 00055 typedef Gps_agg_meta_traits<Arrangement_2> Meta_traits; 00056 typedef typename Meta_traits::Curve_data Curve_data; 00057 typedef typename Meta_traits::X_monotone_curve_2 Meta_X_monotone_curve_2; 00058 typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; 00059 typedef typename Arrangement_2::Halfedge_iterator Halfedge_iterator; 00060 typedef typename Arrangement_2::Face_handle Face_handle; 00061 typedef typename Arrangement_2::Edge_iterator Edge_iterator; 00062 typedef typename Arrangement_2::Vertex_handle Vertex_handle; 00063 typedef typename Arrangement_2::Ccb_halfedge_const_circulator 00064 Ccb_halfedge_const_circulator; 00065 typedef typename Arrangement_2::Ccb_halfedge_circulator 00066 Ccb_halfedge_circulator; 00067 00068 typedef std::pair<Arrangement_2 *, 00069 std::vector<Vertex_handle> *> Arr_entry; 00070 00071 typedef Arr_construction_subcurve<Meta_traits> Subcurve; 00072 00073 typedef Arr_construction_event<Meta_traits, 00074 Subcurve, 00075 // Halfedge_handle> Base_event; 00076 Arrangement_2> Base_event; 00077 00078 typedef Indexed_event<Base_event> Event; 00079 00080 typedef Gps_agg_op_visitor<Meta_traits, 00081 Arrangement_2, 00082 Event, 00083 Subcurve> Visitor; 00084 00085 typedef Gps_agg_op_sweep_line_2<Arrangement_2, 00086 Meta_traits, 00087 Visitor, 00088 Subcurve, 00089 Event> Sweep_line_2; 00090 00091 typedef Unique_hash_map<Halfedge_handle, 00092 unsigned int> Edges_hash; 00093 00094 typedef Unique_hash_map<Face_handle, 00095 unsigned int> Faces_hash; 00096 typedef Bfs_visitor_ Bfs_visitor; 00097 typedef Gps_bfs_scanner<Arrangement_2, Bfs_visitor> Bfs_scanner; 00098 00099 protected: 00100 Arrangement_2* m_arr; 00101 Meta_traits* m_traits; 00102 Visitor m_visitor; 00103 Sweep_line_2 m_sweep_line; 00104 Edges_hash m_edges_hash; // maps halfedge to its BC (boundary counter) 00105 Faces_hash m_faces_hash; // maps face to its IC (inside count) 00106 00107 public: 00108 00110 Gps_agg_op (Arrangement_2& arr, std::vector<Vertex_handle>& vert_vec, 00111 const Traits_2 & tr) : 00112 m_arr (&arr), 00113 m_traits(new Meta_traits(tr)), 00114 m_visitor (&arr, &m_edges_hash, &vert_vec), 00115 m_sweep_line (m_traits, &m_visitor) 00116 {} 00117 00118 void sweep_arrangements(unsigned int lower, 00119 unsigned int upper, 00120 unsigned int jump, 00121 std::vector<Arr_entry>& arr_vec) 00122 { 00123 std::list<Meta_X_monotone_curve_2> curves_list; 00124 00125 typename Meta_traits::Compare_endpoints_xy_2 cmp_endpoints = 00126 m_traits->compare_endpoints_xy_2_object(); 00127 00128 unsigned int n_inf_pgn = 0; // number of infinte polygons (arrangement 00129 // with a contained unbounded face 00130 unsigned int n_pgn = 0; // number of polygons (arrangements) 00131 unsigned int i; 00132 00133 for (i = lower; i <= upper; i += jump, ++n_pgn) 00134 { 00135 // The BFS scan (after the loop) starts in the reference face, 00136 // so we count the number of polygons that contain the reference face. 00137 Arrangement_2* arr = (arr_vec[i]).first; 00138 if (arr->reference_face()->contained()) 00139 ++n_inf_pgn; 00140 00141 Edge_iterator itr = arr->edges_begin(); 00142 for(; itr != arr->edges_end(); ++itr) 00143 { 00144 // take only relevant edges (which seperate between contained and 00145 // non-contained faces. 00146 Halfedge_iterator he = itr; 00147 if(he->face()->contained() == he->twin()->face()->contained()) 00148 continue; 00149 if ((Arr_halfedge_direction)he->direction() == ARR_RIGHT_TO_LEFT) 00150 he = he->twin(); 00151 00152 Curve_data cv_data(arr, he, 1, 0); 00153 curves_list.push_back(Meta_X_monotone_curve_2(he->curve(), cv_data)); 00154 } 00155 } 00156 00157 m_sweep_line.sweep (curves_list.begin(), curves_list.end(), 00158 lower, upper, jump, 00159 arr_vec); 00160 00161 m_faces_hash[m_arr->reference_face()] = n_inf_pgn; 00162 Bfs_visitor visitor(&m_edges_hash, &m_faces_hash, n_pgn); 00163 visitor.visit_ubf(m_arr->faces_begin(), n_inf_pgn); 00164 Bfs_scanner scanner(visitor); 00165 scanner.scan(*m_arr); 00166 visitor.after_scan(*m_arr); 00167 } 00168 00169 ~Gps_agg_op() 00170 { 00171 delete m_traits; 00172 } 00173 }; 00174 00175 CGAL_END_NAMESPACE 00176 00177 #endif