00001 #ifndef NMWR_GB_REG2D_SUBRANGE_H
00002 #define NMWR_GB_REG2D_SUBRANGE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Gral/Grids/Cartesian2D/cartesian-grid2d.h"
00020
00021 namespace GrAL {
00022
00023 namespace cartesian2d {
00024
00039 class SubrangeReg2D {
00040 public:
00041 typedef SubrangeReg2D Range;
00042 typedef RegGrid2D Grid;
00043 typedef Grid grid_type;
00044 typedef Grid::indexmap_type indexmap_type;
00045 typedef Grid::index_type index_type;
00046
00047 typedef Grid::vertex_handle vertex_handle;
00048 typedef Grid::Vertex Vertex;
00049 typedef Grid::cell_handle cell_handle;
00050 typedef Grid::Cell Cell;
00051 typedef Grid::edge_handle edge_handle;
00052 typedef Grid::Edge Edge;
00053
00055
00056
00058 SubrangeReg2D() : g(0) {}
00059
00061 SubrangeReg2D(const Grid& gg, const index_type& llv, const index_type& urv)
00062 : g(&gg),
00063 vertex_index_map(llv,urv),
00064 cell_index_map (llv,index_type(urv.x()-1,urv.y()-1)),
00065 xedge_index_map (llv,index_type(urv.x()-1,urv.y() )),
00066 yedge_index_map (llv,index_type(urv.x(), urv.y()-1))
00067 {}
00068
00070 SubrangeReg2D(const Grid& gg,int llx, int lly, int urx, int ury)
00071 : g(&gg),
00072 vertex_index_map(index_type(llx,lly),index_type(urx,ury)),
00073 cell_index_map (index_type(llx,lly),index_type(urx-1,ury-1)),
00074 xedge_index_map (index_type(llx,lly),index_type(urx-1,ury )),
00075 yedge_index_map (index_type(llx,lly),index_type(urx, ury-1))
00076
00077 {}
00084 SubrangeReg2D(const Grid& gg,
00085 const index_type& llv_v, const index_type& urv_v,
00086 const index_type& llv_c, const index_type& urv_c)
00087 : g(&gg),
00088 vertex_index_map(llv_v, urv_v),
00089 cell_index_map(llv_c, urv_c),
00090
00091 xedge_index_map (llv_v,index_type(urv_v.x()-1,urv_v.y() )),
00092 yedge_index_map (llv_v,index_type(urv_v.x(), urv_v.y()-1))
00093 {}
00095
00097 static unsigned dimension() { return 2;}
00098
00099
00100 class iterator_base_1 {
00101 public:
00102 typedef iterator_base_1 base;
00103 iterator_base_1(const Grid* gg, const Range* rr) : g(gg), r(rr) {}
00104 iterator_base_1(const Grid& gg, const Range& rr) : g(&gg), r(&rr) {}
00105 const Grid& TheGrid() const { return (*g);}
00106 const Range& TheRange() const { return (*r);}
00107 protected:
00108 const Grid* g;
00109 const Range* r;
00110 };
00111
00112 class VertexIterator_1 : public iterator_base_1 {
00113 public:
00114 typedef VertexIterator_1 self;
00115
00116 VertexIterator_1() : base(0,0), v(-1) {}
00117 VertexIterator_1(const Range& r) : base(r.TheGrid(), r) , v(r.MinVertexNum()) {}
00118 VertexIterator_1(const Grid* g, const Range* r) : base(g,r), v(r->MinVertexNum()) {}
00119 VertexIterator_1(const Grid& g, const Range& r) : base(g,r), v(r.MinVertexNum()) {}
00120 VertexIterator_1(vertex_handle vv, const Grid* g, const Range* r)
00121 : base(g,r), v(vv) {}
00122 VertexIterator_1(vertex_handle vv, const Grid& g, const Range& r)
00123 : base(g,r), v(vv) {}
00124
00125 self& operator++() { ++v; return (*this); }
00126 self operator++(int) { self tmp(*this); ++(*this); return tmp;}
00127 Vertex operator*() const { return TheRange().vertex(v);}
00128 vertex_handle handle() const { return v;}
00129
00130 bool IsDone() const { return (v > TheRange().MaxVertexNum());}
00131 friend bool operator==(const self& ls, const self& rs) { return (ls.v == rs.v);}
00132 friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}
00133 friend bool operator< (const self& ls, const self& rs) { return (ls.v < rs.v);}
00134
00135
00136 private:
00137 const indexmap_type& TheMap() const { return TheRange().TheVertexMap();}
00138 vertex_handle v;
00139 };
00140 typedef VertexIterator_1 VertexIterator;
00141
00142
00143 class CellIterator_1 : public iterator_base_1 {
00144 public:
00145 typedef CellIterator_1 self;
00146
00147 CellIterator_1() : base(0,0), c(-1) {}
00148 CellIterator_1(const Range& r) : base(r.TheGrid(), r), c(r.MinCellNum()) {}
00149 CellIterator_1(const Grid* g, const Range* r) : base(g,r), c(r->MinCellNum()) {}
00150 CellIterator_1(const Grid& g, const Range& r) : base(g,r), c(r.MinCellNum()) {}
00151 CellIterator_1(cell_handle cc, const Grid* g, const Range* r)
00152 : base(g,r), c(cc) {}
00153 CellIterator_1(cell_handle cc, const Grid& g, const Range& r)
00154 : base(g,r), c(cc) {}
00155
00156 self& operator++() {
00157 ++c;
00158 return (*this);
00159 }
00160 self operator++(int) { self tmp(*this); ++(*this); return tmp;}
00161 self& operator +=(const index_type& ij) {
00162 c+= TheMap().offset(ij);
00163 return *this;
00164 }
00165 Cell operator*() const { return TheRange().cell(c);}
00166 cell_handle handle() const { return c;}
00167
00168 bool IsDone() const { return (c > TheRange().MaxCellNum());}
00169 friend bool operator==(const self& ls, const self& rs) { return (ls.c == rs.c);}
00170 friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}
00171 friend bool operator< (const self& ls, const self& rs) { return (ls.c < rs.c);}
00172
00173 private:
00174 const indexmap_type& TheMap() const { return TheRange().TheCellMap();}
00175 cell_handle c;
00176 };
00177 typedef CellIterator_1 CellIterator;
00178
00179 class EdgeIterator_1 : public iterator_base_1 {
00180 public:
00181 typedef EdgeIterator_1 self;
00182
00183 EdgeIterator_1() : base(0,0), e(-1) {}
00184 EdgeIterator_1(const Grid* g, const Range* r) : base(g,r), e(r->MinEdgeNum()) {}
00185 EdgeIterator_1(const Grid& g, const Range& r) : base(g,r), e(r.MinEdgeNum()) {}
00186 EdgeIterator_1(edge_handle ee, const Grid* g, const Range* r)
00187 : base(g,r), e(ee) {}
00188 EdgeIterator_1(edge_handle ee, const Grid& g, const Range& r)
00189 : base(g,r), e(ee) {}
00190
00191 self& operator++() {
00192 ++e;
00193 return (*this);
00194 }
00195 self operator++(int) { self tmp(*this); ++(*this); return tmp;}
00196 Edge operator*() const { return TheRange().edge(e);}
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 bool IsDone() const { return (e > TheRange().MaxEdgeNum());}
00208 friend bool operator==(const self& ls, const self& rs) { return (ls.e == rs.e);}
00209 friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}
00210 friend bool operator< (const self& ls, const self& rs) { return (ls.e < rs.e);}
00211 private:
00212
00213 edge_handle e;
00214 };
00215 typedef EdgeIterator_1 EdgeIterator;
00216
00217
00219 const Grid& TheGrid() const { return *g;}
00220
00222
00223
00225 const index_type& ll() const {return TheVertexMap().ll();}
00227 const index_type& ur() const {return TheVertexMap().ur();}
00228 int llx() const { return TheVertexMap().llx();}
00229 int lly() const { return TheVertexMap().lly();}
00230 int urx() const { return TheVertexMap().urx();}
00231 int ury() const { return TheVertexMap().ury();}
00232
00233 index_type low_vertex_index() const { return TheVertexMap().ll();}
00234 index_type high_vertex_index() const { return TheVertexMap().ur();}
00235 index_type beyond_vertex_index() const { return TheVertexMap().ur()+index_type(1);}
00236 index_type low_cell_index() const { return TheCellMap().ll();}
00237 index_type high_cell_index() const { return TheCellMap().ur();}
00238 index_type beyond_cell_index() const { return TheCellMap().ur()+index_type(1);}
00240
00241 index_type side_vertex1(int s) const {
00242 return index_type(llx()+(NumOfXVertices()-1)* Grid::side_vertex_1_[s-1].x(),
00243 lly()+(NumOfYVertices()-1)* Grid::side_vertex_1_[s-1].y());
00244 }
00245 index_type side_vertex2(int s) const {
00246 return index_type(llx()+(NumOfXVertices()-1)* Grid::side_vertex_2_[s-1].x(),
00247 lly()+(NumOfYVertices()-1)* Grid::side_vertex_2_[s-1].y());
00248 }
00249
00251
00254 VertexIterator FirstVertex() const { return VertexIterator(TheGrid(),*this);}
00255 VertexIterator EndVertex() const { return VertexIterator(MaxVertexNum() +1,TheGrid(),*this);}
00256 EdgeIterator FirstEdge() const { return EdgeIterator(TheGrid(),*this);}
00257 EdgeIterator EndEdge() const { return EdgeIterator(MaxEdgeNum()+1,TheGrid(),*this);}
00258 EdgeIterator FirstFacet() const {return FirstEdge();}
00259 EdgeIterator EndFacet() const {return EndEdge();}
00260 CellIterator FirstCell() const { return CellIterator(TheGrid(),*this);}
00261 CellIterator EndCell() const { return CellIterator(MaxCellNum()+1,TheGrid(),*this);}
00262
00263 unsigned NumOfVertices() const { return TheVertexMap().range_size();}
00264 unsigned NumOfEdges() const { return( TheXEdgeMap().range_size()
00265 + TheYEdgeMap().range_size());}
00266 unsigned NumOfFacets() const { return NumOfEdges();}
00267 unsigned NumOfCells() const { return TheCellMap().range_size();}
00269
00270
00272
00275 int NumOfXVertices() const { return (urx()-llx()+1);}
00276 int NumOfYVertices() const { return (ury()-lly()+1);}
00277 int NumOfXCells() const { return (urx()-llx());}
00278 int NumOfYCells() const { return (ury()-lly());}
00280
00282
00285 vertex_handle handle(Vertex const& V) const { return TheGrid().handle(V);}
00286 Vertex vertex(vertex_handle v) const { return TheGrid().vertex(TheVertexMap().index(v));}
00287 vertex_handle MinVertexNum() const { return TheVertexMap().n0();}
00288 vertex_handle MaxVertexNum() const { return TheVertexMap().nmax();}
00289
00290 Edge edge(edge_handle e) const {
00291 return (e <= TheXEdgeMap().nmax()
00292 ? TheGrid().xedge(TheXEdgeMap().index(e))
00293 : TheGrid().yedge(TheYEdgeMap().index(e - (TheXEdgeMap().nmax() + 1)
00294 + TheYEdgeMap().n0())));
00295 }
00296 edge_handle MinEdgeNum() const { return TheXEdgeMap().n0();}
00297 edge_handle MaxEdgeNum() const { return MinEdgeNum() + NumOfEdges() -1;}
00298
00299 cell_handle handle(Cell const& C) const { return TheGrid().handle(C);}
00300 Cell cell(cell_handle v) const { return TheGrid().cell(TheCellMap().index(v));}
00301 cell_handle MinCellNum() const { return TheCellMap().n0();}
00302 cell_handle MaxCellNum() const { return TheCellMap().nmax();}
00304
00305
00306 const indexmap_type& TheVertexMap() const {return vertex_index_map;}
00307 const indexmap_type& TheXEdgeMap() const {return xedge_index_map;}
00308 const indexmap_type& TheYEdgeMap() const {return yedge_index_map;}
00309 const indexmap_type& TheCellMap() const {return cell_index_map;}
00310
00311
00316 typedef grid_type::archetype_iterator archetype_iterator;
00317 typedef grid_type::archetype_type archetype_type;
00318 typedef grid_type::archetype_handle archetype_handle;
00319
00320 static archetype_iterator BeginArchetype() { return grid_type::BeginArchetype();}
00321 static archetype_iterator EndArchetype() { return grid_type::EndArchetype();}
00322 static archetype_type const& Archetype(archetype_handle = 0) { return *BeginArchetype();}
00323 static archetype_type const& ArchetypeOf (Cell const&)
00324 { return *BeginArchetype();}
00325 static archetype_type const& ArchetypeOf (cell_handle)
00326 { return *BeginArchetype();}
00327 static archetype_handle archetype_of(cell_handle)
00328 { return 0;}
00329 static archetype_handle archetype_of(Cell const&)
00330 { return 0;}
00331 static unsigned NumOfArchetypes() { return 1;}
00334 private:
00335 const Grid* g;
00336 indexmap_type vertex_index_map;
00337 indexmap_type cell_index_map;
00338 indexmap_type xedge_index_map;
00339 indexmap_type yedge_index_map;
00340 };
00341
00342 }
00343
00344
00348 template<>
00349 struct grid_types<cartesian2d::SubrangeReg2D> {
00350 typedef cartesian2d::SubrangeReg2D range_type;
00351 typedef range_type::VertexIterator VertexIterator;
00352 typedef range_type::EdgeIterator EdgeIterator;
00353 typedef range_type::EdgeIterator FacetIterator;
00354 typedef range_type::CellIterator CellIterator;
00355
00356 typedef grid_types<cartesian2d::RegGrid2D> gt;
00357 typedef gt::Vertex Vertex;
00358 typedef gt::Edge Edge;
00359 typedef gt::Facet Facet;
00360 typedef gt::Cell Cell;
00361
00362 typedef gt::vertex_handle vertex_handle;
00363 typedef gt::edge_handle edge_handle;
00364 typedef gt::cell_handle cell_handle;
00365
00366 typedef gt::VertexOnCellIterator VertexOnCellIterator;
00367 typedef gt::EdgeOnCellIterator EdgeOnCellIterator;
00368 typedef gt::CellOnCellIterator CellOnCellIterator;
00369
00370 typedef gt::archetype_type archetype_type;
00371 typedef gt::archetype_handle archetype_handle;
00372 typedef gt::archetype_iterator archetype_iterator;
00373 typedef grid_types<archetype_type> archgt;
00374
00375 };
00376
00377 }
00378
00379 #endif
00380