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_polygon_simplifier.h $ 00015 // $Id: Gps_polygon_simplifier.h 48139 2009-02-19 11:00:00Z ophirset $ 00016 // 00017 // 00018 // Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il> 00019 00020 #ifndef CGAL_GPS_POLYGON_SIMPILFIER_H 00021 #define CGAL_GPS_POLYGON_SIMPILFIER_H 00022 00023 #include <CGAL/Boolean_set_operations_2/Gps_simplifier_traits.h> 00024 #include <CGAL/Sweep_line_2.h> 00025 #include <CGAL/Sweep_line_2/Arr_construction_subcurve.h> 00026 #include <CGAL/Sweep_line_2/Arr_construction_event.h> 00027 00028 #include <CGAL/Boolean_set_operations_2/Gps_agg_op_visitor.h> 00029 #include <CGAL/Boolean_set_operations_2/Gps_bfs_scanner.h> 00030 #include <CGAL/Boolean_set_operations_2/Gps_bfs_join_visitor.h> 00031 00032 #include <CGAL/Unique_hash_map.h> 00033 #include <CGAL/Arr_accessor.h> 00034 #include <CGAL/iterator.h> 00035 00036 CGAL_BEGIN_NAMESPACE 00037 00038 template <class Arrangement_> 00039 class Gps_polygon_simplifier 00040 { 00041 typedef Arrangement_ Arrangement_2; 00042 typedef typename Arrangement_2::Geometry_traits_2 Traits_2; 00043 typedef typename Traits_2::Curve_const_iterator Curve_const_iterator; 00044 typedef typename Traits_2::Polygon_2 Polygon_2; 00045 typedef typename Traits_2::Polygon_with_holes_2 Polygon_with_holes_2; 00046 typedef typename Traits_2::Construct_curves_2 Construct_curves_2; 00047 00048 typedef Gps_simplifier_traits<Traits_2> Meta_traits; 00049 typedef typename Meta_traits::Curve_data Curve_data; 00050 typedef typename Meta_traits::X_monotone_curve_2 Meta_X_monotone_curve_2; 00051 typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; 00052 typedef typename Arrangement_2::Halfedge_iterator Halfedge_iterator; 00053 typedef typename Arrangement_2::Face_handle Face_handle; 00054 typedef typename Arrangement_2::Face_iterator Face_iterator; 00055 typedef typename Arrangement_2::Edge_iterator Edge_iterator; 00056 typedef typename Arrangement_2::Vertex_handle Vertex_handle; 00057 typedef typename Arrangement_2::Ccb_halfedge_const_circulator 00058 Ccb_halfedge_const_circulator; 00059 typedef typename Arrangement_2::Ccb_halfedge_circulator 00060 Ccb_halfedge_circulator; 00061 typedef Arr_construction_subcurve<Meta_traits> Subcurve; 00062 typedef Arr_construction_event<Meta_traits, 00063 Subcurve, 00064 Arrangement_2> Event; 00065 00066 typedef Gps_agg_op_base_visitor<Meta_traits, 00067 Arrangement_2, 00068 Event, 00069 Subcurve> Visitor; 00070 00071 typedef CGAL::Sweep_line_2<Meta_traits, 00072 Visitor, 00073 Subcurve, 00074 Event> Sweep_line_2; 00075 00076 typedef Unique_hash_map<Halfedge_handle, 00077 unsigned int> Edges_hash; 00078 00079 typedef Unique_hash_map<Face_handle, 00080 unsigned int> Faces_hash; 00081 typedef Gps_bfs_join_visitor<Arrangement_2> Bfs_visitor; 00082 typedef Gps_bfs_scanner<Arrangement_2, Bfs_visitor> Bfs_scanner; 00083 00084 protected: 00085 Arrangement_2* m_arr; 00086 Meta_traits* m_traits; 00087 Visitor m_visitor; 00088 Sweep_line_2 m_sweep_line; 00089 Edges_hash m_edges_hash; // maps halfedge to its BC (boundary counter) 00090 Faces_hash m_faces_hash; // maps face to its IC (inside count) 00091 00092 public: 00094 Gps_polygon_simplifier (Arrangement_2& arr, Traits_2& tr) : 00095 m_arr (&arr), 00096 m_traits(new Meta_traits(tr)), 00097 m_visitor (&arr, &m_edges_hash), 00098 m_sweep_line (m_traits, &m_visitor) 00099 {} 00100 00101 void simplify(const Polygon_2& pgn) 00102 { 00103 Construct_curves_2 ctr_curves = 00104 reinterpret_cast<Traits_2*>(m_traits)->construct_curves_2_object(); 00105 00106 std::list<Meta_X_monotone_curve_2> curves_list; 00107 00108 std::pair<Curve_const_iterator, 00109 Curve_const_iterator> itr_pair = ctr_curves(pgn); 00110 00111 unsigned int index = 0; 00112 for(Curve_const_iterator itr = itr_pair.first; 00113 itr != itr_pair.second; 00114 ++itr, ++index) 00115 { 00116 Curve_data cv_data(1, 0, index); 00117 curves_list.push_back(Meta_X_monotone_curve_2(*itr, cv_data)); 00118 } 00119 m_traits->set_polygon_size(curves_list.size()); 00120 00121 m_sweep_line.sweep(curves_list.begin(), curves_list.end()); 00122 00123 // we use the first face with out outer ccbs. This assumpsion should 00124 // be fixed when we can make a face with no outer ccb to a face with 00125 // outer ccb. 00126 Face_iterator it; 00127 for (it = m_arr->faces_begin(); it != m_arr->faces_end(); ++it) 00128 if (it->number_of_outer_ccbs() == 0) 00129 break; 00130 CGAL_assertion(it != m_arr->faces_end()); 00131 00132 m_faces_hash[it] = 0; 00133 Bfs_visitor visitor(&m_edges_hash, &m_faces_hash, 1); 00134 visitor.visit_ubf(it, 0); 00135 Bfs_scanner scanner(visitor); 00136 scanner.scan(*m_arr); 00137 visitor.after_scan(*m_arr); 00138 } 00139 00140 const Arrangement_2& arrangement() const 00141 { 00142 return (*m_arr); 00143 } 00144 00145 Arrangement_2& arrangement() 00146 { 00147 return (*m_arr); 00148 } 00149 00150 }; 00151 CGAL_END_NAMESPACE 00152 00153 #endif