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_random_generator.h $ 00015 // $Id: Arr_lm_random_generator.h 44498 2008-07-28 05:46:17Z ophirset $ 00016 // 00017 // Author(s) : Idit Haran <haranidi@post.tau.ac.il> 00018 // Ron Wein <wein@post.tau.ac.il> 00019 #ifndef CGAL_ARR_LM_RANDOM_GENERATOR_H 00020 #define CGAL_ARR_LM_RANDOM_GENERATOR_H 00021 00026 #include <CGAL/Arr_point_location/Arr_lm_generator_base.h> 00027 #include <CGAL/Random.h> 00028 00029 CGAL_BEGIN_NAMESPACE 00030 00036 template <class Arrangement_, 00037 class Nearest_neighbor_ = 00038 Arr_landmarks_nearest_neighbor<typename 00039 Arrangement_::Geometry_traits_2> > 00040 class Arr_random_landmarks_generator : 00041 public Arr_landmarks_generator_base<Arrangement_, Nearest_neighbor_> 00042 { 00043 public: 00044 typedef Arrangement_ Arrangement_2; 00045 typedef typename Arrangement_2::Geometry_traits_2 Geometry_traits_2; 00046 typedef Nearest_neighbor_ Nearest_neighbor; 00047 00048 typedef Arr_landmarks_generator_base<Arrangement_2, 00049 Nearest_neighbor> Base; 00050 typedef Arr_random_landmarks_generator<Arrangement_2, 00051 Nearest_neighbor> Self; 00052 00053 typedef typename Arrangement_2::Point_2 Point_2; 00054 typedef typename Base::Points_set Points_set; 00055 00056 typedef typename Arrangement_2::Vertex_const_iterator 00057 Vertex_const_iterator; 00058 00059 protected: 00060 00061 // Data members: 00062 unsigned int num_landmarks; 00063 00064 private: 00065 00067 Arr_random_landmarks_generator (const Self& ); 00068 00070 Self& operator= (const Self& ); 00071 00072 00073 public: 00074 00076 Arr_random_landmarks_generator (const Arrangement_2& arr, 00077 unsigned int n_landmarks = 0) : 00078 Base (arr), 00079 num_landmarks (n_landmarks) 00080 { 00081 this->build_landmark_set(); 00082 } 00083 00084 protected: 00085 00092 virtual void _create_points_set (Points_set& points) 00093 { 00094 points.clear(); 00095 00096 // Go over the arrangement vertices and construct their boundig box. 00097 const Arrangement_2 *arr = this->arrangement(); 00098 Vertex_const_iterator vit; 00099 double x_min = 0, x_max = 1, y_min = 0, y_max = 1; 00100 double x, y; 00101 bool first = true; 00102 00103 for (vit=arr->vertices_begin(); vit != arr->vertices_end(); ++vit) 00104 { 00105 x = CGAL::to_double(vit->point().x()); 00106 y = CGAL::to_double(vit->point().y()); 00107 00108 if (first) 00109 { 00110 x_min = x_max = x; 00111 y_min = y_max = y; 00112 first = false; 00113 } 00114 else 00115 { 00116 if (x < x_min) 00117 x_min = x; 00118 else if (x > x_max) 00119 x_max = x; 00120 00121 if (y < y_min) 00122 y_min = y; 00123 else if (y > y_max) 00124 y_max = y; 00125 } 00126 } 00127 00128 // Create N random landmarks. If N was not given to the constructor, 00129 // set it to be the number of vertices in the arrangement. 00130 CGAL::Random random; 00131 double px, py; 00132 unsigned int i; 00133 00134 if (num_landmarks == 0) 00135 num_landmarks = arr->number_of_vertices(); 00136 00137 for (i = 0; i < num_landmarks; i++) 00138 { 00139 px = random.get_double(x_min, x_max); 00140 py = random.get_double(y_min, y_max); 00141 points.push_back (Point_2 (px, py)); 00142 } 00143 } 00144 00145 }; 00146 00147 CGAL_END_NAMESPACE 00148 00149 00150 #endif