00001 #ifndef GRAL_GB_COMPLEX2D_C
00002 #define GRAL_GB_COMPLEX2D_C
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <algorithm>
00022
00023 namespace GrAL {
00024
00025 inline Complex2D::vertex_handle Complex2D::handle(const Complex2D::Vertex& V) const {
00026 REQUIRE(( &(V.TheGrid()) == this),
00027 "handle(Vertex): V.TheGrid() == "
00028 << &(V.TheGrid()) << " != this = " << this << '\n',1);
00029 return (V._pos);
00030 }
00031
00032 inline Complex2D::vertex_handle Complex2D::handle(const Complex2D::VertexIterator& v) const
00033 { return v._pos;}
00034 inline Complex2D::vertex_handle Complex2D::handle(const Complex2D::VertexOnCellIterator& v) const
00035 { return v.handle();}
00036
00037
00038 inline Complex2D::cell_handle Complex2D::handle(const Complex2D::Cell& C) const {
00039 REQUIRE(( &(C.TheGrid()) == this),
00040 "handle(Cell): C.TheGrid() == "
00041 << &(C.TheGrid()) << " != this = " << this << '\n',1);
00042 return (C._pos);
00043 }
00044
00045 inline Complex2D::cell_handle Complex2D::handle(const Complex2D::CellIterator& c) const
00046 { return c._pos;}
00047 inline Complex2D::cell_handle Complex2D::handle(const Complex2D::CellNeighbourIterator& c) const
00048 { return (_cells[c._f.C.handle()]._neighbours[c._f.lf]); }
00049
00050 inline Edge2D Complex2D::edge(const Complex2D::edge_handle& e) const
00051 { return Edge(EdgeOnCellIterator(e.le,Cell(*this,e.c)));}
00052
00053 inline Edge2D Complex2D::facet(const Complex2D::edge_handle& e) const
00054 { return Edge(EdgeOnCellIterator(e.le,Cell(*this,e.c)));}
00055
00056 inline Complex2D::edge_handle Complex2D::handle(const Edge2D& E) const
00057 {
00058
00059 cell_handle c1 = E._e.C.handle();
00060 cell_handle c2 = _cells[c1]._neighbours[E._e.lf];
00061 if (c1 > c2)
00062 return edge_handle(c1,E._e.lf);
00063 else
00064 return edge_handle(c2, std::find(_cells[c2]._neighbours.begin(),
00065 _cells[c2]._neighbours.end(), c1)
00066 - _cells[c2]._neighbours.begin());
00067 }
00068
00069 inline bool Complex2D::IsOnBoundary(const EdgeOnCell2D_Iterator& e) const
00070 { return (_cells[e.C.handle()]._neighbours[e.lf] == outer_cell_handle());}
00071 inline bool Complex2D::IsOnBoundary(const Edge2D& e) const
00072 { return (IsOnBoundary(e._e));}
00073
00074
00075
00076
00077
00078 inline Complex2D::VertexIterator Complex2D::FirstVertex() const
00079 { return VertexIterator(*this,0);}
00080
00081 inline Complex2D::VertexIterator Complex2D::EndVertex() const
00082 { return VertexIterator(*this, NumOfVertices());}
00083
00084
00085 inline Complex2D::EdgeIterator Complex2D::FirstEdge() const
00086 {
00087 CellIterator FC(FirstCell());
00088 if( ! FC.IsDone())
00089 return EdgeIterator(FC,(*(FC)).FirstEdge());
00090 else
00091 return EdgeIterator(FC,EdgeOnCellIterator());
00092 }
00093 inline Complex2D::EdgeIterator Complex2D::EndEdge() const
00094 { return EdgeIterator(EndCell(), EdgeOnCellIterator()); }
00095
00096 inline Complex2D::EdgeIterator Complex2D::FirstFacet() const
00097 { return FirstEdge();}
00098 inline Complex2D::EdgeIterator Complex2D::EndFacet() const
00099 { return EndEdge();}
00100
00101 inline void Complex2D::switch_vertex(Complex2D::Vertex & v,
00102 Complex2D::Edge const& e) const
00103 { e.FlipVertex(v);}
00104
00105 inline void Complex2D::switch_edge(Complex2D::Vertex const& v,
00106 Complex2D::Edge & e,
00107 Complex2D::Cell const& c) const
00108 { c.FlipEdge(v,e);}
00109
00110
00111 inline void Complex2D::switch_cell(Complex2D::Edge const& e,
00112 Complex2D::Cell & c) const
00113 { e.FlipCell(c);}
00114
00115 inline Complex2D::Vertex
00116 Complex2D::switched_vertex(Complex2D::Vertex const& v,
00117 Complex2D::Edge const& e) const
00118 { Vertex sv(v); switch_vertex(sv,e); return sv;}
00119
00120 inline Complex2D::Edge
00121 Complex2D::switched_edge(Complex2D::Vertex const& v,
00122 Complex2D::Edge const& e,
00123 Complex2D::Cell const& c) const
00124 { Edge se(e); switch_edge(v,se,c); return se;}
00125
00126 inline Complex2D::Facet
00127 Complex2D::switched_facet(Complex2D::Vertex const& v,
00128 Complex2D::Edge const& e,
00129 Complex2D::Cell const& c) const
00130 { Edge se(e); switch_edge(v,se,c); return se;}
00131
00132 inline Complex2D::Cell
00133 Complex2D::switched_cell(Complex2D::Edge const& e,
00134 Complex2D::Cell const& c) const
00135 { Cell sc(c); switch_cell(e,sc); return sc;}
00136
00137
00138 inline Complex2D::BoundaryFacetIterator Complex2D::FirstBoundaryFacet() const
00139 { return BoundaryFacetIterator(_boundary.begin(),this);}
00140
00141 inline Complex2D::BoundaryFacetIterator Complex2D::FirstBoundaryEdge() const
00142 { return BoundaryFacetIterator(_boundary.begin(),this);}
00143
00144 inline Complex2D::BoundaryVertexIterator Complex2D::FirstBoundaryVertex() const
00145 {
00146
00147
00148 if (! FirstBoundaryFacet().IsDone()) {
00149 return BoundaryVertexIterator(* (FirstBoundaryFacet()));
00150 }
00151 else
00152 return BoundaryVertexIterator();
00153 }
00154
00155 inline Complex2D::CellIterator Complex2D::FirstCell() const
00156 { return CellIterator(0,*this);}
00157 inline Complex2D::CellIterator Complex2D::EndCell() const
00158 { return CellIterator(NumOfCells(),*this);}
00159
00160 inline Complex2D::FaceIterator Complex2D::FirstFace() const
00161 { return FaceIterator(0,*this);}
00162 inline Complex2D::FaceIterator Complex2D::EndFace() const
00163 { return FaceIterator(NumOfFaces(),*this);}
00164
00165
00166
00167
00168 inline Complex2D::cell_handle Complex2D::_new_cell(int num_of_v)
00169 {
00170 _cells.push_back(cell2d_connectivity());
00171 _cells.back().resize(num_of_v);
00172 return (_cells.size() -1);
00173 }
00174
00175 inline Complex2D::vertex_handle Complex2D::_new_vertex(const Complex2D::CoordType& coo)
00176 {
00177 _vertices.push_back(vertex_base(coo));
00178 _vertices.back().reserve(4);
00179 return (_vertices.size() -1);
00180 }
00181
00182
00183
00184
00185 inline void Complex2D::set_neighbour(const Complex2D::EdgeOnCellIterator& n1_it,
00186 const Complex2D::Cell& n2)
00187 { _cells[n1_it.C.handle()]._neighbours[n1_it.lf] = handle(n2);}
00188
00189 inline void Complex2D::add_cell_on_vertex(const Complex2D::Vertex& V, const Complex2D::Cell& C)
00190 { add_cell_on_vertex(V,handle(C)); }
00191
00192 inline void Complex2D::add_cell_on_vertex(const Complex2D::Vertex& V, const Complex2D::cell_handle& c)
00193 { _vertices[handle(V)]._cells.push_back(c);}
00194
00195
00196 inline void Complex2D::swap_orientation(Complex2D::Cell const& c)
00197 {
00198 std::reverse(_cells[c.handle()]._vertices.begin(),
00199 _cells[c.handle()]._vertices.end());
00200 }
00201
00202
00203
00204 inline const Complex2D::CoordType& Complex2D::Coord(const Complex2D::Vertex& v) const
00205 { return (_vertices[v._pos]._coord); }
00206
00207 inline Complex2D::CoordType& Complex2D::Coord(const Complex2D::Vertex& v)
00208 { return (_vertices[v._pos]._coord);}
00209
00210 }
00211
00212 #endif
00213