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/Complex2D/internal/cell2d.C

Go to the documentation of this file.
00001 #ifndef NMWR_GB_CELL2D_C
00002 #define NMWR_GB_CELL2D_C
00003 
00004 // $LICENSE
00005 
00006 
00007 #include "algorithm"
00008 #include "functional"
00009 
00010 inline Cell2D::Cell2D(Complex2D const&  cc)
00011 { *this = *(cc.FirstCell());}
00012 
00013 inline bool Cell2D::is_valid() const { return (_pos != _cc->outer_cell_handle());}
00014 
00015 inline
00016 cell2d_connectivity const& 
00017 Cell2D::base() const { return (_cc->_cells[_pos]);}
00018 
00019 
00020 //----------------------  iteration -----------------------------
00021 
00022 inline VertexOnCell2D_Iterator  Cell2D::FirstVertex() const
00023 { return    VertexOnCellIterator(0,*this);}
00024 inline VertexOnCell2D_Iterator  Cell2D::EndVertex() const
00025 { return    VertexOnCellIterator(NumOfVertices(),*this);}
00026 
00027 inline EdgeOnCell2D_Iterator  Cell2D::FirstEdge() const
00028 { return EdgeOnCellIterator(0,*this);}
00029 inline EdgeOnCell2D_Iterator  Cell2D::EndEdge() const
00030 { return EdgeOnCellIterator(NumOfEdges(),*this);}
00031 
00032 inline   EdgeOnCell2D_Iterator  Cell2D::FirstFacet() const { return FirstEdge();}
00033 inline   EdgeOnCell2D_Iterator  Cell2D::EndFacet()   const { return EndEdge();}
00034 
00035 
00036 inline CellOnCell2D_Iterator Cell2D::FirstNeighbour() const
00037 { return CellNeighbourIterator(0,*this);}
00038 
00039 inline CellOnCell2D_Iterator Cell2D::EndNeighbour() const
00040 { 
00041   // don't use NumOfNeighbors() here, it may be smaller than
00042   // NumOfFacets().
00043   return CellNeighbourIterator(NumOfFacets(),*this);
00044 }
00045 
00046 inline CellOnCell2D_Iterator Cell2D::FirstCell()  const { return FirstNeighbour();}
00047 inline CellOnCell2D_Iterator Cell2D::EndCell()    const { return EndNeighbour();}
00048 
00049 
00050 inline int Cell2D::NumOfNeighbours() const
00051 { 
00052   return count_if(base()._neighbours.begin(), base()._neighbours.end(), 
00053                   bind2nd(std::not_equal_to<int>(),-1)); 
00054 }
00055 
00056 inline Vertex2D Cell2D::V(int i) const
00057 {
00058   REQUIRE((is_valid()),"Cell2D: action with invalid cell!",1);
00059   REQUIRE((1 <= i && i <= NumOfVertices()),\
00060           "Cell2D::Vertex(int i): i = " << i\
00061           << ", must be in [1," << NumOfVertices() << "] !", 1);
00062 
00063   return( _cc->vertex(base()._vertices[i-1]));
00064 }
00065 
00066 inline Edge2D Cell2D::E(int i) const
00067 {
00068   REQUIRE((is_valid()),"Cell2D: action with invalid cell!",1);
00069   REQUIRE((1 <= i && i <= NumOfEdges()),\
00070           "Cell2D::Edge(int i): i = " << i\
00071           << ", must be in [1," << NumOfEdges() << "] !", 1);
00072 
00073   return( Edge(EdgeOnCellIterator(i-1,*this)));
00074 }
00075 
00076 inline Edge2D Cell2D::F(int i) const { return E(i);}
00077 
00078 
00079 
00080 inline Cell2D::vertex_handle
00081 Cell2D::vertex(int lv)  const    
00082 { 
00083   REQUIRE((is_valid()),"Cell2D: action with invalid cell!",1);
00084   REQUIRE( ((0 <= lv) && (lv < NumOfVertices())), 
00085             "local vertex lv = " << lv  
00086            << " out of range [0, " << NumOfVertices() << "]\n",1);
00087   return (base()._vertices[lv]);
00088 } 
00089 
00090 inline Cell2D::cell_handle
00091 Cell2D::cell(int lc)  const    
00092 { 
00093   REQUIRE((is_valid()),"Cell2D: action with invalid cell!",1);
00094   return (base()._neighbours[lc]);
00095 } 
00096 
00097 
00098 inline Cell2D::vertex_handle Cell2D::vertex(unsigned side, 
00099                                             const EdgeOnCell2D_Iterator& nb) const
00100 {
00101   REQUIRE((is_valid()),"Cell2D: action with invalid cell!",1);
00102   REQUIRE( ((side == 1 ) || (side == 2)),\
00103            "Cell2D::_vertex : side was " << side << ", must be in {1,2}! ", 1);
00104 
00105   int v = ((nb.lf + side - 1) % NumOfVertices());
00106   return (base()._vertices[v]);
00107 }
00108 
00109 inline int Cell2D::find_local_facet(const Cell2D& Nb) const
00110 {
00111   REQUIRE((is_valid()),"Cell2D: action with invalid cell!",1);
00112   unsigned cnt = 0;
00113   cell_handle hNb = _cc->handle(Nb);
00114   while(cnt != base()._neighbours.size() && base()._neighbours[cnt] != hNb) {
00115     ++cnt;
00116   }
00117   ENSURE( ((int)cnt < NumOfFacets()),
00118           "Cell2D " << _pos << " _find_facet: neighbour " << Nb._pos << " not found! ",1);
00119   
00120   return(cnt);
00121 }
00122 
00123 
00124 inline  Edge2D 
00125 Cell2D::FlippedEdge(Vertex2D const& v, Edge2D const& e) const
00126 { Edge res = e; FlipEdge(v,res); return res;}
00127 
00128 
00129 inline void Cell2D::FlipEdge(const Vertex2D& v, Edge2D& e) const
00130 {
00131   REQUIRE((is_valid()),"Cell2D: action with invalid cell!",1);
00132   REQUIRE(((v == e.V1()) || (v == e.V2())),
00133           "FlipEdge(v,e): v not in {e.V1,e.V2} !\n",1);
00134   EdgeOnCell2D_Iterator f = FirstEdge();
00135   while( (! (*f == e))  && ( ! f.IsDone())) {
00136     ++f;
00137   }
00138   
00139   REQUIRE((*f == e), 
00140           "FlipEdge(): nb-it does not match! f found = " 
00141           << "(" << f << ")"
00142           << ", e._e = (" << e._e  <<")\n",1);
00143 
00144   if(vertex(1,f) == v.handle()) 
00145     f = f.CyclicPred();
00146   else // *(++w) == v
00147     f = f.CyclicSucc();
00148  
00149   e._e = f;
00150 }
00151 
00152 
00153 #endif
00154 

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

Generated at Tue Feb 26 16:06:43 2002 for GrAL Complex2D by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000