GlobeEngine
UndirectedEdge.h
Go to the documentation of this file.
1 //
2 // VBOVertex.h
3 // GlobeEngine
4 //
5 // Created by Mathias Thöny on 27.12.11.
6 // Copyright (c) 2011 University of Zurich. All rights reserved.
7 //
8 
9 #ifndef GlobeEngine_UndirectedEdge_h
10 #define GlobeEngine_UndirectedEdge_h
11 #include "VBOVertex.h"
12 #include "OpenGL_Includes.h"
13 #include <iostream>
14 
15 namespace geGraph {
16  /*
17  * undirected edge
18  */
19  template <class T> class UndirectedEdge
20  {
21  public:
23  create(std::numeric_limits<T>::max(), std::numeric_limits<T>::max(), std::numeric_limits<T>::max());
24  }
25 
26  UndirectedEdge(T _node1, T _node2) {
27  create(std::numeric_limits<T>::max(), _node1,_node2);
28  }
29 
30  UndirectedEdge(T _uid, T _node1, T _node2) {
31  create(_uid, _node1,_node2);
32  }
33 
34  void create(T _uid, T _node1, T _node2) {
35  marked = false;
36  uid = _uid;
37  setNodes(_node1,_node2);
38  }
39 
40  void setNodes(T _node1, T _node2) {
41  nodes[0] = _node1;
42  nodes[1] = _node2;
43  }
44 
45  const T* getNodes() const {
46  return nodes;
47  }
48 
49  T getOppositeNode(T _nodeID) const {
50  if (_nodeID != nodes[0] && _nodeID != nodes[1]) {
51  //std::cout << "cannot find this node connected to edge" << std::endl;
52  return 0;
53  }
54  if(_nodeID == nodes[0]) {
55  return nodes[1];
56  }
57  return nodes[0];
58  }
59 
60  bool isIDaNeighborNode(T _nodeID) {
61  if(this->nodes[0] == _nodeID || this->nodes[1] == _nodeID){
62  return true;
63  }
64  return false;
65  }
66 
67  void mark(){
68  this->marked = true;
69  }
70 
71  void unmark(){
72  this->marked = false;
73  }
74 
75  bool isMarked(){
76  return this->marked;
77  }
78 
79  friend std::ostream& operator<< (std::ostream &out, const UndirectedEdge< T > &edge) {
80  out << "("<< edge.uid << ": " << edge.nodes[0] << ", " << edge.nodes[1] << ", marked: " << edge.marked << ")";
81  return out;
82  }
83 
84  protected:
85  bool marked;
86  T uid;
87  T nodes[2];
88  };
89 
92 }
93 #endif
UndirectedEdge< unsigned int > Edgeui
Definition: UndirectedEdge.h:90
UndirectedEdge< unsigned int > UndirectedEdgeui
Definition: UndirectedEdge.h:91
UndirectedEdge(T _node1, T _node2)
Definition: UndirectedEdge.h:26
void unmark()
Definition: UndirectedEdge.h:71
void mark()
Definition: UndirectedEdge.h:67
UndirectedEdge(T _uid, T _node1, T _node2)
Definition: UndirectedEdge.h:30
bool marked
Definition: UndirectedEdge.h:85
void setNodes(T _node1, T _node2)
Definition: UndirectedEdge.h:40
Definition: DirectedEdge.h:16
const T * getNodes() const
Definition: UndirectedEdge.h:45
bool isMarked()
Definition: UndirectedEdge.h:75
T nodes[2]
Definition: UndirectedEdge.h:87
UndirectedEdge()
Definition: UndirectedEdge.h:22
Definition: UndirectedEdge.h:19
T uid
Definition: UndirectedEdge.h:86
void create(T _uid, T _node1, T _node2)
Definition: UndirectedEdge.h:34
bool isIDaNeighborNode(T _nodeID)
Definition: UndirectedEdge.h:60
T getOppositeNode(T _nodeID) const
Definition: UndirectedEdge.h:49