00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CONNECTIVITY_HPP
00021 #define CONNECTIVITY_HPP
00022
00033 #include <ReferenceCounting.hpp>
00034 #include <ErrorHandler.hpp>
00035
00036 #include <Vector.hpp>
00037 #include <Edge.hpp>
00038 #include <TinyVector.hpp>
00039 #include <Stringify.hpp>
00040
00041 #include <set>
00042
00043 template <typename MeshType>
00044 class ConnectivityBuilder;
00045
00046 template<typename MeshType>
00047 class Connectivity
00048 {
00049 public:
00050 typedef enum {
00051 CellToCells = (1<< 0),
00052 CellToFaces = (1<< 1),
00053 CellToEdges = (1<< 2),
00054 CellToVertices = (1<< 3),
00055 FaceToCells = (1<< 4),
00056 FaceToEdges = (1<< 5),
00057 FaceToVertices = (1<< 6),
00058 EdgeToCells = (1<< 7),
00059 EdgeToFaces = (1<< 8),
00060 EdgeToVertices = (1<< 9),
00061 VertexToCell = (1<<10),
00062 VertexToFaces = (1<<11),
00063 VertexToEdges = (1<<12),
00064 VertexToVertices = (1<<13),
00065 VertexToVerticesGeneralized = (1<<15)
00066 } Type;
00067
00068 friend class ConnectivityBuilder<MeshType>;
00069
00070 private:
00071 const MeshType& __mesh;
00072
00073 public:
00074 typedef typename MeshType::CellType CellType;
00075 typedef typename MeshType::CellType::FaceType FaceType;
00076
00077 typedef TinyVector<CellType::NumberOfFaces,
00078 const CellType*> CellToCellsType;
00079
00080 typedef TinyVector<CellType::NumberOfFaces,
00081 const FaceType*> CellToFacesType;
00082
00083 typedef TinyVector<CellType::NumberOfEdges,
00084 const Edge*> CellToEdgesType;
00085
00086
00087
00088 typedef TinyVector<2, std::pair<const CellType*,
00089 size_t> > FaceToCellsType;
00090
00091 typedef std::set<const CellType*> EdgeToCellsType;
00092
00093 typedef std::set<const CellType*> VertexToCellsType;
00094 typedef std::set<const Vertex*> VertexToVerticesType;
00095
00096 private:
00097 ReferenceCounting<Vector<CellToCellsType> >
00098 __cellToCells;
00099
00100
00101 ReferenceCounting<Vector<CellToFacesType> > __cellToFaces;
00102
00103 ReferenceCounting<Vector<CellToEdgesType> >
00104 __cellToEdges;
00105
00106 class Undefined {};
00107 ReferenceCounting<Undefined> __cellToVertices;
00108
00109 ReferenceCounting<Vector<FaceToCellsType> > __faceToCells;
00110
00111 ReferenceCounting<Undefined> __faceToEdges;
00112 ReferenceCounting<Undefined> __faceToVertices;
00113
00114 ReferenceCounting<EdgeToCellsType> __edgeToCells;
00115
00116 ReferenceCounting<Undefined> __edgeToFaces;
00117 ReferenceCounting<Undefined> __edgeToVertices;
00118
00119 ReferenceCounting<Vector<VertexToCellsType> >
00120 __vertexToCells;
00121
00122 ReferenceCounting<Undefined> __vertexToFaces;
00123 ReferenceCounting<Undefined> __vertexToEdges;
00124 ReferenceCounting<Undefined> __vertexToVertices;
00125
00126 ReferenceCounting<Vector<VertexToVerticesType> >
00127 __vertexToVerticesGeneralized;
00128
00134 Connectivity(const Connectivity& c);
00135
00136 public:
00137
00138 void setCellToCells(ReferenceCounting<Vector<CellToCellsType> >& c)
00139 {
00140 __cellToCells = c;
00141 }
00142
00143 void setCellToEdges(ReferenceCounting<Vector<CellToEdgesType> >& c)
00144 {
00145 __cellToEdges = c;
00146 }
00147
00148 void setCellToFaces(ReferenceCounting<Vector<CellToFacesType> >& c)
00149 {
00150 __cellToFaces = c;
00151 }
00152
00153 void setFaceToCells(ReferenceCounting<Vector<FaceToCellsType> >& c)
00154 {
00155 __faceToCells = c;
00156 }
00157
00158 void setEdgeToCells(ReferenceCounting<Vector<EdgeToCellsType> >& c)
00159 {
00160 __edgeToCells = c;
00161 }
00162
00163 void setVertexToCells(ReferenceCounting<Vector<VertexToCellsType> >& c)
00164 {
00165 __vertexToCells = c;
00166 }
00167
00168 void setVertexToVerticesGeneralized(ReferenceCounting<Vector<VertexToVerticesType> >& c)
00169 {
00170 __vertexToVerticesGeneralized = c;
00171 }
00172
00173 bool hasCellToCells() const
00174 {
00175 return __cellToCells != 0;
00176 }
00177
00178 bool hasCellToFaces() const
00179 {
00180 return __cellToFaces != 0;
00181 }
00182
00183 bool hasCellToEdges() const
00184 {
00185 return __cellToEdges != 0;
00186 }
00187
00188 bool hasCellToVertices() const
00189 {
00190 return __cellToVertices != 0;
00191 }
00192
00193 bool hasFaceToCells() const
00194 {
00195 return __faceToCells != 0;
00196 }
00197
00198 bool hasFaceToEdges() const
00199 {
00200 return __faceToEdges != 0;
00201 }
00202
00203 bool hasFaceToVertices() const
00204 {
00205 return __faceToVertices != 0;
00206 }
00207
00208 bool hasEdgeToCells() const
00209 {
00210 return __edgeToCells != 0;
00211 }
00212
00213 bool hasEdgeToFaces() const
00214 {
00215 return __edgeToFaces != 0;
00216 }
00217
00218 bool hasEdgeToVertices() const
00219 {
00220 return __edgeToVertices != 0;
00221 }
00222
00223 bool hasVertexToCells() const
00224 {
00225 return __vertexToCells != 0;
00226 }
00227
00228 bool hasVertexToFaces() const
00229 {
00230 return __vertexToFaces != 0;
00231 }
00232
00233 bool hasVertexToEdges() const
00234 {
00235 return __vertexToEdges != 0;
00236 }
00237
00238 bool hasVertexToVerices() const
00239 {
00240 return __vertexToVertices != 0;
00241 }
00242
00243 bool hasVertexToVericesGeneralized() const
00244 {
00245 return __vertexToVerticesGeneralized != 0;
00246 }
00247
00248 const CellToCellsType& cells(const CellType& c) const
00249 {
00250 return (*__cellToCells)[__mesh.cellNumber(c)];
00251 }
00252
00253 CellToCellsType& cells(const CellType& c)
00254 {
00255 return (*__cellToCells)[__mesh.cellNumber(c)];
00256 }
00257
00258 const VertexToCellsType& cells(const Vertex& v) const
00259 {
00260 return (*__vertexToCells)[__mesh.vertexNumber(v)];
00261 }
00262
00263 VertexToCellsType& cells(const Vertex& v)
00264 {
00265 return (*__vertexToCells)[__mesh.vertexNumber(v)];
00266 }
00267
00268 const FaceToCellsType& cells(const FaceType& f) const
00269 {
00270 return (*__faceToCells)[__mesh.faceNumber(f)];
00271 }
00272
00273 FaceToCellsType& cells(const FaceType& f)
00274 {
00275 return (*__faceToCells)[__mesh.faceNumber(f)];
00276 }
00277
00278 const CellToFacesType& faces(const CellType& c) const
00279 {
00280 return (*__cellToFaces)[__mesh.cellNumber(c)];
00281 }
00282
00283 CellToFacesType& faces(const CellType& c)
00284 {
00285 return (*__cellToFaces)[__mesh.cellNumber(c)];
00286 }
00287
00288 const CellToEdgesType& edges(const CellType& c) const
00289 {
00290 return (*__cellToEdges)[__mesh.cellNumber(c)];
00291 }
00292
00293 CellToEdgesType& edges(const CellType& c)
00294 {
00295 return (*__cellToEdges)[__mesh.cellNumber(c)];
00296 }
00297
00298 const VertexToVerticesType& verticesGeneralized(const Vertex& v) const
00299 {
00300 return (*__vertexToVerticesGeneralized)[__mesh.cellNumber(v)];
00301 }
00302
00303 VertexToVerticesType& verticesGeneralized(const Vertex& v)
00304 {
00305 return (*__vertexToVerticesGeneralized)[__mesh.cellNumber(v)];
00306 }
00307
00308 Connectivity(const MeshType& mesh)
00309 : __mesh(mesh),
00310 __cellToCells(0),
00311 __cellToFaces(0),
00312 __cellToEdges(0),
00313 __cellToVertices(0),
00314 __faceToCells(0),
00315 __faceToEdges(0),
00316 __faceToVertices(0),
00317 __edgeToCells(0),
00318 __edgeToFaces(0),
00319 __edgeToVertices(0),
00320 __vertexToCells(0),
00321 __vertexToFaces(0),
00322 __vertexToEdges(0),
00323 __vertexToVertices(0),
00324 __vertexToVerticesGeneralized(0)
00325 {
00326 ;
00327 }
00328
00329 ~Connectivity()
00330 {
00331 ;
00332 }
00333 };
00334
00335 #endif // CONNECTIVITY_HPP