BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Arr_point_location/Arr_lm_halton_generator.h
Go to the documentation of this file.
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 // $Source: /CVSROOT/CGAL/Packages/Arrangement_2/include/CGAL/Arr_point_location/Arr_lm_halton_generator.h,v $
00015 // $Revision: 44498 $ $Date: 2008-07-28 07:46:17 +0200 (Mon, 28 Jul 2008) $
00016 // $Name:  $
00017 //
00018 // Author(s)     : Idit Haran   <haranidi@post.tau.ac.il>
00019 //                 Ron Wein     <haranidi@post.tau.ac.il>
00020 #ifndef CGAL_ARR_LM_HALTON_GENERATOR_H
00021 #define CGAL_ARR_LM_HALTON_GENERATOR_H
00022 
00027 #include <CGAL/Arr_point_location/Arr_lm_generator_base.h>
00028 
00029 CGAL_BEGIN_NAMESPACE
00030 
00035 template <class Arrangement_,
00036           class Nearest_neighbor_  =
00037             Arr_landmarks_nearest_neighbor<typename
00038                                            Arrangement_::Geometry_traits_2> >
00039 class Arr_halton_landmarks_generator :
00040     public Arr_landmarks_generator_base<Arrangement_, Nearest_neighbor_>
00041 {
00042 public:
00043   typedef Arrangement_                                  Arrangement_2;
00044   typedef typename Arrangement_2::Geometry_traits_2     Geometry_traits_2;
00045   typedef Nearest_neighbor_                             Nearest_neighbor;
00046 
00047   typedef Arr_landmarks_generator_base<Arrangement_2,
00048                                        Nearest_neighbor>    Base;
00049   typedef Arr_halton_landmarks_generator<Arrangement_2,
00050                                          Nearest_neighbor>  Self;
00051 
00052   typedef typename Arrangement_2::Point_2               Point_2;
00053   typedef typename Base::Points_set                     Points_set;
00054 
00055   typedef typename Arrangement_2::Vertex_const_iterator
00056                                                 Vertex_const_iterator;
00057 
00058 protected:
00059 
00060     // Data members:
00061   unsigned int     num_landmarks; 
00062 
00063 private:
00064 
00066   Arr_halton_landmarks_generator (const Self& );
00067 
00069   Self& operator= (const Self& );
00070 
00071 
00072 public: 
00073   
00075   Arr_halton_landmarks_generator (const Arrangement_2& arr,
00076                                   unsigned int n_landmarks = 0) : 
00077     Base (arr),
00078     num_landmarks (n_landmarks)
00079   {
00080     this->build_landmark_set();
00081   }
00082 
00083 protected:
00084   
00091   virtual void _create_points_set (Points_set& points)
00092   {
00093     points.clear();
00094 
00095     // Go over the arrangement vertices and construct their boundig box.
00096     const Arrangement_2    *arr = this->arrangement();
00097     Vertex_const_iterator   vit; 
00098     double                  x_min = 0, x_max = 1, y_min = 0, y_max = 1;
00099     double                  x, y;
00100     bool                    first = true;
00101 
00102     for (vit=arr->vertices_begin(); vit != arr->vertices_end(); ++vit)
00103     {
00104       x = CGAL::to_double(vit->point().x());
00105       y = CGAL::to_double(vit->point().y());
00106 
00107       if (first)
00108       {
00109         x_min = x_max = x;
00110         y_min = y_max = y;
00111         first = false;
00112       }
00113       else
00114       {
00115         if (x < x_min)
00116           x_min = x;
00117         else if (x > x_max)
00118           x_max = x;
00119 
00120         if (y < y_min)
00121           y_min = y;
00122         else if (y > y_max)
00123           y_max = y;
00124       }
00125     }
00126 
00127     // Create N Halton points. If N was not given to the constructor,
00128     // set it to be the number of vertices in the arrangement.
00129     if (num_landmarks == 0)
00130       num_landmarks = arr->number_of_vertices();
00131 
00132     if (num_landmarks == 0)
00133       return;
00134 
00135     if (num_landmarks == 1)
00136     {
00137       points.push_back (Point_2 (x_max, y_max)); 
00138       return;
00139     }
00140 
00141     // Create the Halton sequence.
00142     const double  x_scale = x_max - x_min;
00143     const double  y_scale = y_max - y_min;
00144     double        base_inv;
00145     int           digit, i, seed2;
00146     int           base[2], leap[2], seed[2];
00147     double        r[2];
00148     double        px, py;
00149     int           ndim = 2;
00150     unsigned int  step = 1;
00151 
00152     seed[0] = seed[1] = 0;
00153     leap[0] = leap[1] = 1;
00154     base[0] = 2;
00155     base[1] = 3;
00156     for (step = 1; step <= num_landmarks; step++)
00157     {
00158       for (i = 0; i < ndim; i++)
00159       {
00160         seed2 = seed[i] + step * leap[i];
00161         r[i] = 0;
00162         base_inv = 1 / static_cast<double> (base[i]);
00163         while (seed2 != 0)
00164         {
00165           digit = seed2 % base[i];
00166           r[i] = r[i] + static_cast<double> (digit) * base_inv;
00167           base_inv = base_inv / static_cast<double> (base[i]);
00168           seed2 = seed2 / base[i];
00169         }
00170       }
00171 
00172       // Now r[0] and r[1] are the x and y-coordinates of the Halton point
00173       // in the unit square. We scale and shift them to fit out bounding box.
00174       px = r[0] * x_scale + x_min;
00175       py = r[1] * y_scale + y_min;
00176 
00177       points.push_back (Point_2 (px, py));
00178     }
00179     return;
00180   }
00181 
00182 };
00183 
00184 CGAL_END_NAMESPACE
00185 
00186 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines