00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef BALL_STRUCTURE_GRAPHFACE_H
00011 #define BALL_STRUCTURE_GRAPHFACE_H
00012
00013 #ifndef BALL_COMMON_H
00014 # include <BALL/common.h>
00015 #endif
00016
00017 #include <list>
00018 #include <vector>
00019
00020 namespace BALL
00021 {
00022
00023 template <typename Vertex, typename Edge, typename Face>
00024 class GraphVertex;
00025
00026 template <typename Vertex, typename Edge, typename Face>
00027 class GraphEdge;
00028
00032 template <typename Vertex, typename Edge, typename Face>
00033 class GraphFace
00034 {
00035 public:
00036
00043 friend class GraphVertex<Vertex,Edge,Face>;
00044 friend class GraphEdge<Vertex,Edge,Face>;
00045
00046 BALL_CREATE(GraphFace)
00047
00048
00051
00052 typedef typename std::list<Vertex*>::iterator VertexIterator;
00053 typedef typename std::list<Vertex*>::const_iterator ConstVertexIterator;
00054 typedef typename std::list<Edge*>::iterator EdgeIterator;
00055 typedef typename std::list<Edge*>::const_iterator ConstEdgeIterator;
00056
00058
00061
00065 GraphFace();
00066
00074 GraphFace(const GraphFace<Vertex,Edge,Face>& face, bool deep = false);
00075
00079 virtual ~GraphFace();
00080
00082
00085
00092 void set(const GraphFace<Vertex,Edge,Face>& face, bool deep = false);
00093
00099 GraphFace<Vertex,Edge,Face>& operator =
00100 (const GraphFace<Vertex,Edge,Face>& face);
00101
00103
00106
00110 void insert(Vertex* vertex);
00111
00115 void insert(Edge* edge);
00116
00120 void remove(Vertex* vertex);
00121
00125 void remove(Edge* edge);
00126
00130 Position numberOfVertices() const;
00131
00135 Position numberOfEdges() const;
00136
00137
00141 void setIndex(Index index);
00142
00146 Index getIndex() const;
00147
00155 bool getEdges(const Vertex* vertex, Edge*& edge1, Edge*& edge2) const;
00156
00164 bool getEdge
00165 (const Vertex* vertex1,
00166 const Vertex* vertex2,
00167 Edge*& edge) const;
00168
00174 Edge* getSimilarEdge(const Edge* edge) const;
00175
00182 bool substitute(const Vertex* old_vertex, Vertex* new_vertex);
00183
00190 bool substitute(const Edge* old_edge, Edge* new_edge);
00191
00193
00196
00200 virtual bool operator == (const Face& face) const;
00201
00205 virtual bool operator != (const Face& face) const;
00206
00210 virtual bool operator *= (const Face& face) const;
00211
00217 Vertex* has(Vertex* vertex) const;
00218
00223 Edge* has(Edge* edge) const;
00224
00226
00229
00230 VertexIterator beginVertex();
00231 ConstVertexIterator beginVertex() const;
00232 VertexIterator endVertex();
00233 ConstVertexIterator endVertex() const;
00234 EdgeIterator beginEdge();
00235 ConstEdgeIterator beginEdge() const;
00236 EdgeIterator endEdge();
00237 ConstEdgeIterator endEdge() const;
00238
00240
00241 protected:
00242
00243
00244
00246
00247
00248
00249 std::list<Vertex*> vertex_;
00250
00251
00252 std::list<Edge*> edge_;
00253
00254
00255 Index index_;
00256
00258
00259 };
00260
00261
00262
00263 template <typename Vertex, typename Edge, typename Face>
00264 GraphFace<Vertex,Edge,Face>::GraphFace()
00265 : vertex_(),
00266 edge_(),
00267 index_(-1)
00268 {
00269 }
00270
00271
00272 template <typename Vertex, typename Edge, typename Face>
00273 GraphFace<Vertex,Edge,Face>::GraphFace
00274 (const GraphFace<Vertex,Edge,Face>& face, bool deep)
00275 : vertex_(),
00276 edge_(),
00277 index_(face.index_)
00278 {
00279 if (deep)
00280 {
00281 vertex_ = face.vertex_;
00282 edge_ = face.edge_;
00283 }
00284 }
00285
00286
00287 template <typename Vertex, typename Edge, typename Face>
00288 GraphFace<Vertex,Edge,Face>::~GraphFace()
00289 {
00290 }
00291
00292
00293 template <typename Vertex, typename Edge, typename Face>
00294 void GraphFace<Vertex,Edge,Face>::set
00295 (const GraphFace<Vertex,Edge,Face>& face, bool deep)
00296 {
00297 if (this != &face)
00298 {
00299 if (deep)
00300 {
00301 vertex_ = face.vertex_;
00302 edge_ = face.edge_;
00303 }
00304 index_ = face.index_;
00305 }
00306 }
00307
00308
00309 template <typename Vertex, typename Edge, typename Face>
00310 GraphFace<Vertex,Edge,Face>& GraphFace<Vertex,Edge,Face>::operator =
00311 (const GraphFace<Vertex,Edge,Face>& face)
00312 {
00313 if (this != &face)
00314 {
00315 vertex_ = face.vertex_;
00316 edge_ = face.edge_;
00317 index_ = face.index_;
00318 }
00319 return *this;
00320 }
00321
00322
00323 template <typename Vertex, typename Edge, typename Face>
00324 void GraphFace<Vertex,Edge,Face>::insert(Vertex* vertex)
00325 {
00326 typename std::list<Vertex*>::iterator v = vertex_.begin();
00327 bool found = false;
00328 while ((!found) && (v != vertex_.end()))
00329 {
00330 found = (*v == vertex);
00331 v++;
00332 }
00333 if (!found)
00334 {
00335 vertex_.push_back(vertex);
00336 }
00337 }
00338
00339
00340 template <typename Vertex, typename Edge, typename Face>
00341 void GraphFace<Vertex,Edge,Face>::insert(Edge* edge)
00342 {
00343 typename std::list<Edge*>::iterator e = edge_.begin();
00344 bool found = false;
00345 while ((!found) && (e != edge_.end()))
00346 {
00347 found = (*e == edge);
00348 e++;
00349 }
00350 if (!found)
00351 {
00352 edge_.push_back(edge);
00353 }
00354 }
00355
00356
00357 template <typename Vertex, typename Edge, typename Face>
00358 void GraphFace<Vertex,Edge,Face>::remove(Vertex* vertex)
00359 {
00360 vertex_.remove(vertex);
00361 }
00362
00363
00364 template <typename Vertex, typename Edge, typename Face>
00365 void GraphFace<Vertex,Edge,Face>::remove(Edge* edge)
00366 {
00367 edge_.remove(edge);
00368 }
00369
00370
00371 template <typename Vertex, typename Edge, typename Face>
00372 Position GraphFace<Vertex,Edge,Face>::numberOfVertices() const
00373 {
00374 return vertex_.size();
00375 }
00376
00377
00378 template <typename Vertex, typename Edge, typename Face>
00379 Position GraphFace<Vertex,Edge,Face>::numberOfEdges() const
00380 {
00381 return edge_.size();
00382 }
00383
00384
00385 template <typename Vertex, typename Edge, typename Face>
00386 void GraphFace<Vertex,Edge,Face>::setIndex(Index index)
00387 {
00388 index_ = index;
00389 }
00390
00391
00392 template <typename Vertex, typename Edge, typename Face>
00393 Index GraphFace<Vertex,Edge,Face>::getIndex() const
00394 {
00395 return index_;
00396 }
00397
00398
00399 template <typename Vertex, typename Edge, typename Face>
00400 bool GraphFace<Vertex,Edge,Face>::getEdges
00401 (const Vertex* vertex,
00402 Edge*& edge1,
00403 Edge*& edge2) const
00404 {
00405 bool found1 = false;
00406 bool found2 = false;
00407 typename std::list<Edge*>::const_iterator e = edge_.begin();
00408 while ((!found1) && (e != edge_.end()))
00409 {
00410 if (((*e)->vertex_[0] == vertex) || ((*e)->vertex_[1] == vertex))
00411 {
00412 edge1 = *e;
00413 found1 = true;
00414 }
00415 e++;
00416 }
00417 if (found1)
00418 {
00419 while ((!found2) && (e != edge_.end()))
00420 {
00421 if (((*e)->vertex_[0] == vertex) || ((*e)->vertex_[1] == vertex))
00422 {
00423 edge2 = *e;
00424 found2 = true;
00425 }
00426 e++;
00427 }
00428 }
00429 return (found1 && found2);
00430 }
00431
00432
00433 template <typename Vertex, typename Edge, typename Face>
00434 bool GraphFace<Vertex,Edge,Face>::getEdge
00435 (const Vertex* vertex1,
00436 const Vertex* vertex2,
00437 Edge*& edge) const
00438 {
00439 typename std::list<Edge*>::const_iterator e = edge_.begin();
00440 bool found = false;
00441 while ((!found) && (e != edge_.end()))
00442 {
00443 if ((((*e)->vertex_[0] == vertex1) && ((*e)->vertex_[1] == vertex2)) ||
00444 (((*e)->vertex_[0] == vertex2) && ((*e)->vertex_[1] == vertex1)) )
00445 {
00446 edge = *e;
00447 found = true;
00448 }
00449 e++;
00450 }
00451 return found;
00452 }
00453
00454
00455 template <typename Vertex, typename Edge, typename Face>
00456 Edge* GraphFace<Vertex,Edge,Face>::getSimilarEdge(const Edge* edge) const
00457 {
00458 typename std::list<Edge*>::const_iterator e = edge_.begin();
00459 while (e != edge_.end())
00460 {
00461 if (**e *= *edge)
00462 {
00463 return *e;
00464 }
00465 e++;
00466 }
00467 return NULL;
00468 }
00469
00470
00471 template <typename Vertex, typename Edge, typename Face>
00472 bool GraphFace<Vertex,Edge,Face>::substitute
00473 (const Vertex* old_vertex, Vertex* new_vertex)
00474 {
00475 typename std::list<Vertex*>::iterator v = vertex_.begin();
00476 while (v != vertex_.end())
00477 {
00478 if (*v == old_vertex)
00479 {
00480 *v = new_vertex;
00481 return true;
00482 }
00483 v++;
00484 }
00485 return false;
00486 }
00487
00488
00489 template <typename Vertex, typename Edge, typename Face>
00490 bool GraphFace<Vertex,Edge,Face>::substitute
00491 (const Edge* old_edge, Edge* new_edge)
00492 {
00493 typename std::list<Edge*>::iterator e = edge_.begin();
00494 while (e != edge_.end())
00495 {
00496 if (*e == old_edge)
00497 {
00498 *e = new_edge;
00499 return true;
00500 }
00501 e++;
00502 }
00503 return false;
00504 }
00505
00506
00507 template <typename Vertex, typename Edge, typename Face>
00508 bool GraphFace<Vertex,Edge,Face>::operator == (const Face&) const
00509 {
00510 return true;
00511 }
00512
00513
00514 template <typename Vertex, typename Edge, typename Face>
00515 bool GraphFace<Vertex,Edge,Face>::operator != (const Face&) const
00516 {
00517 return false;
00518 }
00519
00520
00521 template <typename Vertex, typename Edge, typename Face>
00522 bool GraphFace<Vertex,Edge,Face>::operator *= (const Face&) const
00523 {
00524 return true;
00525 }
00526
00527
00528 template <typename Vertex, typename Edge, typename Face>
00529 Vertex* GraphFace<Vertex,Edge,Face>::has(Vertex* vertex) const
00530 {
00531 typename std::list<Vertex*>::const_iterator v = vertex_.begin();
00532 while (v != vertex_.end())
00533 {
00534 if (*v == vertex)
00535 {
00536 return *v;
00537 }
00538 v++;
00539 }
00540 return NULL;
00541 }
00542
00543
00544 template <typename Vertex, typename Edge, typename Face>
00545 Edge* GraphFace<Vertex,Edge,Face>::has(Edge* edge) const
00546 {
00547 typename std::list<Edge*>::const_iterator e = edge_.begin();
00548 while (e != edge_.end())
00549 {
00550 if (*e == edge)
00551 {
00552 return *e;
00553 }
00554 e++;
00555 }
00556 return NULL;
00557 }
00558
00559
00560 template <typename Vertex, typename Edge, typename Face>
00561 typename GraphFace<Vertex,Edge,Face>::VertexIterator
00562 GraphFace<Vertex,Edge,Face>::beginVertex()
00563 {
00564 return vertex_.begin();
00565 }
00566
00567
00568 template <typename Vertex, typename Edge, typename Face>
00569 typename GraphFace<Vertex,Edge,Face>::ConstVertexIterator
00570 GraphFace<Vertex,Edge,Face>::beginVertex() const
00571 {
00572 return vertex_.begin();
00573 }
00574
00575
00576 template <typename Vertex, typename Edge, typename Face>
00577 typename GraphFace<Vertex,Edge,Face>::VertexIterator
00578 GraphFace<Vertex,Edge,Face>::endVertex()
00579 {
00580 return vertex_.end();
00581 }
00582
00583
00584 template <typename Vertex, typename Edge, typename Face>
00585 typename GraphFace<Vertex,Edge,Face>::ConstVertexIterator
00586 GraphFace<Vertex,Edge,Face>::endVertex() const
00587 {
00588 return vertex_.end();
00589 }
00590
00591
00592 template <typename Vertex, typename Edge, typename Face>
00593 typename GraphFace<Vertex,Edge,Face>::EdgeIterator
00594 GraphFace<Vertex,Edge,Face>::beginEdge()
00595 {
00596 return edge_.begin();
00597 }
00598
00599
00600 template <typename Vertex, typename Edge, typename Face>
00601 typename GraphFace<Vertex,Edge,Face>::ConstEdgeIterator
00602 GraphFace<Vertex,Edge,Face>::beginEdge() const
00603 {
00604 return edge_.begin();
00605 }
00606
00607
00608 template <typename Vertex, typename Edge, typename Face>
00609 typename GraphFace<Vertex,Edge,Face>::EdgeIterator
00610 GraphFace<Vertex,Edge,Face>::endEdge()
00611 {
00612 return edge_.end();
00613 }
00614
00615
00616 template <typename Vertex, typename Edge, typename Face>
00617 typename GraphFace<Vertex,Edge,Face>::ConstEdgeIterator
00618 GraphFace<Vertex,Edge,Face>::endEdge() const
00619 {
00620 return edge_.end();
00621 }
00622
00623
00624
00628 template <typename Vertex, typename Edge, typename Face>
00629 class GraphTriangle
00630 {
00631 public:
00632
00639 friend class GraphVertex<Vertex,Edge,Face>;
00640 friend class GraphEdge<Vertex,Edge,Face>;
00641
00645
00646 BALL_CREATE(GraphTriangle)
00647
00648
00651 GraphTriangle();
00652
00660 GraphTriangle
00661 (const GraphTriangle<Vertex,Edge,Face>& face, bool deep = false);
00662
00673 GraphTriangle
00674 (Vertex* vertex1, Vertex* vertex2, Vertex* vertex3,
00675 Edge* edge1, Edge* edge2, Edge* edge3,
00676 Index index);
00677
00681 virtual ~GraphTriangle();
00682
00684
00687
00695 void set(const GraphTriangle<Vertex,Edge,Face>& face, bool deep = false);
00696
00702 GraphTriangle<Vertex,Edge,Face>& operator =
00703 (const GraphTriangle<Vertex,Edge,Face>& face);
00704
00714 void set
00715 (Vertex* vertex1, Vertex* vertex2, Vertex* vertex3,
00716 Edge* edge1, Edge* edge2, Edge* edge3,
00717 Index index);
00718
00720
00723
00729 void setVertex(Position i, Vertex* vertex)
00730 throw(Exception::IndexOverflow);
00731
00738 Vertex* getVertex(Position i) const
00739 throw(Exception::IndexOverflow);
00740
00746 void setEdge(Position i, Edge* edge)
00747 throw(Exception::IndexOverflow);
00748
00754 Edge* getEdge(Position i) const
00755 throw(Exception::IndexOverflow);
00756
00760 void setIndex(Index index);
00761
00765 Index getIndex() const;
00766
00774 bool getEdges(const Vertex* vertex, Edge*& edge1, Edge*& edge2) const;
00775
00784 bool getEdge
00785 (const Vertex* vertex1,
00786 const Vertex* vertex2,
00787 Edge*& edge) const;
00788
00796 Index getSimilarEdge(const Edge* edge, Edge*& similar_edge) const;
00797
00801 Index getRelativeIndex(const Vertex* vertex) const;
00802
00806 Index getRelativeIndex(const Edge* edge) const;
00807
00813 Vertex* third(const Vertex* v1, const Vertex* v2) const;
00814
00820 Edge* third(const Edge* e1, const Edge* e2) const;
00821
00822
00828 Edge* getOppositeEdge(const Vertex* vertex) const;
00829
00830
00836 Vertex* getOppositeVertex(const Edge* edge) const;
00837
00844 bool substitute(const Vertex* old_vertex, Vertex* new_vertex);
00845
00852 bool substitute(const Edge* old_edge, Edge* new_edge);
00853
00855
00858
00862 virtual bool operator == (const Face&) const;
00863
00867 virtual bool operator != (const Face&) const;
00868
00872 virtual bool operator *= (const Face&) const;
00873
00879 Vertex* has(Vertex* vertex) const;
00880
00885 Edge* has(Edge* edge) const;
00886
00888
00889 protected:
00890
00891
00892
00893 Vertex* vertex_[3];
00894
00895
00896 Edge* edge_[3];
00897
00898
00899 Index index_;
00900
00901 };
00902
00903
00904
00905 template <typename Vertex, typename Edge, typename Face>
00906 GraphTriangle<Vertex,Edge,Face>::GraphTriangle()
00907 : index_(-1)
00908 {
00909 vertex_[0] = NULL;
00910 vertex_[1] = NULL;
00911 vertex_[2] = NULL;
00912 edge_[0] = NULL;
00913 edge_[1] = NULL;
00914 edge_[2] = NULL;
00915 }
00916
00917
00918 template <typename Vertex, typename Edge, typename Face>
00919 GraphTriangle<Vertex,Edge,Face>::GraphTriangle
00920 (const GraphTriangle<Vertex,Edge,Face>& face, bool deep)
00921 : index_(face.index_)
00922 {
00923 if (deep)
00924 {
00925 vertex_[0] = face.vertex_[0];
00926 vertex_[1] = face.vertex_[1];
00927 vertex_[2] = face.vertex_[2];
00928 edge_[0] = face.edge_[0];
00929 edge_[1] = face.edge_[1];
00930 edge_[2] = face.edge_[2];
00931 }
00932 else
00933 {
00934 vertex_[0] = NULL;
00935 vertex_[1] = NULL;
00936 vertex_[2] = NULL;
00937 edge_[0] = NULL;
00938 edge_[1] = NULL;
00939 edge_[2] = NULL;
00940 }
00941 }
00942
00943
00944 template <typename Vertex, typename Edge, typename Face>
00945 GraphTriangle<Vertex,Edge,Face>::GraphTriangle
00946 (Vertex* vertex1, Vertex* vertex2, Vertex* vertex3,
00947 Edge* edge1, Edge* edge2, Edge* edge3,
00948 Index index)
00949 : index_(index)
00950 {
00951 vertex_[0] = vertex1;
00952 vertex_[1] = vertex2;
00953 vertex_[2] = vertex3;
00954 edge_[0] = edge1;
00955 edge_[1] = edge2;
00956 edge_[2] = edge3;
00957 }
00958
00959
00960 template <typename Vertex, typename Edge, typename Face>
00961 GraphTriangle<Vertex,Edge,Face>::~GraphTriangle()
00962 {
00963 }
00964
00965
00966 template <typename Vertex, typename Edge, typename Face>
00967 void GraphTriangle<Vertex,Edge,Face>::set
00968 (const GraphTriangle<Vertex,Edge,Face>& face, bool deep)
00969 {
00970 if (this != &face)
00971 {
00972 if (deep)
00973 {
00974 vertex_[0] = face.vertex_[0];
00975 vertex_[1] = face.vertex_[1];
00976 vertex_[2] = face.vertex_[2];
00977 edge_[0] = face.edge_[0];
00978 edge_[1] = face.edge_[1];
00979 edge_[2] = face.edge_[2];
00980 }
00981 else
00982 {
00983 vertex_[0] = NULL;
00984 vertex_[1] = NULL;
00985 vertex_[2] = NULL;
00986 edge_[0] = NULL;
00987 edge_[1] = NULL;
00988 edge_[2] = NULL;
00989 }
00990 index_ = face.index_;
00991 }
00992 }
00993
00994
00995 template <typename Vertex, typename Edge, typename Face>
00996 GraphTriangle<Vertex,Edge,Face>& GraphTriangle<Vertex,Edge,Face>::operator =
00997 (const GraphTriangle<Vertex,Edge,Face>& face)
00998 {
00999 if (this != &face)
01000 {
01001 vertex_[0] = face.vertex_[0];
01002 vertex_[1] = face.vertex_[1];
01003 vertex_[2] = face.vertex_[2];
01004 edge_[0] = face.edge_[0];
01005 edge_[1] = face.edge_[1];
01006 edge_[2] = face.edge_[2];
01007 index_ = face.index_;
01008 }
01009 return *this;
01010 }
01011
01012
01013 template <typename Vertex, typename Edge, typename Face>
01014 void GraphTriangle<Vertex,Edge,Face>::set
01015 (Vertex* vertex1, Vertex* vertex2, Vertex* vertex3,
01016 Edge* edge1, Edge* edge2, Edge* edge3,
01017 Index index)
01018 {
01019 vertex_[0] = vertex1;
01020 vertex_[1] = vertex2;
01021 vertex_[2] = vertex3;
01022 edge_[0] = edge1;
01023 edge_[1] = edge2;
01024 edge_[2] = edge3;
01025 index_ = index;
01026 }
01027
01028
01029 template <typename Vertex, typename Edge, typename Face>
01030 void GraphTriangle<Vertex,Edge,Face>::setVertex(Position i, Vertex* vertex)
01031 throw(Exception::IndexOverflow)
01032 {
01033 if (i > 2)
01034 {
01035 throw Exception::IndexOverflow(__FILE__,__LINE__,i,2);
01036 }
01037 else
01038 {
01039 vertex_[i] = vertex;
01040 }
01041 }
01042
01043
01044 template <typename Vertex, typename Edge, typename Face>
01045 Vertex* GraphTriangle<Vertex,Edge,Face>::getVertex(Position i) const
01046 throw(Exception::IndexOverflow)
01047 {
01048 if (i > 2)
01049 {
01050 throw Exception::IndexOverflow(__FILE__,__LINE__,i,2);
01051 }
01052 else
01053 {
01054 return vertex_[i];
01055 }
01056 }
01057
01058
01059 template <typename Vertex, typename Edge, typename Face>
01060 void GraphTriangle<Vertex,Edge,Face>::setEdge(Position i, Edge* edge)
01061 throw(Exception::IndexOverflow)
01062 {
01063 if (i > 2)
01064 {
01065 throw Exception::IndexOverflow(__FILE__,__LINE__,i,2);
01066 }
01067 else
01068 {
01069 edge_[i] = edge;
01070 }
01071 }
01072
01073
01074 template <typename Vertex, typename Edge, typename Face>
01075 Edge* GraphTriangle<Vertex,Edge,Face>::getEdge(Position i) const
01076 throw(Exception::IndexOverflow)
01077 {
01078 if (i > 2)
01079 {
01080 throw Exception::IndexOverflow(__FILE__,__LINE__,i,2);
01081 }
01082 else
01083 {
01084 return edge_[i];
01085 }
01086 }
01087
01088
01089 template <typename Vertex, typename Edge, typename Face>
01090 void GraphTriangle<Vertex,Edge,Face>::setIndex(Index index)
01091 {
01092 index_ = index;
01093 }
01094
01095
01096 template <typename Vertex, typename Edge, typename Face>
01097 Index GraphTriangle<Vertex,Edge,Face>::getIndex() const
01098 {
01099 return index_;
01100 }
01101
01102
01103 template <typename Vertex, typename Edge, typename Face>
01104 bool GraphTriangle<Vertex,Edge,Face>::getEdges
01105 (const Vertex* vertex,
01106 Edge*& edge1,
01107 Edge*& edge2) const
01108 {
01109 Position i = 0;
01110 bool found1 = false;
01111 bool found2 = false;
01112 while ((!found1) && (i < 3))
01113 {
01114 if (edge_[i] != NULL)
01115 {
01116 if ((edge_[i]->vertex_[0] == vertex) ||
01117 (edge_[i]->vertex_[1] == vertex) )
01118 {
01119 edge1 = edge_[i];
01120 found1 = true;
01121 }
01122 }
01123 i++;
01124 }
01125 if (found1)
01126 {
01127 while ((!found2) && (i < 3))
01128 {
01129 if (edge_[i] != NULL)
01130 {
01131 if ((edge_[i]->vertex_[0] == vertex) ||
01132 (edge_[i]->vertex_[1] == vertex) )
01133 {
01134 edge2 = edge_[i];
01135 found2 = true;
01136 }
01137 }
01138 i++;
01139 }
01140 }
01141 return (found1 && found2);
01142 }
01143
01144
01145 template <typename Vertex, typename Edge, typename Face>
01146 bool GraphTriangle<Vertex,Edge,Face>::getEdge
01147 (const Vertex* vertex1,
01148 const Vertex* vertex2,
01149 Edge*& edge) const
01150 {
01151 Position i = 0;
01152 bool found = false;
01153 while ((!found) && (i < 3))
01154 {
01155 if (edge_[i] != NULL)
01156 {
01157 if (((edge_[i]->vertex_[0] == vertex1) &&
01158 (edge_[i]->vertex_[1] == vertex2) ) ||
01159 ((edge_[i]->vertex_[0] == vertex2) &&
01160 (edge_[i]->vertex_[1] == vertex1) ) )
01161 {
01162 edge = edge_[i];
01163 found = true;
01164 }
01165 }
01166 i++;
01167 }
01168 return found;
01169 }
01170
01171
01172 template <typename Vertex, typename Edge, typename Face>
01173 Index GraphTriangle<Vertex,Edge,Face>::getSimilarEdge
01174 (const Edge* edge, Edge*& similar_edge) const
01175 {
01176 if (*edge_[0] *= *edge)
01177 {
01178 similar_edge = edge_[0];
01179 return 0;
01180 }
01181 if (*edge_[1] *= *edge)
01182 {
01183 similar_edge = edge_[1];
01184 return 1;
01185 }
01186 if (*edge_[2] *= *edge)
01187 {
01188 similar_edge = edge_[2];
01189 return 2;
01190 }
01191 similar_edge = NULL;
01192 return -1;
01193 }
01194
01195
01196 template <typename Vertex, typename Edge, typename Face>
01197 Index GraphTriangle<Vertex,Edge,Face>::getRelativeIndex
01198 (const Vertex* vertex) const
01199 {
01200 for (Position i = 0; i < 3; i++)
01201 {
01202 if (vertex_[i] == vertex)
01203 {
01204 return i;
01205 }
01206 }
01207 return -1;
01208 }
01209
01210
01211 template <typename Vertex, typename Edge, typename Face>
01212 Index GraphTriangle<Vertex,Edge,Face>::getRelativeIndex
01213 (const Edge* edge) const
01214 {
01215 for (Position i = 0; i < 3; i++)
01216 {
01217 if (edge_[i] == edge)
01218 {
01219 return i;
01220 }
01221 }
01222 return -1;
01223 }
01224
01225
01226 template <typename Vertex, typename Edge, typename Face>
01227 Vertex* GraphTriangle<Vertex,Edge,Face>::third
01228 (const Vertex* v1, const Vertex* v2) const
01229 {
01230 if ((vertex_[0] == v1) || (vertex_[0] == v2))
01231 {
01232 if ((vertex_[1] == v1) || (vertex_[1] == v2))
01233 {
01234 return vertex_[2];
01235 }
01236 else
01237 {
01238 return vertex_[1];
01239 }
01240 }
01241 else
01242 {
01243 return vertex_[0];
01244 }
01245 }
01246
01247
01248 template <typename Vertex, typename Edge, typename Face>
01249 Edge* GraphTriangle<Vertex,Edge,Face>::third
01250 (const Edge* e1, const Edge* e2) const
01251 {
01252 if ((edge_[0] == e1) || (edge_[0] == e2))
01253 {
01254 if ((edge_[1] == e1) || (edge_[1] == e2))
01255 {
01256 return edge_[2];
01257 }
01258 else
01259 {
01260 return edge_[1];
01261 }
01262 }
01263 else
01264 {
01265 return edge_[0];
01266 }
01267 }
01268
01269
01270 template <typename Vertex, typename Edge, typename Face>
01271 Edge* GraphTriangle<Vertex,Edge,Face>::getOppositeEdge
01272 (const Vertex* vertex) const
01273 {
01274 for (Position i = 0; i < 3; i++)
01275 {
01276 if ((edge_[i]->vertex_[0] != vertex) &&
01277 (edge_[i]->vertex_[1] != vertex) )
01278 {
01279 return edge_[i];
01280 }
01281 }
01282 return NULL;
01283 }
01284
01285
01286 template <typename Vertex, typename Edge, typename Face>
01287 Vertex* GraphTriangle<Vertex,Edge,Face>::getOppositeVertex
01288 (const Edge* edge) const
01289 {
01290 for (Position i = 0; i < 3; i++)
01291 {
01292 if ((vertex_[i] != edge->vertex_[0]) &&
01293 (vertex_[i] != edge->vertex_[1]) )
01294 {
01295 return vertex_[i];
01296 }
01297 }
01298 return NULL;
01299 }
01300
01301
01302 template <typename Vertex, typename Edge, typename Face>
01303 bool GraphTriangle<Vertex,Edge,Face>::substitute
01304 (const Vertex* old_vertex, Vertex* new_vertex)
01305 {
01306 for (Position i = 0; i < 3; i++)
01307 {
01308 if (vertex_[i] == old_vertex)
01309 {
01310 vertex_[i] = new_vertex;
01311 return true;
01312 }
01313 }
01314 return false;
01315 }
01316
01317
01318 template <typename Vertex, typename Edge, typename Face>
01319 bool GraphTriangle<Vertex,Edge,Face>::substitute
01320 (const Edge* old_edge, Edge* new_edge)
01321 {
01322 for (Position i = 0; i < 3; i++)
01323 {
01324 if (edge_[i] == old_edge)
01325 {
01326 edge_[i] = new_edge;
01327 return true;
01328 }
01329 }
01330 return false;
01331 }
01332
01333
01334 template <typename Vertex, typename Edge, typename Face>
01335 bool GraphTriangle<Vertex,Edge,Face>::operator == (const Face&) const
01336 {
01337 return true;
01338 }
01339
01340
01341 template <typename Vertex, typename Edge, typename Face>
01342 bool GraphTriangle<Vertex,Edge,Face>::operator != (const Face&) const
01343 {
01344 return false;
01345 }
01346
01347
01348 template <typename Vertex, typename Edge, typename Face>
01349 bool GraphTriangle<Vertex,Edge,Face>::operator *= (const Face&) const
01350 {
01351 return true;
01352 }
01353
01354
01355 template <typename Vertex, typename Edge, typename Face>
01356 Vertex* GraphTriangle<Vertex,Edge,Face>::has(Vertex* vertex) const
01357 {
01358 if (vertex_[0] == vertex)
01359 {
01360 return vertex_[0];
01361 }
01362 if (vertex_[1] == vertex)
01363 {
01364 return vertex_[1];
01365 }
01366 if (vertex_[2] == vertex)
01367 {
01368 return vertex_[2];
01369 }
01370 return NULL;
01371 }
01372
01373
01374 template <typename Vertex, typename Edge, typename Face>
01375 Edge* GraphTriangle<Vertex,Edge,Face>::has(Edge* edge) const
01376 {
01377 if (edge_[0] == edge)
01378 {
01379 return edge_[0];
01380 }
01381 if (edge_[1] == edge)
01382 {
01383 return edge_[1];
01384 }
01385 if (edge_[2] == edge)
01386 {
01387 return edge_[2];
01388 }
01389 return NULL;
01390 }
01391
01392
01393 }
01394
01395 #endif // BALL_STRUCTURE_RSFACE_H