00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_STRUCTURE_GRAPHVERTEX_H
00008 #define BALL_STRUCTURE_GRAPHVERTEX_H
00009
00010 #ifndef BALL_COMMON_H
00011 # include <BALL/common.h>
00012 #endif
00013
00014 #ifndef BALL_DATATYPE_HASHSET_H
00015 # include <BALL/DATATYPE/hashSet.h>
00016 #endif
00017
00018 namespace BALL
00019 {
00020
00021 template <typename Vertex, typename Edge, typename Face>
00022 class GraphEdge;
00023
00024 template <typename Vertex, typename Edge, typename Face>
00025 class GraphFace;
00026
00027 template <typename Vertex, typename Edge, typename Face>
00028 class GraphTriangle;
00029
00033 template <typename Vertex, typename Edge, typename Face>
00034 class GraphVertex
00035 {
00036 public:
00037
00045 friend class GraphEdge<Vertex,Edge,Face>;
00046 friend class GraphFace<Vertex,Edge,Face>;
00047 friend class GraphTriangle<Vertex,Edge,Face>;
00048
00049 BALL_CREATE(GraphVertex)
00050
00051
00054
00055 typedef typename HashSet<Edge*>::Iterator EdgeIterator;
00056 typedef typename HashSet<Edge*>::ConstIterator ConstEdgeIterator;
00057 typedef typename HashSet<Face*>::Iterator FaceIterator;
00058 typedef typename HashSet<Face*>::ConstIterator ConstFaceIterator;
00059
00061
00064
00068 GraphVertex()
00069 ;
00070
00078 GraphVertex(const GraphVertex<Vertex,Edge,Face>& vertex, bool deep = false)
00079 ;
00080
00084 virtual ~GraphVertex()
00085 ;
00087
00091
00099 void set(const GraphVertex<Vertex,Edge,Face>& vertex, bool deep = false)
00100 ;
00101
00107 GraphVertex<Vertex,Edge,Face>& operator =
00108 (const GraphVertex<Vertex,Edge,Face>& vertex)
00109 ;
00110
00112
00115
00119 void insert(Edge* edge)
00120 ;
00121
00125 void insert(Face* face)
00126 ;
00127
00131 void remove(Edge* edge)
00132 ;
00133
00137 void remove(Face* face)
00138 ;
00139
00143 Position numberOfEdges() const
00144 ;
00145
00149 Position numberOfFaces() const
00150 ;
00151
00155 void setIndex(Index index)
00156 ;
00157
00161 Index getIndex() const
00162 ;
00163
00170 bool join(const Vertex& vertex)
00171 ;
00172
00179 bool substitute(Vertex* vertex)
00180 ;
00181
00182
00184
00187
00191 virtual bool operator == (const Vertex&) const
00192 ;
00193
00197 virtual bool operator != (const Vertex&) const
00198 ;
00199
00203 virtual bool operator *= (const Vertex&) const
00204 ;
00205
00210 Face* has(Face* face) const
00211 ;
00212
00217 Edge* has(Edge* edge) const
00218 ;
00219
00222 bool hasEdges() const
00223 ;
00224
00227 bool hasFaces() const
00228 ;
00229
00231
00234
00235 EdgeIterator beginEdge()
00236 ;
00237 ConstEdgeIterator beginEdge() const
00238 ;
00239 EdgeIterator endEdge()
00240 ;
00241 ConstEdgeIterator endEdge() const
00242 ;
00243 FaceIterator beginFace()
00244 ;
00245 ConstFaceIterator beginFace() const
00246 ;
00247 FaceIterator endFace()
00248 ;
00249 ConstFaceIterator endFace() const
00250 ;
00251
00253
00254 protected:
00255
00256
00257
00259
00260
00261
00262 HashSet<Edge*> edges_;
00263
00264
00265 HashSet<Face*> faces_;
00266
00267
00268 Index index_;
00269
00271
00272 };
00273
00274
00275
00276 template <typename Vertex, typename Edge, typename Face>
00277 GraphVertex<Vertex,Edge,Face>::GraphVertex()
00278
00279 : edges_(),
00280 faces_(),
00281 index_(-1)
00282 {
00283 }
00284
00285
00286 template <typename Vertex, typename Edge, typename Face>
00287 GraphVertex<Vertex,Edge,Face>::GraphVertex
00288 (const GraphVertex<Vertex,Edge,Face>& vertex, bool deep)
00289
00290 : edges_(),
00291 faces_(),
00292 index_(vertex.index_)
00293 {
00294 if (deep)
00295 {
00296 edges_ = vertex.edges_;
00297 faces_ = vertex.faces_;
00298 }
00299 }
00300
00301
00302 template <typename Vertex, typename Edge, typename Face>
00303 GraphVertex<Vertex,Edge,Face>::~GraphVertex()
00304
00305 {
00306 }
00307
00308
00309 template <typename Vertex, typename Edge, typename Face>
00310 void GraphVertex<Vertex,Edge,Face>::set
00311 (const GraphVertex<Vertex,Edge,Face>& vertex, bool deep)
00312
00313 {
00314 if (this != &vertex)
00315 {
00316 if (deep)
00317 {
00318 edges_ = vertex.edges_;
00319 faces_ = vertex.faces_;
00320 }
00321 index_ = vertex.index_;
00322 }
00323 }
00324
00325
00326 template <typename Vertex, typename Edge, typename Face>
00327 GraphVertex<Vertex,Edge,Face>& GraphVertex<Vertex,Edge,Face>::operator =
00328 (const GraphVertex<Vertex,Edge,Face>& vertex)
00329
00330 {
00331 if (this != &vertex)
00332 {
00333 edges_ = vertex.edges_;
00334 faces_ = vertex.faces_;
00335 index_ = vertex.index_;
00336 }
00337 return *this;
00338 }
00339
00340
00341 template <typename Vertex, typename Edge, typename Face>
00342 void GraphVertex<Vertex,Edge,Face>::insert(Edge* edge)
00343
00344 {
00345 edges_.insert(edge);
00346 }
00347
00348
00349 template <typename Vertex, typename Edge, typename Face>
00350 void GraphVertex<Vertex,Edge,Face>::insert(Face* face)
00351
00352 {
00353 faces_.insert(face);
00354 }
00355
00356
00357 template <typename Vertex, typename Edge, typename Face>
00358 void GraphVertex<Vertex,Edge,Face>::remove(Edge* edge)
00359
00360 {
00361 edges_.erase(edge);
00362 }
00363
00364
00365 template <typename Vertex, typename Edge, typename Face>
00366 void GraphVertex<Vertex,Edge,Face>::remove(Face* face)
00367
00368 {
00369 faces_.erase(face);
00370 }
00371
00372
00373 template <typename Vertex, typename Edge, typename Face>
00374 Position GraphVertex<Vertex,Edge,Face>::numberOfEdges() const
00375
00376 {
00377 return edges_.size();
00378 }
00379
00380
00381 template <typename Vertex, typename Edge, typename Face>
00382 Position GraphVertex<Vertex,Edge,Face>::numberOfFaces() const
00383
00384 {
00385 return faces_.size();
00386 }
00387
00388
00389 template <typename Vertex, typename Edge, typename Face>
00390 void GraphVertex<Vertex,Edge,Face>::setIndex(Index index)
00391
00392 {
00393 index_ = index;
00394 }
00395
00396
00397 template <typename Vertex, typename Edge, typename Face>
00398 Index GraphVertex<Vertex,Edge,Face>::getIndex() const
00399
00400 {
00401 return index_;
00402 }
00403
00404
00405 template <typename Vertex, typename Edge, typename Face>
00406 bool GraphVertex<Vertex,Edge,Face>::substitute(Vertex* vertex)
00407
00408 {
00409 if (*this *= *vertex)
00410 {
00411 typename HashSet<Edge*>::Iterator e;
00412 for (e = edges_.begin(); e != edges_.end(); e++)
00413 {
00414 (*e)->substitute((Vertex*)this,vertex);
00415 }
00416 typename HashSet<Face*>::Iterator f;
00417 for (f = faces_.begin(); f != faces_.end(); f++)
00418 {
00419 (*f)->substitute((Vertex*)this,vertex);
00420 }
00421 return true;
00422 }
00423 return false;
00424 }
00425
00426
00427 template <typename Vertex, typename Edge, typename Face>
00428 bool GraphVertex<Vertex,Edge,Face>::join(const Vertex& vertex)
00429
00430 {
00431 if (*this *= vertex)
00432 {
00433 typename HashSet<Edge*>::ConstIterator e;
00434 for (e = vertex.edges_.begin(); e != vertex.edges_.end(); e++)
00435 {
00436 edges_.insert(*e);
00437 }
00438 typename HashSet<Face*>::ConstIterator f;
00439 for (f = vertex.faces_.begin(); f != vertex.faces_.end(); f++)
00440 {
00441 faces_.insert(*f);
00442 }
00443 return true;
00444 }
00445 else
00446 {
00447 return false;
00448 }
00449 }
00450
00451
00452 template <typename Vertex, typename Edge, typename Face>
00453 Face* GraphVertex<Vertex,Edge,Face>::has(Face* face) const
00454
00455 {
00456 typename HashSet<Face*>::ConstIterator f;
00457 for (f = faces_.begin(); f != faces_.end(); f++)
00458 {
00459 if (*(*f) == *face)
00460 {
00461 return *f;
00462 }
00463 }
00464 return NULL;
00465 }
00466
00467
00468 template <typename Vertex, typename Edge, typename Face>
00469 Edge* GraphVertex<Vertex,Edge,Face>::has(Edge* edge) const
00470
00471 {
00472 typename HashSet<Edge*>::ConstIterator e;
00473 for (e = edges_.begin(); e != edges_.end(); e++)
00474 {
00475 if (*(*e) == *edge)
00476 {
00477 return *e;
00478 }
00479 }
00480 return NULL;
00481 }
00482
00483
00484 template <typename Vertex, typename Edge, typename Face>
00485 bool GraphVertex<Vertex,Edge,Face>::hasEdges() const
00486
00487 {
00488 return !edges_.isEmpty();
00489 }
00490
00491
00492 template <typename Vertex, typename Edge, typename Face>
00493 bool GraphVertex<Vertex,Edge,Face>::hasFaces() const
00494
00495 {
00496 return !faces_.isEmpty();
00497 }
00498
00499
00500 template <typename Vertex, typename Edge, typename Face>
00501 typename GraphVertex<Vertex,Edge,Face>::EdgeIterator
00502 GraphVertex<Vertex,Edge,Face>::beginEdge()
00503
00504 {
00505 return edges_.begin();
00506 }
00507
00508
00509 template <typename Vertex, typename Edge, typename Face>
00510 typename GraphVertex<Vertex,Edge,Face>::ConstEdgeIterator
00511 GraphVertex<Vertex,Edge,Face>::beginEdge() const
00512
00513 {
00514 return edges_.begin();
00515 }
00516
00517
00518 template <typename Vertex, typename Edge, typename Face>
00519 typename GraphVertex<Vertex,Edge,Face>::EdgeIterator
00520 GraphVertex<Vertex,Edge,Face>::endEdge()
00521
00522 {
00523 return edges_.end();
00524 }
00525
00526
00527 template <typename Vertex, typename Edge, typename Face>
00528 typename GraphVertex<Vertex,Edge,Face>::ConstEdgeIterator
00529 GraphVertex<Vertex,Edge,Face>::endEdge() const
00530
00531 {
00532 return edges_.end();
00533 }
00534
00535
00536 template <typename Vertex, typename Edge, typename Face>
00537 typename GraphVertex<Vertex,Edge,Face>::FaceIterator
00538 GraphVertex<Vertex,Edge,Face>::beginFace()
00539
00540 {
00541 return faces_.begin();
00542 }
00543
00544
00545 template <typename Vertex, typename Edge, typename Face>
00546 typename GraphVertex<Vertex,Edge,Face>::ConstFaceIterator
00547 GraphVertex<Vertex,Edge,Face>::beginFace() const
00548
00549 {
00550 return faces_.begin();
00551 }
00552
00553
00554 template <typename Vertex, typename Edge, typename Face>
00555 typename GraphVertex<Vertex,Edge,Face>::FaceIterator
00556 GraphVertex<Vertex,Edge,Face>::endFace()
00557
00558 {
00559 return faces_.end();
00560 }
00561
00562
00563 template <typename Vertex, typename Edge, typename Face>
00564 typename GraphVertex<Vertex,Edge,Face>::ConstFaceIterator
00565 GraphVertex<Vertex,Edge,Face>::endFace() const
00566
00567 {
00568 return faces_.end();
00569 }
00570
00571
00572 template <typename Vertex, typename Edge, typename Face>
00573 bool GraphVertex<Vertex,Edge,Face>::operator == (const Vertex&) const
00574
00575 {
00576 return true;
00577 }
00578
00579
00580 template <typename Vertex, typename Edge, typename Face>
00581 bool GraphVertex<Vertex,Edge,Face>::operator != (const Vertex&) const
00582
00583 {
00584 return false;
00585 }
00586
00587
00588 template <typename Vertex, typename Edge, typename Face>
00589 bool GraphVertex<Vertex,Edge,Face>::operator *= (const Vertex&) const
00590
00591 {
00592 return true;
00593 }
00594
00595 }
00596
00597 #endif // BALL_STRUCTURE_GRAPHVERTEX_H