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_subcurve.h $ 00015 // $Id: Sweep_line_subcurve.h 41325 2007-12-26 15:39:40Z golubevs $ 00016 // 00017 // 00018 // Author(s) : Tali Zvi <talizvi@post.tau.ac.il>, 00019 // Baruch Zukerman <baruchzu@post.tau.ac.il> 00020 // Ron Wein <wein@post.tau.ac.il> 00021 00022 #ifndef CGAL_SWEEP_LINE_SUBCURVE_H 00023 #define CGAL_SWEEP_LINE_SUBCURVE_H 00024 00029 #include <CGAL/Sweep_line_2/Sweep_line_functors.h> 00030 #include <CGAL/Sweep_line_2/Sweep_line_event.h> 00031 #include <CGAL/Multiset.h> 00032 #include <CGAL/assertions.h> 00033 00034 CGAL_BEGIN_NAMESPACE 00035 00049 template<class Traits_> 00050 class Sweep_line_subcurve 00051 { 00052 public: 00053 00054 typedef Traits_ Traits_2; 00055 typedef typename Traits_2::Point_2 Point_2; 00056 typedef typename Traits_2::X_monotone_curve_2 X_monotone_curve_2; 00057 00058 typedef Sweep_line_subcurve<Traits_2> Self; 00059 typedef Curve_comparer<Traits_2, Self> Compare_curves; 00060 typedef Multiset<Self*, 00061 Compare_curves, 00062 CGAL_ALLOCATOR(int)> Status_line; 00063 typedef typename Status_line::iterator Status_line_iterator; 00064 00065 typedef Sweep_line_event<Traits_2, Self> Event; 00066 00067 protected: 00068 00069 // Data members: 00070 00071 X_monotone_curve_2 m_lastCurve; // The portion of the curve that lies to 00072 // the right of the last event point 00073 // that occured on the curve. 00074 00075 Event *m_left_event; // The event associated with the left end. 00076 Event *m_right_event; // The event associated with the right end 00077 00078 Status_line_iterator m_hint; // The location of the subcurve in the 00079 // status line (the Y-structure). 00080 00081 Self *m_orig_subcurve1; // The overlapping hierarchy 00082 Self *m_orig_subcurve2; // (relevant only in case of overlaps). 00083 00084 public: 00085 00087 Sweep_line_subcurve () : 00088 m_orig_subcurve1 (NULL), 00089 m_orig_subcurve2 (NULL) 00090 {} 00091 00093 Sweep_line_subcurve (const X_monotone_curve_2 &curve) : 00094 m_lastCurve (curve), 00095 m_orig_subcurve1 (NULL), 00096 m_orig_subcurve2 (NULL) 00097 {} 00098 00100 void init (const X_monotone_curve_2 &curve) 00101 { 00102 m_lastCurve = curve; 00103 } 00104 00106 ~Sweep_line_subcurve() 00107 {} 00108 00110 const X_monotone_curve_2& last_curve () const 00111 { 00112 return (m_lastCurve); 00113 } 00114 00116 X_monotone_curve_2& last_curve() 00117 { 00118 return (m_lastCurve); 00119 } 00120 00122 void set_last_curve (const X_monotone_curve_2 &cv) 00123 { 00124 m_lastCurve = cv; 00125 } 00126 00128 template<class SweepEvent> 00129 bool is_end_point (const SweepEvent* event) const 00130 { 00131 return (m_right_event == (Event*)event); 00132 } 00133 00135 Event* left_event() const 00136 { 00137 return (m_left_event); 00138 } 00139 00141 Event* right_event() const 00142 { 00143 return (m_right_event); 00144 } 00145 00147 template<class SweepEvent> 00148 void set_left_event (SweepEvent* event) 00149 { 00150 m_left_event =(Event*)event; 00151 } 00152 00154 template<class SweepEvent> 00155 void set_right_event(SweepEvent* event) 00156 { 00157 m_right_event = (Event*)event; 00158 } 00159 00161 Status_line_iterator hint() const 00162 { 00163 return (m_hint); 00164 } 00165 00167 void set_hint(Status_line_iterator hint) 00168 { 00169 m_hint = hint; 00170 } 00171 00173 Self* originating_subcurve1() 00174 { 00175 return (m_orig_subcurve1); 00176 } 00177 00178 Self* originating_subcurve2() 00179 { 00180 return (m_orig_subcurve2); 00181 } 00182 00184 void set_originating_subcurve1 (Self* orig_subcurve1) 00185 { 00186 m_orig_subcurve1 = orig_subcurve1; 00187 } 00188 00189 void set_originating_subcurve2 (Self* orig_subcurve2) 00190 { 00191 m_orig_subcurve2 = orig_subcurve2; 00192 } 00193 00195 template <class OutputIterator> 00196 OutputIterator all_leaves (OutputIterator oi) 00197 { 00198 if (m_orig_subcurve1 == NULL) 00199 { 00200 *oi = this; 00201 ++oi; 00202 return (oi); 00203 } 00204 00205 oi = m_orig_subcurve1->all_leaves (oi); 00206 oi = m_orig_subcurve2->all_leaves (oi); 00207 return (oi); 00208 } 00209 00211 template <class OutputIterator> 00212 OutputIterator all_nodes (OutputIterator oi) 00213 { 00214 *oi = this; 00215 ++oi; 00216 00217 if (m_orig_subcurve1 == NULL) 00218 return (oi); 00219 00220 oi = m_orig_subcurve1->get_all_inner_nodes (oi); 00221 oi = m_orig_subcurve2->get_all_inner_nodes (oi); 00222 return (oi); 00223 } 00224 00226 bool is_inner_node (Self *s) 00227 { 00228 if (this == s) 00229 return (true); 00230 00231 if (m_orig_subcurve1 == NULL) 00232 return (false); 00233 00234 return (m_orig_subcurve1->is_inner_node (s) || 00235 m_orig_subcurve2->is_inner_node (s)); 00236 } 00237 00239 bool is_leaf (Self* s) 00240 { 00241 if (m_orig_subcurve1 == NULL) 00242 return (this == s); 00243 00244 return (m_orig_subcurve1->is_leaf (s) || 00245 m_orig_subcurve2->is_leaf (s)); 00246 } 00247 00249 bool has_same_leaves (Self *s) 00250 { 00251 std::list<Self*> my_leaves; 00252 std::list<Self*> other_leaves; 00253 00254 this->all_leaves (std::back_inserter (my_leaves)); 00255 s->all_leaves (std::back_inserter (other_leaves)); 00256 00257 typename std::list<Self*>::iterator iter; 00258 00259 for(iter = my_leaves.begin(); iter != my_leaves.end(); ++iter) 00260 { 00261 if (std::find(other_leaves.begin(), other_leaves.end(), *iter) == 00262 other_leaves.end()) 00263 return (false); 00264 } 00265 00266 for(iter = other_leaves.begin(); iter != other_leaves.end(); ++iter) 00267 { 00268 if (std::find(my_leaves.begin(), my_leaves.end(), *iter) == 00269 my_leaves.end()) 00270 return (false); 00271 } 00272 00273 return (true); 00274 } 00275 00277 bool has_common_leaf (Self *s) 00278 { 00279 std::list<Self*> my_leaves; 00280 std::list<Self*> other_leaves; 00281 00282 this->all_leaves (std::back_inserter (my_leaves)); 00283 s->all_leaves (std::back_inserter (other_leaves)); 00284 00285 typename std::list<Self*>::iterator iter; 00286 00287 for (iter = my_leaves.begin(); iter != my_leaves.end(); ++iter) 00288 { 00289 if (std::find(other_leaves.begin(), other_leaves.end(), *iter) != 00290 other_leaves.end()) 00291 return (true); 00292 } 00293 return (false); 00294 } 00295 00297 template <class OutputIterator> 00298 OutputIterator distinct_nodes(Self *s, OutputIterator oi) 00299 { 00300 if (m_orig_subcurve1 == NULL) 00301 { 00302 if (s->is_leaf(this)) 00303 { 00304 *oi = this; 00305 ++oi; 00306 } 00307 return (oi); 00308 } 00309 00310 if (! s->is_inner_node (m_orig_subcurve1)) 00311 { 00312 *oi = m_orig_subcurve1; 00313 ++oi; 00314 } 00315 else 00316 { 00317 oi = m_orig_subcurve1->distinct_nodes (s, oi); 00318 } 00319 00320 if (! s->is_inner_node (m_orig_subcurve2)) 00321 { 00322 *oi = m_orig_subcurve2; 00323 ++oi; 00324 } 00325 else 00326 { 00327 oi = m_orig_subcurve2->distinct_nodes (s, oi); 00328 } 00329 00330 return (oi); 00331 } 00332 00334 unsigned int overlap_depth() 00335 { 00336 if (m_orig_subcurve1 == NULL) 00337 return (1); 00338 00339 unsigned int depth1 = m_orig_subcurve1->overlap_depth(); 00340 unsigned int depth2 = m_orig_subcurve2->overlap_depth(); 00341 00342 if (depth1 > depth2) 00343 return (depth1 + 1); 00344 else 00345 return (depth2 + 1); 00346 } 00347 00348 #ifdef CGAL_SL_VERBOSE 00349 void Print() const; 00350 #endif 00351 }; 00352 00353 #ifdef CGAL_SL_VERBOSE 00354 template<class Traits> 00355 void Sweep_line_subcurve<Traits>::Print() const 00356 { 00357 std::cout << "Curve " << this 00358 << " (" << m_lastCurve << ") " << std::endl; 00359 } 00360 #endif 00361 00362 CGAL_END_NAMESPACE 00363 00364 #endif