graphEdge.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: graphEdge.h,v 1.12.26.1 2007/03/25 21:25:26 oliver Exp $
00005 //
00006 
00007 #ifndef BALL_STRUCTURE_GRAPHEDGE_H
00008 #define BALL_STRUCTURE_GRAPHEDGE_H
00009 
00010 #ifndef BALL_COMMON_H
00011 # include <BALL/common.h>
00012 #endif
00013 
00014 #include <vector>
00015 
00016 namespace BALL
00017 {
00018 
00019   template <typename Vertex, typename Edge, typename Face>
00020   class GraphVertex;
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 GraphEdge
00033   {
00034     public:
00035 
00043     friend class GraphVertex<Vertex,Edge,Face>;
00044     friend class GraphFace<Vertex,Edge,Face>;
00045     friend class GraphTriangle<Vertex,Edge,Face>;
00046 
00047     BALL_CREATE(GraphEdge)
00048 
00049     
00052 
00056     GraphEdge();
00057 
00065     GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
00066 
00075     GraphEdge(Vertex* vertex1,
00076               Vertex* vertex2,
00077               Face*   face1,
00078               Face*   face2,
00079               Index   index);
00080 
00085     virtual ~GraphEdge();
00086 
00088 
00091 
00098     void set(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
00099 
00105     GraphEdge<Vertex,Edge,Face>& operator =
00106         (const GraphEdge<Vertex,Edge,Face>& edge);
00107 
00115     void set(Vertex*  vertex0,
00116              Vertex*  vertex1,
00117              Face*    face0,
00118              Face*    face1,
00119              Index    index);
00120 
00122 
00125 
00131     void setVertex(Position i, Vertex* vertex);
00132 
00138     Vertex* getVertex(Position i) const;
00139 
00144     void setFace(Position i, Face* face);
00145 
00151     Face* getFace(Position i) const;
00152 
00156     void setIndex(Index index);
00157 
00161     Index getIndex() const;
00162 
00169     Vertex* other(const Vertex* vertex) const
00170       throw(Exception::GeneralException);
00171 
00178     Face* other(const Face* face) const
00179       throw(Exception::GeneralException);
00180 
00187     bool substitute(const Vertex* old_vertex, Vertex* new_vertex);
00188 
00195     bool substitute(const Face* old_vertex, Face* new_vertex);
00196 
00204     Face* remove(const Face* face);
00205 
00206     /*  Swap the two vertices of the GraphEdge
00207     */
00208     void revert();
00209 
00211 
00212 
00216 
00220     virtual bool operator == (const Edge&) const;
00221 
00225     virtual bool operator != (const Edge&) const;
00226 
00230     virtual bool operator *= (const Edge&) const;
00231 
00233 
00234     protected:
00235 
00236     /*_ @name Attributes
00237     */
00239 
00240     /*_ The vertices of the GraphEdge
00241     */
00242     Vertex* vertex_[2];
00243     /*_ The faces of the GraphEdge
00244     */
00245     Face* face_[2];
00246     /*_ The index of the GraphEdge
00247     */
00248     Index index_;
00249 
00251 
00252   };
00253 
00254 
00255 
00256   template <typename Vertex, typename Edge, typename Face>
00257   GraphEdge<Vertex,Edge,Face>::GraphEdge()
00258     : index_(-1)
00259   {
00260     vertex_[0] = NULL;
00261     vertex_[1] = NULL;
00262     face_[0] = NULL;
00263     face_[1] = NULL;
00264   }
00265 
00266 
00267   template <typename Vertex, typename Edge, typename Face>
00268   GraphEdge<Vertex,Edge,Face>::
00269 			GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep)
00270     : index_(edge.index_)
00271   {
00272     if (deep)
00273     {
00274       vertex_[0] = edge.vertex_[0];
00275       vertex_[1] = edge.vertex_[1];
00276       face_[0] = edge.face_[0];
00277       face_[1] = edge.face_[1];
00278     }
00279     else
00280     {
00281       vertex_[0] = NULL;
00282       vertex_[1] = NULL;
00283       face_[0] = NULL;
00284       face_[1] = NULL;
00285     }
00286   }
00287 
00288 
00289   template <typename Vertex, typename Edge, typename Face>
00290   GraphEdge<Vertex,Edge,Face>::GraphEdge
00291     (Vertex*  vertex1,
00292      Vertex*  vertex2,
00293      Face*    face1,
00294      Face*    face2,
00295      Index    index)
00296     : index_(index)
00297   {
00298     vertex_[0] = vertex1;
00299     vertex_[1] = vertex2;
00300     face_[0] = face1;
00301     face_[1] = face2;
00302   }
00303 
00304 
00305   template <typename Vertex, typename Edge, typename Face>
00306   GraphEdge<Vertex,Edge,Face>::~GraphEdge()
00307   {
00308   }
00309 
00310 
00311   template <typename Vertex, typename Edge, typename Face>
00312   void GraphEdge<Vertex,Edge,Face>::set
00313       (const GraphEdge<Vertex,Edge,Face>& edge, bool deep)
00314   {
00315     if (this != &edge)
00316     {
00317       if (deep)
00318       {
00319         vertex_[0] = edge.vertex_[0];
00320         vertex_[1] = edge.vertex_[1];
00321         face_[0] = edge.face_[0];
00322         face_[1] = edge.face_[1];
00323       }
00324       else
00325       {
00326         vertex_[0] = NULL;
00327         vertex_[1] = NULL;
00328         face_[0] = NULL;
00329         face_[1] = NULL;
00330       }
00331       index_ = edge.index_;
00332     }
00333   }
00334 
00335 
00336   template <typename Vertex, typename Edge, typename Face>
00337   GraphEdge<Vertex,Edge,Face>& GraphEdge<Vertex,Edge,Face>::operator =
00338       (const GraphEdge<Vertex,Edge,Face>& edge)
00339   {
00340     if (this != &edge)
00341     {
00342       vertex_[0] = edge.vertex_[0];
00343       vertex_[1] = edge.vertex_[1];
00344       face_[0] = edge.face_[0];
00345       face_[1] = edge.face_[1];
00346       index_ = edge.index_;
00347     }
00348     return *this;
00349   }
00350 
00351 
00352   template <typename Vertex, typename Edge, typename Face>
00353   void GraphEdge<Vertex,Edge,Face>::set
00354     (Vertex*  vertex0,
00355      Vertex*  vertex1,
00356      Face*    face0,
00357      Face*    face1,
00358      Index    index)
00359   {
00360     vertex_[0] = vertex0;
00361     vertex_[1] = vertex1;
00362     face_[0] = face0;
00363     face_[1] = face1;
00364     index_ = index;
00365   }
00366 
00367 
00368   template <typename Vertex, typename Edge, typename Face>
00369   void GraphEdge<Vertex,Edge,Face>::setVertex(Position i, Vertex* vertex)
00370   {
00371     if (i == 0)
00372     {
00373       vertex_[0] = vertex;
00374     }
00375     else
00376     {
00377       vertex_[1] = vertex;
00378     }
00379   }
00380 
00381 
00382   template <typename Vertex, typename Edge, typename Face>
00383   Vertex* GraphEdge<Vertex,Edge,Face>::getVertex(Position i) const
00384   {
00385     if (i == 0)
00386     {
00387       return vertex_[0];
00388     }
00389     else
00390     {
00391       return vertex_[1];
00392     }
00393   }
00394 
00395 
00396   template <typename Vertex, typename Edge, typename Face>
00397   void GraphEdge<Vertex,Edge,Face>::setFace(Position i, Face* face)
00398   {
00399     if (i == 0)
00400     {
00401       face_[0] = face;
00402     }
00403     else
00404     {
00405       face_[1] = face;
00406     }
00407   }
00408 
00409 
00410   template <typename Vertex, typename Edge, typename Face>
00411   Face* GraphEdge<Vertex,Edge,Face>::getFace(Position i) const
00412   {
00413     if (i == 0)
00414     {
00415       return face_[0];
00416     }
00417     else
00418     {
00419       return face_[1];
00420     }
00421   }
00422 
00423 
00424   template <typename Vertex, typename Edge, typename Face>
00425   void GraphEdge<Vertex,Edge,Face>::setIndex(Index index)
00426   {
00427     index_ = index;
00428   }
00429 
00430 
00431   template <typename Vertex, typename Edge, typename Face>
00432   Index GraphEdge<Vertex,Edge,Face>::getIndex() const
00433   {
00434     return index_;
00435   }
00436 
00437 
00438   template <typename Vertex, typename Edge, typename Face>
00439   Vertex* GraphEdge<Vertex,Edge,Face>::other(const Vertex* vertex) const
00440     throw(Exception::GeneralException)
00441   {
00442     if (vertex_[0] == vertex)
00443     {
00444       return vertex_[1];
00445     }
00446     else
00447     {
00448       if (vertex_[1] == vertex)
00449       {
00450         return vertex_[0];
00451       }
00452       else
00453       {
00454         throw Exception::GeneralException(__FILE__, __LINE__);
00455       }
00456     }
00457   }
00458 
00459 
00460   template <typename Vertex, typename Edge, typename Face>
00461   Face* GraphEdge<Vertex,Edge,Face>::other(const Face* face) const
00462     throw(Exception::GeneralException)
00463   {
00464     if (face_[0] == face)
00465     {
00466       return face_[1];
00467     }
00468     else
00469     {
00470       if (face_[1] == face)
00471       {
00472         return face_[0];
00473       }
00474       else
00475       {
00476         throw Exception::GeneralException(__FILE__, __LINE__);
00477       }
00478     }
00479   }
00480 
00481 
00482   template <typename Vertex, typename Edge, typename Face>
00483   bool GraphEdge<Vertex,Edge,Face>::substitute
00484       (const Vertex* old_vertex, Vertex* new_vertex)
00485   {
00486     if (vertex_[0] == old_vertex)
00487     {
00488       vertex_[0] = new_vertex;
00489     }
00490     else
00491     {
00492       if (vertex_[1] == old_vertex)
00493       {
00494         vertex_[1] = new_vertex;
00495       }
00496       else
00497       {
00498         return false;
00499       }
00500     }
00501     return true;
00502   }
00503 
00504 
00505   template <typename Vertex, typename Edge, typename Face>
00506   bool GraphEdge<Vertex,Edge,Face>::substitute
00507       (const Face* old_face, Face* new_face)
00508   {
00509     if (face_[0] == old_face)
00510     {
00511       face_[0] = new_face;
00512     }
00513     else
00514     {
00515       if (face_[1] == old_face)
00516       {
00517         face_[1] = new_face;
00518       }
00519       else
00520       {
00521         return false;
00522       }
00523     }
00524     return true;
00525   }
00526 
00527 
00528   template <typename Vertex, typename Edge, typename Face>
00529   Face* GraphEdge<Vertex,Edge,Face>::remove(const Face* face)
00530   {
00531     if (face_[1] == face)
00532     {
00533       face_[1] = NULL;
00534     }
00535     else
00536     {
00537       if (face_[0] == face)
00538       {
00539         face_[0] = face_[1];
00540         face_[1] = NULL;
00541       }
00542     }
00543     return face_[0];
00544   }
00545 
00546 
00547   template <typename Vertex, typename Edge, typename Face>
00548   void GraphEdge<Vertex,Edge,Face>::revert()
00549   {
00550     Vertex* tmp = vertex_[0];
00551     vertex_[0] = vertex_[1];
00552     vertex_[1] = tmp;
00553   }
00554 
00555 
00556   template <typename Vertex, typename Edge, typename Face>
00557   bool GraphEdge<Vertex,Edge,Face>::operator == (const Edge&) const
00558   {
00559     return true;
00560   }
00561 
00562 
00563   template <typename Vertex, typename Edge, typename Face>
00564   bool GraphEdge<Vertex,Edge,Face>::operator != (const Edge&) const
00565   {
00566     return false;
00567   }
00568 
00569 
00570   template <typename Vertex, typename Edge, typename Face>
00571   bool GraphEdge<Vertex,Edge,Face>::operator *= (const Edge&) const
00572   {
00573     return true;
00574   }
00575 
00576 
00577 
00578 } // namespace BALL
00579 
00580 #endif // BALL_STRUCTURE_GRAPHEDGE_H