BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Arr_batched_point_location.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_batched_point_location.h $
00015 // $Id: Arr_batched_point_location.h 50366 2009-07-05 12:56:48Z efif $
00016 //
00017 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00018 //                 Ron Wein <wein@post.tau.ac.il>
00019 //                 Efi Fogel <efif@post.tau.ac.il>
00020 
00021 #ifndef CGAL_ARR_BATCHED_POINT_LOCATION_H
00022 #define CGAL_ARR_BATCHED_POINT_LOCATION_H
00023 
00024 #include <CGAL/Arrangement_on_surface_2.h>
00025 #include <CGAL/Basic_sweep_line_2.h>
00026 
00027 #include <vector>
00028 #include <boost/mpl/if.hpp>
00029 #include <boost/type_traits.hpp>
00030 
00031 CGAL_BEGIN_NAMESPACE
00032 
00044 template<class GeomTraits, class TopTraits,
00045          class PointsIterator, class OutputIterator> 
00046 OutputIterator locate
00047     (const Arrangement_on_surface_2<GeomTraits, TopTraits>& arr,
00048      PointsIterator points_begin, PointsIterator points_end,
00049      OutputIterator oi)
00050 {
00051   // Arrangement types:
00052   typedef Arrangement_on_surface_2<GeomTraits, TopTraits>  Arr;
00053   typedef typename TopTraits::template
00054           Sweep_line_bacthed_point_location_visitor<OutputIterator>
00055                                                            Bpl_visitor;
00056 
00057   typedef typename Arr::Halfedge_const_handle          Halfedge_const_handle;
00058   typedef typename Arr::Vertex_const_iterator          Vertex_const_iterator;
00059   typedef typename Arr::Edge_const_iterator            Edge_const_iterator;
00060   typedef typename Arr::Vertex_const_handle            Vertex_const_handle;
00061   typedef typename Arr::Halfedge_const_handle          Halfedge_const_handle;
00062 
00063   typedef typename Bpl_visitor::Traits_2               Bpl_traits_2;
00064   typedef typename Bpl_traits_2::X_monotone_curve_2    Bpl_x_monotone_curve_2;
00065   typedef typename Bpl_traits_2::Point_2               Bpl_point_2;
00066 
00067   // Go over all arrangement edges and collect their associated x-monotone
00068   // curves. To each curve we attach a halfedge handle going from right to
00069   // left.
00070   std::vector<Bpl_x_monotone_curve_2>  xcurves_vec (arr.number_of_edges());
00071   Edge_const_iterator                  eit;
00072   Halfedge_const_handle                he;
00073   unsigned int                         i = 0;
00074 
00075   for (eit = arr.edges_begin(); eit != arr.edges_end(); ++eit, ++i) 
00076   {
00077     // Associate each x-monotone curve with the halfedge that represent it
00078     // that is directed from right to left.
00079     if (eit->direction() == ARR_RIGHT_TO_LEFT)
00080       he = eit;
00081     else
00082       he = eit->twin();
00083 
00084     xcurves_vec[i] = Bpl_x_monotone_curve_2 (eit->curve(), he);
00085   }
00086 
00087   // Go over all isolated vertices and collect their points. To each point
00088   // we attach its vertex handle.
00089   std::vector<Bpl_point_2>    iso_pts_vec (arr.number_of_isolated_vertices());
00090   Vertex_const_iterator       vit;
00091   Vertex_const_handle         iso_v;
00092 
00093   i = 0;
00094   for (vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit, ++i)
00095   {
00096     if (vit->is_isolated())
00097     {
00098       iso_v = vit;
00099       iso_pts_vec[i] = Bpl_point_2 (vit->point(), iso_v);
00100     }
00101   }
00102     
00103   // Obtain a extended traits-class object.
00104   GeomTraits    *geom_traits = const_cast<GeomTraits*> (arr.geometry_traits());
00105 
00106   /* We would like to avoid copy construction of the geometry traits class.
00107    * Copy construction is undesired, because it may results with data
00108    * duplication or even data loss.
00109    *
00110    * If the type Bpl_traits_2 is the same as the type
00111    * GeomTraits, use a reference to GeomTraits to avoid constructing a new one.
00112    * Otherwise, instantiate a local variable of the former and provide
00113    * the later as a single parameter to the constructor.
00114    * 
00115    * Use the form 'A a(*b);' and not ''A a = b;' to handle the case where A has
00116    * only an implicit constructor, (which takes *b as a parameter).
00117    */
00118   typename boost::mpl::if_<boost::is_same<GeomTraits, Bpl_traits_2>,
00119                            const Bpl_traits_2&, Bpl_traits_2>::type
00120     ex_traits(*geom_traits);
00121 
00122   // Define the sweep-line visitor and perform the sweep.
00123   Bpl_visitor   visitor (&arr, &oi);
00124   Basic_sweep_line_2<typename Bpl_visitor::Traits_2,
00125                      Bpl_visitor,
00126                      typename Bpl_visitor::Subcurve,
00127                      typename Bpl_visitor::Event>
00128     sweep_line (&ex_traits, &visitor);
00129 
00130   sweep_line.sweep (xcurves_vec.begin(), xcurves_vec.end(), // Curves.
00131                     iso_pts_vec.begin(), iso_pts_vec.end(), // Action points.
00132                     points_begin, points_end);              // Query points.
00133 
00134   return (oi);
00135 }
00136 
00137 CGAL_END_NAMESPACE
00138 
00139 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines