BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Arr_point_location/Arr_lm_vertices_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 // $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_vertices_generator.h $
00015 // $Id: Arr_lm_vertices_generator.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_VERTICES_GENERATOR_H
00020 #define CGAL_ARR_LANDMARKS_VERTICES_GENERATOR_H
00021 
00026 #include <CGAL/Arr_point_location/Arr_lm_generator_base.h>
00027 
00028 CGAL_BEGIN_NAMESPACE
00029 
00034 template <class Arrangement_,
00035           class Nearest_neighbor_  =
00036             Arr_landmarks_nearest_neighbor<typename
00037                                            Arrangement_::Geometry_traits_2> >
00038 class Arr_landmarks_vertices_generator :
00039     public Arr_landmarks_generator_base<Arrangement_, Nearest_neighbor_>
00040 {
00041 public:
00042 
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_landmarks_vertices_generator<Arrangement_2,
00050                                            Nearest_neighbor>  Self;
00051   
00052   typedef typename Arrangement_2::Vertex_const_handle   Vertex_const_handle;
00053   typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle;
00054   typedef typename Arrangement_2::Face_const_handle     Face_const_handle;
00055   typedef typename Arrangement_2::Vertex_handle         Vertex_handle;
00056   typedef typename Arrangement_2::Halfedge_handle       Halfedge_handle;
00057   typedef typename Arrangement_2::Face_handle           Face_handle;
00058   typedef typename Arrangement_2::Vertex_const_iterator Vertex_const_iterator;
00059   
00060   typedef typename Arrangement_2::Point_2               Point_2;
00061   typedef typename Arrangement_2::X_monotone_curve_2    X_monotone_curve_2;
00062 
00063   typedef typename Base::Points_set                     Points_set;
00064 
00065   typedef typename Nearest_neighbor::NN_Point_2         NN_Point_2;
00066   typedef std::list<NN_Point_2>                         NN_Point_list;
00067 
00068 protected:
00069 
00070   typedef Arr_traits_basic_adaptor_2<Geometry_traits_2> Traits_adaptor_2;
00071 
00072   // Data members:
00073   const Traits_adaptor_2  *m_traits;  // Its associated traits object.
00074   int                      num_landmarks;
00075 
00076 private:
00077 
00079   Arr_landmarks_vertices_generator (const Self& );
00080 
00082   Self& operator= (const Self& );
00083 
00084 public: 
00085 
00087   Arr_landmarks_vertices_generator (const Arrangement_2& arr) :
00088     Base (arr),
00089     num_landmarks(0)
00090   {
00091     m_traits = static_cast<const Traits_adaptor_2*> (arr.geometry_traits());
00092     build_landmark_set();//this->
00093   }
00094 
00095   virtual void _create_points_set (Points_set & /* points */)
00096   {
00097     std::cerr << "should not reach here!"<< std::endl;
00098     CGAL_error();
00099   }
00100 
00104   virtual void build_landmark_set ()
00105   {
00106     // Go over the arrangement, and insert all its vertices as landmarks.
00107     NN_Point_list           nnp_list; 
00108     const Arrangement_2    *arr = this->arrangement();
00109     Vertex_const_iterator   vit;
00110     Vertex_const_handle     vh;
00111 
00112     num_landmarks = 0;
00113     for (vit = arr->vertices_begin(); vit != arr->vertices_end(); ++vit)
00114     {
00115       vh = vit;
00116       nnp_list.push_back (NN_Point_2 (vh->point(),
00117                                       CGAL::make_object (vh)));
00118       num_landmarks++;
00119     }
00120 
00121     // Update the search structure.
00122     this->nn.clear();
00123     this->nn.init (nnp_list.begin(), nnp_list.end());
00124 
00125     this->num_small_not_updated_changes = 0;
00126     this->updated = true;
00127   }
00128 
00132   virtual void clear_landmark_set ()
00133   {
00134     this->nn.clear();
00135     num_landmarks = 0;
00136     this->num_small_not_updated_changes = 0;
00137     this->updated = false;
00138   }
00139 
00140 protected:
00141 
00143   void _handle_local_change_notification ()
00144   {
00145     // Rebuild the landmark set only if the number of small
00146     // changes is greater than sqrt(num_landmarks).
00147     double    nl = static_cast<double> (num_landmarks);
00148     const int sqrt_num_landmarks = 
00149       static_cast<int> (std::sqrt (nl) + 0.5);
00150 
00151     this->num_small_not_updated_changes++;
00152     if ((num_landmarks < 10) ||
00153         (this->num_small_not_updated_changes >=  sqrt_num_landmarks))
00154     {
00155       clear_landmark_set();
00156       build_landmark_set();//this->
00157     }
00158 
00159     return;
00160   }
00161 
00162 };
00163 
00164 CGAL_END_NAMESPACE
00165 
00166 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines