Go to Overview over all GrAL packages.
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Gral/Iterators/facet-iterator.h

Go to the documentation of this file.
00001 #ifndef GRAL_BASE_GB_FACET_ITERATOR_H
00002 #define GRAL_BASE_GB_FACET_ITERATOR_H
00003 
00004 
00005 // $LICENSE
00006 
00007 #include "Gral/Base/common-grid-basics.h"
00008 
00013 //----------------------------------------------------------------
00014 //
00027 //----------------------------------------------------------------
00028 
00029 template<class FacOnCellIt>
00030 class FacetIterator  {
00031 public:
00032   typedef typename FacOnCellIt::grid_type grid_type;
00033   typedef grid_types<grid_type>           gt;
00034   typedef FacOnCellIt                     local_it;
00035   typedef typename gt::CellIterator       global_it;
00036 
00037   typedef typename gt::Facet              Facet;
00038 private:
00039   //----- DATA --------
00040   global_it         c;  // current cell
00041   local_it          fc; // current facet on c
00042   // invariant:  ! IsDone() => *c == fc.TheCell()
00043 
00044   typedef FacetIterator<FacOnCellIt> self;
00045 public:
00046   typedef grid_type anchor_type;
00047   typedef Facet     value_type;
00048 
00049   //--------- constructors -------------------------
00050 
00051   FacetIterator() {}
00052   FacetIterator(grid_type const& g) { init(g.FirstCell()); }
00053   FacetIterator(const global_it& cc) { init(cc) ;}
00054 
00055 private:
00056   void init(const global_it& cc)
00057     {
00058       c = cc;
00059       if(!c.IsDone()) 
00060         fc = (*c).FirstFacet();
00061       while(! IsDone() && ! is_new_facet())
00062         advance();
00063     }
00064 
00065 public:  
00066   //---------- iterator operations ------------------
00067 
00068   inline self& operator++() {
00069     advance();
00070     while( ! IsDone() && ! is_new_facet())
00071       advance();
00072     return *this;
00073   }
00074 
00075   Facet operator*() const {return (*fc);}
00076   bool  IsDone() const {return (c.IsDone());}
00077 
00078   const grid_type& TheGrid() {return (c.TheGrid());}
00079 
00080   friend bool operator==(const self& ls, const self& rs) {
00081     // relies on shortcircuit to prevent (ls._nb == rs._nb) from
00082     // being executed if (ls._c != rs._c), thus violating the precondition
00083     // of the first comparision.
00084     // Also, this relies on Edge2D_Iterator visiting edges always from
00085     // one and the same side -- the inverse iterator won't be compare to equal.
00086     return (    (ls.IsDone() && rs.IsDone()) 
00087              || ((ls.c == rs.c) && (ls.fc == rs.fc)));
00088   }
00089   friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}
00090   friend bool operator<(const self& ls, const self& rs) {
00091     return ((ls.c < rs.c) || ((ls.c == rs.c) && (ls.fc < rs.fc )));
00092   }
00093 
00094 private:
00095   //---------- helper functions for iteration -------
00096 
00097   inline void advance();
00098 
00099   // check, if the current edge (facet) is not
00100   // already visited from the other side.
00101   bool is_new_facet() { 
00102     return (   TheGrid().IsOnBoundary(fc)
00103                || (fc.other_cell() < c.handle()));
00104   }
00105 
00106 };
00107 
00108 
00109 template<class FacOnCellIt>
00110 inline void
00111 FacetIterator<FacOnCellIt>::advance()
00112 { 
00113   ++fc;
00114   if(fc.IsDone()) {
00115     ++c;
00116     if(! c.IsDone()){
00117       fc = (*c).FirstFacet();
00118     }
00119   }
00120 }
00121 
00122 
00123 
00124 
00125 #endif
00126 

Copyright (c) Guntram Berti 1997-2002. See the GrAL Homepage for up-to-date information.

Generated at Tue Feb 26 16:05:47 2002 for GrAL Base by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000