BWAPI
|
00001 // Copyright (c) 2006 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_vertical_decomposition_2.h $ 00015 // $Id: Arr_vertical_decomposition_2.h 50366 2009-07-05 12:56:48Z efif $ 00016 // 00017 // Author(s) : Ron Wein <wein@post.tau.ac.il> 00018 00019 #ifndef CGAL_ARR_VERTICAL_DECOMPOSITION_2_H 00020 #define CGAL_ARR_VERTICAL_DECOMPOSITION_2_H 00021 00022 #include <CGAL/Arrangement_on_surface_2.h> 00023 #include <CGAL/Basic_sweep_line_2.h> 00024 00025 #include <vector> 00026 #include <boost/mpl/if.hpp> 00027 #include <boost/type_traits.hpp> 00028 00029 CGAL_BEGIN_NAMESPACE 00030 00044 template<typename GeomTraits, typename TopTraits, 00045 typename OutputIterator> 00046 OutputIterator 00047 decompose(const Arrangement_on_surface_2<GeomTraits, TopTraits>& arr, 00048 OutputIterator oi) 00049 { 00050 // Arrangement types: 00051 typedef Arrangement_on_surface_2<GeomTraits, TopTraits> Arrangement_2; 00052 typedef typename TopTraits::template 00053 Sweep_line_vertical_decomposition_visitor<OutputIterator> 00054 Vd_visitor; 00055 00056 typedef typename Arrangement_2::Vertex_const_iterator Vertex_const_iterator; 00057 typedef typename Arrangement_2::Edge_const_iterator Edge_const_iterator; 00058 typedef typename Arrangement_2::Vertex_const_handle Vertex_const_handle; 00059 typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle; 00060 typedef typename Arrangement_2::X_monotone_curve_2 X_monotone_curve_2; 00061 typedef typename Arrangement_2::Point_2 Point_2; 00062 typedef typename Vd_visitor::Traits_2 Vd_traits_2; 00063 typedef typename Vd_traits_2::X_monotone_curve_2 Vd_x_monotone_curve_2; 00064 typedef typename Vd_traits_2::Point_2 Vd_point_2; 00065 00066 // Go over all arrangement edges and collect their associated x-monotone 00067 // curves. To each curve we attach a halfedge handle going from right to 00068 // left. 00069 std::vector<Vd_x_monotone_curve_2> xcurves_vec (arr.number_of_edges()); 00070 Edge_const_iterator eit; 00071 Halfedge_const_handle he; 00072 unsigned int i = 0; 00073 00074 for (eit = arr.edges_begin(); eit != arr.edges_end(); ++eit, ++i) 00075 { 00076 // Associate each x-monotone curve with the halfedge that represents it 00077 // and is directed from right to left. 00078 if (eit->direction() == ARR_RIGHT_TO_LEFT) 00079 he = eit; 00080 else 00081 he = eit->twin(); 00082 //attempt to solve compile problem in one of the tests. created the 00083 // tmp_curve instead of passing eit->curve() as a parmeter to the function 00084 X_monotone_curve_2 tmp_curve = eit->curve(); 00085 xcurves_vec[i] = Vd_x_monotone_curve_2 (tmp_curve, he); 00086 } 00087 00088 // Go over all isolated vertices and collect their points. To each point 00089 // we attach its vertex handle. 00090 std::vector<Vd_point_2> iso_pts_vec (arr.number_of_isolated_vertices()); 00091 Vertex_const_iterator vit; 00092 Vertex_const_handle iso_v; 00093 00094 i = 0; 00095 for (vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) 00096 { 00097 // Associate isolated point with the vertex that represents it. 00098 if (vit->is_isolated()) 00099 { 00100 iso_v = vit; 00101 //attempt to solve compile problem in one of the tests. created the 00102 // tmp_curve instead of passing eit->curve() as a parmeter to the 00103 // function 00104 Point_2 tmp_point = vit->point(); 00105 iso_pts_vec[i] = Vd_point_2 (tmp_point, iso_v); 00106 ++i; 00107 } 00108 } 00109 00110 // Obtain a extended traits-class object. 00111 const GeomTraits * geom_traits = arr.geometry_traits(); 00112 00113 /* We would like to avoid copy construction of the geometry traits class. 00114 * Copy construction is undesired, because it may results with data 00115 * duplication or even data loss. 00116 * 00117 * If the type Vd_traits_2 is the same as the type 00118 * GeomTraits, use a reference to GeomTraits to avoid constructing a new one. 00119 * Otherwise, instantiate a local variable of the former and provide 00120 * the later as a single parameter to the constructor. 00121 * 00122 * Use the form 'A a(*b);' and not ''A a = b;' to handle the case where A has 00123 * only an implicit constructor, (which takes *b as a parameter). 00124 */ 00125 typename boost::mpl::if_<boost::is_same<GeomTraits, Vd_traits_2>, 00126 const Vd_traits_2&, Vd_traits_2>::type 00127 ex_traits(*geom_traits); 00128 00129 // Define the sweep-line visitor and perform the sweep. 00130 Vd_visitor visitor (&arr, &oi); 00131 Basic_sweep_line_2<typename Vd_visitor::Traits_2, 00132 Vd_visitor, 00133 typename Vd_visitor::Subcurve, 00134 typename Vd_visitor::Event> 00135 sweep_line (&ex_traits, &visitor); 00136 00137 sweep_line.sweep (xcurves_vec.begin(), xcurves_vec.end(), // Curves. 00138 iso_pts_vec.begin(), iso_pts_vec.end()); // Action points. 00139 00140 // Return a past-the-end iterator. 00141 return (oi); 00142 } 00143 00144 00145 CGAL_END_NAMESPACE 00146 00147 #endif