BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Arr_point_location/Arr_lm_specified_points_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://golubevs@scm.gforge.inria.fr/svn/cgal/trunk/Arrangement_on_surface_2/include/CGAL/Arr_point_location/Arr_lm_specified_points_generator.h $
00015 // $Id: Arr_lm_specified_points_generator.h 41703 2008-01-20 17:57:12Z golubevs $
00016 // 
00017 // Author(s)     : Shlomo Golubev   <golubevs@post.tau.ac.il>
00018 #ifndef CGAL_ARR_SPECIFIED_POINTS_GENERATOR_H
00019 #define CGAL_ARR_SPECIFIED_POINTS_GENERATOR_H
00020 
00025 #include <CGAL/Arr_point_location/Arr_lm_generator_base.h>
00026 
00027 CGAL_BEGIN_NAMESPACE
00028 
00033 template <class Arrangement_,
00034           class Nearest_neighbor_  =
00035             Arr_landmarks_nearest_neighbor<typename
00036                                            Arrangement_::Geometry_traits_2> >
00037 class Arr_landmarks_specified_points_generator :
00038     public Arr_landmarks_generator_base<Arrangement_, Nearest_neighbor_>
00039 {
00040 public:
00041 
00042   typedef Arrangement_                                  Arrangement_2;
00043   typedef typename Arrangement_2::Geometry_traits_2     Geometry_traits_2;
00044   typedef Nearest_neighbor_                             Nearest_neighbor;
00045 
00046   typedef Arr_landmarks_generator_base<Arrangement_2,
00047                                        Nearest_neighbor>      Base;
00048   typedef Arr_landmarks_vertices_generator<Arrangement_2,
00049                                            Nearest_neighbor>  Self;
00050 
00051   typedef typename Arrangement_2::Vertex_const_handle   Vertex_const_handle;
00052   typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle;
00053   typedef typename Arrangement_2::Face_const_handle     Face_const_handle;
00054   typedef typename Arrangement_2::Vertex_handle         Vertex_handle;
00055   typedef typename Arrangement_2::Halfedge_handle       Halfedge_handle;
00056   typedef typename Arrangement_2::Face_handle           Face_handle;
00057   typedef typename Arrangement_2::Vertex_const_iterator Vertex_const_iterator;
00058 
00059   typedef typename Arrangement_2::Point_2               Point_2;
00060   typedef typename Arrangement_2::X_monotone_curve_2    X_monotone_curve_2;
00061 
00062   typedef typename Base::Points_set                     Points_set;
00063 
00064   typedef typename Nearest_neighbor::NN_Point_2         NN_Point_2;
00065   typedef std::list<NN_Point_2>                         NN_Point_list;
00066 
00067 protected:
00068 
00069   typedef Arr_traits_basic_adaptor_2<Geometry_traits_2> Traits_adaptor_2;
00070   typedef std::pair<Point_2,CGAL::Object>               PL_pair;
00071   typedef std::vector<PL_pair>                          Pairs_set;
00072 
00073   // Data members:
00074   const Traits_adaptor_2  *m_traits;  // Its associated traits object.
00075   Points_set              m_points;  // container of the specified points
00076   Pairs_set               lm_pairs;
00077   int                     num_landmarks;
00078 
00079 private:
00080 
00082   Arr_landmarks_specified_points_generator (const Self& );
00083 
00085   Self& operator= (const Self& );
00086 
00087 public: 
00088 
00090   Arr_landmarks_specified_points_generator (const Arrangement_2& arr,
00091                                     const Points_set points) :
00092     Base (arr),
00093     num_landmarks(points.size())
00094   {
00095     //this constructor creates landmarks in the points that are given to it
00096     m_traits = static_cast<const Traits_adaptor_2*> (arr.geometry_traits());
00097     m_points = points;
00098     build_landmark_set();
00099   }
00100 
00101   Arr_landmarks_specified_points_generator (const Arrangement_2& arr) :
00102     Base (arr)
00103   {
00104     //this constructor creates a single landmark in the origin
00105     Points_set points;
00106     points.push_back(Point_2(0,0));
00107     num_landmarks = points.size();
00108     m_traits = static_cast<const Traits_adaptor_2*> (arr.geometry_traits());
00109     m_points = points;
00110     build_landmark_set();
00111   }
00112 
00113   virtual void _create_points_set (Points_set & /* points */)
00114   {
00115     std::cerr << "should not reach here!"<< std::endl;
00116     CGAL_error();
00117   }
00118 
00122   void build_landmark_set ()
00123   {
00124 
00125     lm_pairs.clear();
00126     locate (*(this->arrangement()), m_points.begin(), m_points.end(),
00127             std::back_inserter(lm_pairs));
00128 
00129     // Go over the container of the specified points and insert them as landmarks.
00130     NN_Point_list                   nnp_list; 
00131     typename Points_set::iterator   pt_it;
00132     typename Pairs_set::iterator    pairs_it;
00133     for (pt_it = m_points.begin(); pt_it != m_points.end(); ++pt_it)
00134     {
00135       for (pairs_it = lm_pairs.begin();
00136            pairs_it != lm_pairs.end() && (*pairs_it).first != (*pt_it);
00137            ++pairs_it) {};
00138       if ((*pairs_it).first == (*pt_it))
00139       {
00140         nnp_list.push_back (NN_Point_2 ((*pt_it),(*pairs_it).second));
00141       }
00142     }
00143 
00144     // Update the search structure.
00145     this->nn.clear();
00146     this->nn.init (nnp_list.begin(), nnp_list.end());
00147 
00148     this->num_small_not_updated_changes = 0;
00149     this->updated = true;
00150   }
00151 
00155   void clear_landmark_set ()
00156   {
00157     this->nn.clear();
00158 
00159     num_landmarks = 0;
00160     this->num_small_not_updated_changes = 0;
00161     this->updated = false;
00162   }
00163 
00171   virtual Point_2 closest_landmark (const Point_2& q, Object &obj)
00172   {
00173     CGAL_assertion(this->updated);
00174     return (this->nn.find_nearest_neighbor (q, obj));
00175   }
00176 
00177 };
00178 
00179 CGAL_END_NAMESPACE
00180 
00181 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines