BALL  1.4.1
graphVertex.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 
00005 #ifndef BALL_STRUCTURE_GRAPHVERTEX_H
00006 #define BALL_STRUCTURE_GRAPHVERTEX_H
00007 
00008 #ifndef BALL_COMMON_H
00009 # include <BALL/common.h>
00010 #endif
00011 
00012 #ifndef BALL_DATATYPE_HASHSET_H
00013 # include <BALL/DATATYPE/hashSet.h>
00014 #endif
00015 
00016 namespace BALL
00017 {
00018 
00019   template <typename Vertex, typename Edge, typename Face>
00020   class GraphEdge;
00021 
00022   template <typename Vertex, typename Edge, typename Face>
00023   class GraphFace;
00024 
00025   template <typename Vertex, typename Edge, typename Face>
00026   class GraphTriangle;
00027 
00031   template <typename Vertex, typename Edge, typename Face>
00032   class GraphVertex
00033   {
00034     public:
00035 
00043     friend class GraphEdge<Vertex,Edge,Face>;
00044     friend class GraphFace<Vertex,Edge,Face>;
00045     friend class GraphTriangle<Vertex,Edge,Face>;
00046 
00047     BALL_CREATE(GraphVertex)
00048 
00049     
00052 
00053     typedef typename HashSet<Edge*>::Iterator EdgeIterator;
00054     typedef typename HashSet<Edge*>::ConstIterator ConstEdgeIterator;
00055     typedef typename HashSet<Face*>::Iterator FaceIterator;
00056     typedef typename HashSet<Face*>::ConstIterator ConstFaceIterator;
00057 
00059 
00062 
00066     GraphVertex()
00067       ;
00068 
00076     GraphVertex(const GraphVertex<Vertex,Edge,Face>& vertex, bool deep = false)
00077       ;
00078 
00082     virtual ~GraphVertex()
00083       ;
00085 
00089 
00097     void set(const GraphVertex<Vertex,Edge,Face>& vertex, bool deep = false)
00098       ;
00099 
00105     GraphVertex<Vertex,Edge,Face>& operator =
00106         (const GraphVertex<Vertex,Edge,Face>& vertex)
00107       ;
00108 
00110 
00113 
00117     void insert(Edge* edge)
00118       ;
00119 
00123     void insert(Face* face)
00124       ;
00125 
00129     void remove(Edge* edge)
00130       ;
00131 
00135     void remove(Face* face)
00136       ;
00137 
00141     Position numberOfEdges() const
00142       ;
00143 
00147     Position numberOfFaces() const
00148       ;
00149 
00153     void setIndex(Index index)
00154       ;
00155 
00159     Index getIndex() const
00160       ;
00161 
00168     bool join(const Vertex& vertex)
00169       ;
00170 
00177     bool substitute(Vertex* vertex)
00178       ;
00179 
00180 
00182 
00185 
00189     virtual bool operator == (const Vertex&) const
00190       ;
00191 
00195     virtual bool operator != (const Vertex&) const
00196       ;
00197 
00201     virtual bool operator *= (const Vertex&) const
00202       ;
00203 
00208     Face* has(Face* face) const
00209       ;
00210 
00215     Edge* has(Edge* edge) const
00216       ;
00217 
00220     bool hasEdges() const
00221       ;
00222 
00225     bool hasFaces() const
00226       ;
00227 
00229 
00232 
00233     EdgeIterator beginEdge()
00234       ;
00235     ConstEdgeIterator beginEdge() const
00236       ;
00237     EdgeIterator endEdge()
00238       ;
00239     ConstEdgeIterator endEdge() const
00240       ;
00241     FaceIterator beginFace()
00242       ;
00243     ConstFaceIterator beginFace() const
00244       ;
00245     FaceIterator endFace()
00246       ;
00247     ConstFaceIterator endFace() const
00248       ;
00249 
00251 
00252     protected:
00253 
00254     /*_ @name Attributes
00255     */
00257 
00258     /*_ The RSEdges the RSVetex belongs to
00259     */
00260     HashSet<Edge*> edges_;
00261     /*_ The RSFaces the RSVetex belongs to
00262     */
00263     HashSet<Face*> faces_;
00264     /*_ The index of the GraphVertex
00265     */
00266     Index index_;
00267 
00269 
00270   };
00271 
00272 
00273 
00274   template <typename Vertex, typename Edge, typename Face>
00275   GraphVertex<Vertex,Edge,Face>::GraphVertex()
00276     
00277     : edges_(),
00278       faces_(),
00279       index_(-1)
00280   {
00281   }
00282 
00283 
00284   template <typename Vertex, typename Edge, typename Face>
00285   GraphVertex<Vertex,Edge,Face>::GraphVertex
00286       (const GraphVertex<Vertex,Edge,Face>& vertex, bool deep)
00287     
00288     : edges_(),
00289       faces_(),
00290       index_(vertex.index_)
00291   {
00292     if (deep)
00293     {
00294       edges_ = vertex.edges_;
00295       faces_ = vertex.faces_;
00296     }
00297   }
00298 
00299 
00300   template <typename Vertex, typename Edge, typename Face>
00301   GraphVertex<Vertex,Edge,Face>::~GraphVertex()
00302     
00303   {
00304   }
00305 
00306 
00307   template <typename Vertex, typename Edge, typename Face>
00308   void GraphVertex<Vertex,Edge,Face>::set
00309       (const GraphVertex<Vertex,Edge,Face>& vertex, bool deep)
00310     
00311   {
00312     if (this != &vertex)
00313     {
00314       if (deep)
00315       {
00316         edges_ = vertex.edges_;
00317         faces_ = vertex.faces_;
00318       }
00319       index_ = vertex.index_;
00320     }
00321   }
00322 
00323 
00324   template <typename Vertex, typename Edge, typename Face>
00325   GraphVertex<Vertex,Edge,Face>& GraphVertex<Vertex,Edge,Face>::operator =
00326       (const GraphVertex<Vertex,Edge,Face>& vertex)
00327     
00328   {
00329     if (this != &vertex)
00330     {
00331       edges_ = vertex.edges_;
00332       faces_ = vertex.faces_;
00333       index_ = vertex.index_;
00334     }
00335     return *this;
00336   }
00337 
00338 
00339   template <typename Vertex, typename Edge, typename Face>
00340   void GraphVertex<Vertex,Edge,Face>::insert(Edge* edge)
00341     
00342   {
00343     edges_.insert(edge);
00344   }
00345 
00346 
00347   template <typename Vertex, typename Edge, typename Face>
00348   void GraphVertex<Vertex,Edge,Face>::insert(Face* face)
00349     
00350   {
00351     faces_.insert(face);
00352   }
00353 
00354 
00355   template <typename Vertex, typename Edge, typename Face>
00356   void GraphVertex<Vertex,Edge,Face>::remove(Edge* edge)
00357     
00358   {
00359     edges_.erase(edge);
00360   }
00361 
00362 
00363   template <typename Vertex, typename Edge, typename Face>
00364   void GraphVertex<Vertex,Edge,Face>::remove(Face* face)
00365     
00366   {
00367     faces_.erase(face);
00368   }
00369 
00370 
00371   template <typename Vertex, typename Edge, typename Face>
00372   Position GraphVertex<Vertex,Edge,Face>::numberOfEdges() const
00373     
00374   {
00375     return edges_.size();
00376   }
00377 
00378 
00379   template <typename Vertex, typename Edge, typename Face>
00380   Position GraphVertex<Vertex,Edge,Face>::numberOfFaces() const
00381     
00382   {
00383     return faces_.size();
00384   }
00385 
00386 
00387   template <typename Vertex, typename Edge, typename Face>
00388   void GraphVertex<Vertex,Edge,Face>::setIndex(Index index)
00389     
00390   {
00391     index_ = index;
00392   }
00393 
00394 
00395   template <typename Vertex, typename Edge, typename Face>
00396   Index GraphVertex<Vertex,Edge,Face>::getIndex() const
00397     
00398   {
00399     return index_;
00400   }
00401 
00402 
00403   template <typename Vertex, typename Edge, typename Face>
00404   bool GraphVertex<Vertex,Edge,Face>::substitute(Vertex* vertex)
00405     
00406   {
00407     if (*this *= *vertex)
00408     {
00409       typename HashSet<Edge*>::Iterator e;
00410       for (e = edges_.begin(); e != edges_.end(); e++)
00411       {
00412         (*e)->substitute((Vertex*)this,vertex);
00413       }
00414       typename HashSet<Face*>::Iterator f;
00415       for (f = faces_.begin(); f != faces_.end(); f++)
00416       {
00417         (*f)->substitute((Vertex*)this,vertex);
00418       }
00419       return true;
00420     }
00421     return false;
00422   }
00423 
00424 
00425   template <typename Vertex, typename Edge, typename Face>
00426   bool GraphVertex<Vertex,Edge,Face>::join(const Vertex& vertex)
00427     
00428   {
00429     if (*this *= vertex)
00430     {
00431       typename HashSet<Edge*>::ConstIterator e;
00432       for (e = vertex.edges_.begin(); e != vertex.edges_.end(); e++)
00433       {
00434         edges_.insert(*e);
00435       }
00436       typename HashSet<Face*>::ConstIterator f;
00437       for (f = vertex.faces_.begin(); f != vertex.faces_.end(); f++)
00438       {
00439         faces_.insert(*f);
00440       }
00441       return true;
00442     }
00443     else
00444     {
00445       return false;
00446     }
00447   }
00448 
00449 
00450   template <typename Vertex, typename Edge, typename Face>
00451   Face* GraphVertex<Vertex,Edge,Face>::has(Face* face) const
00452     
00453   {
00454     typename HashSet<Face*>::ConstIterator f;
00455     for (f = faces_.begin(); f != faces_.end(); f++)
00456     {
00457       if (*(*f) == *face)
00458       {
00459         return *f;
00460       }
00461     }
00462     return NULL;
00463   }
00464 
00465 
00466   template <typename Vertex, typename Edge, typename Face>
00467   Edge* GraphVertex<Vertex,Edge,Face>::has(Edge* edge) const
00468     
00469   {
00470     typename HashSet<Edge*>::ConstIterator e;
00471     for (e = edges_.begin(); e != edges_.end(); e++)
00472     {
00473       if (*(*e) == *edge)
00474       {
00475         return *e;
00476       }
00477     }
00478     return NULL;
00479   }
00480 
00481 
00482   template <typename Vertex, typename Edge, typename Face>
00483   bool GraphVertex<Vertex,Edge,Face>::hasEdges() const
00484     
00485   {
00486     return !edges_.isEmpty();
00487   }
00488 
00489 
00490   template <typename Vertex, typename Edge, typename Face>
00491   bool GraphVertex<Vertex,Edge,Face>::hasFaces() const
00492     
00493   {
00494     return !faces_.isEmpty();
00495   }
00496 
00497 
00498   template <typename Vertex, typename Edge, typename Face>
00499   typename GraphVertex<Vertex,Edge,Face>::EdgeIterator
00500       GraphVertex<Vertex,Edge,Face>::beginEdge()
00501     
00502   {
00503     return edges_.begin();
00504   }
00505 
00506 
00507   template <typename Vertex, typename Edge, typename Face>
00508   typename GraphVertex<Vertex,Edge,Face>::ConstEdgeIterator
00509       GraphVertex<Vertex,Edge,Face>::beginEdge() const
00510     
00511   {
00512     return edges_.begin();
00513   }
00514 
00515 
00516   template <typename Vertex, typename Edge, typename Face>
00517   typename GraphVertex<Vertex,Edge,Face>::EdgeIterator
00518       GraphVertex<Vertex,Edge,Face>::endEdge()
00519     
00520   {
00521     return edges_.end();
00522   }
00523 
00524 
00525   template <typename Vertex, typename Edge, typename Face>
00526   typename GraphVertex<Vertex,Edge,Face>::ConstEdgeIterator
00527       GraphVertex<Vertex,Edge,Face>::endEdge() const
00528     
00529   {
00530     return edges_.end();
00531   }
00532 
00533 
00534   template <typename Vertex, typename Edge, typename Face>
00535   typename GraphVertex<Vertex,Edge,Face>::FaceIterator
00536       GraphVertex<Vertex,Edge,Face>::beginFace()
00537     
00538   {
00539     return faces_.begin();
00540   }
00541 
00542 
00543   template <typename Vertex, typename Edge, typename Face>
00544   typename GraphVertex<Vertex,Edge,Face>::ConstFaceIterator
00545       GraphVertex<Vertex,Edge,Face>::beginFace() const
00546     
00547   {
00548     return faces_.begin();
00549   }
00550 
00551 
00552   template <typename Vertex, typename Edge, typename Face>
00553   typename GraphVertex<Vertex,Edge,Face>::FaceIterator
00554       GraphVertex<Vertex,Edge,Face>::endFace()
00555     
00556   {
00557     return faces_.end();
00558   }
00559 
00560 
00561   template <typename Vertex, typename Edge, typename Face>
00562   typename GraphVertex<Vertex,Edge,Face>::ConstFaceIterator
00563       GraphVertex<Vertex,Edge,Face>::endFace() const
00564     
00565   {
00566     return faces_.end();
00567   }
00568 
00569 
00570   template <typename Vertex, typename Edge, typename Face>
00571   bool GraphVertex<Vertex,Edge,Face>::operator == (const Vertex&) const
00572     
00573   {
00574     return true;
00575   }
00576 
00577 
00578   template <typename Vertex, typename Edge, typename Face>
00579   bool GraphVertex<Vertex,Edge,Face>::operator != (const Vertex&) const
00580     
00581   {
00582     return false;
00583   }
00584 
00585 
00586   template <typename Vertex, typename Edge, typename Face>
00587   bool GraphVertex<Vertex,Edge,Face>::operator *= (const Vertex&) const
00588     
00589   {
00590     return true;
00591   }
00592 
00593 } // namespace BALL
00594 
00595 #endif // BALL_STRUCTURE_GRAPHVERTEX_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines