00001 #ifndef GRAL_GB_VIEWS_RESTRICTED_GRID_VIEW_H
00002 #define GRAL_GB_VIEWS_RESTRICTED_GRID_VIEW_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "Gral/Base/common-grid-basics.h"
00019 #include "Gral/Base/archetypes-from-base.h"
00020 #include "Gral/Base/grid-function-hash.h"
00021 #include "Gral/Base/wrap-elements.h"
00022
00023 #include "Gral/Subranges/enumerated-element-range.h"
00024 #include "Gral/Iterators/closure-iterator.h"
00025
00026
00027
00028 #include <boost/mpl/if.hpp>
00029
00030 namespace GrAL {
00031
00032
00043 namespace restricted_grid_view {
00050 template<class GT, class PRED> struct cfg {
00051 typedef GT gt;
00052 typedef typename gt::grid_type grid_type;
00053
00054 typedef PRED pred_type;
00055 };
00056
00057 template<class CFG> class grid_view;
00058
00059 template<class CFG> class vertex;
00060 template<class CFG>
00061 class cell;
00062
00063 template<class CFG>
00064 class vertex_iterator;
00065 template<class CFG>
00066 class cell_iterator;
00067
00068 template<class CFG>
00069 class vertex_on_cell_iterator;
00070 template<class CFG>
00071 class cell_on_cell_iterator;
00072 template<class CFG>
00073 class cell_on_vertex_iterator;
00074
00075
00076 template<class CFG>
00077 struct grid_types_grid_view_base1
00078 : public archetypes_from_base_grid_types<typename CFG::gt>,
00079 public grid_types_detail::grid_types_root
00080 {
00081 typedef grid_types_grid_view_base1<CFG> self;
00082 typedef grid_view<CFG> grid_type;
00083
00084 typedef typename CFG::gt bgt;
00085 typedef typename bgt::dimension_tag dimension_tag;
00086 typedef typename bgt::size_type size_type;
00087 typedef typename bgt::vertex_handle vertex_handle;
00088 typedef typename bgt::cell_handle cell_handle;
00089
00090 typedef vertex <CFG> Vertex;
00091 typedef cell <CFG> Cell;
00092 typedef cell_iterator <CFG> CellIterator;
00093 typedef vertex_iterator<CFG> VertexIterator;
00094
00095 typedef vertex_on_cell_iterator<CFG> VertexOnCellIterator;
00096 };
00097
00098
00099 template<class CFG>
00100 struct grid_types_grid_view_base2
00101 : public wrap_all_downward_incidence_iterator_types<grid_types_grid_view_base1<CFG>, typename CFG::gt>
00102 {};
00103
00104 template<class CFG>
00105 struct grid_types_grid_view_base :
00106 public grid_types_grid_view_base2<CFG>
00107 {};
00108
00109
00110
00111 template<class CFG>
00112 struct grid_types_grid_view_all :
00113 public grid_types_grid_view_base<CFG>
00114 {
00115 typedef grid_types_grid_view_base<CFG> base;
00116
00117 typedef typename boost::mpl::if_c<has_CellOnCellIterator<typename CFG::gt>::value,
00118 cell_on_cell_iterator<CFG>,
00119 typename incidence_iterator_cd<base,0,0>::type>::type
00120 CellOnCellIterator;
00121 typedef typename boost::mpl::if_c<has_CellOnVertexIterator<typename CFG::gt>::value,
00122 cell_on_vertex_iterator<CFG>,
00123 typename incidence_iterator_cd_d<base,0,0>::type>::type
00124 CellOnVertexIterator;
00125
00126 typedef closure_iterator<typename base::CellIterator,
00127 typename base::EdgeOnCellIterator, base> EdgeIterator;
00128
00129 static typename base::cell_handle invalid_cell_handle(typename base::grid_type const& g)
00130 { return CFG::gt::invalid_cell_handle(g.BaseGrid()); }
00131
00132 };
00133
00134 }
00135
00136
00144 template<class CFG>
00145 struct grid_types<restricted_grid_view::grid_view<CFG> >
00146 : public grid_types_base<restricted_grid_view::grid_types_grid_view_all<CFG> >
00147 {};
00148
00149
00150 template<class CFG>
00151 struct element_traits<restricted_grid_view::vertex<CFG> >
00152 : public element_traits_vertex_base<restricted_grid_view::grid_view<CFG> >
00153 {
00154 typedef element_traits_vertex_base<restricted_grid_view::grid_view<CFG> > base;
00155 typedef typename base::hasher_type_elem_base hasher_type;
00156 };
00157
00158
00159 template<class CFG>
00160 struct element_traits<restricted_grid_view::cell<CFG> >
00161 : public element_traits_cell_base<restricted_grid_view::grid_view<CFG> >
00162 {
00163 typedef element_traits_cell_base<restricted_grid_view::grid_view<CFG> > base;
00164 typedef typename base::hasher_type_elem_base hasher_type;
00165 };
00166
00167
00168
00169
00170
00171
00172
00173 namespace restricted_grid_view {
00174
00175
00176
00177 template<class CFG, class VERTEX, unsigned HASCELLONVERTEX>
00178 struct vertex_mixin_cov_iterator { };
00179 template<class CFG, class VERTEX>
00180 struct vertex_mixin_cov_iterator<CFG, VERTEX, 1>
00181 {
00182 cell_on_vertex_iterator<CFG> FirstCell() const;
00183 unsigned NumOfCells() const;
00184 };
00185
00186
00187 template<class CFG, class CELL, unsigned HASCELLONCELL>
00188 struct cell_mixin_coc_iterator { };
00189 template<class CFG, class CELL>
00190 struct cell_mixin_coc_iterator<CFG, CELL, 1>
00191 {
00192 cell_on_cell_iterator<CFG> FirstCell() const;
00193 cell_on_cell_iterator<CFG> EndCell() const;
00194 unsigned NumOfCells() const;
00195 };
00196
00197
00198
00230 template<class CFG>
00231 class grid_view : public archetypes_from_base<grid_view<CFG>, typename CFG::grid_type, typename CFG::gt> {
00232 typedef grid_view<CFG> self;
00233 public:
00234 typedef self grid_type;
00235 typedef typename CFG::grid_type base_grid_type;
00236 typedef typename CFG::pred_type pred_type;
00237 typedef typename CFG::gt basegt;
00238
00239 typedef typename basegt::Vertex baseVertex;
00240 typedef typename basegt::Cell baseCell;
00241 typedef typename basegt::CellIterator baseCellIterator;
00242 typedef typename basegt::VertexOnCellIterator baseVertexOnCellIterator;
00243 typedef typename basegt::vertex_handle vertex_handle;
00244 typedef typename basegt::cell_handle cell_handle;
00245
00246 typedef enumerated_vertex_range<base_grid_type> range_type;
00247 typedef grid_types_grid_view_base1<CFG> gt;
00248
00249 typedef typename gt::size_type size_type;
00250 enum { dim = gt::dimension_tag::dim };
00251 typedef grid_view_category_d<dim> category;
00252
00253 private:
00254 ref_ptr<base_grid_type const> g;
00255 ref_ptr<pred_type> inside_p;
00256
00257 mutable range_type range;
00258 mutable bool vertices_initialized;
00259 mutable size_type num_of_cells;
00260 public:
00261 grid_view() {}
00262 grid_view(base_grid_type const& gg,
00263 pred_type ins)
00264 { init(const_ref_to_ref_ptr(gg), copy_to_ref_ptr(ins)); }
00265
00266 grid_view(ref_ptr<base_grid_type const> gg,
00267 ref_ptr<pred_type> ins)
00268 { init(gg, ins);}
00269
00270 void init(ref_ptr<base_grid_type const> gg,
00271 ref_ptr<pred_type> ins)
00272 {
00273 g = gg;
00274 inside_p = ins;
00275 range.set_grid(g);
00276 vertices_initialized = false;
00277 num_of_cells = -1;
00278 }
00279
00280 unsigned dimension() const { return g->dimension();}
00281 public:
00282 typedef vertex <CFG> Vertex;
00283 typedef vertex_iterator<CFG> VertexIterator;
00284 typedef cell <CFG> Cell;
00285 typedef cell_iterator <CFG> CellIterator;
00286
00287 VertexIterator FirstVertex() const { init_vertices(); return VertexIterator(*this);}
00288 VertexIterator EndVertex() const { init_vertices(); return VertexIterator(*this, range.EndVertex());}
00289 size_type NumOfVertices() const { init_vertices(); return range.NumOfVertices();}
00290
00291 CellIterator FirstCell() const { return CellIterator(*this);}
00292 CellIterator EndCell() const { return CellIterator(*this, BaseGrid().EndCell());}
00293 size_type NumOfCells() const { if(num_of_cells < 0) init_num_cells(); return num_of_cells;}
00294
00295
00296 base_grid_type const& BaseGrid() const { return *g;}
00297
00298 base_grid_type const& TheGrid() const { return *g;}
00299
00300 pred_type const& pred() const { return *inside_p;}
00301 bool inside(baseCell const& c) const { return (*inside_p)(c);}
00302
00303 bool valid_cell (cell_handle h) const { return BaseGrid().valid_cell(h) && inside(baseCell(BaseGrid(), h));}
00304
00305
00306 private:
00307 void init_num_cells() const;
00308 void init_vertices() const;
00309
00310 friend class restricted_grid_view::vertex_iterator<CFG>;
00311 friend class restricted_grid_view::vertex <CFG>;
00312 friend class restricted_grid_view::cell_iterator <CFG>;
00313
00314 };
00315
00316
00317
00318
00319
00320
00321
00322 template<class CFG>
00323 class vertex : public vertex_mixin_cov_iterator<CFG, vertex<CFG>,
00324 has_CellOnVertexIterator<typename CFG::gt>::result>
00325 {
00326 typedef vertex<CFG> self;
00327 public:
00328 typedef grid_view<CFG> grid_type;
00329 typedef typename grid_type::baseVertex baseVertex;
00330 typedef typename grid_type::baseVertex base_element_type;
00331 typedef typename grid_type::vertex_handle vertex_handle;
00332
00333 typedef vertex_type_tag element_type_tag;
00334 typedef grid_vertex_category category;
00335 private:
00336 grid_type const* g;
00337 baseVertex v;
00338 public:
00339 vertex() : g(0) {}
00340 vertex(grid_type const& gg)
00341 : g(&gg)
00342 {
00343 g->init_vertices();
00344 v = * g->range.FirstVertex();
00345 }
00346
00347
00348
00349 vertex(grid_type const& gg, vertex_handle vv)
00350 : g(&gg)
00351 {
00352 g->init_vertices();
00353 v = baseVertex(g->BaseGrid(), vv);
00354 }
00355 vertex(grid_type const& gg, baseVertex vv)
00356 : g(&gg)
00357 {
00358 g->init_vertices();
00359 v = vv;
00360 }
00361
00362 operator baseVertex() const { return v;}
00363 baseVertex Base() const { return v;}
00364 vertex_handle handle() const { return v.handle();}
00365 grid_type const& TheGrid () const { return *g;}
00366 grid_type const& BaseGrid() const { return *g;}
00367
00368 bool operator==(self const& rhs) const { return v == rhs.v;}
00369 bool operator!=(self const& rhs) const { return !(*this == rhs);}
00370 bool operator< (self const& rhs) const { return v < rhs.v;}
00371 };
00372
00373
00374
00375 template<class CFG>
00376 class vertex_iterator {
00377 typedef vertex_iterator<CFG> self;
00378 public:
00379 typedef grid_vertex_iterator_category category;
00380 typedef grid_view<CFG> grid_type;
00381 typedef typename grid_type::range_type range_type;
00382 typedef typename range_type::VertexIterator rangeVertexIterator;
00383 typedef typename grid_type::baseVertex baseVertex;
00384 typedef typename grid_type::Vertex Vertex;
00385 typedef typename grid_type::vertex_handle vertex_handle;
00386
00387 typedef grid_type anchor_type;
00388 typedef Vertex value_type;
00389 private:
00390 grid_type const* g;
00391 rangeVertexIterator v;
00392 public:
00393 vertex_iterator() : g(0) {}
00394 vertex_iterator(grid_type const& gg)
00395 : g(&gg)
00396 {
00397 v = g->range.FirstVertex();
00398 }
00399 vertex_iterator(grid_type const& gg, rangeVertexIterator vv)
00400 : g(&gg), v(vv)
00401 {
00402 }
00403
00404
00405 self& operator++() { cv(); ++v; return *this;}
00406 Vertex operator*() const { cv(); return Vertex(*g, handle());}
00407 operator baseVertex() const { cv(); return *v;}
00408 baseVertex Base() const { cv(); return *v;}
00409 bool IsDone() const { cb(); return v.IsDone();}
00410
00411 anchor_type const& TheAnchor() const { cb(); return *g;}
00412 grid_type const& TheGrid () const { cb(); return *g;}
00413 grid_type const& BaseGrid () const { cb(); return *g;}
00414
00415 vertex_handle handle() const { return v.handle();}
00416
00417 bool operator==(self const& rhs) const { cb(); rhs.cb(); return v == rhs.v;}
00418 bool operator!=(self const& rhs) const { return !(*this == rhs);}
00419 bool operator< (self const& rhs) const { cb(); rhs.cb(); return v < rhs.v;}
00420
00421 static self begin(anchor_type const& gg) { return gg.FirstVertex();}
00422 static self end (anchor_type const& gg) { return gg.EndVertex ();}
00423
00424 bool bound() const { return g != 0;}
00425 bool valid() const { return bound() && !IsDone();}
00426 void cb() const { REQUIRE(bound(),"",1);}
00427 void cv() const { REQUIRE(valid(),"", 1);}
00428 };
00429
00430
00431
00432
00433 template<class CFG>
00434 class cell : public cell_mixin_coc_iterator<CFG, cell<CFG>,
00435 has_CellOnCellIterator<typename CFG::gt>::result>
00436 {
00437 typedef cell<CFG> self;
00438 typedef grid_types_grid_view_base<CFG> gt;
00439 typedef grid_types<typename gt::archetype_type> archgt;
00440 public:
00441 typedef cell_type_tag element_type_tag;
00442 typedef grid_cell_category category;
00443
00444 typedef grid_view<CFG> grid_type;
00445 typedef grid_types<typename grid_type ::range_type> rgt;
00446 typedef typename grid_type::baseCell baseCell;
00447 typedef typename grid_type::baseCell base_element_type;
00448 typedef typename grid_type::cell_handle cell_handle;
00449 typedef typename grid_type::baseCellIterator baseCellIterator;
00450
00451 private:
00452 grid_type const* g;
00453 baseCell c;
00454 public:
00455 cell() : g(0) {}
00456 cell(grid_type const& gg)
00457 : g(&gg) {}
00458 cell(grid_type const& gg, baseCell cc)
00459 : g(&gg), c(cc)
00460 { REQUIRE(g->inside(c), "Base cell not in component!", 1); }
00461 cell(grid_type const& gg, cell_handle h)
00462 : g(&gg), c(g->BaseGrid(),h)
00463 { REQUIRE(g->inside(c), "Base cell not in component!", 1); }
00464
00465
00466 operator baseCell() const { return c;}
00467 baseCell Base() const { return c;}
00468 grid_type const& TheGrid() const { return *g;}
00469 cell_handle handle() const { return c.handle();}
00470 int NumOfVertices() const { return Base().NumOfVertices();}
00471 vertex_on_cell_iterator<CFG> FirstVertex() const;
00472 vertex_on_cell_iterator<CFG> EndVertex () const;
00473
00474 vertex<CFG> V(typename archgt::Vertex v) const {
00475 return vertex<CFG>(TheGrid(), Base().V(v));
00476 }
00477
00478 bool operator==(self const& rhs) const { cb(); rhs.cb(); return c == rhs.c;}
00479 bool operator!=(self const& rhs) const { return !(*this == rhs);}
00480 bool operator< (self const& rhs) const { cb(); rhs.cb(); return c < rhs.c;}
00481
00482 bool bound() const { return g != 0;}
00483 bool valid() const { return bound() && c.valid();}
00484 void cb() const { REQUIRE(bound(),"",1);}
00485 void cv() const { REQUIRE(valid(),"", 1);}
00486 };
00487
00488
00489
00490
00491 template<class CFG>
00492 class cell_iterator {
00493 typedef cell_iterator<CFG> self;
00494 public:
00495 typedef grid_cell_iterator_category category;
00496 typedef grid_view<CFG> grid_type;
00497 typedef grid_types<typename grid_type ::range_type> rgt;
00498 typedef typename grid_type::baseCell baseCell;
00499 typedef typename grid_type::cell_handle cell_handle;
00500 typedef typename grid_type::baseCellIterator baseCellIterator;
00501
00502
00503 typedef grid_type anchor_type;
00504 typedef cell<CFG> value_type;
00505 private:
00506 ref_ptr<grid_type const> g;
00507 baseCellIterator c;
00508 public:
00509 cell_iterator() : g(0) {}
00510 cell_iterator(grid_type const& gg)
00511 : g(gg)
00512 {
00513 c = g->BaseGrid().FirstCell();
00514 advance_till_valid();
00515 }
00516 cell_iterator(grid_type const& gg, baseCellIterator cc) : g(gg), c(cc) {}
00517
00518 self& operator++() { cv(); ++c; advance_till_valid(); return *this;}
00519 cell<CFG> operator*() const { cv(); return cell<CFG>(*g,*c); }
00520 operator baseCell() const { cv(); return *c;}
00521 baseCell Base() const { cv(); return *c;}
00522 bool IsDone() const { cb(); return c.IsDone();}
00523
00524 cell_handle handle() const { cv(); return c.handle();}
00525
00526
00527
00528
00529 anchor_type const& TheAnchor() const { cb(); return *g;}
00530 grid_type const& TheGrid () const { cb(); return *g;}
00531 grid_type const& BaseGrid () const { cb(); return *g;}
00532
00533 static self begin(anchor_type const& gg) { return gg.FirstCell();}
00534 static self end (anchor_type const& gg) { return gg.EndCell ();}
00535
00536 bool operator==(self const& rhs) const { cb(); rhs.cb(); return c == rhs.c;}
00537 bool operator!=(self const& rhs) const { return !(*this == rhs);}
00538 bool operator< (self const& rhs) const { cb(); rhs.cb(); return c < rhs.c;}
00539
00540 bool bound() const { return g != 0;}
00541 bool valid() const { return bound() && !IsDone();}
00542 void cb() const { REQUIRE(bound(),"",1);}
00543 void cv() const { REQUIRE(valid(),"", 1);}
00544 private:
00545 void advance_till_valid() {
00546 while(! IsDone() && ! g->inside(*c))
00547 ++c;
00548 }
00549 };
00550
00551
00552
00553 template<class CFG>
00554 class vertex_on_cell_iterator {
00555 typedef vertex_on_cell_iterator<CFG> self;
00556 public:
00557 typedef grid_view<CFG> grid_type;
00558 typedef typename grid_type::baseVertexOnCellIterator baseVertexOnCellIterator;
00559 typedef typename grid_type::vertex_handle vertex_handle;
00560 typedef typename grid_type::Cell Cell;
00561 typedef typename grid_type::Vertex Vertex;
00562
00563 typedef grid_incidence_iterator_category_d<0,0> category;
00564 typedef Cell anchor_type;
00565 typedef Vertex value_type;
00566 private:
00567 typedef grid_types_grid_view_base<CFG> gt;
00568 typedef grid_types<typename gt::archetype_type> archgt;
00569 typedef typename archgt::vertex_handle arch_vertex_handle;
00570 private:
00571 Cell c;
00572 baseVertexOnCellIterator vc;
00573 public:
00574 vertex_on_cell_iterator() {}
00575 vertex_on_cell_iterator(Cell const& cc) : c(cc), vc(c.Base()) {}
00576 vertex_on_cell_iterator(Cell const& cc, baseVertexOnCellIterator vcc) : c(cc), vc(vcc) {}
00577
00578 self& operator++() { ++vc; return *this;}
00579 Vertex operator*() const { return Vertex(TheGrid(),handle());}
00580 bool IsDone() const { return vc.IsDone();}
00581
00582 vertex_handle handle() const { return vc.handle();}
00583 arch_vertex_handle local_handle() const { return vc.local_handle();}
00584
00585 grid_type const& TheGrid() const { return c.TheGrid();}
00586 anchor_type const& TheAnchor() const { return c;}
00587 anchor_type const& TheCell() const { return c;}
00588
00589 bool operator==(self const& rhs) const { return c == rhs.c && vc == rhs.vc;}
00590 bool operator!=(self const& rhs) const { return !(*this == rhs);}
00591
00592 };
00593
00594
00595 template<class CFG>
00596 inline
00597 vertex_on_cell_iterator<CFG>
00598 cell<CFG>::FirstVertex() const
00599 { return vertex_on_cell_iterator<CFG>(*this);}
00600
00601 template<class CFG>
00602 inline
00603 vertex_on_cell_iterator<CFG>
00604 cell<CFG>::EndVertex() const
00605 { return vertex_on_cell_iterator<CFG>(*this, Base().EndVertex());}
00606
00607
00608
00609
00610
00611 template<class CFG>
00612 class cell_on_cell_iterator {
00613 typedef cell_on_cell_iterator<CFG> self;
00614 public:
00615
00616 typedef grid_view<CFG> grid_type;
00617 typedef typename CFG::gt bgt;
00618 typedef typename bgt::CellOnCellIterator baseCellOnCellIterator;
00619 typedef grid_types<grid_type> gt;
00620 typedef typename grid_type::cell_handle cell_handle;
00621 typedef typename grid_type::Cell Cell;
00622
00623 typedef grid_incidence_iterator_category_cd<0,0> category;
00624 typedef Cell value_type;
00625 typedef Cell anchor_type;
00626 private:
00627 Cell c;
00628 baseCellOnCellIterator cc;
00629 public:
00630 cell_on_cell_iterator() {}
00631 cell_on_cell_iterator(Cell const& c1) : c(c1), cc(c1.Base()) { advance_till_valid();}
00632 cell_on_cell_iterator(Cell const& c1, baseCellOnCellIterator cc1) : c(c1), cc(cc1) { advance_till_valid();}
00633
00634 self& operator++() { ++cc; advance_till_valid(); return *this;}
00635 Cell operator*() const { return Cell(TheGrid(),*cc);}
00636 bool IsDone() const { return cc.IsDone();}
00637 cell_handle handle() const { return cc.handle();}
00638
00639 grid_type const& TheGrid () const { return c.TheGrid();}
00640 Cell const& TheCell () const { return c;}
00641 Cell const& TheAnchor() const { return c;}
00642 typename gt::Facet TheFacet() const { return typename gt::Facet(TheGrid(), cc.TheFacet());}
00643
00644 bool operator==(self const& rhs) const { return c == rhs.c && cc == rhs.cc;}
00645 bool operator!=(self const& rhs) const { return !(*this == rhs);}
00646
00647 private:
00648 void advance_till_valid() {
00649 while(!cc.IsDone() && ! TheGrid().inside(*cc))
00650 ++cc;
00651 }
00652 };
00653
00654
00655
00656
00657
00658 template<class CFG, class CELL>
00659 cell_on_cell_iterator<CFG>
00660 cell_mixin_coc_iterator<CFG, CELL, 1>::FirstCell() const
00661 { return cell_on_cell_iterator<CFG>(static_cast<CELL const&>(*this)); }
00662
00663 template<class CFG, class CELL>
00664 cell_on_cell_iterator<CFG>
00665 cell_mixin_coc_iterator<CFG, CELL, 1>::EndCell() const
00666 { return cell_on_cell_iterator<CFG>(static_cast<CELL const&>(*this),
00667 static_cast<CELL const&>(*this).Base().EndCell()); }
00668
00669
00670 template<class CFG, class CELL>
00671 unsigned
00672 cell_mixin_coc_iterator<CFG, CELL, 1>::NumOfCells() const
00673 {
00674 unsigned n = 0;
00675 cell_on_cell_iterator<CFG> cc = FirstCell();
00676 while(! cc.IsDone()) {
00677 ++cc;
00678 ++n;
00679 }
00680 return n;
00681 }
00682
00683
00684
00685
00686 template<class CFG>
00687 class cell_on_vertex_iterator {
00688 typedef cell_on_vertex_iterator<CFG> self;
00689 public:
00690 typedef grid_view<CFG> grid_type;
00691 typedef typename CFG::gt bgt;
00692 typedef typename bgt::CellOnVertexIterator baseCellOnVertexIterator;
00693 typedef typename grid_type::cell_handle cell_handle;
00694 typedef typename grid_type::Cell Cell;
00695 typedef typename grid_type::Vertex Vertex;
00696
00697 typedef grid_incidence_iterator_category_d<grid_type::dim,0> category;
00698 typedef Cell value_type;
00699 typedef Vertex anchor_type;
00700 private:
00701 Vertex v;
00702 baseCellOnVertexIterator cv;
00703 public:
00704 cell_on_vertex_iterator() {}
00705 cell_on_vertex_iterator(Vertex const& v1) : v(v1), cv(v1.Base()) {}
00706
00707 self& operator++() { ++cv; advance_till_valid(); return *this;}
00708 Cell operator*() const { return Cell(TheGrid(),*cv);}
00709 bool IsDone() const { return cv.IsDone();}
00710 grid_type const& TheGrid() const { return v.TheGrid();}
00711 anchor_type const& TheAnchor() const { return v;}
00712
00713 cell_handle handle() const { return cv.handle();}
00714
00715 bool operator==(self const& rhs) const { return v == rhs.v && cv == rhs.cv;}
00716 bool operator!=(self const& rhs) const { return !(*this == rhs);}
00717
00718 private:
00719 void advance_till_valid() {
00720 while(!cv.IsDone() && ! TheGrid().inside(*cv))
00721 ++cv;
00722 }
00723 };
00724
00725
00726 template<class CFG, class VERTEX>
00727 cell_on_vertex_iterator<CFG>
00728 vertex_mixin_cov_iterator<CFG, VERTEX, 1>::FirstCell() const
00729 { return cell_on_vertex_iterator<CFG>(static_cast<VERTEX const&>(*this)); }
00730
00731 template<class CFG, class VERTEX>
00732 unsigned
00733 vertex_mixin_cov_iterator<CFG, VERTEX, 1>::NumOfCells() const
00734 {
00735 unsigned n = 0;
00736 cell_on_vertex_iterator<CFG> cv = FirstCell();
00737 while(! cv.IsDone()) {
00738 ++cv;
00739 ++n;
00740 }
00741 return n;
00742 }
00743
00744
00745
00746 template<class CFG>
00747 vertex_iterator<CFG>
00748 gral_begin(grid_view<CFG> const& g, vertex_iterator<CFG>)
00749 { return g.FirstVertex();}
00750
00751 template<class CFG>
00752 vertex_iterator<CFG>
00753 gral_end(grid_view<CFG> const& g, vertex_iterator<CFG>)
00754 { return g.EndVertex();}
00755
00756 template<class CFG>
00757 typename grid_types<grid_view<CFG> >::size_type
00758 gral_size(grid_view<CFG> const& g, vertex_iterator<CFG>)
00759 { return g.NumOfVertices();}
00760
00761
00762
00763 template<class CFG>
00764 cell_iterator<CFG>
00765 gral_begin(grid_view<CFG> const& g, cell_iterator<CFG>)
00766 { return g.FirstCell();}
00767
00768 template<class CFG>
00769 cell_iterator<CFG>
00770 gral_end(grid_view<CFG> const& g, cell_iterator<CFG>)
00771 { return g.EndCell();}
00772
00773 template<class CFG>
00774 typename grid_types<grid_view<CFG> >::size_type
00775 gral_size(grid_view<CFG> const& g, cell_iterator<CFG>)
00776 { return g.NumOfCells();}
00777
00778
00779 template<class CFG>
00780 vertex_on_cell_iterator<CFG>
00781 gral_begin(cell<CFG> const& c, vertex_on_cell_iterator<CFG>)
00782 { return c.FirstVertex();}
00783
00784 template<class CFG>
00785 vertex_on_cell_iterator<CFG>
00786 gral_end (cell<CFG> const& c, vertex_on_cell_iterator<CFG>)
00787 { return c.EndVertex();}
00788
00789 template<class CFG>
00790 typename grid_types<grid_view<CFG> >::size_type
00791 gral_size (cell<CFG> const& c, vertex_on_cell_iterator<CFG>)
00792 { return c.NumOfVertices();}
00793
00794
00795 template<class CFG>
00796 cell_on_cell_iterator<CFG>
00797 gral_begin(cell<CFG> const& c, cell_on_cell_iterator<CFG>)
00798 { return c.FirstCell();}
00799
00800 template<class CFG>
00801 cell_on_cell_iterator<CFG>
00802 gral_end (cell<CFG> const& c, cell_on_cell_iterator<CFG>)
00803 { return c.EndCell();}
00804
00805 template<class CFG>
00806 typename grid_types<grid_view<CFG> >::size_type
00807 gral_size (cell<CFG> const& c, cell_on_cell_iterator<CFG>)
00808 { return c.NumOfCells();}
00809
00810
00811
00812
00813
00814 }
00815
00816
00826 template<class CFG, class T>
00827 class grid_function<restricted_grid_view::vertex<CFG>, T>
00828 : public grid_function_hash<restricted_grid_view::vertex<CFG>, T>
00829 {
00830 typedef grid_function_hash<restricted_grid_view::vertex<CFG>, T> base;
00831 typedef restricted_grid_view::grid_view<CFG> grid_type;
00832 public:
00833 grid_function() {}
00834 grid_function(grid_type const& g) : base(g) {}
00835 grid_function(grid_type const& g, T const& t) : base(g,t) {}
00836 };
00837
00847 template<class CFG, class T>
00848 class grid_function<restricted_grid_view::cell<CFG>, T>
00849 : public grid_function_hash<restricted_grid_view::cell<CFG>, T>
00850 {
00851 typedef grid_function_hash<restricted_grid_view::cell<CFG>, T> base;
00852 typedef restricted_grid_view::grid_view<CFG> grid_type;
00853 public:
00854 grid_function() {}
00855 grid_function(grid_type const& g) : base(g) {}
00856 grid_function(grid_type const& g, T const& t) : base(g,t) {}
00857 };
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883 }
00884
00885
00886
00887
00888 #ifdef NMWR_INCLUDE_TEMPLATE_DEFS
00889 #include "restricted-grid-view.C"
00890 #endif
00891
00892 #endif
00893