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: 00015 // $Id: 00016 // 00017 // 00018 // Author(s) : Ophir Setter <ophirset@post.tau.ac.il> 00019 // 00020 #ifndef CGAL_ARR_COMPUTE_ZONE_VISITOR_H 00021 #define CGAL_ARR_COMPUTE_ZONE_VISITOR_H 00022 00027 CGAL_BEGIN_NAMESPACE 00028 00037 template <class Arrangement_, class OutputIterator_> 00038 class Arr_compute_zone_visitor 00039 { 00040 public: 00041 00042 typedef OutputIterator_ OutputIterator; 00043 typedef Arrangement_ Arrangement_2; 00044 00045 typedef typename Arrangement_2::Vertex_handle Vertex_handle; 00046 typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; 00047 typedef typename Arrangement_2::Face_handle Face_handle; 00048 00049 typedef typename Arrangement_2::Point_2 Point_2; 00050 typedef typename Arrangement_2::X_monotone_curve_2 X_monotone_curve_2; 00051 00052 typedef std::pair<Halfedge_handle, bool> Result; 00053 00054 private: 00055 00056 const Halfedge_handle invalid_he; // Invalid halfedge. 00057 const Vertex_handle invalid_v; // Invalid vertex. 00058 00059 OutputIterator& out_iter; // for outputing the zone objects. 00060 // Its value type is CGAL::Object. 00061 bool output_left; // Determines wheter we should 00062 // output the left end point of a 00063 // subcurve (to avoid outputing 00064 // the same feature twice). 00065 00066 public: 00067 00069 Arr_compute_zone_visitor (OutputIterator& oi) : 00070 invalid_he(), 00071 invalid_v(), 00072 out_iter (oi), 00073 output_left (true) 00074 {} 00075 00077 void init (Arrangement_2 *) 00078 { 00079 output_left = true; 00080 } 00081 00097 Result found_subcurve (const X_monotone_curve_2&, 00098 Face_handle face, 00099 Vertex_handle left_v, Halfedge_handle left_he, 00100 Vertex_handle right_v, Halfedge_handle right_he) 00101 { 00102 if (output_left) 00103 { 00104 // Only the first subcurve should output the arrangement feature incident 00105 // to its left endpoint. This way we avoid reporting the same feature 00106 // twice. 00107 if (left_v != invalid_v) 00108 { 00109 *out_iter = CGAL::make_object (left_v); 00110 ++out_iter; 00111 } 00112 else if (left_he != invalid_he) 00113 { 00114 *out_iter = CGAL::make_object (left_he); 00115 ++out_iter; 00116 } 00117 00118 output_left = false; 00119 } 00120 00121 // Report the face that contains the interior of the subcurve. 00122 *out_iter = CGAL::make_object (face); 00123 ++out_iter; 00124 00125 // If the right endpoint of the subcurve is incident to an arrangement 00126 // vertex or an arrangement edge, report this feature. 00127 if (right_v != invalid_v) 00128 { 00129 *out_iter = CGAL::make_object(right_v); 00130 ++out_iter; 00131 } 00132 else if (right_he != invalid_he) 00133 { 00134 *out_iter = CGAL::make_object(right_he); 00135 ++out_iter; 00136 } 00137 00138 // We did not modify the arrangement, so we return an invalid handle 00139 // and a flag indicating that the zone-computation process should continue. 00140 return (Result (invalid_he, false)); 00141 } 00142 00154 Result found_overlap (const X_monotone_curve_2&, 00155 Halfedge_handle he, 00156 Vertex_handle left_v, Vertex_handle right_v) 00157 { 00158 if (output_left) 00159 { 00160 // Only the first subcurve should output the arrangement feature incident 00161 // to its left endpoint. This way we avoid reporting the same feature 00162 // twice. 00163 if (left_v != invalid_v) 00164 { 00165 *out_iter = CGAL::make_object (left_v); 00166 ++out_iter; 00167 } 00168 00169 output_left = false; 00170 } 00171 00172 // Report the arrangement edge the curve currently overlaps. 00173 *out_iter = CGAL::make_object(he); 00174 ++out_iter; 00175 00176 // If the right endpoint of the overlapping subcurve is incident to an 00177 // arrangement vertex, report this vertex as well. 00178 if (right_v != invalid_v) 00179 { 00180 *out_iter = CGAL::make_object (right_v); 00181 ++out_iter; 00182 } 00183 00184 // We did not modify the arrangement, so we return an invalid handle 00185 // and a flag indicating that the zone-computation process should continue. 00186 return (Result (invalid_he, false)); 00187 } 00188 }; 00189 00190 00191 CGAL_END_NAMESPACE 00192 00193 #endif