BWAPI
|
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_base_visitor.h $ 00015 // $Id: Gps_bfs_base_visitor.h 49861 2009-06-09 00:14:50Z eric $ 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_BPS_BASE_VISITOR_H 00022 #define CGAL_GPS_BPS_BASE_VISITOR_H 00023 00024 #include <CGAL/Unique_hash_map.h> 00025 00026 CGAL_BEGIN_NAMESPACE 00027 00029 00035 template <class Arrangement_, class DerivedVisitor> 00036 class Gps_bfs_base_visitor 00037 { 00038 typedef Arrangement_ Arrangement; 00039 typedef typename Arrangement::Face_iterator Face_iterator; 00040 typedef typename Arrangement::Halfedge_iterator Halfedge_iterator; 00041 public: 00042 typedef Unique_hash_map<Halfedge_iterator, unsigned int> Edges_hash; 00043 typedef Unique_hash_map<Face_iterator, unsigned int> Faces_hash; 00044 00045 protected: 00046 Edges_hash* m_edges_hash; 00047 Faces_hash* m_faces_hash; 00048 unsigned int m_num_of_polygons; // number of polygons 00049 00050 public: 00051 00052 Gps_bfs_base_visitor(Edges_hash* edges_hash, 00053 Faces_hash* faces_hash, 00054 unsigned int n_pgn): 00055 m_edges_hash(edges_hash), 00056 m_faces_hash(faces_hash), 00057 m_num_of_polygons(n_pgn) 00058 {} 00059 00060 00062 00069 void discovered_face(Face_iterator old_face, 00070 Face_iterator new_face, 00071 Halfedge_iterator he) 00072 { 00073 unsigned int ic = compute_ic(old_face, new_face, he); 00074 00075 if (static_cast<DerivedVisitor*>(this)->contained_criteria(ic)) 00076 new_face->set_contained(true); 00077 } 00078 00079 // mark the unbounded_face (true iff contained) 00080 void visit_ubf(Face_iterator ubf, unsigned int ubf_ic) 00081 { 00082 CGAL_assertion(ubf->is_unbounded()); 00083 if(static_cast<DerivedVisitor*>(this)->contained_criteria(ubf_ic)) 00084 ubf->set_contained(true); 00085 } 00086 00087 protected: 00088 00089 // compute the inside count of a face 00090 unsigned int compute_ic(Face_iterator f1, 00091 Face_iterator f2, 00092 Halfedge_iterator he) 00093 { 00094 CGAL_assertion(m_edges_hash->is_defined(he) && 00095 m_edges_hash->is_defined(he->twin()) && 00096 m_faces_hash->is_defined(f1) && 00097 !m_faces_hash->is_defined(f2)); 00098 unsigned int ic_f2 = 00099 (*m_faces_hash)[f1] - (*m_edges_hash)[he] + (*m_edges_hash)[he->twin()]; 00100 (*m_faces_hash)[f2] = ic_f2; 00101 00102 return (ic_f2); 00103 } 00104 }; 00105 00106 CGAL_END_NAMESPACE 00107 00108 #endif