BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Triangulation_ds_circulators_2.h
Go to the documentation of this file.
00001 // Copyright (c) 1997  INRIA Sophia-Antipolis (France).
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/Triangulation_2/include/CGAL/Triangulation_ds_circulators_2.h $
00015 // $Id: Triangulation_ds_circulators_2.h 48844 2009-04-21 18:28:04Z spion $
00016 // 
00017 //
00018 // Author(s)     : Mariette Yvinec
00019 //                 Menelaos Karavelas <mkaravel@cse.nd.edu>
00020 
00021 #ifndef CGAL_TRIANGULATION_DS_CIRCULATORS_2_H
00022 #define CGAL_TRIANGULATION_DS_CIRCULATORS_2_H
00023 
00024 #include <utility>
00025 #include <iterator>
00026 #include <CGAL/circulator.h>
00027 #include <CGAL/triangulation_assertions.h>
00028 #include <CGAL/Triangulation_utils_2.h>
00029 
00030 CGAL_BEGIN_NAMESPACE
00031 
00032 template < class Tds>
00033 class Triangulation_ds_face_circulator_2
00034   : public Bidirectional_circulator_base< typename Tds::Face,
00035                                  std::ptrdiff_t,
00036                                  std::size_t>,
00037     public Triangulation_cw_ccw_2
00038       
00039 {
00040 private:
00041   typedef
00042   Bidirectional_circulator_base< typename Tds::Face,
00043                                  std::ptrdiff_t,
00044                                  std::size_t>  Base_circulator;
00045 
00046 public:
00047   typedef Triangulation_ds_face_circulator_2<Tds> Face_circulator;
00048   typedef typename Tds::Face                      Face;
00049   typedef typename Tds::Vertex                    Vertex;
00050   typedef typename Tds::Face_handle               Face_handle;
00051   typedef typename Tds::Vertex_handle             Vertex_handle;
00052 
00053 
00054 private: 
00055   Vertex_handle _v;
00056   Face_handle    pos;
00057 
00058 public:
00059   Triangulation_ds_face_circulator_2()
00060     : _v(), pos()
00061   {}
00062   
00063   Triangulation_ds_face_circulator_2(Vertex_handle v, 
00064                                      Face_handle f = Face_handle());
00065 
00066   // MK: added to satisfy the mips CC 7.40 compiler
00067   Face_circulator& operator=(const Face_circulator& other);
00068 
00069   Face_circulator& operator++();
00070   Face_circulator operator++(int);
00071   Face_circulator& operator--();
00072   Face_circulator operator--(int);
00073 
00074   bool operator==(const Face_circulator &fc) const;
00075   bool operator!=(const Face_circulator &fc) const;
00076 
00077   bool operator==(const Face_handle &fh) const { return pos == fh; }
00078   bool operator!=(const Face_handle &fh) const { return pos != fh; }
00079 
00080   bool is_empty() const;
00081   bool operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const;
00082   bool operator!=(Nullptr_t CGAL_triangulation_assertion_code(n)) const;
00083 
00084   Face&
00085   operator*() const
00086   {
00087     CGAL_triangulation_precondition(pos != Face_handle() && 
00088                                  _v != Vertex_handle());
00089     return *pos;
00090   }
00091 
00092   Face*
00093   operator->() const
00094   {
00095     CGAL_triangulation_precondition(pos != Face_handle() && 
00096                                  _v != Vertex_handle());
00097     return &*pos;
00098   }
00099   
00100   Face_handle base()  const {return pos;}
00101   operator Face_handle()  const {return pos;}
00102 };
00103 
00104 template < class Tds_ >
00105 bool
00106 operator==(typename Tds_::Face_handle fh,
00107            Triangulation_ds_face_circulator_2<Tds_> fc)
00108 {
00109   return (fc==fh);
00110 }
00111 
00112 template < class Tds_ >
00113 bool
00114 operator!=(typename Tds_::Face_handle fh,
00115            Triangulation_ds_face_circulator_2<Tds_> fc)
00116 {
00117   return (fc!=fh);
00118 }
00119 
00120 
00121 template < class Tds >
00122 class Triangulation_ds_vertex_circulator_2 :
00123   public Bidirectional_circulator_base< typename Tds::Vertex, 
00124                                        std::ptrdiff_t,
00125                                        std::size_t>,
00126   public  Triangulation_cw_ccw_2
00127 {
00128 public:
00129   typedef Triangulation_ds_vertex_circulator_2<Tds> Vertex_circulator;
00130   typedef typename Tds::Face                      Face;
00131   typedef typename Tds::Vertex                    Vertex;
00132   typedef typename Tds::Face_handle               Face_handle;
00133   typedef typename Tds::Vertex_handle             Vertex_handle; 
00134 
00135 private:
00136   Vertex_handle _v;
00137   Face_handle   pos;
00138   int _ri;
00139   
00140 public:
00141   Triangulation_ds_vertex_circulator_2()
00142     :  _v(), pos()
00143   {}
00144                 
00145   Triangulation_ds_vertex_circulator_2(Vertex_handle v,
00146                                        Face_handle f = Face_handle());
00147        
00148   Vertex_circulator& operator++();
00149   Vertex_circulator  operator++(int);
00150   Vertex_circulator& operator--();
00151   Vertex_circulator  operator--(int);
00152  
00153   bool operator==(const Vertex_circulator &vc) const;
00154   bool operator!=(const Vertex_circulator &vc) const;
00155 
00156   bool operator==(const Vertex_handle &vh) const
00157   { return pos->vertex(_ri) == vh; }
00158   bool operator!=(const Vertex_handle &vh) const
00159   { return pos->vertex(_ri) != vh; }
00160 
00161   bool is_empty() const;
00162   bool operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const;
00163   bool operator!=(Nullptr_t CGAL_triangulation_assertion_code(n)) const;
00164 
00165   Vertex&
00166   operator*() const
00167   {
00168     CGAL_triangulation_precondition(pos != Face_handle() && 
00169                                  _v != Vertex_handle());
00170     return *(pos->vertex(_ri));
00171   }
00172 
00173   Vertex*
00174   operator->() const
00175   {
00176     CGAL_triangulation_precondition(pos != Face_handle() && 
00177                                  _v != Vertex_handle());
00178     return &*(pos->vertex(_ri));
00179   }
00180 
00181    Vertex_handle base() const {return pos->vertex(_ri);}
00182    operator Vertex_handle() const {return pos->vertex(_ri);}
00183 };
00184 
00185 template < class Tds_ >
00186 inline
00187 bool
00188 operator==(typename Tds_::Vertex_handle vh,
00189            Triangulation_ds_vertex_circulator_2<Tds_> vc)
00190 {
00191   return (vc==vh);
00192 }
00193 
00194 template < class Tds_ >
00195 inline
00196 bool
00197 operator!=(typename Tds_::Vertex_handle vh,
00198            Triangulation_ds_vertex_circulator_2<Tds_> vc)
00199 {
00200   return !(vc==vh);
00201 }
00202 
00203 
00204 template < class Tds >
00205 class Triangulation_ds_edge_circulator_2 :
00206   public Bidirectional_circulator_base < typename Tds::Edge, 
00207                                          std::ptrdiff_t,
00208                                          std::size_t>,
00209   public Triangulation_cw_ccw_2
00210 {
00211 public:
00212   typedef Triangulation_ds_edge_circulator_2<Tds>  Edge_circulator;
00213   typedef typename Tds::Face                       Face;
00214   typedef typename Tds::Vertex                     Vertex;
00215   typedef typename Tds::Edge                       Edge;
00216   typedef typename Tds::Face_handle                Face_handle;
00217   typedef typename Tds::Vertex_handle              Vertex_handle;
00218 
00219 private:
00220   int _ri;
00221   Vertex_handle _v;
00222   Face_handle  pos;
00223   mutable Edge edge;
00224 
00225 public:
00226   Triangulation_ds_edge_circulator_2()
00227     : _v(), pos()
00228   {}
00229             
00230   Triangulation_ds_edge_circulator_2( Vertex_handle v, 
00231                                       Face_handle f = Face_handle());
00232 
00233   Edge_circulator& operator++();
00234   Edge_circulator operator++(int);
00235   Edge_circulator& operator--();
00236   Edge_circulator operator--(int);
00237  
00238   bool operator==(const Edge_circulator &vc) const;
00239   bool operator!=(const Edge_circulator &vc) const;
00240   bool is_empty() const;
00241   bool operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const;
00242   bool operator!=(Nullptr_t CGAL_triangulation_assertion_code(n)) const;
00243 
00244   Edge*  operator->() const { 
00245     edge.first=pos;
00246     edge.second= _ri;
00247     return &edge;
00248   }
00249 
00250   Edge& operator*() const {
00251     edge.first=pos;
00252     edge.second= _ri;
00253     return edge;
00254   }
00255 
00256 };
00257 
00258 
00259 template < class Tds >
00260 Triangulation_ds_face_circulator_2<Tds> ::
00261 Triangulation_ds_face_circulator_2(Vertex_handle v, Face_handle f)
00262   : _v(v), pos(f)
00263 {
00264   if (_v == Vertex_handle()) pos = Face_handle();
00265   else if ( pos == Face_handle()) pos = v->face();
00266 
00267   if (pos ==  Face_handle()|| pos->dimension() < 2) { 
00268     _v =  Vertex_handle() ; pos = Face_handle(); return;}
00269   else CGAL_triangulation_precondition( pos->has_vertex(v));
00270 }
00271  
00272 template < class Tds >
00273 Triangulation_ds_face_circulator_2<Tds>&
00274 Triangulation_ds_face_circulator_2<Tds> ::
00275 operator=(const Face_circulator& other)
00276 {
00277    static_cast<Base_circulator &>(*this) =
00278     static_cast<const Base_circulator &> (other);
00279    _v = other._v;
00280   pos = other.pos;
00281   return *this;
00282 } 
00283     
00284 template < class Tds >
00285 Triangulation_ds_face_circulator_2<Tds>&
00286 Triangulation_ds_face_circulator_2<Tds> ::
00287 operator++()
00288 {
00289   CGAL_triangulation_precondition( pos != Face_handle() && 
00290                                  _v != Vertex_handle());
00291   int i = pos->index(_v);
00292   pos = pos->neighbor(ccw(i));
00293   return *this;
00294 }
00295 
00296 template < class Tds >
00297 Triangulation_ds_face_circulator_2<Tds>
00298 Triangulation_ds_face_circulator_2<Tds> ::
00299 operator++(int)
00300 {
00301   CGAL_triangulation_precondition(pos != Face_handle() && 
00302                                  _v != Vertex_handle());
00303   Face_circulator tmp(*this);
00304   ++(*this);
00305   return tmp;
00306 }
00307 
00308 template < class Tds >
00309 Triangulation_ds_face_circulator_2<Tds>&
00310 Triangulation_ds_face_circulator_2<Tds> ::
00311 operator--()
00312 {
00313    CGAL_triangulation_precondition(pos != Face_handle() && 
00314                                  _v != Vertex_handle());
00315    int i = pos->index(_v);
00316    pos = pos->neighbor(cw(i));
00317    return *this;
00318 }
00319 
00320 template < class Tds >
00321 Triangulation_ds_face_circulator_2<Tds>
00322 Triangulation_ds_face_circulator_2<Tds> ::
00323 operator--(int)
00324 {
00325   CGAL_triangulation_precondition(pos != Face_handle() && 
00326                                  _v != Vertex_handle());
00327   Face_circulator tmp(*this);
00328   --(*this);
00329   return tmp;
00330 }
00331 
00332 template < class Tds >
00333 inline bool
00334 Triangulation_ds_face_circulator_2<Tds> ::
00335 operator==(const Face_circulator &fc) const
00336 {    
00337   return (_v == fc._v) &&  (pos == fc.pos);  
00338 }
00339 
00340 template < class Tds >
00341 inline bool
00342 Triangulation_ds_face_circulator_2<Tds> ::
00343 operator!=(const Face_circulator &fc) const
00344 {    
00345 return ! (*this == fc);  
00346 }
00347    
00348 template < class Tds >
00349 inline bool
00350 Triangulation_ds_face_circulator_2<Tds> ::
00351 is_empty() const
00352 {    
00353 return (_v == Vertex_handle() ||  pos == Face_handle() );  
00354 }
00355 
00356 template < class Tds >
00357 inline bool
00358 Triangulation_ds_face_circulator_2<Tds> ::
00359 operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const
00360 {
00361   CGAL_triangulation_assertion( n == NULL);
00362   return (_v == Vertex_handle() ||  pos == Face_handle() );  
00363 }
00364         
00365 template < class Tds >
00366 inline bool
00367 Triangulation_ds_face_circulator_2<Tds> ::
00368 operator!=(Nullptr_t CGAL_triangulation_assertion_code(n)) const
00369 {
00370   CGAL_triangulation_assertion( n == NULL);
00371   return ! (*this == NULL);
00372 }
00373 
00374 template < class Tds >
00375 Triangulation_ds_vertex_circulator_2<Tds> ::
00376 Triangulation_ds_vertex_circulator_2 (Vertex_handle v,  
00377                                       Face_handle f)
00378   : _v( v ), pos(f)
00379 {
00380   if (_v == Vertex_handle()) { pos = Face_handle();}
00381   else if (pos == Face_handle()) {pos = v->face();}
00382 
00383   if (pos == Face_handle() || pos->dimension() < 1){
00384     _v = Vertex_handle(); pos = Face_handle(); return;}
00385   int i = pos->index(_v);
00386   if (pos->dimension() == 2) {_ri = ccw(i);}
00387   else {_ri = 1-i;}
00388   return;
00389 }
00390 
00391 
00392 template < class Tds >
00393 Triangulation_ds_vertex_circulator_2<Tds>&
00394 Triangulation_ds_vertex_circulator_2<Tds> ::
00395 operator++()
00396 {
00397   CGAL_triangulation_precondition(pos != Face_handle() &&
00398                                   _v != Vertex_handle());
00399   int i = pos->index(_v);
00400     
00401   if (pos->dimension() == 1) { 
00402     pos = pos->neighbor(1-i);
00403     _ri = 1 - pos->index(_v);
00404   }
00405   else{
00406     pos = pos->neighbor(ccw(i));
00407     i = pos->index(_v);
00408     _ri = ccw(i);
00409   }
00410   return *this;
00411 }
00412         
00413 template < class Tds >
00414 Triangulation_ds_vertex_circulator_2<Tds>
00415 Triangulation_ds_vertex_circulator_2<Tds> ::
00416 operator++(int)
00417 {
00418   Vertex_circulator tmp(*this);
00419   ++(*this);
00420   return tmp;
00421 }
00422 
00423 template < class Tds >
00424 Triangulation_ds_vertex_circulator_2<Tds>&
00425 Triangulation_ds_vertex_circulator_2<Tds> ::
00426 operator--()
00427 {
00428   CGAL_triangulation_precondition(pos != Face_handle() &&
00429                                   _v != Vertex_handle());
00430   int i = pos->index(_v);
00431     
00432   if (pos->dimension() == 1) { 
00433     pos = pos->neighbor(1-i);
00434     _ri = 1 - pos->index(_v);
00435   }
00436   else{
00437     pos = pos->neighbor(cw(i));
00438     i = pos->index(_v);
00439     _ri = ccw(i);
00440   }
00441   return *this;
00442 }
00443         
00444 template < class Tds >
00445 Triangulation_ds_vertex_circulator_2<Tds>
00446 Triangulation_ds_vertex_circulator_2<Tds> ::     
00447 operator--(int)
00448 {
00449   Vertex_circulator tmp(*this);
00450   --(*this);
00451   return tmp;
00452 }
00453 
00454 template < class Tds >
00455 inline bool
00456 Triangulation_ds_vertex_circulator_2<Tds> ::
00457 operator==(const Vertex_circulator &vc) const
00458 {
00459   return (_v == vc._v) &&  (_ri == vc._ri) && (pos == vc.pos);
00460 }
00461                
00462 template < class Tds >
00463 inline bool
00464 Triangulation_ds_vertex_circulator_2<Tds> ::
00465 operator!=(const Vertex_circulator &vc) const
00466 {
00467   return ! (*this == vc);
00468 }
00469                
00470 template < class Tds >
00471 inline bool
00472 Triangulation_ds_vertex_circulator_2<Tds> ::
00473 is_empty() const
00474 {
00475   return (_v == Vertex_handle() || pos == Face_handle());
00476 }
00477 
00478 template < class Tds >
00479 inline bool
00480 Triangulation_ds_vertex_circulator_2<Tds> ::
00481 operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const
00482 {
00483   CGAL_triangulation_assertion( n == NULL);
00484   return (_v == Vertex_handle() || pos == Face_handle());
00485 }
00486         
00487 template < class Tds >
00488 inline bool
00489 Triangulation_ds_vertex_circulator_2<Tds> ::        
00490 operator!=(Nullptr_t CGAL_triangulation_assertion_code(n)) const
00491 {
00492   CGAL_triangulation_assertion( n == NULL);
00493   return !(*this == NULL);
00494 }
00495         
00496 
00497 template < class Tds >
00498 Triangulation_ds_edge_circulator_2<Tds> ::
00499 Triangulation_ds_edge_circulator_2(Vertex_handle v, Face_handle f)
00500     : _v(v), pos(f)
00501 {
00502   if (_v == Vertex_handle()) { pos = Face_handle();}
00503   else if (pos==Face_handle()) {pos = v->face();}
00504  
00505   if (pos == Face_handle() || pos->dimension() < 1){
00506     _v = Vertex_handle(); pos = Face_handle();return;}
00507   int i = pos->index(_v);
00508   if (pos->dimension() == 2) {_ri = ccw(i);}
00509   else {_ri = 2;}
00510   return;
00511 }
00512 
00513 template < class Tds >
00514 Triangulation_ds_edge_circulator_2<Tds>&
00515 Triangulation_ds_edge_circulator_2<Tds> ::
00516 operator++()
00517 {
00518   CGAL_triangulation_precondition(pos != Face_handle() &&
00519                                   _v != Vertex_handle());
00520   int i = pos->index(_v);
00521   if (pos->dimension() == 1) { 
00522     pos = pos->neighbor(1-i);
00523     return *this;
00524   }
00525   else{
00526     pos = pos->neighbor(ccw(i));
00527     i = pos->index(_v);
00528     _ri = ccw(i);
00529   }    
00530   return *this;
00531 }
00532 
00533 template < class Tds >
00534 Triangulation_ds_edge_circulator_2<Tds>
00535 Triangulation_ds_edge_circulator_2<Tds> ::
00536 operator++(int)
00537 {
00538   Edge_circulator tmp(*this);
00539   ++(*this);
00540   return tmp;
00541 }
00542 
00543 template < class Tds >
00544 Triangulation_ds_edge_circulator_2<Tds>&
00545 Triangulation_ds_edge_circulator_2<Tds> ::
00546 operator--()
00547 {
00548   CGAL_triangulation_precondition(pos != Face_handle() &&
00549                                   _v != Vertex_handle());
00550   int i = pos->index(_v);
00551 
00552   if (pos->dimension() == 1) { 
00553     pos = pos->neighbor(1-i);
00554     return *this;
00555   }
00556   else{
00557     pos = pos->neighbor(cw(i));
00558     i = pos->index(_v);
00559     _ri = ccw(i);
00560   }    
00561   return *this;
00562 }
00563    
00564 template < class Tds >
00565 Triangulation_ds_edge_circulator_2<Tds>
00566 Triangulation_ds_edge_circulator_2<Tds> ::
00567 operator--(int)
00568 {
00569   Edge_circulator tmp(*this);
00570   --(*this);
00571   return tmp;
00572 }
00573 
00574 template < class Tds >
00575 inline bool
00576 Triangulation_ds_edge_circulator_2<Tds> ::
00577 operator==(const Edge_circulator &vc) const
00578 {
00579   return (_v == vc._v) &&  (_ri == vc._ri) && (pos == vc.pos);
00580 }
00581                 
00582 template < class Tds >
00583 inline bool
00584 Triangulation_ds_edge_circulator_2<Tds> ::
00585 operator!=(const Edge_circulator &vc) const
00586 {
00587   return ! (*this == vc);
00588 }
00589 
00590 template < class Tds >
00591 inline bool
00592 Triangulation_ds_edge_circulator_2<Tds> ::
00593 is_empty() const
00594 {
00595   return (_v == Vertex_handle() || pos == Face_handle());
00596 }
00597 
00598 template < class Tds >
00599 inline bool
00600 Triangulation_ds_edge_circulator_2<Tds> ::
00601 operator==(Nullptr_t CGAL_triangulation_assertion_code(n)) const
00602 {
00603   CGAL_triangulation_assertion( n == NULL);
00604   return (_v == Vertex_handle() || pos == Face_handle());
00605 }
00606                
00607 template < class Tds >
00608 inline bool
00609 Triangulation_ds_edge_circulator_2<Tds> ::
00610 operator!=(Nullptr_t CGAL_triangulation_assertion_code(n)) const
00611 {
00612   CGAL_triangulation_assertion( n == NULL);
00613   return !(*this == NULL);
00614 }
00615        
00616 
00617 CGAL_END_NAMESPACE
00618 
00619 #endif //CGAL_TRIANGULATION_DS_CIRCULATORS_2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines