BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/General_polygon_with_holes_2.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/General_polygon_with_holes_2.h $
00015 // $Id: General_polygon_with_holes_2.h 45280 2008-09-02 10:54:01Z guyzucke $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 
00020 #ifndef CGAL_GENERAL_POLYGON_WITH_HOLES_2_H
00021 #define CGAL_GENERAL_POLYGON_WITH_HOLES_2_H
00022 
00023 #include <list>
00024 
00025 CGAL_BEGIN_NAMESPACE
00026 
00027 template <class Polygon_>
00028 class General_polygon_with_holes_2
00029 {
00030 
00031 public:
00032   typedef General_polygon_with_holes_2<Polygon_>                Self;
00033   typedef Polygon_                                    Polygon_2;
00034   typedef typename Self::Polygon_2                                                      General_polygon_2;  
00035   typedef std::list<Polygon_>                         Holes_container;
00036 
00037   typedef typename Holes_container::iterator          Hole_iterator;
00038   typedef typename Holes_container::const_iterator    Hole_const_iterator;
00039 
00040   typedef unsigned int                                 Size;
00041 
00042   General_polygon_with_holes_2() : m_pgn()
00043   {}
00044 
00045 
00046   explicit General_polygon_with_holes_2(const General_polygon_2& pgn_boundary) 
00047   : m_pgn(pgn_boundary)
00048   {}
00049 
00050 
00051   template <class HolesInputIterator>
00052   General_polygon_with_holes_2(const General_polygon_2& pgn_boundary,
00053                        HolesInputIterator h_begin,
00054                        HolesInputIterator h_end) : m_pgn(pgn_boundary),
00055                                                    m_holes(h_begin, h_end)
00056   {}
00057 
00058   Hole_iterator holes_begin()
00059   {
00060     return m_holes.begin();
00061   }
00062 
00063   Hole_iterator holes_end()
00064   {
00065     return m_holes.end();
00066   }
00067 
00068   Hole_const_iterator holes_begin() const
00069   {
00070     return m_holes.begin();
00071   }
00072 
00073   Hole_const_iterator holes_end() const
00074   {
00075     return m_holes.end();
00076   }
00077 
00078   bool is_unbounded() const
00079   {
00080     return m_pgn.is_empty();
00081   }
00082 
00083   General_polygon_2& outer_boundary()
00084   {
00085     return m_pgn;
00086   }
00087 
00088   const General_polygon_2& outer_boundary() const
00089   {
00090     return m_pgn;
00091   }
00092 
00093   void add_hole(const General_polygon_2& pgn_hole)
00094   {
00095     m_holes.push_back(pgn_hole);
00096   }
00097 
00098   void erase_hole(Hole_iterator hit)
00099   {
00100     m_holes.erase(hit);
00101   }
00102 
00103   bool has_holes() const
00104   {
00105     return (!m_holes.empty());
00106   }
00107 
00108   Size number_of_holes() const
00109   {
00110     return m_holes.size();
00111   }
00112 
00113   void clear()
00114   {
00115     m_pgn.clear();
00116     m_holes.clear();
00117   }
00118 
00119   bool is_plane() const
00120   {
00121     return (m_pgn.is_empty() && m_holes.empty());
00122   }
00123 
00124 
00125 
00126 protected:
00127 
00128   General_polygon_2           m_pgn;
00129   Holes_container            m_holes;
00130 };
00131 
00132 
00133 //-----------------------------------------------------------------------//
00134 //                          operator<<
00135 //-----------------------------------------------------------------------//
00136 
00137 template <class Polygon_>
00138 std::ostream
00139 &operator<<(std::ostream &os, const General_polygon_with_holes_2<Polygon_>& p)
00140 {
00141   typename General_polygon_with_holes_2<Polygon_>::Hole_const_iterator hit;
00142 
00143   switch(os.iword(IO::mode)) {
00144     case IO::ASCII :
00145       os << p.outer_boundary() << ' ' << p.number_of_holes()<< ' ';
00146       for (hit = p.holes_begin(); hit != p.holes_end(); ++hit) {
00147         os << *hit << ' ';
00148       }
00149       return os;
00150 
00151     case IO::BINARY :
00152       os << p.outer_boundary()  << p.number_of_holes();
00153       for (hit = p.holes_begin(); hit != p.holes_end(); ++hit) {
00154         os << *hit;
00155       }
00156       return os;
00157      
00158 
00159     default:
00160       os << "General_polygon_with_holes_2( " << std::endl;
00161       os << p.outer_boundary() << " " << p.number_of_holes()<< " ";
00162       for (hit = p.holes_begin(); hit != p.holes_end(); ++hit) {
00163         os << *hit << " )";
00164       }
00165       return os;
00166   }
00167 }
00168 
00169 //-----------------------------------------------------------------------//
00170 //                          operator>>
00171 //-----------------------------------------------------------------------//
00172 
00173 template <class Polygon_>
00174 std::istream &operator>>(std::istream &is, General_polygon_with_holes_2<Polygon_>& p)
00175 {
00176   p.clear();
00177   is >> p.outer_boundary();
00178 
00179   unsigned int n_holes;
00180   is >> n_holes;
00181   if (is) 
00182   {
00183     Polygon_ pgn_hole;
00184     for (unsigned int i=0; i<n_holes; i++) 
00185     {
00186       is >> pgn_hole;
00187       p.add_hole(pgn_hole);
00188     }
00189   }
00190  
00191   return is;
00192 }
00193 
00194 
00195 CGAL_END_NAMESPACE
00196 
00197 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines