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/Arrangement_on_surface_2/include/CGAL/Sweep_line_2/Sweep_line_2_utils.h $ 00015 // $Id: Sweep_line_2_utils.h 50366 2009-07-05 12:56:48Z efif $ 00016 // 00017 // 00018 // Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il> 00019 // Ron Wein <wein@post.tau.ac.il> 00020 // Efi Fogel <efif@post.tau.ac.il> 00021 00022 #ifndef CGAL_SWEEP_LINE_2_UTILS 00023 #define CGAL_SWEEP_LINE_2_UTILS 00024 00029 #include <CGAL/basic.h> 00030 00031 #include <CGAL/Object.h> 00032 #include <CGAL/assertions.h> 00033 #include <vector> 00034 #include <algorithm> 00035 #include <CGAL/Arr_enums.h> 00036 00037 CGAL_BEGIN_NAMESPACE 00038 00048 template <class Traits, 00049 class CurveInputIter, 00050 class XCurveOutIter, 00051 class PointOutIter> 00052 void make_x_monotone (CurveInputIter begin, CurveInputIter end, 00053 XCurveOutIter x_curves, 00054 PointOutIter iso_points, 00055 const Traits * tr) 00056 { 00057 // Split the input curves into x-monotone objects. 00058 unsigned int num_of_curves = std::distance(begin, end); 00059 std::vector<Object> object_vec; 00060 CurveInputIter iter; 00061 00062 object_vec.reserve (num_of_curves); 00063 for (iter = begin; iter != end; ++iter) 00064 { 00065 tr->make_x_monotone_2_object()(*iter, 00066 std::back_inserter(object_vec)); 00067 } 00068 00069 // Transform each object to either a point or an x-monotone curve. 00070 typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2; 00071 typedef typename Traits::Point_2 Point_2; 00072 00073 const X_monotone_curve_2 *xcv; 00074 const Point_2 *pt; 00075 unsigned int i; 00076 00077 for (i = 0 ; i < object_vec.size() ; ++i) 00078 { 00079 xcv = object_cast<X_monotone_curve_2> (&(object_vec[i])); 00080 00081 if (xcv != NULL) 00082 { 00083 // The object is an x-monotone curve. 00084 *x_curves = *xcv; 00085 ++x_curves; 00086 } 00087 else 00088 { 00089 // The object is an isolated point. 00090 pt = object_cast<Point_2> (&(object_vec[i])); 00091 CGAL_assertion (pt != NULL); 00092 00093 *iso_points = *pt; 00094 ++iso_points; 00095 } 00096 } 00097 00098 return; 00099 } 00100 00121 template <class Arrangement, 00122 class ExTraits, 00123 class XCurveInputIter, 00124 class PointInputIter, 00125 class XCurveOutIter, 00126 class PointOutIter> 00127 void prepare_for_sweep (Arrangement& arr, 00128 XCurveInputIter xcvs_begin, XCurveInputIter xcvs_end, 00129 PointInputIter pts_begin, PointInputIter pts_end, 00130 XCurveOutIter x_curves, 00131 PointOutIter iso_points, 00132 const ExTraits * /* ex_tr */) 00133 { 00134 typedef typename Arrangement::X_monotone_curve_2 X_monotone_curve_2; 00135 typedef typename Arrangement::Point_2 Point_2; 00136 00137 typedef typename Arrangement::Vertex_iterator Vertex_iterator; 00138 typedef typename Arrangement::Edge_iterator Edge_iterator; 00139 typedef typename Arrangement::Vertex_handle Vertex_handle; 00140 typedef typename Arrangement::Halfedge_handle Halfedge_handle; 00141 00142 typedef typename ExTraits::X_monotone_curve_2 Ex_x_monotone_curve_2; 00143 typedef typename ExTraits::Point_2 Ex_point_2; 00144 00145 // Go over the input objects and copy them to the output iterators. 00146 XCurveInputIter xcv_it; 00147 PointInputIter pt_it; 00148 00149 for (xcv_it = xcvs_begin; xcv_it != xcvs_end; ++xcv_it) 00150 { 00151 *x_curves = Ex_x_monotone_curve_2 (*xcv_it); 00152 ++x_curves; 00153 } 00154 00155 for (pt_it = pts_begin; pt_it != pts_end; ++pt_it) 00156 { 00157 *iso_points = Ex_point_2 (*pt_it); 00158 ++iso_points; 00159 } 00160 00161 // Go over the arrangement edges and insert their associated x-monotone 00162 // curves into the output iterator. To each curve we attach a handle to the 00163 // halfedge that goes from right to left. 00164 Edge_iterator eit; 00165 Halfedge_handle he; 00166 00167 for (eit = arr.edges_begin(); eit != arr.edges_end(); ++eit) 00168 { 00169 if (eit->direction() == ARR_LEFT_TO_RIGHT) 00170 he = eit->twin(); 00171 else 00172 he = eit; 00173 00174 *x_curves = Ex_x_monotone_curve_2 (he->curve(), he); 00175 ++x_curves; 00176 } 00177 00178 // Go over the isolated arrangement vertices and insert their associated 00179 // points into the output iterator. To each point we attach a handle to its 00180 // vertex. 00181 Vertex_iterator vit; 00182 Vertex_handle v; 00183 00184 for (vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) 00185 { 00186 v = vit; 00187 if (v->is_isolated()) 00188 { 00189 *iso_points = Ex_point_2 (v->point(), v); 00190 ++iso_points; 00191 } 00192 } 00193 00194 return; 00195 } 00196 00197 00198 CGAL_END_NAMESPACE 00199 00200 #endif