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

Gral/Grids/Cartesian2D/subrange.h

Go to the documentation of this file.
00001 #ifndef NMWR_GB_REG2D_SUBRANGE_H
00002 #define NMWR_GB_REG2D_SUBRANGE_H
00003 
00004 
00005 // $LICENSE
00006 
00007 #include "Gral/Grids/Cartesian2D/cartesian-grid2d.h"
00008 
00021 class SubrangeReg2D {
00022 public:
00023   typedef SubrangeReg2D Range;
00024   typedef RegGrid2D Grid;
00025   typedef  Grid::indexmap_type indexmap_type;
00026   typedef  Grid::index_type index_type;
00027 
00028   typedef  Grid::vertex_handle vertex_handle;
00029   typedef  Grid::Vertex Vertex;
00030   typedef  Grid::cell_handle cell_handle;
00031   typedef  Grid::Cell Cell;
00032   typedef  Grid::edge_handle edge_handle;
00033   typedef  Grid::Edge Edge;
00034 
00035   SubrangeReg2D() : g(0) {}
00036   // what should be the behavior if  llv ! <= urv ? 
00037   SubrangeReg2D(const Grid& gg, const index_type& llv, const index_type& urv)
00038     : g(&gg), 
00039       vertex_index_map(llv,urv), 
00040       cell_index_map  (llv,index_type(urv.x-1,urv.y-1)),
00041       xedge_index_map (llv,index_type(urv.x-1,urv.y  )), 
00042       yedge_index_map (llv,index_type(urv.x,  urv.y-1))
00043     {}
00044   SubrangeReg2D(const Grid& gg,int llx, int lly, int urx, int ury) 
00045     : g(&gg), 
00046       vertex_index_map(index_type(llx,lly),index_type(urx,ury)),
00047       cell_index_map  (index_type(llx,lly),index_type(urx-1,ury-1)), 
00048       xedge_index_map (index_type(llx,lly),index_type(urx-1,ury  )), 
00049       yedge_index_map (index_type(llx,lly),index_type(urx,  ury-1))
00050 
00051     {}
00052 
00053   //  SubrangeReg2D(const Grid& gg, const rect& b) 
00054   // : g(gg), vertex_index_map(b.ll,b.ur) {}
00055 
00056   class iterator_base_1 {
00057   public:
00058     typedef iterator_base_1 base;
00059     iterator_base_1(const Grid* gg, const Range* rr) : g(gg), r(rr) {}
00060     iterator_base_1(const Grid& gg, const Range& rr) : g(&gg), r(&rr) {}
00061     const Grid&  TheGrid()  const { return (*g);}
00062     const Range& TheRange() const { return (*r);}
00063   protected:
00064     const Grid*  g;
00065     const Range* r;
00066   };
00067 
00068   class VertexIterator_1 : public iterator_base_1 {
00069   public:
00070     typedef VertexIterator_1 self;
00071 
00072     VertexIterator_1() : base(0,0), v(-1) {}
00073     VertexIterator_1(const Grid* g, const Range* r) : base(g,r), v(r->MinVertexNum()) {}
00074     VertexIterator_1(const Grid& g, const Range& r) : base(g,r), v(r.MinVertexNum()) {}
00075     VertexIterator_1(vertex_handle vv, const Grid* g, const Range* r) 
00076       : base(g,r), v(vv) {}
00077     VertexIterator_1(vertex_handle vv, const Grid& g, const Range& r) 
00078       : base(g,r), v(vv) {}
00079 
00080     self& operator++()     { ++v; return (*this); }
00081     self  operator++(int)  { self tmp(*this); ++(*this); return tmp;}
00082     // random access: use IndexMap of underlying grid!
00083     //  self& operator +=(const index_type& ij) {
00084     //  v+= TheMap().offset(ij);
00085     //  return *this;
00086     //}
00087     Vertex   operator*() const { return TheRange().vertex(v);} 
00088     // random access
00089     //    Vertex operator()(int     friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}i, int j) const { 
00090     //  return TheGrid().vertex(v + TheMap().offset(i,j));
00091     //}
00092     
00093     bool     IsDone()    const { return  (v > TheRange().MaxVertexNum());}
00094     friend bool operator==(const self& ls, const self& rs) { return (ls.v == rs.v);}
00095     friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}
00096     friend bool operator< (const self& ls, const self& rs) { return (ls.v <  rs.v);}
00097 
00098     //    vertex_handle GlobalNumber() const {return v;}
00099   private:
00100     const indexmap_type& TheMap() const { return TheRange().TheVertexMap();}
00101     vertex_handle v;
00102   };
00103   typedef VertexIterator_1 VertexIterator;
00104 
00105 
00106   class CellIterator_1 : public iterator_base_1 {
00107   public:
00108     typedef CellIterator_1 self;
00109 
00110     CellIterator_1() : base(0,0), c(-1) {}
00111     CellIterator_1(const Grid* g, const Range* r) : base(g,r), c(r->MinCellNum()) {}
00112     CellIterator_1(const Grid& g, const Range& r) : base(g,r), c(r.MinCellNum()) {}
00113     CellIterator_1(cell_handle cc, const Grid* g, const Range* r) 
00114       : base(g,r), c(cc) {}
00115     CellIterator_1(cell_handle cc, const Grid& g, const Range& r) 
00116       : base(g,r), c(cc) {}
00117 
00118     self& operator++() {
00119       ++c;
00120       return (*this);
00121     }
00122     self  operator++(int)    { self tmp(*this); ++(*this); return tmp;}
00123     self& operator +=(const index_type& ij) {
00124       c+= TheMap().offset(ij);
00125       return *this;
00126     }
00127     Cell   operator*() const { return TheRange().cell(c);} 
00128     // random access
00129     // Cell operator()(int i, int j) const { 
00130     //  return TheGrid().cell(c + TheMap().offset(i,j));
00131     //}
00132     
00133     bool     IsDone()    const { return  (c > TheRange().MaxCellNum());}
00134     friend bool operator==(const self& ls, const self& rs) { return (ls.c == rs.c);}
00135     friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}
00136     friend bool operator< (const self& ls, const self& rs) { return (ls.c <  rs.c);}
00137     //    cell_handle GlobalNumber() const {
00138   private:
00139     const indexmap_type& TheMap() const { return TheRange().TheCellMap();}
00140     cell_handle c;
00141   };
00142   typedef CellIterator_1 CellIterator;
00143 
00144   class EdgeIterator_1 : public iterator_base_1 {
00145   public:
00146     typedef EdgeIterator_1 self;
00147 
00148     EdgeIterator_1() : base(0,0), e(-1) {}
00149     EdgeIterator_1(const Grid* g, const Range* r) : base(g,r), e(r->MinEdgeNum()) {}
00150     EdgeIterator_1(const Grid& g, const Range& r) : base(g,r), e(r.MinEdgeNum()) {}
00151     EdgeIterator_1(edge_handle ee, const Grid* g, const Range* r) 
00152       : base(g,r), e(ee) {}
00153     EdgeIterator_1(edge_handle ee, const Grid& g, const Range& r) 
00154       : base(g,r), e(ee) {}
00155 
00156     self& operator++() {
00157       ++e;
00158       return (*this);
00159     }
00160     self  operator++(int)    { self tmp(*this); ++(*this); return tmp;}
00161     Edge   operator*() const { return TheRange().edge(e);} 
00162 
00163     //    self& operator +=(const index_type& ij) {
00164     //  e+= TheMap().offset(ij);
00165     //  return *this;
00166     // }
00167     // random access
00168     // Edge operator()(int i, int j) const { 
00169     //  return TheGrid().edge(e + TheMap().offset(i,j));
00170     //}
00171     
00172     bool     IsDone()    const { return  (e > TheRange().MaxEdgeNum());}
00173     friend bool operator==(const self& ls, const self& rs) { return (ls.e == rs.e);}
00174     friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}
00175     friend bool operator< (const self& ls, const self& rs) { return (ls.e <  rs.e);}
00176   private:
00177     //    const indexmap_type& TheMap() const { return TheRange().TheEdgeMap();}
00178     edge_handle e;
00179   };
00180   typedef EdgeIterator_1 EdgeIterator;
00181 
00182 
00183 
00184   const Grid& TheGrid() const { return *g;}
00185 
00186   const index_type& ll() const {return TheVertexMap().ll();}
00187   const index_type& ur() const {return TheVertexMap().ur();}
00188 
00189   int  llx() const { return TheVertexMap().llx();}
00190   int  lly() const { return TheVertexMap().lly();}
00191   int  urx() const { return TheVertexMap().urx();}
00192   int  ury() const { return TheVertexMap().ury();}
00193   index_type side_vertex1(int s) const {
00194     return index_type(llx()+(NumOfXVertices()-1)* Grid::side_vertex_1_[s-1].x,
00195                       lly()+(NumOfYVertices()-1)* Grid::side_vertex_1_[s-1].y);
00196   }
00197   index_type side_vertex2(int s) const {
00198     return index_type(llx()+(NumOfXVertices()-1)* Grid::side_vertex_2_[s-1].x,
00199                       lly()+(NumOfYVertices()-1)* Grid::side_vertex_2_[s-1].y);
00200   }
00201   
00202   const indexmap_type& TheVertexMap() const {return vertex_index_map;}
00203   VertexIterator FirstVertex() const { return VertexIterator(TheGrid(),*this);}
00204   VertexIterator EndVertex()   const { return VertexIterator(MaxVertexNum() +1,TheGrid(),*this);}
00205   vertex_handle handle(Vertex const& V) const { return TheGrid().handle(V);}
00206   Vertex vertex(vertex_handle v) const { return TheGrid().vertex(TheVertexMap().index(v));}
00207   vertex_handle MinVertexNum()   const { return  TheVertexMap().n0();}
00208   vertex_handle MaxVertexNum()   const { return  TheVertexMap().nmax();}
00209   unsigned NumOfVertices() const { return TheVertexMap().range_size();}
00210   int NumOfXVertices() const { return (urx()-llx()+1);}
00211   int NumOfYVertices() const { return (ury()-lly()+1);}
00212 
00213   const indexmap_type& TheCellMap() const {return cell_index_map;}
00214   CellIterator FirstCell() const { return CellIterator(TheGrid(),*this);}
00215   CellIterator EndCell()   const { return CellIterator(MaxCellNum()+1,TheGrid(),*this);}
00216   cell_handle handle(Cell const& C) const { return TheGrid().handle(C);}
00217   Cell cell(cell_handle v) const { return TheGrid().cell(TheCellMap().index(v));}
00218   cell_handle MinCellNum()   const { return  TheCellMap().n0();}
00219   cell_handle MaxCellNum()   const { return  TheCellMap().nmax();}
00220   unsigned NumOfCells() const { return TheCellMap().range_size();}
00221   int NumOfXCells() const { return (urx()-llx());}
00222   int NumOfYCells() const { return (ury()-lly());}
00223 
00224 
00225   const indexmap_type& TheXEdgeMap() const {return xedge_index_map;}
00226   const indexmap_type& TheYEdgeMap() const {return yedge_index_map;}
00227   EdgeIterator FirstEdge() const { return EdgeIterator(TheGrid(),*this);}
00228   EdgeIterator EndEdge()   const { return EdgeIterator(MaxEdgeNum()+1,TheGrid(),*this);} 
00229   Edge edge(edge_handle e) const { 
00230     return (e <= TheXEdgeMap().nmax() 
00231             ?  TheGrid().xedge(TheXEdgeMap().index(e))
00232             :  TheGrid().yedge(TheYEdgeMap().index(e - (TheXEdgeMap().nmax() + 1)
00233                                                      + TheYEdgeMap().n0()))); 
00234   }
00235 
00236   edge_handle MinEdgeNum()   const { return  TheXEdgeMap().n0();}
00237   edge_handle MaxEdgeNum()   const { return  MinEdgeNum() + NumOfEdges() -1;}
00238   unsigned NumOfEdges() const { return(  TheXEdgeMap().range_size() 
00239                                        + TheYEdgeMap().range_size());}
00240   // aliases for facets
00241   unsigned NumOfFacets() const { return NumOfEdges();}
00242   EdgeIterator FirstFacet() const {return FirstEdge();}
00243   EdgeIterator EndFacet()   const {return EndEdge();} // past-the-end!
00244 private:
00245   const Grid* g;
00246   indexmap_type vertex_index_map;
00247   indexmap_type cell_index_map;
00248   indexmap_type xedge_index_map;
00249   indexmap_type yedge_index_map;
00250 };
00251 
00252 
00256 struct grid_types<SubrangeReg2D> {
00257   typedef SubrangeReg2D range_type;
00258   typedef  range_type::VertexIterator VertexIterator;
00259   typedef  range_type::EdgeIterator   EdgeIterator;
00260   typedef  range_type::EdgeIterator   FacetIterator;
00261   typedef  range_type::CellIterator   CellIterator;
00262 
00263   typedef grid_types<RegGrid2D> gt;
00264   typedef  gt::Vertex Vertex;
00265   typedef  gt::Edge   Edge;
00266   typedef  gt::Facet  Facet;
00267   typedef  gt::Cell   Cell;
00268 
00269   typedef  gt::vertex_handle vertex_handle; 
00270   typedef  gt::edge_handle   edge_handle;
00271   typedef  gt::cell_handle   cell_handle;
00272 
00273   typedef  gt::VertexOnCellIterator VertexOnCellIterator;
00274   typedef  gt::EdgeOnCellIterator   EdgeOnCellIterator;
00275   typedef  gt::CellOnCellIterator   CellOnCellIterator;
00276 };
00277 
00278 
00279 #endif
00280 

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

Generated at Tue Feb 26 16:08:10 2002 for GrAL Cartesian2D by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000