BALL  1.4.1
graphEdge.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_GRAPHEDGE_H
00006 #define BALL_STRUCTURE_GRAPHEDGE_H
00007 
00008 #ifndef BALL_COMMON_H
00009 # include <BALL/common.h>
00010 #endif
00011 
00012 #include <vector>
00013 
00014 namespace BALL
00015 {
00016 
00017   template <typename Vertex, typename Edge, typename Face>
00018   class GraphVertex;
00019 
00020   template <typename Vertex, typename Edge, typename Face>
00021   class GraphFace;
00022 
00023   template <typename Vertex, typename Edge, typename Face>
00024   class GraphTriangle;
00025 
00029   template <typename Vertex, typename Edge, typename Face>
00030   class GraphEdge
00031   {
00032     public:
00033 
00041     friend class GraphVertex<Vertex,Edge,Face>;
00042     friend class GraphFace<Vertex,Edge,Face>;
00043     friend class GraphTriangle<Vertex,Edge,Face>;
00044 
00045     BALL_CREATE(GraphEdge)
00046 
00047     
00050 
00054     GraphEdge();
00055 
00063     GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
00064 
00073     GraphEdge(Vertex* vertex1,
00074               Vertex* vertex2,
00075               Face*   face1,
00076               Face*   face2,
00077               Index   index);
00078 
00083     virtual ~GraphEdge();
00084 
00086 
00089 
00096     void set(const GraphEdge<Vertex,Edge,Face>& edge, bool deep = false);
00097 
00103     GraphEdge<Vertex,Edge,Face>& operator =
00104         (const GraphEdge<Vertex,Edge,Face>& edge);
00105 
00113     void set(Vertex*  vertex0,
00114              Vertex*  vertex1,
00115              Face*    face0,
00116              Face*    face1,
00117              Index    index);
00118 
00120 
00123 
00129     void setVertex(Position i, Vertex* vertex);
00130 
00136     Vertex* getVertex(Position i) const;
00137 
00142     void setFace(Position i, Face* face);
00143 
00149     Face* getFace(Position i) const;
00150 
00154     void setIndex(Index index);
00155 
00159     Index getIndex() const;
00160 
00167     Vertex* other(const Vertex* vertex) const
00168       throw(Exception::GeneralException);
00169 
00176     Face* other(const Face* face) const
00177       throw(Exception::GeneralException);
00178 
00185     bool substitute(const Vertex* old_vertex, Vertex* new_vertex);
00186 
00193     bool substitute(const Face* old_vertex, Face* new_vertex);
00194 
00202     Face* remove(const Face* face);
00203 
00204     /*  Swap the two vertices of the GraphEdge
00205     */
00206     void revert();
00207 
00209 
00210 
00214 
00218     virtual bool operator == (const Edge&) const;
00219 
00223     virtual bool operator != (const Edge&) const;
00224 
00228     virtual bool operator *= (const Edge&) const;
00229 
00231 
00232     protected:
00233 
00234     /*_ @name Attributes
00235     */
00237 
00238     /*_ The vertices of the GraphEdge
00239     */
00240     Vertex* vertex_[2];
00241     /*_ The faces of the GraphEdge
00242     */
00243     Face* face_[2];
00244     /*_ The index of the GraphEdge
00245     */
00246     Index index_;
00247 
00249 
00250   };
00251 
00252 
00253 
00254   template <typename Vertex, typename Edge, typename Face>
00255   GraphEdge<Vertex,Edge,Face>::GraphEdge()
00256     : index_(-1)
00257   {
00258     vertex_[0] = NULL;
00259     vertex_[1] = NULL;
00260     face_[0] = NULL;
00261     face_[1] = NULL;
00262   }
00263 
00264 
00265   template <typename Vertex, typename Edge, typename Face>
00266   GraphEdge<Vertex,Edge,Face>::
00267 			GraphEdge(const GraphEdge<Vertex,Edge,Face>& edge, bool deep)
00268     : index_(edge.index_)
00269   {
00270     if (deep)
00271     {
00272       vertex_[0] = edge.vertex_[0];
00273       vertex_[1] = edge.vertex_[1];
00274       face_[0] = edge.face_[0];
00275       face_[1] = edge.face_[1];
00276     }
00277     else
00278     {
00279       vertex_[0] = NULL;
00280       vertex_[1] = NULL;
00281       face_[0] = NULL;
00282       face_[1] = NULL;
00283     }
00284   }
00285 
00286 
00287   template <typename Vertex, typename Edge, typename Face>
00288   GraphEdge<Vertex,Edge,Face>::GraphEdge
00289     (Vertex*  vertex1,
00290      Vertex*  vertex2,
00291      Face*    face1,
00292      Face*    face2,
00293      Index    index)
00294     : index_(index)
00295   {
00296     vertex_[0] = vertex1;
00297     vertex_[1] = vertex2;
00298     face_[0] = face1;
00299     face_[1] = face2;
00300   }
00301 
00302 
00303   template <typename Vertex, typename Edge, typename Face>
00304   GraphEdge<Vertex,Edge,Face>::~GraphEdge()
00305   {
00306   }
00307 
00308 
00309   template <typename Vertex, typename Edge, typename Face>
00310   void GraphEdge<Vertex,Edge,Face>::set
00311       (const GraphEdge<Vertex,Edge,Face>& edge, bool deep)
00312   {
00313     if (this != &edge)
00314     {
00315       if (deep)
00316       {
00317         vertex_[0] = edge.vertex_[0];
00318         vertex_[1] = edge.vertex_[1];
00319         face_[0] = edge.face_[0];
00320         face_[1] = edge.face_[1];
00321       }
00322       else
00323       {
00324         vertex_[0] = NULL;
00325         vertex_[1] = NULL;
00326         face_[0] = NULL;
00327         face_[1] = NULL;
00328       }
00329       index_ = edge.index_;
00330     }
00331   }
00332 
00333 
00334   template <typename Vertex, typename Edge, typename Face>
00335   GraphEdge<Vertex,Edge,Face>& GraphEdge<Vertex,Edge,Face>::operator =
00336       (const GraphEdge<Vertex,Edge,Face>& edge)
00337   {
00338     if (this != &edge)
00339     {
00340       vertex_[0] = edge.vertex_[0];
00341       vertex_[1] = edge.vertex_[1];
00342       face_[0] = edge.face_[0];
00343       face_[1] = edge.face_[1];
00344       index_ = edge.index_;
00345     }
00346     return *this;
00347   }
00348 
00349 
00350   template <typename Vertex, typename Edge, typename Face>
00351   void GraphEdge<Vertex,Edge,Face>::set
00352     (Vertex*  vertex0,
00353      Vertex*  vertex1,
00354      Face*    face0,
00355      Face*    face1,
00356      Index    index)
00357   {
00358     vertex_[0] = vertex0;
00359     vertex_[1] = vertex1;
00360     face_[0] = face0;
00361     face_[1] = face1;
00362     index_ = index;
00363   }
00364 
00365 
00366   template <typename Vertex, typename Edge, typename Face>
00367   void GraphEdge<Vertex,Edge,Face>::setVertex(Position i, Vertex* vertex)
00368   {
00369     if (i == 0)
00370     {
00371       vertex_[0] = vertex;
00372     }
00373     else
00374     {
00375       vertex_[1] = vertex;
00376     }
00377   }
00378 
00379 
00380   template <typename Vertex, typename Edge, typename Face>
00381   Vertex* GraphEdge<Vertex,Edge,Face>::getVertex(Position i) const
00382   {
00383     if (i == 0)
00384     {
00385       return vertex_[0];
00386     }
00387     else
00388     {
00389       return vertex_[1];
00390     }
00391   }
00392 
00393 
00394   template <typename Vertex, typename Edge, typename Face>
00395   void GraphEdge<Vertex,Edge,Face>::setFace(Position i, Face* face)
00396   {
00397     if (i == 0)
00398     {
00399       face_[0] = face;
00400     }
00401     else
00402     {
00403       face_[1] = face;
00404     }
00405   }
00406 
00407 
00408   template <typename Vertex, typename Edge, typename Face>
00409   Face* GraphEdge<Vertex,Edge,Face>::getFace(Position i) const
00410   {
00411     if (i == 0)
00412     {
00413       return face_[0];
00414     }
00415     else
00416     {
00417       return face_[1];
00418     }
00419   }
00420 
00421 
00422   template <typename Vertex, typename Edge, typename Face>
00423   void GraphEdge<Vertex,Edge,Face>::setIndex(Index index)
00424   {
00425     index_ = index;
00426   }
00427 
00428 
00429   template <typename Vertex, typename Edge, typename Face>
00430   Index GraphEdge<Vertex,Edge,Face>::getIndex() const
00431   {
00432     return index_;
00433   }
00434 
00435 
00436   template <typename Vertex, typename Edge, typename Face>
00437   Vertex* GraphEdge<Vertex,Edge,Face>::other(const Vertex* vertex) const
00438     throw(Exception::GeneralException)
00439   {
00440     if (vertex_[0] == vertex)
00441     {
00442       return vertex_[1];
00443     }
00444     else
00445     {
00446       if (vertex_[1] == vertex)
00447       {
00448         return vertex_[0];
00449       }
00450       else
00451       {
00452         throw Exception::GeneralException(__FILE__, __LINE__);
00453       }
00454     }
00455   }
00456 
00457 
00458   template <typename Vertex, typename Edge, typename Face>
00459   Face* GraphEdge<Vertex,Edge,Face>::other(const Face* face) const
00460     throw(Exception::GeneralException)
00461   {
00462     if (face_[0] == face)
00463     {
00464       return face_[1];
00465     }
00466     else
00467     {
00468       if (face_[1] == face)
00469       {
00470         return face_[0];
00471       }
00472       else
00473       {
00474         throw Exception::GeneralException(__FILE__, __LINE__);
00475       }
00476     }
00477   }
00478 
00479 
00480   template <typename Vertex, typename Edge, typename Face>
00481   bool GraphEdge<Vertex,Edge,Face>::substitute
00482       (const Vertex* old_vertex, Vertex* new_vertex)
00483   {
00484     if (vertex_[0] == old_vertex)
00485     {
00486       vertex_[0] = new_vertex;
00487     }
00488     else
00489     {
00490       if (vertex_[1] == old_vertex)
00491       {
00492         vertex_[1] = new_vertex;
00493       }
00494       else
00495       {
00496         return false;
00497       }
00498     }
00499     return true;
00500   }
00501 
00502 
00503   template <typename Vertex, typename Edge, typename Face>
00504   bool GraphEdge<Vertex,Edge,Face>::substitute
00505       (const Face* old_face, Face* new_face)
00506   {
00507     if (face_[0] == old_face)
00508     {
00509       face_[0] = new_face;
00510     }
00511     else
00512     {
00513       if (face_[1] == old_face)
00514       {
00515         face_[1] = new_face;
00516       }
00517       else
00518       {
00519         return false;
00520       }
00521     }
00522     return true;
00523   }
00524 
00525 
00526   template <typename Vertex, typename Edge, typename Face>
00527   Face* GraphEdge<Vertex,Edge,Face>::remove(const Face* face)
00528   {
00529     if (face_[1] == face)
00530     {
00531       face_[1] = NULL;
00532     }
00533     else
00534     {
00535       if (face_[0] == face)
00536       {
00537         face_[0] = face_[1];
00538         face_[1] = NULL;
00539       }
00540     }
00541     return face_[0];
00542   }
00543 
00544 
00545   template <typename Vertex, typename Edge, typename Face>
00546   void GraphEdge<Vertex,Edge,Face>::revert()
00547   {
00548     Vertex* tmp = vertex_[0];
00549     vertex_[0] = vertex_[1];
00550     vertex_[1] = tmp;
00551   }
00552 
00553 
00554   template <typename Vertex, typename Edge, typename Face>
00555   bool GraphEdge<Vertex,Edge,Face>::operator == (const Edge&) const
00556   {
00557     return true;
00558   }
00559 
00560 
00561   template <typename Vertex, typename Edge, typename Face>
00562   bool GraphEdge<Vertex,Edge,Face>::operator != (const Edge&) const
00563   {
00564     return false;
00565   }
00566 
00567 
00568   template <typename Vertex, typename Edge, typename Face>
00569   bool GraphEdge<Vertex,Edge,Face>::operator *= (const Edge&) const
00570   {
00571     return true;
00572   }
00573 
00574 
00575 
00576 } // namespace BALL
00577 
00578 #endif // BALL_STRUCTURE_GRAPHEDGE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines