BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Boolean_set_operations_2/Gps_bfs_scanner.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/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_bfs_scanner.h $
00015 // $Id: Gps_bfs_scanner.h 48113 2009-02-17 16:21:43Z ophirset $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 //                 Ophir Setter    <ophir.setter@cs.tau.ac.il>
00020 
00021 #ifndef CGAL_GPS_BFS_SCANNER_H
00022 #define CGAL_GPS_BFS_SCANNER_H
00023 
00024 #include <queue>
00025 #include <stack>
00026 
00027 CGAL_BEGIN_NAMESPACE
00028 
00029 template <class Arrangement_, class Visitor_>
00030 class Gps_bfs_scanner
00031 {
00032   typedef Arrangement_     Arrangement;
00033 
00034   typedef typename Arrangement::Inner_ccb_iterator    Inner_ccb_iterator;
00035   typedef typename Arrangement::Ccb_halfedge_circulator 
00036                                                   Ccb_halfedge_circulator;
00037   typedef typename Arrangement::Face_iterator    Face_iterator;
00038   typedef typename Arrangement::Halfedge_iterator Halfedge_iterator;
00039   
00040   typedef Visitor_         Visitor;
00041 
00042 protected:
00043   Visitor*                     m_visitor;
00044   std::queue<Inner_ccb_iterator>   m_holes;
00045   std::stack<Ccb_halfedge_circulator>  m_ccb_stcak;
00046 
00047 public:
00048 
00049   Gps_bfs_scanner(Visitor& v): m_visitor(&v)
00050   {}
00051 
00052   void scan(Arrangement& arr)
00053   {
00054     Face_iterator ubf;
00055     for (ubf = arr.faces_begin(); ubf != arr.faces_end(); ++ubf)
00056     {
00057       if (ubf->number_of_outer_ccbs() != 0)
00058         continue;
00059       if (ubf->visited() == true)
00060         continue;
00061 
00062       ubf->set_visited(true);
00063       push_to_queue_holes_of_face(ubf);
00064       
00065       while(!m_holes.empty())
00066       {
00067         Inner_ccb_iterator hole = m_holes.front();
00068         m_holes.pop();
00069         scan(*hole);
00070       }
00071     }
00072   }
00073 
00074   void scan(Ccb_halfedge_circulator ccb)
00075   {
00076     _scan(ccb);
00077     while(!m_ccb_stcak.empty())
00078     {
00079       Ccb_halfedge_circulator curr_ccb = m_ccb_stcak.top();
00080       m_ccb_stcak.pop();
00081       _scan(curr_ccb);
00082     }
00083 
00084   }
00085   void _scan(Ccb_halfedge_circulator ccb)
00086   {
00087     Ccb_halfedge_circulator ccb_circ = ccb;
00088     Ccb_halfedge_circulator ccb_end  = ccb;
00089           Face_iterator new_f;
00090     do
00091     {
00092       Halfedge_iterator he  = ccb_circ;
00093       new_f = he->twin()->face();
00094       if(!new_f->visited())
00095       {
00096         push_to_queue_holes_of_face(he->twin()->face());
00097         new_f->set_visited(true);
00098         m_visitor->discovered_face(he->face(), new_f, he); 
00099         
00100         //scan(he->twin());
00101         m_ccb_stcak.push(he->twin());
00102       }
00103       ++ccb_circ;
00104     }
00105     while(ccb_circ != ccb_end);
00106   }
00107 
00108   
00109   void push_to_queue_holes_of_face(Face_iterator f)
00110   {
00111     for(Inner_ccb_iterator hit = f->inner_ccbs_begin(); 
00112         hit!= f->inner_ccbs_end(); ++hit)
00113     {
00114       m_holes.push(hit);
00115     }
00116   }
00117 };
00118 
00119 CGAL_END_NAMESPACE
00120 
00121 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines