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/Arr_point_location/Arr_lm_generator_base.h $ 00015 // $Id: Arr_lm_generator_base.h 41847 2008-01-26 09:05:42Z golubevs $ 00016 // 00017 // Author(s) : Idit Haran <haranidi@post.tau.ac.il> 00018 // Ron Wein <wein@post.tau.ac.il> 00019 #ifndef CGAL_ARR_LANDMARKS_GENERATOR_H 00020 #define CGAL_ARR_LANDMARKS_GENERATOR_H 00021 00025 #include <CGAL/Arr_observer.h> 00026 #include <CGAL/Arrangement_2/Arr_traits_adaptor_2.h> 00027 #include <CGAL/Arr_point_location/Arr_lm_nearest_neighbor.h> 00028 #include <CGAL/Arr_batched_point_location.h> 00029 #include <list> 00030 #include <algorithm> 00031 #include <vector> 00032 00033 CGAL_BEGIN_NAMESPACE 00034 00044 template <class Arrangement_, 00045 class Nearest_neighbor_ = 00046 Arr_landmarks_nearest_neighbor <typename 00047 Arrangement_::Geometry_traits_2> > 00048 class Arr_landmarks_generator_base 00049 : public Arr_observer <Arrangement_> 00050 { 00051 public: 00052 00053 typedef Arrangement_ Arrangement_2; 00054 typedef typename Arrangement_2::Geometry_traits_2 Geometry_traits_2; 00055 typedef Nearest_neighbor_ Nearest_neighbor; 00056 00057 typedef Arr_landmarks_generator_base<Arrangement_2, 00058 Nearest_neighbor> Self; 00059 00060 typedef typename Arrangement_2::Vertex_const_handle Vertex_const_handle; 00061 typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle; 00062 typedef typename Arrangement_2::Face_const_handle Face_const_handle; 00063 typedef typename Arrangement_2::Vertex_handle Vertex_handle; 00064 typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; 00065 typedef typename Arrangement_2::Face_handle Face_handle; 00066 typedef typename Arrangement_2::Vertex_const_iterator 00067 Vertex_const_iterator; 00068 typedef typename Arrangement_2::Ccb_halfedge_circulator 00069 Ccb_halfedge_circulator; 00070 00071 typedef typename Arrangement_2::Point_2 Point_2; 00072 typedef typename Arrangement_2::X_monotone_curve_2 X_monotone_curve_2; 00073 00074 typedef typename Nearest_neighbor::NN_Point_2 NN_Point_2; 00075 typedef std::list<NN_Point_2> NN_Points_set; 00076 00077 typedef std::vector<Point_2> Points_set; 00078 typedef std::pair<Point_2,CGAL::Object> PL_pair; 00079 typedef std::vector<PL_pair> Pairs_set; 00080 typedef typename std::vector<PL_pair>::iterator Pairs_iterator; 00081 00082 protected: 00083 00084 typedef Arr_traits_basic_adaptor_2<Geometry_traits_2> Traits_adaptor_2; 00085 00086 // Data members: 00087 const Traits_adaptor_2 *m_traits; // The associated traits object. 00088 Nearest_neighbor nn; // The associated nearest neighbor object. 00089 bool ignore_notifications; 00090 bool updated; 00091 int num_small_not_updated_changes; 00092 00093 private: 00094 00096 Arr_landmarks_generator_base (const Self& ); 00097 00099 Self& operator= (const Self& ); 00100 00101 public: 00102 00104 Arr_landmarks_generator_base (const Arrangement_2& arr) : 00105 Arr_observer<Arrangement_2> (const_cast<Arrangement_2 &>(arr)), 00106 ignore_notifications (false), 00107 updated (false), 00108 num_small_not_updated_changes(0) 00109 { 00110 m_traits = static_cast<const Traits_adaptor_2*> (arr.geometry_traits()); 00111 // One needs to call build_landmark_set() in the constructor of any 00112 // inherited class. 00113 } 00114 00119 virtual void build_landmark_set () 00120 { 00121 // Create the landmark points. 00122 NN_Points_set nn_points; 00123 00124 _create_nn_points_set(nn_points); 00125 00126 // Update the search structure. 00127 nn.clear(); 00128 nn.init (nn_points.begin(), nn_points.end()); 00129 00130 num_small_not_updated_changes = 0; 00131 updated = true; 00132 } 00133 00137 virtual void clear_landmark_set () 00138 { 00139 nn.clear(); 00140 num_small_not_updated_changes = 0; 00141 updated = false; 00142 } 00143 00151 virtual Point_2 closest_landmark (Point_2 p, Object &obj) 00152 { 00153 CGAL_assertion(updated); 00154 return (nn.find_nearest_neighbor(p, obj)); 00155 } 00156 00158 00159 00165 virtual void before_assign (const Arrangement_2& arr) 00166 { 00167 this->clear_landmark_set(); 00168 m_traits = static_cast<const Traits_adaptor_2*> (arr.geometry_traits()); 00169 ignore_notifications = true; 00170 } 00171 00176 virtual void after_assign () 00177 { 00178 this->build_landmark_set(); 00179 ignore_notifications = false; 00180 } 00181 00186 virtual void before_attach (const Arrangement_2& arr) 00187 { 00188 this->clear_landmark_set(); 00189 m_traits = static_cast<const Traits_adaptor_2*> (arr.geometry_traits()); 00190 ignore_notifications = true; 00191 } 00192 00196 virtual void after_attach () 00197 { 00198 this->build_landmark_set(); 00199 ignore_notifications = false; 00200 } 00201 00205 virtual void before_detach () 00206 { 00207 this->clear_landmark_set(); 00208 } 00209 00214 virtual void after_clear () 00215 { 00216 this->clear_landmark_set(); 00217 this->build_landmark_set(); 00218 } 00219 00221 virtual void before_global_change () 00222 { 00223 this->clear_landmark_set(); 00224 ignore_notifications = true; 00225 } 00226 00228 virtual void after_global_change () 00229 { 00230 this->build_landmark_set(); 00231 ignore_notifications = false; 00232 } 00234 00236 00237 00239 virtual void after_create_vertex (Vertex_handle ) 00240 { 00241 this->_handle_local_change_notification(); 00242 } 00243 00245 virtual void after_create_edge (Halfedge_handle ) 00246 { 00247 this->_handle_local_change_notification(); 00248 } 00249 00251 virtual void after_split_edge (Halfedge_handle , 00252 Halfedge_handle ) 00253 { 00254 this->_handle_local_change_notification(); 00255 } 00256 00258 virtual void after_split_face (Face_handle , 00259 Face_handle , 00260 bool ) 00261 { 00262 this->_handle_local_change_notification(); 00263 } 00264 00266 virtual void after_split_outer_ccb (Face_handle , 00267 Ccb_halfedge_circulator , 00268 Ccb_halfedge_circulator ) 00269 { 00270 this->_handle_local_change_notification(); 00271 } 00272 00274 virtual void after_split_inner_ccb (Face_handle , 00275 Ccb_halfedge_circulator , 00276 Ccb_halfedge_circulator ) 00277 { 00278 this->_handle_local_change_notification(); 00279 } 00280 00282 virtual void after_add_outer_ccb (Ccb_halfedge_circulator ) 00283 { 00284 this->_handle_local_change_notification(); 00285 } 00286 00288 virtual void after_add_inner_ccb (Ccb_halfedge_circulator ) 00289 { 00290 this->_handle_local_change_notification(); 00291 } 00292 00294 virtual void after_add_isolated_vertex (Vertex_handle ) 00295 { 00296 this->_handle_local_change_notification(); 00297 } 00298 00300 virtual void after_merge_edge (Halfedge_handle ) 00301 { 00302 this->_handle_local_change_notification(); 00303 } 00304 00306 virtual void after_merge_face (Face_handle ) 00307 { 00308 this->_handle_local_change_notification(); 00309 } 00310 00312 virtual void after_merge_outer_ccb (Face_handle , 00313 Ccb_halfedge_circulator ) 00314 { 00315 this->_handle_local_change_notification(); 00316 } 00317 00319 virtual void after_merge_inner_ccb (Face_handle , 00320 Ccb_halfedge_circulator ) 00321 { 00322 this->_handle_local_change_notification(); 00323 } 00324 00326 virtual void after_move_outer_ccb (Ccb_halfedge_circulator ) 00327 { 00328 this->_handle_local_change_notification(); 00329 } 00330 00332 virtual void after_move_inner_ccb (Ccb_halfedge_circulator ) 00333 { 00334 this->_handle_local_change_notification(); 00335 } 00336 00338 virtual void after_move_isolated_vertex (Vertex_handle ) 00339 { 00340 this->_handle_local_change_notification(); 00341 } 00342 00344 virtual void after_remove_vertex () 00345 { 00346 this->_handle_local_change_notification(); 00347 } 00348 00350 virtual void after_remove_edge () 00351 { 00352 this->_handle_local_change_notification(); 00353 } 00354 00356 virtual void after_remove_outer_ccb (Face_handle ) 00357 { 00358 this->_handle_local_change_notification(); 00359 } 00360 00362 virtual void after_remove_inner_ccb (Face_handle ) 00363 { 00364 this->_handle_local_change_notification(); 00365 } 00367 00368 protected: 00369 00371 void _handle_local_change_notification () 00372 { 00373 if (! ignore_notifications) 00374 { 00375 clear_landmark_set(); 00376 build_landmark_set(); 00377 } 00378 return; 00379 } 00380 00386 virtual void _create_points_set (Points_set &) = 0; 00387 00388 virtual void _create_nn_points_set (NN_Points_set &nn_points) 00389 { 00390 Points_set points; 00391 Pairs_set pairs; 00392 00393 // Create the set of landmark points. 00394 _create_points_set(points); 00395 00396 // Locate the landmarks in the arrangement using batched point-location 00397 // global function. 00398 locate (*(this->arrangement()), points.begin(), points.end(), 00399 std::back_inserter(pairs)); 00400 00401 // Apply a random shuffle on the points, since the batched point-location 00402 // returns them sorted. 00403 std::random_shuffle (pairs.begin(), pairs.end()); 00404 00405 // Insert all landmarks (paired with their current location in the 00406 // arrangement) into the nearest-neighbor search structure. 00407 Pairs_iterator itr; 00408 00409 for (itr = pairs.begin(); itr != pairs.end(); ++itr) 00410 { 00411 NN_Point_2 np(itr->first, itr->second); 00412 nn_points.push_back(np); 00413 } 00414 } 00415 }; 00416 00417 CGAL_END_NAMESPACE 00418 00419 #endif